andre 6 місяців тому
батько
коміт
4a85f78f85
1 змінених файлів з 25 додано та 7 видалено
  1. 25 7
      core/Helper/DnsHelper.php

+ 25 - 7
core/Helper/DnsHelper.php

@@ -23,15 +23,15 @@ class DnsHelper
 //        $this->nameserver = array(trim($this->server->nameserver1ip), trim($this->server->nameserver2ip));
         $this->nameserver = array('127.0.0.1', '127.0.0.2'); //test
         $this->clientDomains = localAPI('GetClientsDomains', array('clientid' => $this->params['userid']));
-        $this->productManager = new ProductManager();
-        $this->productManager->loadById($this->params['pid']);
+        $productManager = new ProductManager();
+        $productManager->loadById($this->params['pid']);
+        $this->spfConfig = $productManager->get('spf_string');
+        $this->dmarcConfig = $productManager->get('dmarc_string');
     }    
     
     public function KerioEmailCheckDNS()
     {
         $vars['maildomain'] = $this->params['domain'];
-        $spfConfig = $this->productManager->get('spf_string');
-        $dmarcConfig = $this->productManager->get('dmarc_string');
         if($this->clientDomains['totalresults'] == 0){
             $vars['selfdomain'] = FALSE;
             $vars['dmarcconfig'] = $dmarcConfig;
@@ -135,12 +135,12 @@ class DnsHelper
         }
         if(empty($domainMX)){
             $vars['mx'] = 'unset';
-            $vars['mxtarget'] = $params['serverhostname'];
+            $vars['mxtarget'] = $this->params['serverhostname'];
         } else {
             $vars['domainMX'] = $domainMX;
             $domainMXrecord = array_shift($domainMX);
             $vars['mxtarget'] = $domainMXrecord->exchange;
-            if($domainMXrecord->exchange == $params['serverhostname']) {
+            if($domainMXrecord->exchange == $this->params['serverhostname']) {
                 $vars['mx'] = 'set';
             } else {
                 $var['mx'] = 'wrong';
@@ -162,7 +162,7 @@ class DnsHelper
         return $vars;
     }
 
-    function KerioEmail_setMX()
+    function KerioEmail_setDNS()
     {
         $zoneIDcollection = Capsule::table('dns_manager2_zone')
             ->select('id')
@@ -194,6 +194,24 @@ class DnsHelper
                 array_push($zoneRecords, $record);
             };
         }
+                $spfRecord = array(
+                'line' => $params['domain'].'.|TXT|0',
+                'name' => '@',
+                'type' => 'TXT',
+                'class' => 'IN',
+                'data' => $this->spfConfig
+            );
+        array_push($zoneRecords, $spfRecord);
+
+        foreach($dnsZone['data']->records as $record) {
+
+            if(!$record->type === 'TXT'){
+                array_push($zoneRecords, $record);
+            } elseif (!preg_match('/^v=spf(.*)$/i', trim($record->rdata->txtdata,'"'))) {
+                array_push($zoneRecords, $record);
+            };
+        }
+
         $result = localAPI('dnsmanager' ,
             array(
                 'dnsaction' => 'updateZone',