StatusHelper.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. namespace MGModule\DNSManager2\mgLibs\custom\helpers;
  3. use \MGModule\DNSManager2\models\custom\zone;
  4. use \MGModule\DNSManager2\mgLibs\whmcsAPI;
  5. use \MGModule\DNSManager2\mgLibs\MySQL\query;
  6. use \MGModule\DNSManager2\models\custom\status;
  7. use \MGModule\DNSManager2\models\custom\globalsetting\GlobalSetting;
  8. use MGModule\DNSManager2\mgLibs\custom\helpers\IdnaHelper;
  9. class StatusHelper {
  10. private $zone;
  11. private $domain;
  12. private $domainId;
  13. public function __construct($zoneId)
  14. {
  15. $this->zone = new zone\Zone($zoneId);
  16. $this->domain = $this->zone->name;
  17. $this->domainId = $this->zone->relid;
  18. }
  19. public function whoisCheckDomain()
  20. {
  21. $result = whmcsAPI\whmcsAPI::request('DomainWhois', array('domain' => $this->domain));
  22. if($result['status'] == 'available')
  23. {
  24. return true;
  25. }
  26. return false;
  27. }
  28. public function getNameservers()
  29. {
  30. $nsAuth = [];
  31. $nsAnswer = dns_get_record(IdnaHelper::idnaEncode($this->domain),DNS_NS, $nsAuth);
  32. $result = $nsAuth ?: $nsAnswer;
  33. $nameservers = array();
  34. foreach($result as $r)
  35. {
  36. $nameservers[] = $r['target'];
  37. }
  38. return $nameservers;
  39. }
  40. public function checkNameserversStatus($domainNameservers,$server)
  41. {
  42. $serverNS = $server->getNameservers();
  43. $serverNameservers = array();
  44. foreach($serverNS as $ns)
  45. {
  46. if($ns->name != NULL)
  47. {
  48. $serverNameservers[] = $ns->name;
  49. }
  50. }
  51. foreach($domainNameservers as $domainNS)
  52. {
  53. if(in_array($domainNS, $serverNameservers))
  54. {
  55. return true;
  56. }
  57. }
  58. return false;
  59. }
  60. public function verifyStatus($domainAvailable,$soaNameservers,$pending)
  61. {
  62. if(!$domainAvailable && $soaNameservers && !$pending)
  63. {
  64. return true;
  65. }
  66. return false;
  67. }
  68. public function getZone()
  69. {
  70. return $this->zone;
  71. }
  72. public static function getRows()
  73. {
  74. $result = query::query('SELECT z.id,z.name,s.relid,s.id as sid '
  75. . 'FROM dns_manager2_zone as z '
  76. . 'LEFT JOIN dns_manager2_status as s '
  77. . 'ON s.relid = z.id '
  78. . 'WHERE s.date is NULL '
  79. . 'OR s.date <= DATE_SUB(NOW(),INTERVAL 2 HOUR) '
  80. . 'ORDER BY s.date '
  81. . 'LIMIT 100')->fetchAll();
  82. return $result;
  83. }
  84. public static function parseStatus($status)
  85. {
  86. if($status == 0)
  87. {
  88. return 'pending';
  89. }
  90. if($status == 1)
  91. {
  92. return 'notRegistered';
  93. }
  94. if($status == 2)
  95. {
  96. return 'soaWarning';
  97. }
  98. if($status == 3)
  99. {
  100. return 'active';
  101. }
  102. }
  103. public static function removeZoneStatus($zoneId)
  104. {
  105. $rep = status\Repository::factory()->setFilter('relid', $zoneId)->one();
  106. if($rep)
  107. {
  108. $status = new status\Status($rep->id);
  109. $status->delete();
  110. }
  111. return;
  112. }
  113. public static function loadStatusContent($tpl)
  114. {
  115. switch ($tpl)
  116. {
  117. case 'pending':
  118. $key = 'is_pending_status_text';
  119. $content = GlobalSetting::byKey($key);
  120. return $content;
  121. case 'notRegistered':
  122. $key = 'whois_missing_status_text';
  123. $content = GlobalSetting::byKey($key);
  124. return $content;
  125. case 'soaWarning':
  126. $key = 'soa_is_not_ns_status_text';
  127. $content = GlobalSetting::byKey($key);
  128. return $content;
  129. case 'active':
  130. $key = 'is_ok_status_text';
  131. $content = GlobalSetting::byKey($key);
  132. return $content;
  133. default:
  134. return;
  135. }
  136. }
  137. }