InfoSettingDataProvider.php 5.5 KB

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