Settings.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\App\UI\Client\Setting\Pages;
  3. use ThurData\Servers\KerioEmail\App\UI\Admin\Custom\Fields\EnabledField;
  4. use ThurData\Servers\KerioEmail\App\UI\Client\Setting\Buttons\EditSettingButton;
  5. use function ThurData\Servers\KerioEmail\Core\Helper\di;
  6. use ThurData\Servers\KerioEmail\Core\UI\Widget\DataTable\Column;
  7. use ThurData\Servers\KerioEmail\Core\UI\Widget\DataTable\DataProviders\DataProvider;
  8. use ThurData\Servers\KerioEmail\Core\UI\Interfaces\ClientArea;
  9. use ThurData\Servers\KerioEmail\Core\UI\Widget\DataTable\DataProviders\Providers\ArrayDataProvider;
  10. use ThurData\Servers\KerioEmail\Core\UI\Widget\DataTable\DataTable;
  11. use ThurData\Servers\KerioEmail\Api\KerioWhmcs;
  12. use ThurData\Servers\KerioEmail\App\Libs\Product\ProductManager;
  13. /**
  14. *
  15. * Created by PhpStorm.
  16. * User: ThurData
  17. * Date: 10.09.19
  18. * Time: 10:51
  19. * Class Setting
  20. */
  21. class Settings extends DataTable implements ClientArea
  22. {
  23. /**
  24. * labels for statuses
  25. */
  26. const STATUS_LABEL = [
  27. 'active' => 'success',
  28. 'inactive' => 'default',
  29. 'default' => 'default'
  30. ];
  31. protected $id = 'Setting';
  32. protected $name = 'Setting';
  33. protected $title = null;
  34. /**
  35. * load columns
  36. */
  37. protected function loadHtml()
  38. {
  39. $this
  40. ->addColumn((new Column('domain'))
  41. ->setOrderable(DataProvider::SORT_ASC)
  42. ->setSearchable(true, Column::TYPE_STRING))
  43. ->addColumn((new Column('active(mx)'))
  44. ->setOrderable()
  45. ->setSearchable(true, Column::TYPE_STRING))
  46. ->addColumn((new Column('spf'))
  47. ->setOrderable()
  48. ->setSearchable(true, Column::TYPE_STRING))
  49. ->addColumn((new Column('dmarc'))
  50. ->setOrderable()
  51. ->setSearchable(true, Column::TYPE_STRING))
  52. ->addColumn((new Column('dkim'))
  53. ->setOrderable()
  54. ->setSearchable(true));
  55. }
  56. /**
  57. * @param $key
  58. * @param $row
  59. * @return mixed
  60. */
  61. public function replaceFieldStatus($key, $row)
  62. {
  63. $status = self::STATUS_LABEL[$row[$key]] ? self::STATUS_LABEL[$row[$key]] : self::STATUS_LABEL['default'];
  64. $label = di('lang')->absoluteT('kerio','account','status',$row[$key]);
  65. $field = new EnabledField();
  66. $field->setRawType($status);
  67. $field->setRawTitle($label);
  68. return $field->getHtml();
  69. }
  70. /**
  71. * @param $key
  72. * @param $row
  73. * @return mixed
  74. */
  75. public function replaceFieldLast_login($key, $row)
  76. {
  77. return $row[$key] ? $row[$key] : '-';
  78. }
  79. /**
  80. * @param $key
  81. * @param $row
  82. * @return mixed
  83. */
  84. public function replaceFieldType($key, $row)
  85. {
  86. return $row[$key] == 'Room' ? di('lang')->absoluteT('kerio','setting','type','location') : di('lang')->absoluteT('kerio','setting','type','equipment');
  87. }
  88. /**
  89. * load buttons
  90. */
  91. public function initContent()
  92. {
  93. $this->addActionButton(new EditSettingButton());
  94. }
  95. /**
  96. * load data
  97. */
  98. public function loadData()
  99. {
  100. $maildomain = $this->getWhmcsParamByKey('domain');
  101. $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
  102. try {
  103. $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
  104. $domains = $api->getDomains(['id','name','aliasList']);
  105. } catch (KerioApiException $error) {
  106. logModuleCall(
  107. 'kerioEmail',
  108. __FUNCTION__,
  109. $error,
  110. 'Debug Error',
  111. $error->getMessage()
  112. );
  113. return ['error' => $error->getMessage()];
  114. }
  115. $api->logout();
  116. foreach($domains as $domain) {
  117. if(($domain['name']) === $maildomain){
  118. $aliasList = $domain['aliasList'];
  119. }
  120. }
  121. logModuleCall(
  122. 'kerioEmail',
  123. __FUNCTION__,
  124. $this,
  125. 'Debug Settings',
  126. $maildomain
  127. );
  128. $dkimSet = $api->getDkimDnsRecord($maildomain);
  129. $dkimArray = explode(PHP_EOL,$dkimSet['detail']);
  130. $dkimValue = explode(":",$dkimArray[1]);
  131. $this->domainKey = ltrim($dkimValue[1]);
  132. $dkimName = explode(":",$dkimArray[0]);
  133. $this->dkimName = ltrim($dkimName[1]);
  134. $api->logout();
  135. // get settings from product configuration
  136. $productManager = new ProductManager();
  137. $productManager->loadById($this->getWhmcsParamByKey('pid'));
  138. $this->spfConfig = $productManager->get('spf_string');
  139. $this->dmarcConfig = $productManager->get('dmarc_string');
  140. /**
  141. * format model to array
  142. */
  143. $data = [];
  144. $dataProv = new ArrayDataProvider();
  145. $dataProv->setDefaultSorting('setting', 'ASC')->setData($data);
  146. $this->setDataProvider($dataProv);
  147. }
  148. }