InfoSettingDataProvider.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\App\UI\Client\Setting\Providers;
  3. use ThurData\Servers\KerioEmail\App\Enums\Kerio;
  4. use function ThurData\Servers\KerioEmail\Core\Helper\di;
  5. use ThurData\Servers\KerioEmail\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
  6. use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
  7. use ThurData\Servers\KerioEmail\Api\KerioWhmcs;
  8. /**
  9. *
  10. * Created by PhpStorm.
  11. * User: ThurData
  12. * Date: 10.09.19
  13. * Time: 13:06
  14. * Class SettingDataProvider
  15. */
  16. class InfoSettingDataProvider extends BaseDataProvider
  17. {
  18. public function read()
  19. {
  20. $maildomain = $this->actionElementId;
  21. $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
  22. try {
  23. $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
  24. $dkimSet = $api->getDkimDnsRecord($maildomain);
  25. } catch (KerioApiException $error) {
  26. logModuleCall(
  27. 'kerioEmail',
  28. __FUNCTION__,
  29. $error,
  30. 'Debug Error',
  31. $error->getMessage()
  32. );
  33. return ['error' => $error->getMessage()];
  34. }
  35. $api->logout();
  36. // format dkim response
  37. $dkimArray = explode(PHP_EOL,$dkimSet['detail']);
  38. $dkimValue = explode(":",$dkimArray[1]);
  39. $this->domainKey = ltrim($dkimValue[1]);
  40. $dkimName = explode(":",$dkimArray[0]);
  41. $this->dkimName = ltrim($dkimName[1]);
  42. // get settings from product configuration
  43. $productManager = new ProductManager();
  44. $productManager->loadById($this->getWhmcsParamByKey('pid'));
  45. $this->spfConfig = $productManager->get('spf_string');
  46. $this->dmarcConfig = $productManager->get('dmarc_string');
  47. $clientDomains = localAPI('GetClientsDomains', array('clientid' => $params['userid']));
  48. $dns = new DnsHelper();
  49. /**
  50. * format model to array
  51. */
  52. $data = [];
  53. in_array($domain,$clientDomains) ? $selfdomain = 1 : $selfdomain = 0;
  54. $dnsRecords = $dns->getRecords($domain);
  55. $dnsRecords['selfdns'] ? $selfDns = 1 : $selfDns = 0;
  56. if(empty($dnsRecords['mx'])){
  57. $mx = 'unset';
  58. } else {
  59. in_array($params['serverhostname'],$dnsRecords['mx']) ? $mx = 'set' : $mx = 'wrong';
  60. }
  61. if(empty($dnsRecords['spf'])) {
  62. $spf = 'unset';
  63. } else {
  64. if (count($dnsRecords['spf']) > 1) {
  65. $spf = 'multi';
  66. } else {
  67. if($dnsRecords['spf'][0] === $this->spfConfig){
  68. $spf = 'set';
  69. } else {
  70. $spf = 'wrong';
  71. }
  72. }
  73. }
  74. if(empty($dnsRecords['dmarc'])) {
  75. $dmarc = 'unset';
  76. } else {
  77. if (count($dnsRecords['dmarc']) > 1) {
  78. $dmarc = 'multi';
  79. } else {
  80. if($dnsRecords['dmarc'][0] === $this->dmarcConfig){
  81. $dmarc = 'set';
  82. } else {
  83. $dmarc = 'wrong';
  84. }
  85. }
  86. }
  87. in_array($this->domainKey, $dnsRecords['dkim']) ? $dkim = 'set' : $dkim = 'unset';
  88. $tmp = [
  89. 'id' => $domain,
  90. 'domain' => $domain,
  91. 'mxactive' => $mx,
  92. 'spf' => $spf,
  93. 'dmarc' => $dmarc,
  94. 'dkim' => $dkim,
  95. 'selfdns' => $selfDns,
  96. 'selfdomain' => $selfdomain
  97. ];
  98. $this->data[] = $tmp;
  99. logModuleCall(
  100. 'kerioEmail',
  101. __FUNCTION__,
  102. $this->data,
  103. 'Debug Data',
  104. $this->actionElementId
  105. );
  106. }
  107. public function create()
  108. {
  109. }
  110. public function updateStatus()
  111. {
  112. }
  113. public function update()
  114. {
  115. }
  116. }