PowerDNS.php 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918
  1. <?php
  2. namespace MGModule\DNSManager2\mgLibs\custom\dns\submodules;
  3. use Exception;
  4. use \MGModule\DNSManager2\mgLibs\custom\dns;
  5. use MGModule\DNSManager2\mgLibs\custom\dns\dnssec\DnsSec;
  6. use \MGModule\DNSManager2\mgLibs\custom\dns\exceptions;
  7. use \MGModule\DNSManager2\mgLibs\custom\dns\interfaces;
  8. use \MGModule\DNSManager2\mgLibs\custom\dns\utils\Patterns;
  9. use MGModule\DNSManager2 as main;
  10. class PowerDNS extends dns\SubmoduleAbstract implements
  11. interfaces\SubmoduleIPInterface, interfaces\SubmoduleRDNSInterface, interfaces\SubmoduleTTLInterface, interfaces\SubmoduleImportInterface, interfaces\SubmoduleDNSSecInterface
  12. {
  13. public $configFields = [
  14. 'username' => [
  15. 'friendlyName' => 'Username',
  16. 'validators' => [
  17. 'required' => 'required',
  18. ]
  19. ],
  20. 'password' => [
  21. 'friendlyName' => 'User Password',
  22. 'type' => 'password',
  23. 'validators' => [
  24. 'required' => 'required',
  25. ]
  26. ],
  27. 'hostname' => [
  28. 'friendlyName' => 'Hostname/IP',
  29. 'validators' => [
  30. 'required' => 'required',
  31. ]
  32. ],
  33. 'database' => [
  34. 'friendlyName' => 'Database',
  35. 'validators' => [
  36. 'required' => 'required',
  37. ]
  38. ],
  39. 'ssh_host' => [
  40. 'friendlyName' => 'SSH Host',
  41. 'type' => 'text',
  42. ],
  43. 'ssh_username' => [
  44. 'friendlyName' => 'SSH User',
  45. 'type' => 'text',
  46. ],
  47. 'ssh_password' => [
  48. 'friendlyName' => 'SSH Password',
  49. 'type' => 'password',
  50. ],
  51. 'ssh_port' => [
  52. 'friendlyName' => 'SSH Port',
  53. 'type' => 'text'
  54. ],
  55. 'ssh_public_key' => [
  56. 'friendlyName' => 'SSH Public Key',
  57. 'type' => 'text',
  58. ],
  59. 'ssh_private_key' => [
  60. 'friendlyName' => 'SSH Private Key',
  61. 'type' => 'text',
  62. ],
  63. 'pdnsutil_path' => [
  64. 'friendlyName' => 'Path To PDNSUTIL',
  65. 'type' => 'text',
  66. ],
  67. 'default_ip' => [
  68. 'friendlyName' => 'Default IP',
  69. 'validators' => [
  70. 'required' => 'required',
  71. 'pattern' => Patterns::IP4_OR_IP6,
  72. ]
  73. ],
  74. 'soa_name' => [
  75. 'friendlyName' => 'Name',
  76. 'help' => '{$domain} will be repleaced with name of the domain',
  77. ],
  78. 'domain_type' => [
  79. 'friendlyName' => 'Domain Type',
  80. 'type' => 'select',
  81. 'options' => ['MASTER' => 'MASTER', 'SLAVE' => 'SLAVE', 'NATIVE' => 'NATIVE'],
  82. ],
  83. 'soa_primary' => [
  84. 'friendlyName' => 'Primary',
  85. ],
  86. 'soa_hostmaster' => [
  87. 'friendlyName' => 'Hostmaster',
  88. ],
  89. 'soa_refresh' => [
  90. 'friendlyName' => 'Refresh',
  91. ],
  92. 'soa_retry' => [
  93. 'friendlyName' => 'Retry',
  94. ],
  95. 'soa_expire' => [
  96. 'friendlyName' => 'Expire',
  97. ],
  98. 'soa_default_ttl' => [
  99. 'friendlyName' => 'Default TTL',
  100. 'type' => 'number',
  101. ],
  102. 'soa_ttl' => [
  103. 'friendlyName' => 'TTL',
  104. 'type' => 'number',
  105. 'value' => '555',
  106. ],
  107. 'soa_edit' => [
  108. 'friendlyName' => 'Allow To Edit SOA Records',
  109. 'type' => 'yesno'
  110. ],
  111. 'disable_validation' => [
  112. 'friendlyName' => 'Disable Records Validation',
  113. 'type' => 'yesno'
  114. ],
  115. 'disable_doubled' => [
  116. 'friendlyName' => 'Double Records',
  117. 'type' => 'yesno',
  118. 'help' => 'Select to enable creating double records'
  119. ],
  120. 'zone_account' => [
  121. 'friendlyName' => 'Zone Account',
  122. ],
  123. 'update_notified_serial' => [
  124. 'friendlyName' => 'Update Notified Serial',
  125. 'type' => 'yesno'
  126. ],
  127. ];
  128. private $error;
  129. private $ssh = null;
  130. private $remote_db = null;
  131. /** available records types * */
  132. public $availableTypes = ['A', 'AAAA', 'NS', 'MX', 'CNAME', 'DNAME', 'TXT', 'SPF', 'SRV', 'PTR', 'SOA', 'CAA', 'AFSDB', 'ALIAS', 'DNSKEY', 'DS', 'HINFO', 'LOC', 'MINFO', 'MR', 'NAPTR', 'RP', 'RRSIG', 'WKS', 'URI', 'URL']; //LOC
  133. public $typesCantBeDoubled = ['A', 'AAAA', 'SPF', 'SRV', 'PTR', 'SOA'];
  134. public function __destruct()
  135. {
  136. $this->disconnect();
  137. }
  138. protected function validateIP()
  139. {
  140. if(empty($this->ip)) return false;
  141. return (ip2long($this->ip) !== false);
  142. }
  143. private function mysql_safequery($query, $params = [] )
  144. {
  145. try
  146. {
  147. $this->connect();
  148. $qsql = main\mgLibs\MySQL\query::debugQuery($query, $params);
  149. $sql_query = main\mgLibs\MySQL\query::query($query, $params, 'pdns');
  150. $this->disconnect();
  151. $this->log('SQL: ' . $qsql);
  152. }
  153. catch( Exception $ex)
  154. {
  155. $this->disconnect();
  156. throw new exceptions\DNSSubmoduleException($ex, dns\SubmoduleExceptionCodes::COMMAND_ERROR);
  157. }
  158. return ($sql_query);
  159. }
  160. private function connect()
  161. {
  162. try
  163. {
  164. main\mgLibs\MySQL\query::createInstance([
  165. 'host' => $this->config['hostname'],
  166. 'user' => $this->config['username'],
  167. 'pass' => $this->config['password'],
  168. 'name' => $this->config['database']
  169. ]);
  170. }
  171. catch( Exception $ex)
  172. {
  173. throw new exceptions\DNSSubmoduleException('Unable to connect to the Power DNS database', dns\SubmoduleExceptionCodes::CONNECTION_PROBLEM);
  174. }
  175. return true;
  176. }
  177. private function disconnect()
  178. {
  179. main\mgLibs\MySQL\query::dropInstance('pdns');
  180. }
  181. public function testConnection()
  182. {
  183. $this->log('TEST CONNECTION');
  184. $this->connect();
  185. $this->mysql_safequery('SELECT * FROM domains ');
  186. $this->disconnect();
  187. }
  188. private function updateSoaSerial()
  189. {
  190. if (in_array($this->config['domain_type'], ['MASTER','NATIVE']) || preg_match('/in-addr.arpa$/', $this->domain))
  191. {
  192. $q = $this->mysql_safequery("SELECT r.id as record_id, r.content FROM records r JOIN domains d ON(r.domain_id = d.id) WHERE r.type = 'SOA' AND d.name = ?", [$this->domain]);
  193. $row = $q->fetch();
  194. $record_id = $row['record_id'];
  195. $content = explode(' ', $row['content']);
  196. if ($content[2])
  197. {
  198. $inc = (int) substr($content[2], 8, 2);
  199. $current_date = date('Ymd');
  200. $serial_current_date = substr($content[2], 0, 8);
  201. $date = $serial_current_date === $current_date ? substr($content[2], 0, 8) : $current_date;
  202. if ($serial_current_date !== $current_date)
  203. {
  204. $serial = $current_date . '00';
  205. }
  206. elseif ($inc === 99)
  207. {
  208. $serial = date('Ymd', strtotime($date) + (60 * 60 * 24)) . '00';
  209. }
  210. else
  211. {
  212. $inc++;
  213. $serial = $date . ($inc <= 9 ? '0' . $inc : $inc);
  214. }
  215. }
  216. if (!empty($serial))
  217. {
  218. $content[2] = $serial;
  219. $this->mysql_safequery('UPDATE records SET content = ? WHERE id = ?', [implode(' ', $content), $record_id]);
  220. }
  221. }
  222. }
  223. private function updateNotifiedSerial()
  224. {
  225. if ($this->config['update_notified_serial'] === 'on')
  226. {
  227. $q = $this->mysql_safequery('SELECT notified_serial FROM domains WHERE name = ?', [$this->domain]);
  228. $row = $q->fetch();
  229. if ($row !== false)
  230. {
  231. $notified_serial = $row['notified_serial'];
  232. if (empty($notified_serial))
  233. {
  234. $current_date = date('Ymd');
  235. $serial = $current_date . '01';
  236. }
  237. else
  238. {
  239. $inc = (int) substr($notified_serial, 8, 2);
  240. $current_date = date('Ymd');
  241. $serial_current_date = substr($notified_serial, 0, 8);
  242. $date = $serial_current_date == $current_date ? substr($notified_serial, 0, 8) : $current_date;
  243. if ($serial_current_date !== $current_date)
  244. {
  245. $serial = $current_date . '01';
  246. }
  247. elseif ($inc === 99)
  248. {
  249. $serial = date('Ymd', strtotime($date) + (60 * 60 * 24)) . '01';
  250. }
  251. else
  252. {
  253. $inc += 2;
  254. $serial = $date . ($inc <= 9 ? '0' . $inc : $inc);
  255. }
  256. }
  257. $this->mysql_safequery('UPDATE domains SET notified_serial = ? WHERE name = ?', [$serial, $this->domain]);
  258. }
  259. }
  260. }
  261. public function zoneExists()
  262. {
  263. $this->log('CHECK ZONE EXIST');
  264. $this->domain = main\mgLibs\custom\helpers\IdnaHelper::idnaEncode($this->domain);
  265. if($this->connect())
  266. {
  267. $q = $this->mysql_safequery('SELECT name, account FROM domains WHERE name = ?', [$this->domain]);
  268. $row = $q->fetch();
  269. $this->disconnect();
  270. return strtolower($row['name']) === strtolower($this->domain);
  271. }
  272. return false;
  273. }
  274. public function activateZone()
  275. {
  276. $this->log('ACTIVATE ZONE');
  277. $this->domain = main\mgLibs\custom\helpers\IdnaHelper::idnaEncode($this->domain);
  278. if ($this->zoneExists())
  279. {
  280. throw new exceptions\DNSSubmoduleException('Domain name already exists!', dns\SubmoduleExceptionCodes::COMMAND_ERROR);
  281. }
  282. if (empty($this->domain))
  283. {
  284. throw new exceptions\DNSSubmoduleException('Domain name is not valid!', dns\SubmoduleExceptionCodes::INVALID_PARAMETERS);
  285. }
  286. if (preg_match('/in-addr.arpa$/', $this->domain))
  287. {
  288. $this->config['domain_type'] = 'MASTER';
  289. }
  290. if ($this->config['domain_type'] === 'SLAVE')
  291. {
  292. $ip = $this->ip == '' ? $this->config['default_ip'] : $this->ip;
  293. if (!filter_var($ip, FILTER_VALIDATE_IP))
  294. {
  295. throw new exceptions\DNSSubmoduleException('This is not a valid IPv4 or IPv6 address.', dns\SubmoduleExceptionCodes::INVALID_PARAMETERS);
  296. }
  297. }
  298. if ($this->config['update_notified_serial'] === 'on' )
  299. {
  300. $current_date = date('Ymd');
  301. $serial = $current_date . '00';
  302. }
  303. else
  304. {
  305. $serial = 0;
  306. }
  307. if ($this->connect())
  308. {
  309. if (in_array($this->config['domain_type'], ['MASTER','NATIVE']) || preg_match('/in-addr.arpa$/', $this->domain) || preg_match('/ip6.arpa$/', $this->domain))
  310. {
  311. if (!empty($this->config['zone_account']))
  312. {
  313. $args = [$this->domain, $serial, $this->config['zone_account']];
  314. $query = "INSERT INTO domains (name, type, notified_serial, account) VALUES( ?, '" . $this->config['domain_type'] . "', ?, ? )";
  315. }
  316. else
  317. {
  318. $args = [$this->domain, $serial];
  319. $query = "INSERT INTO domains (name, type, notified_serial) VALUES( ?, '" . $this->config['domain_type'] . "', ? )";
  320. }
  321. }
  322. elseif(!empty($this->config['zone_account']))
  323. {
  324. $args = [$this->domain, $ip, $serial, $this->config['zone_account']];
  325. $query = "INSERT INTO domains (name, type, master, notified_serial, account) VALUES( ?, 'SLAVE', ?, ?, ? )";
  326. }
  327. else
  328. {
  329. $args = [$this->domain, $ip, $serial];
  330. $query = "INSERT INTO domains (name, type, master, notified_serial) VALUES( ?, 'SLAVE', ?, ?)";
  331. }
  332. if ($this->mysql_safequery($query, $args))
  333. {
  334. if ($this->config['domain_type'] === 'MASTER' || $this->config['domain_type'] === 'NATIVE' || preg_match('/in-addr.arpa$/', $this->domain) || preg_match('/ip6.arpa$/', $this->domain))
  335. {
  336. $to_search = ['{$domain}'];
  337. $to_replace = [$this->domain];
  338. $name = preg_match('/in-addr.arpa$/', $this->domain) || preg_match('/ip6.arpa$/', $this->domain) ? $this->domain : str_replace($to_search, $to_replace, $this->config['soa_name']);
  339. if (preg_match('/in-addr.arpa$/', $this->domain) || preg_match('/ip6.arpa$/', $this->domain))
  340. {
  341. $content = $this->domain . ' ' . 'hostmaster.' . $this->domain . ' ' . date('Ymd') . '00' . ' ' . $this->config['soa_refresh'] . ' ' . $this->config['soa_retry'] . ' ' . $this->config['soa_expire'] . ' ' . $this->config['soa_default_ttl'];
  342. }
  343. else
  344. {
  345. $content = str_replace($to_search, $to_replace, $this->config['soa_primary']) . ' ' . str_replace($to_search, $to_replace, $this->config['soa_hostmaster']) . ' ' . date('Ymd') . '00' . ' ' . $this->config['soa_refresh'] . ' ' . $this->config['soa_retry'] . ' ' . $this->config['soa_expire'] . ' ' . $this->config['soa_default_ttl'];
  346. }
  347. $input = [
  348. $this->domain,
  349. $name,
  350. 'SOA',
  351. $this->config['soa_ttl'],
  352. time(),
  353. $content
  354. ];
  355. $this->mysql_safequery('INSERT INTO records (domain_id, name, type, ttl, prio, change_date, content) VALUES((SELECT id FROM domains WHERE name = ?), ?, ?, ?, 0, ?, ?)', $input);
  356. }
  357. $this->disconnect();
  358. return true;
  359. }
  360. else
  361. {
  362. $this->disconnect();
  363. throw new exceptions\DNSSubmoduleException($this->remote_db->error, dns\SubmoduleExceptionCodes::COMMAND_ERROR);
  364. }
  365. }
  366. return false;
  367. }
  368. public function terminateZone()
  369. {
  370. $this->domain = main\mgLibs\custom\helpers\IdnaHelper::idnaEncode($this->domain);
  371. if (!$this->zoneExists())
  372. {
  373. throw new exceptions\DNSSubmoduleException('Domain name not exists!', dns\SubmoduleExceptionCodes::COMMAND_ERROR);
  374. }
  375. $this->log('TERMINATE ZONE');
  376. if (empty($this->domain))
  377. {
  378. throw new exceptions\DNSSubmoduleException('Domain name is not valid!', dns\SubmoduleExceptionCodes::INVALID_PARAMETERS);
  379. }
  380. if ($this->connect())
  381. {
  382. $q = $this->mysql_safequery('SELECT id FROM domains WHERE name = ?', [$this->domain]);
  383. $row = $q->fetch();
  384. if($this->mysql_safequery('DELETE FROM domains WHERE name = ?', [$this->domain]))
  385. {
  386. $this->mysql_safequery('DELETE FROM records WHERE domain_id = ?', [$row['id']]);
  387. $this->disconnect();
  388. return true;
  389. }
  390. else
  391. {
  392. $this->disconnect();
  393. throw new exceptions\DNSSubmoduleException($this->remote_db->error, dns\SubmoduleExceptionCodes::COMMAND_ERROR);
  394. }
  395. }
  396. return false;
  397. }
  398. public function getRecords($recordType = false)
  399. {
  400. $this->log('GET RECORDS');
  401. $out = [];
  402. $this->domain = main\mgLibs\custom\helpers\IdnaHelper::idnaEncode($this->domain);
  403. if ($this->connect())
  404. {
  405. $q = $this->mysql_safequery('SELECT r.id as record_id, r.name, r.type, r.ttl, r.prio, r.content FROM records r JOIN domains d ON(r.domain_id = d.id) WHERE d.name = ?', [$this->domain]);
  406. while ($row = $q->fetch())
  407. {
  408. if ( !$recordType && $this->config['soa_edit'] !== 'on' && $row['type'] === 'SOA')
  409. {
  410. continue;
  411. }
  412. if ( in_array($row['type'], $recordType ? [strtoupper($recordType)] : $this->getAvailableRecordTypes(), true) )
  413. {
  414. $record = new dns\record\Record();
  415. $record->line = $row['record_id'];
  416. $record->name = rtrim($row['name'],'.') .'.';
  417. $record->type = $row['type'];
  418. $record->ttl = $row['ttl'];
  419. $record->createRDATAObject();
  420. if($record['type'] !=='TXT')
  421. {
  422. $row['content'] = main\mgLibs\custom\helpers\IdnaHelper::idnaDecode($row['content']);
  423. }
  424. switch ($row['type'])
  425. {
  426. case 'SRV':
  427. $content = preg_split('/\s+/', $row['content']);
  428. $record->rdata->priority = $row['prio'];
  429. $record->rdata->weight = $content[0];
  430. $record->rdata->port = $content[1];
  431. $record->rdata->target = $content[2];
  432. break;
  433. case 'MX':
  434. case 'URI':
  435. $record->rdata->fromString($row['prio'] . ' ' . $row['content']);
  436. break;
  437. case 'DNSKEY':
  438. $exploded = preg_split('/\s+/', $row['content']);
  439. $newRecord['protocol'] = $exploded[0];
  440. $newRecord['flags'] = $exploded[1];
  441. $newRecord['algorithm'] = $exploded[2];
  442. unset($exploded[0], $exploded[1], $exploded[2]);
  443. $newRecord['publickey'] = implode(' ', $exploded);
  444. $record->rdata->setDataFromArray($newRecord);
  445. break;
  446. default:
  447. $record->rdata->fromString($row['content']);
  448. break;
  449. }
  450. $out[] = $record;
  451. }
  452. }
  453. $this->disconnect();
  454. }
  455. return $out;
  456. }
  457. public function addRecord(dns\record\Record $record)
  458. {
  459. $this->domain = main\mgLibs\custom\helpers\IdnaHelper::idnaEncode($this->domain);
  460. if ( $record->type !== 'PTR' && (preg_match('/in-addr.arpa$/', $this->domain) || preg_match('/ip6.arpa$/', $this->domain)) )
  461. {
  462. throw new exceptions\DNSSubmoduleException('This record type (' . $record->type . ') is not allowe for rDNS zone', dns\SubmoduleExceptionCodes::COMMAND_ERROR);
  463. }
  464. switch ($record->type)
  465. {
  466. case 'MX':
  467. $prio = $record->rdata->preference;
  468. $value = $record->rdata->exchange;
  469. break;
  470. case 'SRV':
  471. $prio = $record->rdata->priority;
  472. $value = $record->rdata->toString(['weight', 'port', 'target']);
  473. break;
  474. case 'URI':
  475. $prio = $record->rdata->priority;
  476. $value = $record->rdata->toString(['weight', 'target']);
  477. break;
  478. case 'CNAME':
  479. $prio = 0;
  480. $value = rtrim($record->rdata->toString(), '.');
  481. break;
  482. default:
  483. $prio = 0;
  484. $value = $record->rdata->toString();
  485. break;
  486. }
  487. $value = str_replace("\t", ' ', $value);
  488. $value = main\mgLibs\custom\helpers\IdnaHelper::idnaEncode($value);
  489. $input = [
  490. strtolower($this->domain),
  491. main\mgLibs\custom\helpers\IdnaHelper::idnaEncode($record->nameToAbsolute($this->domain, false)),
  492. $record->type,
  493. $record->ttl,
  494. $prio,
  495. time(),
  496. $value
  497. ];
  498. $record->name = main\mgLibs\custom\helpers\IdnaHelper::idnaEncode($record->name);
  499. $valid = $this->validate_input(false, $record->type, $value, $record->name, $prio, $record->ttl);
  500. if ($valid === true)
  501. {
  502. $this->log('ADD RECORDS');
  503. if ($this->connect())
  504. {
  505. if(empty($this->config['disable_doubled']) && in_array($record->type, $this->typesCantBeDoubled))
  506. {
  507. if($this->checkIfRecordSameExist($record))
  508. {
  509. $this->disconnect();
  510. throw new exceptions\DNSSubmoduleException('Such record alredy exists', dns\SubmoduleExceptionCodes::COMMAND_ERROR);
  511. }
  512. }
  513. if ($this->mysql_safequery('INSERT INTO records (domain_id, name, type, ttl, prio, change_date, content) VALUES((SELECT id FROM domains WHERE LOWER(name) = ?), ?, ?, ?, ?, ?, ?)', $input))
  514. {
  515. $this->updateSoaSerial();
  516. $this->updateNotifiedSerial();
  517. $this->disconnect();
  518. try
  519. {
  520. if($this->isSigned())
  521. {
  522. $this->rectify();
  523. }
  524. }
  525. catch( Exception $ex)
  526. {}
  527. return true;
  528. }
  529. else
  530. {
  531. $this->disconnect();
  532. throw new exceptions\DNSSubmoduleException($this->remote_db->error, dns\SubmoduleExceptionCodes::COMMAND_ERROR);
  533. }
  534. }
  535. else
  536. {
  537. $this->disconnect();
  538. throw new exceptions\DNSSubmoduleException('Connection problem', dns\SubmoduleExceptionCodes::CONNECTION_PROBLEM);
  539. }
  540. }
  541. else
  542. {
  543. $this->disconnect();
  544. throw new exceptions\DNSSubmoduleException('Validation error: ' . $this->error, dns\SubmoduleExceptionCodes::INVALID_PARAMETERS);
  545. }
  546. }
  547. public function editRecord(dns\record\Record $record) //Prawie ctr + c -> ctrl + v
  548. {
  549. $this->domain = main\mgLibs\custom\helpers\IdnaHelper::idnaEncode($this->domain);
  550. $record->name = main\mgLibs\custom\helpers\IdnaHelper::idnaEncode($record->name);
  551. switch ($record->type)
  552. {
  553. case 'MX':
  554. $prio = $record->rdata->preference;
  555. $value = $record->rdata->exchange;
  556. break;
  557. case 'SRV':
  558. $prio = $record->rdata->priority;
  559. $value = $record->rdata->toString(['weight', 'port' , 'target']);
  560. break;
  561. case 'URI':
  562. $prio = $record->rdata->priority;
  563. $value = $record->rdata->toString(['weight', 'target']);
  564. break;
  565. case 'CNAME':
  566. $prio = 0;
  567. $value = rtrim($record->rdata->toString(), '.');
  568. break;
  569. default:
  570. $prio = 0;
  571. $value = $record->rdata->toString();
  572. break;
  573. }
  574. $value = main\mgLibs\custom\helpers\IdnaHelper::idnaEncode($value);
  575. $input = [
  576. main\mgLibs\custom\helpers\IdnaHelper::idnaEncode( $record->nameToAbsolute($this->domain, false)),
  577. $record->type,
  578. $record->ttl,
  579. $prio,
  580. time(),
  581. $value,
  582. $record->line
  583. ];
  584. $valid = $this->validate_input($record->line, $record->type, $value, $input[0], $prio, $record->ttl);
  585. if ($valid === true)
  586. {
  587. $this->log('MODIFY RECORDS');
  588. if ($this->connect())
  589. {
  590. if(empty($this->config['disable_doubled']) && in_array($record->type, $this->typesCantBeDoubled))
  591. {
  592. if($this->checkIfRecordSameExist($record))
  593. {
  594. $this->disconnect();
  595. throw new exceptions\DNSSubmoduleException('You cannot add two the same ' .$record->type. ' records', dns\SubmoduleExceptionCodes::COMMAND_ERROR);
  596. }
  597. }
  598. if ($this->mysql_safequery('UPDATE records SET name = ?, type = ?, ttl = ?, prio = ?, change_date = ?, content = ? WHERE id = ?', $input))
  599. {
  600. $this->updateSoaSerial();
  601. $this->updateNotifiedSerial();
  602. $this->disconnect();
  603. try
  604. {
  605. if($this->isSigned())
  606. {
  607. $this->rectify();
  608. }
  609. }
  610. catch( Exception $ex)
  611. {}
  612. return true;
  613. }
  614. else
  615. {
  616. $this->disconnect();
  617. throw new exceptions\DNSSubmoduleException($this->remote_db->error, dns\SubmoduleExceptionCodes::COMMAND_ERROR);
  618. }
  619. }
  620. else
  621. {
  622. $this->disconnect();
  623. throw new exceptions\DNSSubmoduleException('Connection problem', dns\SubmoduleExceptionCodes::CONNECTION_PROBLEM);
  624. }
  625. }
  626. else
  627. {
  628. $this->disconnect();
  629. throw new exceptions\DNSSubmoduleException('Validation error: ' . $this->error, dns\SubmoduleExceptionCodes::INVALID_PARAMETERS);
  630. }
  631. }
  632. public function deleteRecord(dns\record\Record $record)
  633. {
  634. $this->domain = main\mgLibs\custom\helpers\IdnaHelper::idnaEncode($this->domain);
  635. if ($this->connect())
  636. {
  637. if (strtoupper($record->type) == 'SOA')
  638. {
  639. $this->disconnect();
  640. throw new exceptions\DNSSubmoduleException('You can not remove the SOA record', dns\SubmoduleExceptionCodes::COMMAND_ERROR);
  641. }
  642. else
  643. {
  644. $q = $this->mysql_safequery('DELETE FROM records WHERE id = ?', [$record->line]);
  645. $this->log('DELETE RECORD');
  646. if ($q)
  647. {
  648. $this->updateSoaSerial();
  649. $this->updateNotifiedSerial();
  650. $this->disconnect();
  651. try
  652. {
  653. if($this->isSigned())
  654. {
  655. $this->rectify();
  656. }
  657. }
  658. catch( Exception $ex)
  659. {}
  660. return true;
  661. }
  662. else
  663. {
  664. $this->disconnect();
  665. throw new exceptions\DNSSubmoduleException('Error occured: ' . $this->remote_db->error, dns\SubmoduleExceptionCodes::COMMAND_ERROR);
  666. }
  667. }
  668. }
  669. else
  670. {
  671. $this->disconnect();
  672. throw new exceptions\DNSSubmoduleException('Connection problem', dns\SubmoduleExceptionCodes::CONNECTION_PROBLEM);
  673. }
  674. }
  675. public function getZones()
  676. {
  677. $this->connect();
  678. $q = $this->mysql_safequery('SELECT name, master FROM domains');
  679. $this->log('GET ZONES');
  680. $out = [];
  681. while ($row = $q->fetch())
  682. {
  683. $out[$row['name']] = $row['master'];
  684. }
  685. $this->disconnect();
  686. return $out;
  687. }
  688. /* * ****************************************
  689. *
  690. * VALIDATION
  691. *
  692. * **************************************** */
  693. private function validate_input( $rid = false, $type, $content, $name, $prio, $ttl)
  694. {
  695. if ($this->config['disable_validation'] === 'on' || $type === 'PTR')
  696. return true;
  697. switch ($type)
  698. {
  699. case 'A':
  700. if (!$this->is_valid_ipv4($content))
  701. return false;
  702. if (!$this->is_valid_rr_cname_exists($name, $rid))
  703. return false;
  704. if (!$this->is_valid_hostname_fqdn($name, 1))
  705. return false;
  706. break;
  707. case 'AAAA':
  708. if (!$this->is_valid_ipv6($content))
  709. return false;
  710. if (!$this->is_valid_rr_cname_exists($name, $rid))
  711. return false;
  712. if (!$this->is_valid_hostname_fqdn($name, 1))
  713. return false;
  714. break;
  715. case 'CNAME':
  716. if (!$this->is_valid_rr_cname_name($name))
  717. return false;
  718. if (!$this->is_valid_rr_cname_unique($name, $rid))
  719. return false;
  720. if (!$this->is_valid_hostname_fqdn($name, 1))
  721. return false;
  722. if (!$this->is_valid_hostname_fqdn($content, 0))
  723. return false;
  724. if (!$this->is_not_empty_cname_rr($name, $this->domain))
  725. return false;
  726. break;
  727. case 'NS':
  728. case 'MX':
  729. if (!$this->is_valid_hostname_fqdn($content, 0))
  730. return false;
  731. if (!$this->is_valid_hostname_fqdn($name, 1))
  732. return false;
  733. if (!$this->is_valid_non_alias_target($content))
  734. return false;
  735. break;
  736. case 'SOA':
  737. if (!$this->is_valid_rr_soa_name($name, $this->domain))
  738. return false;
  739. if (!$this->is_valid_hostname_fqdn($name, 1))
  740. return false;
  741. if (!$this->is_valid_rr_soa_content($content))
  742. return false;
  743. break;
  744. case 'SRV':
  745. if (!$this->is_valid_rr_srv_name($name))
  746. return false;
  747. if (!$this->is_valid_rr_srv_content($content))
  748. return false;
  749. break;
  750. case 'SPF':
  751. case 'TXT':
  752. if (!$this->is_valid_printable($name))
  753. return false;
  754. if (!$this->is_valid_printable(main\mgLibs\custom\helpers\IdnaHelper::idnaEncode(trim($content,'"'))))
  755. return false;
  756. break;
  757. case 'LOC':
  758. if (!$this->is_valid_loc($content))
  759. return false;
  760. if (!$this->is_valid_hostname_fqdn($name, 1))
  761. return false;
  762. break;
  763. case 'CAA':
  764. if(!$this->is_valid_caa($content))
  765. return false;
  766. break;
  767. //2.9.0
  768. case 'ALIAS':
  769. if (!$this->is_valid_hostname_fqdn($name, 0))
  770. return false;
  771. if (!$this->is_valid_caa_target($content))
  772. return false;
  773. break;
  774. case 'AFSDB':
  775. if (!$this->is_valid_hostname_fqdn($name, 0))
  776. return false;
  777. if (!$this->is_valid_afsdb_record($content))
  778. return false;
  779. break;
  780. case 'WKS':
  781. if (!$this->is_valid_hostname_fqdn($name, 0))
  782. return false;
  783. if (!$this->is_valid_wks_record($content))
  784. return false;
  785. break;
  786. case 'RP':
  787. case 'NAPTR':
  788. case 'MR':
  789. case 'MINFO':
  790. case 'HINFO':
  791. case 'DS':
  792. case 'DNSKEY':
  793. case 'DNAME':
  794. case 'RRSIG':
  795. if (!$this->is_valid_hostname_fqdn($name, 0))
  796. return false;
  797. break;
  798. case 'URL':
  799. break;
  800. default:
  801. $this->error = ERR_DNS_RR_TYPE;
  802. return false;
  803. }
  804. if (!$this->is_valid_rr_prio($prio, $type))
  805. return false;
  806. if (!$this->is_valid_rr_ttl($ttl))
  807. return false;
  808. return true;
  809. }
  810. private function is_valid_hostname_fqdn($hostname, $wildcard)
  811. {
  812. $hostname = main\mgLibs\custom\helpers\IdnaHelper::idnaEncode($hostname);
  813. $dns_strict_tld_check = false;
  814. $valid_tlds = false;
  815. $hostname = preg_replace("/\.$/", '', $hostname);
  816. # The full domain name may not exceed a total length of 253 characters.
  817. if (strlen($hostname) > 253)
  818. {
  819. $this->error = ERR_DNS_HN_TOO_LONG;
  820. return false;
  821. }
  822. $hostname_labels = explode('.', $hostname);
  823. $label_count = count($hostname_labels);
  824. if ($label_count == 1)
  825. {
  826. $this->error = ERR_DNS_HN_LENGTH;
  827. return false;
  828. }
  829. foreach ($hostname_labels as
  830. $hostname_label)
  831. {
  832. if ($wildcard == 1 && !isset($first))
  833. {
  834. if (!preg_match('/^(\*|[\w\-\/]+)$/', $hostname_label))
  835. {
  836. $this->error = ERR_DNS_HN_INV_CHARS;
  837. return false;
  838. }
  839. $first = 1;
  840. }
  841. else
  842. {
  843. if (!preg_match('/^[\w\-\/]+$/', $hostname_label))
  844. {
  845. $this->error = ERR_DNS_HN_INV_CHARS;
  846. return false;
  847. }
  848. }
  849. if ( strpos($hostname_label, '-') === 0 )
  850. {
  851. $this->error = ERR_DNS_HN_DASH;
  852. return false;
  853. }
  854. if (substr($hostname_label, -1, 1) === '-' )
  855. {
  856. $this->error = ERR_DNS_HN_DASH;
  857. return false;
  858. }
  859. if ( $hostname_label === '' || strlen($hostname_label) > 63)
  860. {
  861. $this->error = ERR_DNS_HN_LENGTH;
  862. return false;
  863. }
  864. }
  865. if ($hostname_labels[$label_count - 1] === 'arpa' && (substr_count($hostname_labels[0], '/') === 1 XOR substr_count($hostname_labels[1], '/') === 1))
  866. {
  867. if (substr_count($hostname_labels[0], '/') === 1)
  868. {
  869. $array = explode('/', $hostname_labels[0]);
  870. }
  871. else
  872. {
  873. $array = explode('/', $hostname_labels[1]);
  874. }
  875. if (count($array) !== 2)
  876. {
  877. $this->error = ERR_DNS_HOSTNAME;
  878. return false;
  879. }
  880. if (!is_numeric($array[0]) || $array[0] < 0 || $array[0] > 255)
  881. {
  882. $this->error = ERR_DNS_HOSTNAME;
  883. return false;
  884. }
  885. if (!is_numeric($array[1]) || $array[1] < 25 || $array[1] > 31)
  886. {
  887. $this->error = ERR_DNS_HOSTNAME;
  888. return false;
  889. }
  890. }
  891. else
  892. {
  893. if (substr_count($hostname, '/') > 0)
  894. {
  895. $this->error = ERR_DNS_HN_SLASH;
  896. return false;
  897. }
  898. }
  899. if ($dns_strict_tld_check && !in_array(strtolower($hostname_labels[$label_count - 1]), $valid_tlds))
  900. {
  901. $this->error = ERR_DNS_INV_TLD;
  902. return false;
  903. }
  904. return true;
  905. }
  906. private function is_valid_ipv4($ipv4, $answer = true)
  907. {
  908. if (!preg_match('/^[0-9.]{7,15}$/', $ipv4))
  909. {
  910. if ($answer)
  911. {
  912. $this->error = ERR_DNS_IPV4;
  913. }
  914. return false;
  915. }
  916. $quads = explode('.', $ipv4);
  917. $numquads = count($quads);
  918. if ($numquads !== 4)
  919. {
  920. if ($answer)
  921. {
  922. $this->error = ERR_DNS_IPV4;
  923. }
  924. return false;
  925. }
  926. for ($i = 0;
  927. $i < 4;
  928. $i++)
  929. {
  930. if ($quads[$i] > 255)
  931. {
  932. if ($answer)
  933. {
  934. $this->error = ERR_DNS_IPV4;
  935. }
  936. return false;
  937. }
  938. }
  939. return true;
  940. }
  941. private function is_valid_ipv6($ipv6, $answer = true)
  942. {
  943. if (!preg_match('/^[0-9a-f]{0,4}:([0-9a-f]{0,4}:){0,6}[0-9a-f]{0,4}$/i', $ipv6))
  944. {
  945. if ($answer)
  946. {
  947. $this->error = ERR_DNS_IPV6;
  948. }
  949. return false;
  950. }
  951. $quads = explode(':', $ipv6);
  952. $numquads = count($quads);
  953. if ($numquads > 8 || $numquads < 3)
  954. {
  955. if ($answer)
  956. {
  957. $this->error = ERR_DNS_IPV6;
  958. }
  959. return false;
  960. }
  961. $emptyquads = 0;
  962. for ($i = 1;
  963. $i < $numquads - 1;
  964. $i++)
  965. {
  966. if ($quads[$i] == '' )
  967. $emptyquads++;
  968. }
  969. if ($emptyquads > 1)
  970. {
  971. if ($answer)
  972. {
  973. $this->error = ERR_DNS_IPV6;
  974. }
  975. return false;
  976. }
  977. if ($emptyquads === 0 && $numquads !== 8)
  978. {
  979. if ($answer)
  980. {
  981. $this->error = ERR_DNS_IPV6;
  982. }
  983. return false;
  984. }
  985. return true;
  986. }
  987. private function is_valid_printable($string)
  988. {
  989. if (!preg_match('/^[[:print:]]+$/', trim($string)))
  990. {
  991. $this->error = ERR_DNS_PRINTABLE;
  992. return false;
  993. }
  994. return true;
  995. }
  996. private function is_valid_afsdb_record($string)
  997. {
  998. $record = explode(' ', $string);
  999. if (!$this->is_valid_hostname_fqdn($record[1], 1)){
  1000. return false;
  1001. }
  1002. if(!$this->is_valid_subtype($record[0])){
  1003. return false;
  1004. }
  1005. return true;
  1006. }
  1007. private function is_valid_subtype($type){
  1008. if($type == 1 || $type == 2){
  1009. return true;
  1010. }
  1011. $this->error = ERR_DNS_SUBTYPE;
  1012. return false;
  1013. }
  1014. private function is_valid_wks_record($string)
  1015. {
  1016. $record = explode(' ', $string);
  1017. if (!$this->is_valid_ipv4($record[0])){
  1018. return false;
  1019. }
  1020. return true;
  1021. }
  1022. private function is_valid_rr_cname_name($name)
  1023. {
  1024. if ($this->connect())
  1025. {
  1026. $q = $this->mysql_safequery("SELECT type, content FROM records WHERE content = ? AND (type = 'MX' OR type = 'NS')", [
  1027. $name
  1028. ]);
  1029. if ($q !== false)
  1030. {
  1031. if($q->numRows() > 0)
  1032. {
  1033. $this->error = ERR_DNS_CNAME;
  1034. return false;
  1035. }
  1036. }
  1037. else
  1038. {
  1039. $this->error = 'Power DNS database error: ' . $this->remote_db->error;
  1040. return false;
  1041. }
  1042. $this->disconnect();
  1043. }
  1044. else
  1045. {
  1046. $this->error = 'Unable connect to Power DNS database';
  1047. return false;
  1048. }
  1049. return true;
  1050. }
  1051. private function is_valid_rr_cname_exists($name, $rid)
  1052. {
  1053. if ($this->connect())
  1054. {
  1055. $args[] = $name;
  1056. if ($rid > 0)
  1057. {
  1058. $where = ' AND id != ? ';
  1059. $args[] = $rid;
  1060. }
  1061. else
  1062. {
  1063. $where = '';
  1064. }
  1065. $q = $this->mysql_safequery('SELECT type, name FROM records WHERE name = ?' . $where . " AND TYPE = 'CNAME'", $args);
  1066. if($q !== false)
  1067. {
  1068. if($q->numRows() > 0)
  1069. {
  1070. $this->error = ERR_DNS_CNAME_EXISTS;
  1071. return false;
  1072. }
  1073. }
  1074. else
  1075. {
  1076. $this->error = 'Power DNS database error: ' . $this->remote_db->error;
  1077. return false;
  1078. }
  1079. $this->disconnect();
  1080. }
  1081. else
  1082. {
  1083. $this->error = 'Unable connect to Power DNS database';
  1084. return false;
  1085. }
  1086. return true;
  1087. }
  1088. private function is_valid_rr_cname_unique($name, $rid)
  1089. {
  1090. if ($this->connect())
  1091. {
  1092. $args[] = $name;
  1093. if ($rid > 0)
  1094. {
  1095. $where = ' AND id != ? ';
  1096. $args[] = $rid;
  1097. }
  1098. else
  1099. {
  1100. $where = '';
  1101. }
  1102. $q = $this->mysql_safequery('SELECT * FROM records WHERE name = ? ' . $where . " AND TYPE IN ('A', 'AAAA', 'CNAME')", $args);
  1103. if ($q !== false)
  1104. {
  1105. if($q->numRows() > 0)
  1106. {
  1107. $this->error = ERR_DNS_CNAME_UNIQUE;
  1108. return false;
  1109. }
  1110. }
  1111. else
  1112. {
  1113. $this->error = 'Power DNS database error: ' . $this->remote_db->error;
  1114. return false;
  1115. }
  1116. $this->disconnect();
  1117. }
  1118. else
  1119. {
  1120. $this->error = 'Unable connect to Power DNS database';
  1121. return false;
  1122. }
  1123. return true;
  1124. }
  1125. private function is_not_empty_cname_rr($name, $zone)
  1126. {
  1127. if ($name == $zone)
  1128. {
  1129. $this->error = ERR_DNS_CNAME_EMPTY;
  1130. return false;
  1131. }
  1132. return true;
  1133. }
  1134. private function is_valid_non_alias_target($target)
  1135. {
  1136. if ($this->connect())
  1137. {
  1138. $q = $this->mysql_safequery("SELECT type, name FROM records WHERE name = ? AND TYPE = 'CNAME'", [
  1139. $target
  1140. ]);
  1141. if ($q !== false)
  1142. {
  1143. if($q->numRows() > 0)
  1144. {
  1145. $this->error = ERR_DNS_NON_ALIAS_TARGET;
  1146. return false;
  1147. }
  1148. }
  1149. else
  1150. {
  1151. $this->error = 'Power DNS database error: ' . $this->remote_db->error;
  1152. return false;
  1153. }
  1154. $this->disconnect();
  1155. }
  1156. else
  1157. {
  1158. $this->error = 'Unable connect to Power DNS database';
  1159. return false;
  1160. }
  1161. return true;
  1162. }
  1163. private function is_valid_rr_soa_content($content)
  1164. {
  1165. $fields = preg_split("/\s+/", trim($content));
  1166. $field_count = count($fields);
  1167. if ($field_count == 0 || $field_count > 7)
  1168. {
  1169. return false;
  1170. }
  1171. else
  1172. {
  1173. if (!$this->is_valid_hostname_fqdn($fields[0], 0) || preg_match('/\.arpa\.?$/', $fields[0]))
  1174. {
  1175. return false;
  1176. }
  1177. $final_soa = $fields[0];
  1178. if (isset($fields[1]))
  1179. {
  1180. $addr_input = $fields[1];
  1181. }
  1182. else
  1183. {
  1184. global $dns_hostmaster;
  1185. $addr_input = $dns_hostmaster;
  1186. }
  1187. if (!preg_match('/@/', $addr_input))
  1188. {
  1189. $addr_input = preg_split('/(?<!\\\)\./', $addr_input, 2);
  1190. $addr_to_check = str_replace("\\", '', $addr_input[0]) . '@' . $addr_input[1];
  1191. }
  1192. else
  1193. {
  1194. $addr_to_check = $addr_input;
  1195. }
  1196. if (!$this->is_valid_email($addr_to_check))
  1197. {
  1198. return false;
  1199. }
  1200. else
  1201. {
  1202. $addr_final = explode('@', $addr_to_check, 2);
  1203. $final_soa .= ' ' . str_replace('.', "\\.", $addr_final[0]) . '.' . $addr_final[1];
  1204. }
  1205. if (isset($fields[2]))
  1206. {
  1207. if (!is_numeric($fields[2]))
  1208. {
  1209. return false;
  1210. }
  1211. $final_soa .= ' ' . $fields[2];
  1212. }
  1213. else
  1214. {
  1215. $final_soa .= ' 0';
  1216. }
  1217. if ($field_count == 7)
  1218. {
  1219. for ($i = 3;
  1220. ($i < 7);
  1221. $i++)
  1222. {
  1223. if (!is_numeric($fields[$i]))
  1224. {
  1225. return false;
  1226. }
  1227. else
  1228. {
  1229. $final_soa .= ' ' . $fields[$i];
  1230. }
  1231. }
  1232. }
  1233. }
  1234. $content = $final_soa;
  1235. return true;
  1236. }
  1237. private function is_valid_email($addr)
  1238. {
  1239. if (filter_var($addr, FILTER_VALIDATE_EMAIL) === false)
  1240. {
  1241. $this->error = ERR_INV_EMAIL;
  1242. return false;
  1243. }
  1244. else
  1245. {
  1246. return true;
  1247. }
  1248. }
  1249. private function is_valid_rr_soa_name($name, $zone)
  1250. {
  1251. $zone = rtrim($zone,'.').'.';
  1252. $name = rtrim($name,'.').'.';
  1253. if ($name != $zone)
  1254. {
  1255. $this->error = ERR_DNS_SOA_NAME;
  1256. return false;
  1257. }
  1258. return true;
  1259. }
  1260. private function is_valid_rr_prio(&$prio, $type)
  1261. {
  1262. if ($type == 'MX' || $type == 'SRV' )
  1263. {
  1264. if (!is_numeric($prio) || $prio < 0 || $prio > 65535)
  1265. {
  1266. $this->error = ERR_DNS_INV_PRIO;
  1267. return false;
  1268. }
  1269. }
  1270. else
  1271. {
  1272. $prio = 0;
  1273. }
  1274. return true;
  1275. }
  1276. private function is_valid_rr_srv_name(&$name)
  1277. {
  1278. if (strlen($name) > 255)
  1279. {
  1280. $this->error = ERR_DNS_HN_TOO_LONG;
  1281. return false;
  1282. }
  1283. $fields = explode('.', $name, 3);
  1284. if (!preg_match('/^_[\w-]+$/', $fields[0]))
  1285. {
  1286. $this->error = ERR_DNS_SRV_NAME;
  1287. return false;
  1288. }
  1289. if (!preg_match('/^_[\w]+$/', $fields[1]))
  1290. {
  1291. $this->error = ERR_DNS_SRV_NAME;
  1292. return false;
  1293. }
  1294. if (!$this->is_valid_hostname_fqdn($fields[2], 0))
  1295. {
  1296. $this->error = ERR_DNS_SRV_NAME;
  1297. return false;
  1298. }
  1299. $name = implode('.', $fields);
  1300. return true;
  1301. }
  1302. private function is_valid_rr_srv_content(&$content)
  1303. {
  1304. $fields = preg_split("/\s+/", trim($content), 3);
  1305. if (!is_numeric($fields[0]) || $fields[0] < 0 || $fields[0] > 65535)
  1306. {
  1307. $this->error = ERR_DNS_SRV_WGHT;
  1308. return false;
  1309. }
  1310. if (!is_numeric($fields[1]) || $fields[1] < 0 || $fields[1] > 65535)
  1311. {
  1312. $this->error = ERR_DNS_SRV_PORT;
  1313. return false;
  1314. }
  1315. if ($fields[2] === '' || ($fields[2] !== '.' && !$this->is_valid_hostname_fqdn($fields[2], 0)))
  1316. {
  1317. $this->error = ERR_DNS_SRV_TRGT;
  1318. return false;
  1319. }
  1320. $content = implode(' ', $fields);
  1321. return true;
  1322. }
  1323. private function is_valid_rr_ttl(&$ttl)
  1324. {
  1325. if (!isset($ttl) || $ttl == '' )
  1326. {
  1327. global $dns_ttl;
  1328. $ttl = $dns_ttl;
  1329. }
  1330. if (!is_numeric($ttl) || $ttl < 0 || $ttl > 2147483647)
  1331. {
  1332. $this->error = ERR_DNS_INV_TTL;
  1333. return false;
  1334. }
  1335. return true;
  1336. }
  1337. private function is_valid_loc($content)
  1338. {
  1339. $regex = "^(90|[1-8]\d|0?\d)( ([1-5]\d|0?\d)( ([1-5]\d|0?\d)(\.\d{1,3})?)?)? [NS] (180|1[0-7]\d|[1-9]\d|0?\d)( ([1-5]\d|0?\d)( ([1-5]\d|0?\d)(\.\d{1,3})?)?)? [EW] (-(100000(\.00)?|\d{1,5}(\.\d\d)?)|([1-3]?\d{1,7}(\.\d\d)?|4([01][0-9]{6}|2([0-7][0-9]{5}|8([0-3][0-9]{4}|4([0-8][0-9]{3}|9([0-5][0-9]{2}|6([0-6][0-9]|7[01]))))))(\.\d\d)?|42849672(\.([0-8]\d|9[0-5]))?))[m]?( (\d{1,7}|[1-8]\d{7})(\.\d\d)?[m]?){0,3}$^";
  1340. if (!preg_match($regex, $content))
  1341. {
  1342. return false;
  1343. }
  1344. else
  1345. {
  1346. return true;
  1347. }
  1348. }
  1349. private function is_valid_caa($content)
  1350. {
  1351. $vars = explode(' ',$content);
  1352. if($this->is_valid_caa_flag($vars[0]) && $this->is_valid_caa_tag($vars[1]) && $this->is_valid_caa_target($vars[2]))
  1353. {
  1354. return true;
  1355. }
  1356. return false;
  1357. }
  1358. private function is_valid_caa_flag($flag)
  1359. {
  1360. if(is_numeric($flag) && $flag >= 0 && $flag <= 255)
  1361. {
  1362. return true;
  1363. }
  1364. $this->error = ERR_DNS_CAA_FLAG;
  1365. return false;
  1366. }
  1367. private function is_valid_caa_tag($tag)
  1368. {
  1369. return is_string($tag);
  1370. }
  1371. private function is_valid_caa_target($target)
  1372. {
  1373. if($target[0] === '"' && $target[strlen($target) - 1] === '"')
  1374. {
  1375. return true;
  1376. }
  1377. $this->error = ERR_DNS_CAA_TARGET;
  1378. return false;
  1379. }
  1380. /**********************************************
  1381. * DNS SEC
  1382. *********************************************/
  1383. public function generateSignKeys()
  1384. {
  1385. }
  1386. /**
  1387. *
  1388. * @return DnsSec
  1389. */
  1390. public function getSignKeys()
  1391. {
  1392. $dnssec = new DnsSec();
  1393. $command = $this->pdnsutil("show-zone $this->domain");
  1394. $keys = array_filter(explode("\n", substr($command['stdio'], strpos($command['stdio'], 'keys:')+5)));
  1395. foreach($keys as $index => $key)
  1396. {
  1397. if(strpos($key, 'DS') === 0)
  1398. {
  1399. $ex = preg_split('/\s+/', $key);
  1400. $ds = new dns\record\type\DS();
  1401. $ds->setKeytag($ex[5]);
  1402. $ds->setAlgorithm($ex[6]);
  1403. $ds->setDigestType($ex[7]);
  1404. $ds->setDigest($ex[8]);
  1405. $dnssec->addDs($ds);
  1406. }
  1407. elseif(strpos($key, 'CSK DNSKEY') === 0)
  1408. {
  1409. $ex = preg_split('/\s+/', $key);
  1410. $dnskey = new dns\record\type\DNSKEY();
  1411. $dnskey->setFlags($ex[6]);
  1412. $dnskey->setProtocol($ex[7]);
  1413. $dnskey->setAlgorithm($ex[8]);
  1414. $dnskey->setPublicKey($ex[9]);
  1415. $ex = array_map(function($field){return explode('=', $field);}, explode(',', $keys[$index-1]));
  1416. $ex = array_map(function($field){return [trim($field[0]) => trim($field[1])];}, $ex);
  1417. $zoneKey = new dns\dnssec\CSK();
  1418. $zoneKey->setId((int)$ex[2]['tag']);
  1419. $zoneKey->setBits((int)$ex[4]['bits']);
  1420. $zoneKey->setDnsKey($dnskey);
  1421. $dnssec->addKey($zoneKey);
  1422. }
  1423. elseif(strpos($key, 'KSK DNSKEY') === 0)
  1424. {
  1425. $ex = preg_split('/\s+/', $key);
  1426. $dnskey = new dns\record\type\DNSKEY();
  1427. $dnskey->setFlags($ex[6]);
  1428. $dnskey->setProtocol($ex[7]);
  1429. $dnskey->setAlgorithm($ex[8]);
  1430. $dnskey->setPublicKey($ex[9]);
  1431. $dnskey2 = new dns\record\type\DNSKEY();
  1432. $dnskey2->setFlags($ex[6]);
  1433. $dnskey2->setProtocol($ex[7]);
  1434. $dnskey2->setAlgorithm($ex[8]);
  1435. $ex = array_map(function($field){return explode('=', $field);}, explode(',', $keys[$index-1]));
  1436. $ex = array_map(function($field){return [trim($field[0]) => trim($field[1])];}, $ex);
  1437. $ksk = new dns\dnssec\KSK();
  1438. $ksk->setId((int)$ex[2]['tag']);
  1439. $ksk->setBits((int)$ex[4]['bits']);
  1440. $ksk->setDnsKey($dnskey);
  1441. $ex = array_map(function($field){return explode('=', $field);}, explode(',', $keys[$index-2]));
  1442. $ex = array_map(function($field){return [trim($field[0]) => trim($field[1])];}, $ex);
  1443. $zsk = new dns\dnssec\ZSK();
  1444. $zsk->setId((int)$ex[2]['tag']);
  1445. $zsk->setBits((int)$ex[4]['bits']);
  1446. $zsk->setDnsKey($dnskey2);
  1447. $dnssec->addKey($ksk);
  1448. $dnssec->addKey($zsk);
  1449. }
  1450. }
  1451. return $dnssec;
  1452. }
  1453. public function isSigned()
  1454. {
  1455. $command = $this->pdnsutil("show-zone $this->domain");
  1456. if(stripos($command['stderr'], 'No keys for zone') !== false)
  1457. {
  1458. return false;
  1459. }
  1460. return true;
  1461. }
  1462. public function sign()
  1463. {
  1464. $command = $this->pdnsutil("secure-zone $this->domain", false);
  1465. $match = preg_match("/Zone {$this->domain}\.? secured/", $command['stdio']);
  1466. if(!$match && $command['stderr'])
  1467. {
  1468. throw new exceptions\DNSSubmoduleException($command['stderr'], dns\SubmoduleExceptionCodes::COMMAND_ERROR);
  1469. }
  1470. }
  1471. public function unsign()
  1472. {
  1473. $command = $this->pdnsutil("disable-dnssec $this->domain");
  1474. if(!empty($command['stderr']))
  1475. {
  1476. throw new exceptions\DNSSubmoduleException($command['stderr'], dns\SubmoduleExceptionCodes::COMMAND_ERROR);
  1477. }
  1478. }
  1479. public function rectify()
  1480. {
  1481. $command = $this->pdnsutil("rectify-zone $this->domain");
  1482. if(!empty($command['stderr']) && stripos($command['stderr'], 'Adding NSEC') === false)
  1483. {
  1484. throw new exceptions\DNSSubmoduleException($command['stderr'], dns\SubmoduleExceptionCodes::COMMAND_ERROR);
  1485. }
  1486. }
  1487. protected function connectSSH()
  1488. {
  1489. if(!function_exists('ssh2_connect'))
  1490. {
  1491. throw new exceptions\DNSSubmoduleException('Cannot find SSH2 for PHP. Please <a href="http://php.net/manual/en/ssh2.installation.php">install</a> SSH2 extension', dns\SubmoduleExceptionCodes::COMMAND_ERROR);
  1492. }
  1493. if(empty($this->config['ssh_host']))
  1494. {
  1495. throw new exceptions\DNSSubmoduleException('SSH Host field is empty. Cannot connect to server', dns\SubmoduleExceptionCodes::INVALID_PARAMETERS);
  1496. }
  1497. if(empty($this->config['ssh_username']))
  1498. {
  1499. throw new exceptions\DNSSubmoduleException('SSH Username field is empty. Cannot connect to server', dns\SubmoduleExceptionCodes::INVALID_PARAMETERS);
  1500. }
  1501. if(empty($this->config['ssh_password']) && (empty($this->config['ssh_public_key']) && empty($this->config['ssh_private_key'])))
  1502. {
  1503. throw new exceptions\DNSSubmoduleException('SSH Password or SSH Key field is empty. Cannot connect to server', dns\SubmoduleExceptionCodes::INVALID_PARAMETERS);
  1504. }
  1505. if(empty($this->config['ssh_port']))
  1506. {
  1507. throw new exceptions\DNSSubmoduleException('SSH Port field is empty. Cannot connect to server', dns\SubmoduleExceptionCodes::INVALID_PARAMETERS);
  1508. }
  1509. $this->ssh = ssh2_connect($this->config['ssh_host'], $this->config['ssh_port']);
  1510. if(!$this->ssh)
  1511. {
  1512. throw new exceptions\DNSSubmoduleException('Cannot connect to SSH', dns\SubmoduleExceptionCodes::INVALID_PARAMETERS);
  1513. }
  1514. if(!empty($this->config['ssh_public_key']) && !empty($this->config['ssh_private_key']))
  1515. {
  1516. $sshPublicKey =
  1517. $this->config['ssh_public_key'][0] === '/'
  1518. ? $this->config['ssh_public_key']
  1519. : ROOTDIR.DIRECTORY_SEPARATOR.'ssh_keys'.DIRECTORY_SEPARATOR.$this->config['ssh_public_key'];
  1520. $shhPrivateKey =
  1521. $this->config['ssh_private_key'][0] === '/'
  1522. ? $this->config['ssh_private_key']
  1523. : ROOTDIR.DIRECTORY_SEPARATOR.'ssh_keys'.DIRECTORY_SEPARATOR.$this->config['ssh_private_key'];
  1524. if(!file_get_contents($sshPublicKey)) {
  1525. throw new exceptions\DNSSubmoduleException('SSH public key file does not exist at path: ' . $sshPublicKey, dns\SubmoduleExceptionCodes::INVALID_PARAMETERS);
  1526. }
  1527. if(!file_get_contents($shhPrivateKey)) {
  1528. throw new exceptions\DNSSubmoduleException('SSH private key file does not exist at path: ' . $shhPrivateKey, dns\SubmoduleExceptionCodes::INVALID_PARAMETERS);
  1529. }
  1530. $auth = ssh2_auth_pubkey_file($this->ssh, $this->config['ssh_username'], $sshPublicKey, $shhPrivateKey);
  1531. if(!$auth)
  1532. {
  1533. $this->ssh = null;
  1534. throw new exceptions\DNSSubmoduleException('Cannot login to server (SSH). Check your credentials', dns\SubmoduleExceptionCodes::INVALID_PARAMETERS);
  1535. }
  1536. }
  1537. else
  1538. {
  1539. $auth = ssh2_auth_password($this->ssh, $this->config['ssh_username'], $this->config['ssh_password']);
  1540. if(!$auth)
  1541. {
  1542. $this->ssh = null;
  1543. throw new exceptions\DNSSubmoduleException('Cannot login to server. Check your credentials', dns\SubmoduleExceptionCodes::INVALID_PARAMETERS);
  1544. }
  1545. }
  1546. }
  1547. protected function pdnsutil($command = '', $throwErrorWhenStdErr = true)
  1548. {
  1549. if(!$this->ssh)
  1550. {
  1551. $this->connectSSH();
  1552. }
  1553. if(!$this->config['pdnsutil_path'])
  1554. {
  1555. throw new exceptions\DNSSubmoduleException('PDNSUTIL path empty. Cannot run command', dns\SubmoduleExceptionCodes::INVALID_PARAMETERS);
  1556. }
  1557. $pdnsutil = $this->config['pdnsutil_path'];
  1558. $stream = ssh2_exec($this->ssh, $pdnsutil.' '.$command);
  1559. $errorStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);
  1560. stream_set_blocking($errorStream, true);
  1561. stream_set_blocking($stream, true);
  1562. $streamContent = stream_get_contents($stream);
  1563. $errorStreamContent = stream_get_contents($errorStream);
  1564. // Close the streams
  1565. fclose($errorStream);
  1566. fclose($stream);
  1567. return
  1568. [
  1569. 'stdio' => $streamContent,
  1570. 'stderr' => $errorStreamContent
  1571. ];
  1572. }
  1573. public function checkIfRecordSameExist($record)
  1574. {
  1575. if(empty($record->line))
  1576. {
  1577. $res = $this->mysql_safequery('SELECT id, name, content FROM records WHERE domain_id = (SELECT id FROM domains WHERE LOWER(name) = ?) AND type = ? AND name = ?',
  1578. [strtolower($this->domain), $record->type, $record->name]);
  1579. }
  1580. else
  1581. {
  1582. $res = $this->mysql_safequery('SELECT id, name, content FROM records WHERE domain_id = (SELECT id FROM domains WHERE name = ?) AND type = ? AND name = ? AND id != ?',
  1583. [$this->domain, $record->type, $record->name, $record->line]);
  1584. }
  1585. return $res->numRows() > 0;
  1586. }
  1587. public function validateRecord($record)
  1588. {
  1589. if($this->server->getModuleConfiguration()['disable_validation'] !== 'on') {
  1590. parent::validateRecord($record);
  1591. }
  1592. }
  1593. }
  1594. $messages_file = substr(__DIR__, 0, strpos(__DIR__, '' . DIRECTORY_SEPARATOR . 'includes')) . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'addons' . DIRECTORY_SEPARATOR . 'dns_manager' . DIRECTORY_SEPARATOR . 'powerdns_messages.php';
  1595. if (file_exists($messages_file))
  1596. {
  1597. require_once($messages_file);
  1598. }
  1599. else
  1600. {
  1601. define('ERR_PERM_SEARCH', 'You do not have the permission to perform searches.');
  1602. define('ERR_PERM_ADD_RECORD', 'You do not have the permission to add a record to this zone.');
  1603. define('ERR_PERM_EDIT_RECORD', 'You do not have the permission to edit this record.');
  1604. define('ERR_PERM_VIEW_RECORD', 'You do not have the permission to view this record.');
  1605. define('ERR_PERM_DEL_RECORD', 'You do not have the permission to delete this record.');
  1606. define('ERR_PERM_ADD_ZONE_MASTER', 'You do not have the permission to add a master zone.');
  1607. define('ERR_PERM_ADD_ZONE_SLAVE', 'You do not have the permission to add a slave zone.');
  1608. define('ERR_PERM_DEL_ZONE', 'You do not have the permission to delete a zone.');
  1609. define('ERR_PERM_VIEW_COMMENT', 'You do not have the permission to view this comment.');
  1610. define('ERR_PERM_EDIT_COMMENT', 'You do not have the permission to edit this comment.');
  1611. define('ERR_PERM_DEL_SM', 'You do not have the permission to delete a supermaster.');
  1612. define('ERR_PERM_VIEW_ZONE', 'You do not have the permission to view this zone.');
  1613. define('ERR_PERM_EDIT_USER', 'You do not have the permission to edit this user.');
  1614. define('ERR_PERM_EDIT_PERM_TEMPL', 'You do not have the permission to edit permission templates.');
  1615. define('ERR_PERM_DEL_PERM_TEMPL', 'You do not have the permission to delete permission templates.');
  1616. define('ERR_PERM_ADD_USER', 'You do not have the permission to add a new user.');
  1617. define('ERR_PERM_DEL_USER', 'You do not have the permission to delete this user.');
  1618. define('ERR_PERM_EDIT_ZONE_TEMPL', 'You do not have the permission to edit zone templates.');
  1619. define('ERR_PERM_DEL_ZONE_TEMPL', 'You do not have the permission to delete zone templates.');
  1620. define('ERR_PERM_ADD_ZONE_TEMPL', 'You do not have the permission to add a zone template.');
  1621. /* DOMAIN STUFF */
  1622. define('ERR_DOMAIN_INVALID', 'This is an invalid zone name.');
  1623. define('ERR_SM_EXISTS', 'There is already a supermaster with this IP address and hostname.');
  1624. define('ERR_DOMAIN_EXISTS', 'There is already a zone with this name.');
  1625. /* USER STUFF */
  1626. define('ERR_USER_EXIST', 'Username exist already, please choose another one.');
  1627. define('ERR_USER_NOT_EXIST', 'User does not exist.');
  1628. define('ERR_USER_WRONG_CURRENT_PASS', 'You did not enter the correct current password.');
  1629. define('ERR_USER_MATCH_NEW_PASS', 'The two new password fields do not match.');
  1630. define('ERR_PERM_TEMPL_ASSIGNED', 'This template is assigned to at least one user.');
  1631. /* OTHER */
  1632. define('ERR_INV_INPUT', 'Invalid or unexpected input given.');
  1633. define('ERR_INV_ARG', 'Invalid argument(s) given to function %s');
  1634. define('ERR_INV_ARGC', 'Invalid argument(s) given to function %s %s');
  1635. define('ERR_UNKNOWN', 'Unknown error.');
  1636. define('ERR_INV_EMAIL', 'Enter a valid email address.');
  1637. define('ERR_ZONE_NOT_EXIST', 'There is no zone with this ID.');
  1638. define('ERR_REVERS_ZONE_NOT_EXIST', 'There is no matching reverse-zone for: %s.');
  1639. define('ERR_ZONE_TEMPL_NOT_EXIST', 'There is no zone template with this ID.');
  1640. define('ERR_INSTALL_DIR_EXISTS', 'The <a href="install/">install/</a> directory exists, you must remove it first before proceeding.');
  1641. define('ERR_ZONE_TEMPL_EXIST', 'Zone template with this name already exists, please choose another one.');
  1642. define('ERR_ZONE_TEMPL_IS_EMPTY', 'Template name can\'t be an empty string.');
  1643. define('ERR_DEFAULT_CRYPTOKEY_USED', 'Default session encryption key is used, please set it in your configuration file.');
  1644. define('ERR_LOCALE_FAILURE', 'Failed to set locale.');
  1645. define('ERR_ZONE_UPD', 'Zone has not been updated successfully.');
  1646. define('ERR_EXEC_NOT_ALLOWED', 'Failed to call function exec. Make sure that exec is not listed in disable_functions at php.ini');
  1647. /* DATABASE */
  1648. define('ERR_DB_NO_DB_NAME', 'No database name has been set in config.inc.php.');
  1649. define('ERR_DB_NO_DB_HOST', 'No database host has been set in config.inc.php.');
  1650. define('ERR_DB_NO_DB_USER', 'No database username has been set in config.inc.php.');
  1651. define('ERR_DB_NO_DB_PASS', 'No database password has been set in config.inc.php.');
  1652. define('ERR_DB_NO_DB_TYPE', 'No or unknown database type has been set in config.inc.php.');
  1653. define('ERR_DB_NO_DB_FILE', 'No database file has been set in config.inc.php.');
  1654. define('ERR_DB_NO_DB_UPDATE', 'It seems that you forgot to update the database after Poweradmin upgrade to new version.');
  1655. define('ERR_DB_UNK_TYPE', 'Unknown database type.');
  1656. /* DNS */
  1657. define('ERR_DNS_CONTENT', 'Your content field doesnt have a legit value.');
  1658. define('ERR_DNS_HOSTNAME', 'Invalid hostname.');
  1659. define('ERR_DNS_HN_INV_CHARS', 'You have invalid characters in your hostname.');
  1660. define('ERR_DNS_HN_INV_CONTENT', 'Invalid content.');
  1661. define('ERR_DNS_HN_DASH', 'A hostname can not start or end with a dash.');
  1662. define('ERR_DNS_HN_LENGTH', 'Given hostname or one of the labels is too short or too long.');
  1663. define('ERR_DNS_HN_SLASH', 'Given hostname has too many slashes.');
  1664. define('ERR_DNS_RR_TYPE', 'Unknown record type.');
  1665. define('ERR_DNS_IP', 'This is not a valid IPv4 or IPv6 address.');
  1666. define('ERR_DNS_IPV6', 'This is not a valid IPv6 address.');
  1667. define('ERR_DNS_IPV4', 'This is not a valid IPv4 address.');
  1668. define('ERR_DNS_CNAME', 'This is not a valid CNAME. Did you assign an MX or NS record to the record?');
  1669. define('ERR_DNS_CNAME_EXISTS', 'This is not a valid record. There is already exists a CNAME with this name.');
  1670. define('ERR_DNS_CNAME_UNIQUE', 'This is not a valid CNAME. There is already exists an A, AAAA or CNAME with this name.');
  1671. define('ERR_DNS_CNAME_EMPTY', 'Empty CNAME records are not allowed.');
  1672. define('ERR_DNS_NON_ALIAS_TARGET', 'You can not point a NS or MX record to a CNAME record. Remove or rame the CNAME record first, or take another name.');
  1673. define('ERR_DNS_NS_HNAME', 'NS records must be a hostnames.');
  1674. define('ERR_DNS_MX_PRIO', 'A prio field should be numeric.');
  1675. define('ERR_DNS_SOA_NAME', 'Invalid value for name field of SOA record. It should be the name of the zone.');
  1676. define('ERR_DNS_SOA_MNAME', 'You have an error in the MNAME field of the SOA record.');
  1677. define('ERR_DNS_HINFO_INV_CONTENT', 'Invalid value for content field of HINFO record.');
  1678. define('ERR_DNS_HN_TOO_LONG', 'The hostname is too long.');
  1679. define('ERR_DNS_INV_TLD', 'You are using an invalid top level domain.');
  1680. define('ERR_DNS_INV_TTL', 'Invalid value for TTL field. It should be numeric.');
  1681. define('ERR_DNS_INV_PRIO', 'Invalid value for prio field. It should be numeric.');
  1682. define('ERR_DNS_SRV_NAME', 'Invalid value for name field of SRV record.');
  1683. define('ERR_DNS_SRV_WGHT', 'Invalid value for the priority field of the SRV record.');
  1684. define('ERR_DNS_SRV_PORT', 'Invalid value for the weight field of the SRV record.');
  1685. define('ERR_DNS_SRV_TRGT', 'Invalid SRV target.');
  1686. define('ERR_DNS_PRINTABLE', 'Invalid characters have been used in this record.');
  1687. define('ERR_DNS_CAA_FLAG', 'Invalid flag value.');
  1688. define('ERR_DNS_CAA_TARGET', 'Target has to be in " "');
  1689. /* PDNSSEC */
  1690. define('ERR_EXEC_PDNSSEC', 'Failed to call pdnssec utility.');
  1691. define('ERR_EXEC_PDNSSEC_SECURE_ZONE', 'Failed to secure zone.');
  1692. define('ERR_EXEC_PDNSSEC_RECTIFY_ZONE', 'Failed to rectify zone.');
  1693. /* GOOD! */
  1694. define('SUC_ZONE_ADD', 'Zone has been added successfully.');
  1695. define('SUC_ZONE_DEL', 'Zone has been deleted successfully.');
  1696. define('SUC_ZONE_UPD', 'Zone has been updated successfully.');
  1697. define('SUC_ZONES_UPD', 'Zones have been updated successfully.');
  1698. define('SUC_USER_UPD', 'The user has been updated successfully.');
  1699. define('SUC_USER_ADD', 'The user has been created successfully.');
  1700. define('SUC_USER_DEL', 'The user has been deleted successfully.');
  1701. define('SUC_RECORD_UPD', 'The record has been updated successfully.');
  1702. define('SUC_RECORD_DEL', 'The record has been deleted successfully.');
  1703. define('SUC_COMMENT_UPD', 'The comment has been updated successfully.');
  1704. define('SUC_SM_DEL', 'The supermaster has been deleted successfully.');
  1705. define('SUC_SM_ADD', 'The supermaster has been added successfully.');
  1706. define('SUC_PERM_TEMPL_ADD', 'The permission template has been added successfully.');
  1707. define('SUC_PERM_TEMPL_UPD', 'The permission template has been updated successfully.');
  1708. define('SUC_PERM_TEMPL_DEL', 'The permission template has been deleted successfully.');
  1709. define('SUC_ZONE_TEMPL_ADD', 'Zone template has been added successfully.');
  1710. define('SUC_ZONE_TEMPL_UPD', 'Zone template has been updated successfully.');
  1711. define('SUC_ZONE_TEMPL_DEL', 'Zone template has been deleted successfully.');
  1712. define('SUC_EXEC_PDNSSEC_RECTIFY_ZONE', 'Zone has been rectified successfully.');
  1713. //2.9.0
  1714. define('ERR_DNS_SUBTYPE', 'This is not a valid subtype. Valid type is 1 or 2 depending on whether the endpoint is an AFS Volume Location Server or DCE Authentication Server.');
  1715. }