| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <?php
- namespace MGModule\DNSManager2\mgLibs\custom\helpers;
- use \MGModule\DNSManager2\models\custom\zone;
- use \MGModule\DNSManager2\mgLibs\whmcsAPI;
- use \MGModule\DNSManager2\mgLibs\MySQL\query;
- use \MGModule\DNSManager2\models\custom\status;
- use \MGModule\DNSManager2\models\custom\globalsetting\GlobalSetting;
- use MGModule\DNSManager2\mgLibs\custom\helpers\IdnaHelper;
- class StatusHelper {
-
- private $zone;
- private $domain;
- private $domainId;
-
- public function __construct($zoneId)
- {
- $this->zone = new zone\Zone($zoneId);
- $this->domain = $this->zone->name;
- $this->domainId = $this->zone->relid;
- }
-
- public function whoisCheckDomain()
- {
- $result = whmcsAPI\whmcsAPI::request('DomainWhois', array('domain' => $this->domain));
-
- if($result['status'] == 'available')
- {
- return true;
- }
-
- return false;
- }
-
- public function getNameservers()
- {
- $nsAuth = [];
- $nsAnswer = dns_get_record(IdnaHelper::idnaEncode($this->domain),DNS_NS, $nsAuth);
- $result = $nsAuth ?: $nsAnswer;
- $nameservers = array();
-
- foreach($result as $r)
- {
- $nameservers[] = $r['target'];
- }
-
- return $nameservers;
- }
-
- public function checkNameserversStatus($domainNameservers,$server)
- {
- $serverNS = $server->getNameservers();
- $serverNameservers = array();
-
- foreach($serverNS as $ns)
- {
- if($ns->name != NULL)
- {
- $serverNameservers[] = $ns->name;
- }
- }
-
- foreach($domainNameservers as $domainNS)
- {
- if(in_array($domainNS, $serverNameservers))
- {
- return true;
- }
- }
-
- return false;
- }
-
- public function verifyStatus($domainAvailable,$soaNameservers,$pending)
- {
- if(!$domainAvailable && $soaNameservers && !$pending)
- {
- return true;
- }
-
- return false;
- }
-
- public function getZone()
- {
- return $this->zone;
- }
-
- public static function getRows()
- {
- $result = query::query('SELECT z.id,z.name,s.relid,s.id as sid '
- . 'FROM dns_manager2_zone as z '
- . 'LEFT JOIN dns_manager2_status as s '
- . 'ON s.relid = z.id '
- . 'WHERE s.date is NULL '
- . 'OR s.date <= DATE_SUB(NOW(),INTERVAL 2 HOUR) '
- . 'ORDER BY s.date '
- . 'LIMIT 100')->fetchAll();
-
- return $result;
- }
-
- public static function parseStatus($status)
- {
- if($status == 0)
- {
- return 'pending';
- }
-
- if($status == 1)
- {
- return 'notRegistered';
- }
-
- if($status == 2)
- {
- return 'soaWarning';
- }
-
- if($status == 3)
- {
- return 'active';
- }
- }
-
- public static function removeZoneStatus($zoneId)
- {
- $rep = status\Repository::factory()->setFilter('relid', $zoneId)->one();
- if($rep)
- {
- $status = new status\Status($rep->id);
- $status->delete();
- }
-
- return;
- }
-
- public static function loadStatusContent($tpl)
- {
- switch ($tpl)
- {
- case 'pending':
- $key = 'is_pending_status_text';
- $content = GlobalSetting::byKey($key);
- return $content;
- case 'notRegistered':
- $key = 'whois_missing_status_text';
- $content = GlobalSetting::byKey($key);
- return $content;
- case 'soaWarning':
- $key = 'soa_is_not_ns_status_text';
- $content = GlobalSetting::byKey($key);
- return $content;
- case 'active':
- $key = 'is_ok_status_text';
- $content = GlobalSetting::byKey($key);
- return $content;
- default:
- return;
-
- }
- }
- }
|