InfoSettingDataProvider.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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' => $this->getWhmcsParamByKey('userid')));
  50. $dns = new DnsHelper();
  51. /**
  52. * format model to array
  53. */
  54. in_array($maildomain,$clientDomains) ? $selfdomain = 1 : $selfdomain = 0;
  55. $dnsRecords = $dns->getRecords($maildomain);
  56. $dnsRecords['selfdns'] ? $selfDns = 1 : $selfDns = 0;
  57. $this->mxthurdata = $this->getWhmcsParamByKey('serverhostname');
  58. if(empty($dnsRecords['mx'])){
  59. $mx = 'unset';
  60. $mxmulti = false;
  61. } else {
  62. count($dnsRecords['mx']) > 1 ? $mxmulti = true : $mxmulti = false;
  63. $mx = implode(' ',$dnsRecords['mx']);
  64. }
  65. if(empty($dnsRecords['spf'])) {
  66. $spf = 'unset';
  67. $spfmulti = false;
  68. } else {
  69. count($dnsRecords['spf']) > 1 ? $spfmulti = true : $spfmulti = false;
  70. $spf = implode(' ',$dnsRecords['spf']);
  71. }
  72. if(empty($dnsRecords['dmarc'])) {
  73. $dmarc = 'unset';
  74. $dmarcmulti = false;
  75. } else {
  76. count($dnsRecords['dmarc']) > 1 ? $dmarcmulti = true : $dmarcmulti = false;
  77. $dmarc = implode(' ',$dnsRecords['dmarc']);
  78. }
  79. $dkim = 'unset';
  80. if(empty($dnsRecords['dkim'])) {
  81. $dkimmulti = false;
  82. } else {
  83. count($dnsRecords['dkim']) > 1 ? $dkimmulti = true : $dkimmulti = false;
  84. foreach($dnsRecords['dkim'] as $dkimRecord) {
  85. if($dkimRecord[0] == $this->dkimName) {
  86. $dkim = $dkimRecord[1];
  87. }
  88. }
  89. }
  90. if(in_array($this->mxthurdata, $dnsRecords['mx'])){
  91. if($this->spfConfig == $spf && $this->dmarcConfig == $dmarc && in_array($this->domainKey, $dnsRecords['dkim'])){
  92. $dnsok = 'success';
  93. } else {
  94. $dnsok = 'warning';
  95. }
  96. } else {
  97. $dnsok = 'danger';
  98. }
  99. $this->data = [
  100. 'dnsmessage' => 'DNS Informationen für',
  101. 'infomaildomain' => $maildomain,
  102. 'mxactive' => $mx,
  103. 'spf' => $spf,
  104. 'dmarc' => $dmarc,
  105. 'dkim' => $dkim,
  106. 'mxthurdata' => $this->mxthurdata,
  107. 'spfthurdata' => $this->spfConfig,
  108. 'dmarcthurdata' => $this->dmarcConfig,
  109. 'dkimthurdata' => $this->domainKey,
  110. 'dkimname' => $this->dkimName,
  111. 'selfdns' => $selfDns,
  112. 'dnsok' => $dnsok,
  113. 'mxmulti' => $mxmulti,
  114. 'dkimmulti' => $dkimmulti,
  115. 'dmarcmulti' => $dmarcmulti,
  116. 'spfmulti' => $spfmulti
  117. ];
  118. }
  119. public function create()
  120. {
  121. }
  122. public function updateStatus()
  123. {
  124. }
  125. public function update()
  126. {
  127. }
  128. }