|
|
@@ -15,21 +15,21 @@ use \Net\DNS2\Net_DNS2_Resolver as Net_DNS2_Resolver;
|
|
|
class DnsHelper
|
|
|
{
|
|
|
use \ThurData\Servers\KerioEmail\Core\UI\Traits\WhmcsParams;
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
+ $this->params = $this->getWhmcsParamsByKeys(['domain', 'userid', 'serverhostname', 'domainid', 'serverid', 'pid']);
|
|
|
+ $this->server = Server::select('id', 'nameserver1ip', 'nameserver2ip')->findOrFail($this->params['serverid']);
|
|
|
+ $this->nameserver = array(trim($this->server->nameserver1ip), trim($this->server->nameserver2ip));
|
|
|
+ $this->clientDomains = localAPI('GetClientsDomains', array('clientid' => $this->params['userid']));
|
|
|
+ $this->productManager = new ProductManager();
|
|
|
+ $this->productManager->loadById($this->params['pid']);
|
|
|
+ }
|
|
|
+
|
|
|
public function KerioEmailCheckDNS()
|
|
|
{
|
|
|
- unset($zoneID);
|
|
|
- unset($mxStatus);
|
|
|
- unset($dnsData);
|
|
|
- unset($vars);
|
|
|
- $params = $this->getWhmcsParamsByKeys(['domain', 'userid', 'serverhostname', 'domainid', 'serverid', 'pid']);
|
|
|
- $vars['maildomain'] = $params['domain'];
|
|
|
- $server = Server::select('id', 'nameserver1ip', 'nameserver2ip')->findOrFail($params['serverid']);
|
|
|
- $nameserver = array(trim($server->nameserver1ip), trim($server->nameserver2ip));
|
|
|
- $clientDomains = localAPI('GetClientsDomains', array('clientid' => $params['userid']));
|
|
|
- $productManager = new ProductManager();
|
|
|
- $productManager->loadById($params['pid']);
|
|
|
- $spfConfig = $productManager->get('spf_string');
|
|
|
- $dmarcConfig = $productManager->get('dmarc_string');
|
|
|
+ $vars['maildomain'] = $this->params['domain'];
|
|
|
+ $spfConfig = $this->productManager->get('spf_string');
|
|
|
+ $dmarcConfig = $this->productManager->get('dmarc_string');
|
|
|
if($clientDomains['totalresults'] == 0){
|
|
|
$vars['selfdomain'] = FALSE;
|
|
|
$vars['dmarcconfig'] = $dmarcConfig;
|
|
|
@@ -38,9 +38,9 @@ class DnsHelper
|
|
|
} else {
|
|
|
$vars['selfdomain'] = TRUE;
|
|
|
}
|
|
|
- $resolver = new \Net_DNS2_Resolver(array('nameservers' => $nameserver));
|
|
|
+ $resolver = new \Net_DNS2_Resolver(array('nameservers' => $this->nameserver));
|
|
|
try {
|
|
|
- $result = $resolver->query($params['domain'], 'MX');
|
|
|
+ $result = $resolver->query($this->params['domain'], 'MX');
|
|
|
|
|
|
} catch(\Net_DNS2_Exception $e) {
|
|
|
|
|
|
@@ -48,7 +48,7 @@ class DnsHelper
|
|
|
}
|
|
|
$domainMX = $result->answer;
|
|
|
try {
|
|
|
- $result = $resolver->query($params['domain'], 'TXT');
|
|
|
+ $result = $resolver->query($this->params['domain'], 'TXT');
|
|
|
|
|
|
} catch(\Net_DNS2_Exception $e) {
|
|
|
|
|
|
@@ -73,10 +73,10 @@ class DnsHelper
|
|
|
}
|
|
|
# self hosted DNS
|
|
|
$vars['selfDNS'] = FALSE;
|
|
|
- for($i=$clientDomains['startnumber'];$i<=$clientDomains['numreturned'];$i++) {
|
|
|
- if($params['domain'] == $clientDomains['domains']['domain'][$i]['domainname']) {
|
|
|
+ for($i=$this->clientDomains['startnumber'];$i<=$this->clientDomains['numreturned'];$i++) {
|
|
|
+ if($params['domain'] == $this->clientDomains['domains']['domain'][$i]['domainname']) {
|
|
|
$vars['selfDNS'] = TRUE;
|
|
|
- $vars['domainId'] = $clientDomains['domains']['domain'][$i]['id'];
|
|
|
+ $vars['domainId'] = $this->clientDomains['domains']['domain'][$i]['id'];
|
|
|
}
|
|
|
}
|
|
|
# SPF
|
|
|
@@ -146,4 +146,50 @@ class DnsHelper
|
|
|
}
|
|
|
return $vars;
|
|
|
}
|
|
|
+
|
|
|
+ function KerioEmail_setMX()
|
|
|
+ {
|
|
|
+ $zoneIDcollection = Capsule::table('dns_manager2_zone')
|
|
|
+ ->select('id')
|
|
|
+ ->where('name', '=', $this->params['domain'])
|
|
|
+ ->get();
|
|
|
+ $zoneIDobj = $zoneIDcollection[0];
|
|
|
+ $zoneID = $zoneIDobj->{'id'};
|
|
|
+ if(!isset($zoneID)) {
|
|
|
+ return 'Error: zone ID not found for domain ' . $this->params['domain'];
|
|
|
+ }
|
|
|
+ $dnsZone = localAPI('dnsmanager', array( 'dnsaction' => 'getZone', 'zone_id' => $zoneID));
|
|
|
+ if($dnsZone['result'] != 'success') {
|
|
|
+ return 'Error: cloud not fetch zone for ID ' . $zoneID;
|
|
|
+ }
|
|
|
+ $zoneRecords = array();
|
|
|
+ $mxRecord = array(
|
|
|
+ 'line' => $this->params['domain'].'.|MX|0',
|
|
|
+ 'name' => '@',
|
|
|
+ 'type' => 'MX',
|
|
|
+ 'class' => 'IN',
|
|
|
+ 'data' => array(
|
|
|
+ 'preference' => '10',
|
|
|
+ 'exchange' => MX,
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ array_push($zoneRecords, $mxRecord);
|
|
|
+ foreach($dnsZone['data']->records as $record) {
|
|
|
+ if($record->type != 'MX') {
|
|
|
+ array_push($zoneRecords, $record);
|
|
|
+ };
|
|
|
+ }
|
|
|
+ $result = localAPI('dnsmanager' ,
|
|
|
+ array(
|
|
|
+ 'dnsaction' => 'updateZone',
|
|
|
+ 'zone_id' => $zoneID,
|
|
|
+ 'records' => $zoneRecords,
|
|
|
+ )
|
|
|
+ );
|
|
|
+ if($result['result'] != 'success') {
|
|
|
+ return 'Error: cloud not update zone for ID ' . $zoneID;
|
|
|
+ }
|
|
|
+ return 'success';
|
|
|
+ }
|
|
|
+
|
|
|
}
|