andre il y a 5 mois
Parent
commit
cf0763ac64

+ 1 - 1
app/UI/Client/Setting/Forms/EditSettingForm.php

@@ -37,6 +37,6 @@ class EditSettingForm extends SortedFieldForm implements ClientArea
     public function initFields()
     {
         $this->addSection(new EditGeneralSection());
-        $this->addSection(new EditAdditionalSection());
+//        $this->addSection(new EditAdditionalSection());
     }
 }

+ 99 - 67
app/UI/Client/Setting/Providers/EditSettingDataProvider.php

@@ -4,6 +4,8 @@ namespace ThurData\Servers\KerioEmail\App\UI\Client\Setting\Providers;
 
 use ThurData\Servers\KerioEmail\App\Enums\Kerio;
 use function ThurData\Servers\KerioEmail\Core\Helper\di;
+use ThurData\Servers\KerioEmail\Core\Helper\DnsHelper;
+use ThurData\Servers\KerioEmail\App\Libs\Product\ProductManager;
 use ThurData\Servers\KerioEmail\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
 use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
 use ThurData\Servers\KerioEmail\Api\KerioWhmcs;
@@ -24,38 +26,97 @@ class EditSettingDataProvider extends BaseDataProvider
      */
     public function read()
     {
-        $fields = array(
-            'id',
-            "domain",
-            "test",
-            "notes",
-            "2FA",
-            "AD"
-        );
-        $cond = array(
-                "fieldName" => "id",
-                "comparator" => "Eq",
-                "value" => $this->actionElementId
-        );
-
-        $this->availableValues['manager'][$ressource[0]['manager']['id']] = $ressource[0]['manager']['name'] . '@' . $ressource[0]['manager']['domainName'];
-        $this->data['name']          = $ressource[0]['name'];
-        $this->data['domain']        = $this->getWhmcsParamByKey('domain');
-        $this->data['status']        = $ressource[0]['isEnabled'] == true ? Kerio::ACC_STATUS_ACTIVE : Kerio::ACC_STATUS_CLOSED;
-        $this->data['type']          = $ressource[0]['type'] === 'Room' ? Kerio::RES_TYPE_LOCATION : Kerio::RES_TYPE_EQUIPMENT;
-        $this->data['description']   = $ressource[0]['description'];
-        $this->data['manager']       = $ressource[0]['manager']['name'] . '@' . $ressource[0]['manager']['domainName'];
-
-        $this->availableValues['status'] = [
-            Kerio::ACC_STATUS_ACTIVE        => $lang->absoluteT('kerio','account','status','active'),
-            Kerio::ACC_STATUS_CLOSED        => $lang->absoluteT('kerio','account','status','closed'),
-        ];
+        $maildomain = $this->actionElementId;
+        $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
+        try {
+            $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
+            $dkimSet = $api->getDkimDnsRecord($maildomain);
+        } catch (KerioApiException $error) {
+            logModuleCall(
+                'kerioEmail',
+                __FUNCTION__,
+                $error,
+                'Debug Error',
+                $error->getMessage()
+            );
+            return ['error' => $error->getMessage()];
+        }
+        $api->logout();
+        // format dkim response
+        $dkimArray = explode(PHP_EOL,$dkimSet['detail']);
+        $dkimValue = explode(":",$dkimArray[1]);
+        $this->domainKey = ltrim($dkimValue[1]);
+        $dkimName = explode(":",$dkimArray[0]);
+        $this->dkimName = ltrim($dkimName[1]);
+
+        // get settings from product configuration
+        $productManager = new ProductManager();
+        $productManager->loadById($this->getWhmcsParamByKey('pid'));
+        $this->spfConfig = $productManager->get('spf_string');
+        $this->dmarcConfig = $productManager->get('dmarc_string');
+        $clientDomains = localAPI('GetClientsDomains', array('clientid' => $this->getWhmcsParamByKey('userid')));
+
+        $dns = new DnsHelper();
+
+        /**
+         * format model to array
+         */
+        in_array($maildomain,$clientDomains) ? $selfdomain = 1 : $selfdomain = 0;
+        $dnsRecords = $dns->getRecords($maildomain);
+                
+            logModuleCall(
+                'kerioEmail',
+                __FUNCTION__,
+                implode('',$dnsRecords['spf']),
+                'DEbug',
+                $this->spfConfig
+            );
 
-        $this->availableValues['type'] = [
-            Kerio::RES_TYPE_LOCATION        => $lang->absoluteT('kerio','ressource','type','location'),
-            Kerio::RES_TYPE_EQUIPMENT       => $lang->absoluteT('kerio','ressource','type','equipment')
+        $dnsRecords['selfdns'] ? $selfDns = 1 : $selfDns = 0;
+        $this->mxthurdata = $this->getWhmcsParamByKey('serverhostname');
+        if(empty($dnsRecords['mx'])){
+            $mx = 'unset';
+        } else {
+            $mx = implode('',$dnsRecords['mx']);
+        }
+        if(empty($dnsRecords['spf'])) {
+            $spf = 'unset';
+        } else {
+            $spf = implode('',$dnsRecords['spf']);
+        }
+        if(empty($dnsRecords['dmarc'])) {
+            $dmarc = 'unset';
+        } else {
+            $dmarc = implode('',$dnsRecords['dmarc']);
+        }
+        if(empty($dnsRecords['dkim'])) {
+            $dkim = 'unset';
+        } else {
+            $dkim = implode('',$dnsRecords['dkim']);
+        }
+        if($this->mxthurdata == $mx){
+            if($this->spfConfig == $spf && $this->dmarcConfig == $dmarc && in_array($this->domainKey, $dnsRecords['dkim'])){
+                $dnsok = 'success';
+            } else {
+                $dnsok = 'warning';
+            }
+        } else {
+            $dnsok = 'danger';
+        }
+        $this->data = [
+            'maildomain' => $maildomain,
+            'mxactive' => $mx,
+            'spf' => $spf,
+            'dmarc' => $dmarc,
+            'dkimname' => $this->dkimName,
+            'dkim' => $dkim,
+            'mxthurdata' => $this->mxthurdata,
+            'spfthurdata' => $this->spfConfig,
+            'dmarcthurdata' => $this->dmarcConfig,
+            'dkimthurdata' => $this->domainKey,
+            'zoneid' => $selfDns,
+            'dnsok' => $dnsok
         ];
-
     }
 
     /**
@@ -64,11 +125,13 @@ class EditSettingDataProvider extends BaseDataProvider
     public function update()
     {
         $fieldToProtection = [
-            'name',
-            'status',
-            'type',
-            'description',
-            'managert'
+            'maildomain',
+            'mxthurdata',
+            'spfthurdata',
+            'dmarcthurdata',
+            'dkimthurdata',
+            'dkimname',
+            'zoneid'
         ];
 
         foreach ($this->formData as $field => &$value)
@@ -113,7 +176,7 @@ class EditSettingDataProvider extends BaseDataProvider
             return ['error' => $error->getMessage()];
         }
         $api->logout();
-        return (new HtmlDataJsonResponse())->setMessageAndTranslate('ressourceHasBeenUpdated')->setStatusSuccess();
+        return (new HtmlDataJsonResponse())->setMessageAndTranslate('settingHasBeenUpdated')->setStatusSuccess();
     }
 
     /**
@@ -121,37 +184,6 @@ class EditSettingDataProvider extends BaseDataProvider
      */
     public function updateStatus()
     {
-        $attr = array(
-            'isEnabled' => $this->formData['status'] === 'active' ? true : false,
-        );
-        $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
-        try {
-            $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
-        } catch (KerioApiException $error) {
-            logModuleCall(
-                'kerioEmail',
-                __FUNCTION__,
-                $error,
-                'Debug Error',
-                $error->getMessage()
-            );
-            return ['error' => $error->getMessage()];
-        }
-        try {
-            $result = $api->updateResouce($attr,$this->formData['id']);
-        } catch (KerioApiException $error) {
-            logModuleCall(
-                'kerioEmail',
-                __FUNCTION__,
-                $error,
-                'Debug Error',
-                $error->getMessage()
-            );
-            return ['error' => $error->getMessage()];
-        }
-        $api->logout();
-
-        return (new HtmlDataJsonResponse())->setMessageAndTranslate('ressourceStatusHasBeenUpdated')->setStatusSuccess();
 
     }
 

+ 2 - 2
app/UI/Client/Templates/assets/js/setting/index.js

@@ -75,10 +75,10 @@ mgEventHandler.on('ModalLoaded', null,function(){
         });
         if($('input[name="dnsok"]').val() != 'success'){
             if($('input[name="selfdns"]').val() == 1){
-                 $("#addalertfooter").append(' Nutzen Sie dafür die Edit Funktion!');
+                $("#addalertfooter").append(' Nutzen Sie dafür die Edit Funktion!');
+                $("#transferDomain").addClass('hidden');
             }else{
                 $("#addalertfooter").append(' Tragen Sie die vorgegebenen Werte bei Ihrem Domain Registrar ein oder transferieren Sie Ihre Domain zu ThurData');
-                $("#transferDomain").removeClass('hidden');
                 $("#transferDomain").click(function(){
                     document.location.href = 'cart.php?a=add&domain=transfer&sld=' + maildomain.val();
                 });

+ 17 - 11
core/Helper/DnsHelper.php

@@ -115,17 +115,16 @@ class DnsHelper
         return $vars;
     }
 
-    function KerioEmailsetDNS()
+    function KerioEmailsetDNS($maildomain,$dnsparams)
     {
-        return 'success';
         $zoneIDcollection = Capsule::table('dns_manager2_zone')
             ->select('id')
-            ->where('name', '=', $this->params['domain'])
+            ->where('name', '=', $maildomain)
             ->get();
         $zoneIDobj = $zoneIDcollection[0];
         $zoneID = $zoneIDobj->{'id'};
         if(!isset($zoneID)) {
-            return 'Error: zone ID not found for domain ' . $this->params['domain'];
+            return 'Error: zone ID not found for domain ' . $maildomain;
         }
         $dnsZone = localAPI('dnsmanager', array( 'dnsaction' => 'getZone', 'zone_id' => $zoneID));
         if($dnsZone['result'] != 'success') {
@@ -133,30 +132,37 @@ class DnsHelper
         }
         $zoneRecords = array();
         $mxRecord = array(
-            'line' => $this->params['domain'].'.|MX|0',
+            'line' => $maildomain.'.|MX|0',
             'name' => '@',
             'type' => 'MX',
             'class' => 'IN',
             'data' => array(
                 'preference' => '10',
-                'exchange' => $this->params['serverhostname'],
+                'exchange' => $dnsparams['mxthurdata'],
             ),
         );
         array_push($zoneRecords, $mxRecord);
         $spfRecord = array(
-            'line' => $this->params['domain'].'.|TXT|0',
+            'line' => $maildomain.'.|TXT|0',
             'name' => '@',
             'type' => 'TXT',
             'class' => 'IN',
-            'data' => $this->spfConfig
+            'data' => $dnsparams['spfthurdata']
         );
         array_push($zoneRecords, $spfRecord);
         $dmarcRecord = array(
-            'line' => $this->params['domain'].'.|TXT|0',
+            'line' => $maildomain.'.|TXT|0',
             'name' => '@',
             'type' => 'TXT',
             'class' => 'IN',
-            'data' => $this->dmarcConfig
+            'data' => $dnsparams['dmarcthurdata']
+        );
+        $dkimRecord = array(
+            'line' => $maildomain.'.|TXT|0',
+            'name' => $dnsparams['dkimname'],
+            'type' => 'TXT',
+            'class' => 'IN',
+            'data' => $dnsparams['dkimthurdata']
         );
         array_push($zoneRecords, $dmarcRecord);
         foreach($dnsZone['data']->records as $record) {
@@ -167,7 +173,7 @@ class DnsHelper
                 // skip spf
                 if(preg_match('/^v=spf(.*)$/i', trim($record->rdata->txtdata,'"'))) continue; 
                 // skip own dkim
-                if(($this->dkimName == $record->name) && ($this->domainKey == trim($record->rdata->txtdata,'"'))) continue; 
+                if(($dnsparams['dkimname'] == $record->name) && ($dnsparams['dkimthurdata'] == trim($record->rdata->txtdata,'"'))) continue; 
             };
             array_push($zoneRecords, $record);
         }