InfoSettingDataProvider.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. $domain = $this->getWhmcsParamByKey('domain');
  23. $maildomain = $this->actionElementId;
  24. $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
  25. try {
  26. $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
  27. $dkimSet = $api->getDkimDnsRecord($maildomain);
  28. $securitys = $api->getDomains(['id','name','isDkimEnabled','twoFAEnabled']);
  29. } catch (KerioApiException $error) {
  30. logModuleCall(
  31. 'kerioEmail',
  32. __FUNCTION__,
  33. $error,
  34. 'Debug Error',
  35. $error->getMessage()
  36. );
  37. return ['error' => $error->getMessage()];
  38. }
  39. $api->logout();
  40. // find own domain
  41. foreach($securitys as $security) {
  42. if($security['name'] === $domain){
  43. $domainID = $security['id'];
  44. $security['twoFAEnabled'] == true ? $tfaenabled = 'on' : $tfaenabled = 'off' ;
  45. $security['isDkimEnabled'] == true ? $dkimsigenabled = 'on' : $dkimsigenabled = 'off';
  46. }
  47. }
  48. // format dkim response
  49. $dkimArray = explode(PHP_EOL,$dkimSet['detail']);
  50. $dkimValue = explode(":",$dkimArray[1]);
  51. $this->domainKey = ltrim($dkimValue[1]);
  52. $dkimName = explode(":",$dkimArray[0]);
  53. $this->dkimName = ltrim($dkimName[1]);
  54. // get settings from product configuration
  55. $productManager = new ProductManager();
  56. $productManager->loadById($this->getWhmcsParamByKey('pid'));
  57. $this->spfConfig = $productManager->get('spf_string');
  58. $this->dmarcConfig = $productManager->get('dmarc_string');
  59. $clientDomains = localAPI('GetClientsDomains', array('clientid' => $this->getWhmcsParamByKey('userid')));
  60. $dns = new DnsHelper();
  61. /**
  62. * format model to array
  63. */
  64. in_array($maildomain,$clientDomains) ? $selfdomain = 1 : $selfdomain = 0;
  65. $dnsRecords = $dns->getRecords($maildomain);
  66. $dnsRecords['selfdns'] ? $selfDns = 1 : $selfDns = 0;
  67. $this->mxthurdata = $this->getWhmcsParamByKey('serverhostname');
  68. if(empty($dnsRecords['mx'])){
  69. $mx = 'unset';
  70. $mxmulti = false;
  71. } else {
  72. count($dnsRecords['mx']) > 1 ? $mxmulti = true : $mxmulti = false;
  73. $mx = implode(' ',$dnsRecords['mx']);
  74. }
  75. if(empty($dnsRecords['spf'])) {
  76. $spf = 'unset';
  77. $spfmulti = false;
  78. } else {
  79. count($dnsRecords['spf']) > 1 ? $spfmulti = true : $spfmulti = false;
  80. $spf = implode(' ',$dnsRecords['spf']);
  81. }
  82. if(empty($dnsRecords['dmarc'])) {
  83. $dmarc = 'unset';
  84. $dmarcmulti = false;
  85. } else {
  86. count($dnsRecords['dmarc']) > 1 ? $dmarcmulti = true : $dmarcmulti = false;
  87. $dmarc = implode(' ',$dnsRecords['dmarc']);
  88. }
  89. $dkim = 'unset';
  90. if(empty($dnsRecords['dkim'])) {
  91. $dkimmulti = false;
  92. } else {
  93. count($dnsRecords['dkim']) > 1 ? $dkimmulti = true : $dkimmulti = false;
  94. foreach($dnsRecords['dkim'] as $dkimRecord) {
  95. if($dkimRecord[0] == $this->dkimName) {
  96. $dkim = $dkimRecord[1];
  97. }
  98. }
  99. }
  100. if(in_array($this->mxthurdata, $dnsRecords['mx'])){
  101. if($this->spfConfig == $spf && $this->dmarcConfig == $dmarc && in_array($this->domainKey, $dnsRecords['dkim'])){
  102. $dnsok = 'success';
  103. } else {
  104. $dnsok = 'warning';
  105. }
  106. } else {
  107. $dnsok = 'danger';
  108. }
  109. $this->data = [
  110. 'dnsmessage' => 'DNS Informationen für',
  111. 'infomaildomain' => $maildomain,
  112. 'mxactive' => $mx,
  113. 'spf' => $spf,
  114. 'dmarc' => $dmarc,
  115. 'dkim' => $dkim,
  116. 'mxthurdata' => $this->mxthurdata,
  117. 'spfthurdata' => $this->spfConfig,
  118. 'dmarcthurdata' => $this->dmarcConfig,
  119. 'dkimthurdata' => $this->domainKey,
  120. 'dkimname' => $this->dkimName,
  121. 'selfdns' => $selfDns,
  122. 'dnsok' => $dnsok,
  123. 'mxmulti' => $mxmulti,
  124. 'dkimmulti' => $dkimmulti,
  125. 'dmarcmulti' => $dmarcmulti,
  126. 'spfmulti' => $spfmulti,
  127. 'tfaenabled' => $tfaenabled,
  128. 'dkimsigenabled' => $dkimsigenabled
  129. ];
  130. }
  131. public function create()
  132. {
  133. }
  134. public function updateStatus()
  135. {
  136. }
  137. public function update()
  138. {
  139. }
  140. }