InfoSettingDataProvider.php 4.2 KB

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