PageRenderTime 57ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/domains.php

https://github.com/Cha0sgr/DNS-Registry
PHP | 1282 lines | 903 code | 219 blank | 160 comment | 225 complexity | 6b51b41e8fbab9409df8c704debee4f1 MD5 | raw file
Possible License(s): GPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*-----------------------------------------------------------------------------
  3. * Domain Registry Control Panel *
  4. * *
  5. * Main Author: Vaggelis Koutroumpas vaggelis@koutroumpas.gr (c)2014 for AWMN *
  6. * Credits: see CREDITS file *
  7. * *
  8. * This program is free software: you can redistribute it and/or modify *
  9. * it under the terms of the GNU General Public License as published by *
  10. * the Free Software Foundation, either version 3 of the License, or *
  11. * (at your option) any later version. *
  12. * *
  13. * This program is distributed in the hope that it will be useful, *
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  16. * GNU General Public License for more details. *
  17. * *
  18. * You should have received a copy of the GNU General Public License *
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  20. * *
  21. *-----------------------------------------------------------------------------*/
  22. // Protect page from anonymous users
  23. admin_auth();
  24. // include dns validation functions
  25. require ("./includes/dns.php");
  26. //Define current page data
  27. $mysql_table = 'records';
  28. $sorting_array = array("id", "name", "content", "change_date", "created");
  29. // ----------------------------------------------------------------------
  30. $action_title = "All My Domain Names";
  31. $search_vars = "";
  32. $q = mysql_real_escape_string($_GET['q'], $db);
  33. if ($q) {
  34. $search_vars .= "&q=".$q;
  35. $action_title = "Search: " . $q;
  36. }
  37. if ($_SESSION['admin_default_ttl_domains']){
  38. $CONF['RECORDS_TTL'] = $_SESSION['admin_default_ttl_domains'];
  39. }
  40. if ($_SESSION['admin_level'] == 'user'){
  41. $user_id = " AND user_id = '".$_SESSION['admin_id']."' ";
  42. }else{
  43. $qu = mysql_real_escape_string($_GET['search_user_id'], $db);
  44. if ($qu) {
  45. $search_vars .= "&search_user_id=".$qu;
  46. $user_id = " AND user_id = '".$qu."' ";
  47. }else{
  48. if ($_GET['show_system_domains'] == '1'){
  49. $user_id = " ";
  50. }elseif ($_GET['show_system_domains'] == '2'){
  51. $user_id = " AND user_id = '0' AND domain_id ";
  52. }else{
  53. $user_id = " AND user_id > '0' ";
  54. }
  55. $search_vars .= "&show_system_domains=".mysql_real_escape_string($_GET['show_system_domains'], $db);;
  56. }
  57. }
  58. $search_query = "WHERE (".$mysql_table.".name LIKE '%".$q."%' OR ".$mysql_table.".content LIKE '%".$q."%' ) AND type = 'NS' ". $user_id . " GROUP BY `name` ";
  59. // Sorting
  60. if (isset($_GET['sort'])){
  61. if (in_array($_GET['sort'], $sorting_array)) {
  62. if ($_GET['by'] !== "desc" && $_GET['by'] !== "asc") {
  63. $_GET['by'] = "desc";
  64. }
  65. $order = "ORDER BY `". mysql_escape_string($_GET['sort']) ."` ". mysql_escape_string($_GET['by']) . " ";
  66. }
  67. } else {
  68. $order = "ORDER BY `created` DESC ";
  69. $_GET['sort'] = "created";
  70. $_GET['by'] = "desc";
  71. }
  72. $sort_vars = "&sort=".$_GET['sort']."&by=".$_GET['by'];
  73. // Paging
  74. $count = mysql_query("SELECT id FROM ".$mysql_table." ".$search_query,$db);
  75. $items_number = mysql_num_rows($count);
  76. if ($_GET['items_per_page'] && is_numeric($_GET['items_per_page'])){
  77. $_SESSION['items_per_page'] = $_GET['items_per_page'];
  78. }
  79. if ($_POST['items_per_page'] && is_numeric($_POST['items_per_page'])){
  80. $_SESSION['items_per_page'] = $_POST['items_per_page'];
  81. }
  82. if (isset($_SESSION['items_per_page']) && is_numeric($_SESSION['items_per_page'])){
  83. $num = $_SESSION['items_per_page'];
  84. } else {
  85. $_SESSION['items_per_page'] = $CONF['ADMIN_ITEMS_PER_PAGE'];
  86. $num = $CONF['ADMIN_ITEMS_PER_PAGE'];
  87. }
  88. $e = $num;
  89. $pages = $items_number/$num;
  90. if (!$_GET['pageno']){
  91. $pageno = 0;
  92. }else{
  93. $pageno = $_GET['pageno'];
  94. }
  95. if (isset($_POST['goto'])) {
  96. if ($_POST['goto'] <= $pages + 1) {
  97. $pageno = $num * ($_POST['goto'] - 1);
  98. } else {
  99. $pageno = 0;
  100. }
  101. }
  102. $current_page = 0;
  103. for($i=0;$i<$pages;$i++){
  104. $y=$i+1;
  105. $page=$i*$num;
  106. if ($page == $pageno){
  107. $current_page = $y;
  108. }
  109. }
  110. $total_pages=$i; // sinolo selidon
  111. //Final Query for records listing
  112. $SELECT_RESULTS = mysql_query("SELECT `".$mysql_table."`.* FROM `".$mysql_table."` ".$search_query." ".$order . " LIMIT ".$pageno.", ".$e ,$db);
  113. $url_vars = "action=".$_GET['action'] . $sort_vars . $search_vars;
  114. //ADD NEW RECORD
  115. if ($_POST['action'] == "add" ) {
  116. $errors = array();
  117. //Check if user has reached daily limit of new domain registrations
  118. if ($_SESSION['admin_level'] == "user"){
  119. $SELECT_DOMAINS_TODAY = mysql_query("SELECT created FROM records WHERE type = 'NS' ". $user_id . " AND created >= '".(time() - 86400 )."' GROUP BY `name` ORDER BY created DESC", $db);
  120. $TOTAL_DOMAINS_TODAY = mysql_num_rows($SELECT_DOMAINS_TODAY);
  121. $DOMAINS_TODAY = mysql_fetch_array($SELECT_DOMAINS_TODAY);
  122. if ($TOTAL_DOMAINS_TODAY >= $CONF['NEW_DOMAINS_PER_DAY'] && $DOMAINS_TODAY['created'] > (time() - 86400 )){
  123. $errors['domains_per_day'] = "You have reached the daily limit (".$CONF['NEW_DOMAINS_PER_DAY'].") of new domain registrations. Please try again tomorrow.";
  124. }
  125. }
  126. if ($_POST['tld'] < 1) {
  127. $errors['tld'] = "Please choose a TLD.";
  128. $tld = "";
  129. } else {
  130. $SELECT_TLD = mysql_query("SELECT name, id FROM `tlds` WHERE `id` = '".mysql_escape_string($_POST['tld'])."' ",$db);
  131. $TLD = mysql_fetch_array($SELECT_TLD);
  132. $SELECT_TLD_ID = mysql_query("SELECT domain_id, name FROM `".$mysql_table."` WHERE name = '".$TLD['name']."' AND type = 'SOA' ",$db);
  133. $TLDID = mysql_fetch_array($SELECT_TLD_ID);
  134. if (!$TLDID['name'] && !$TLDID['domain_id']){
  135. $errors['tld'] = "Please choose a TLD.";
  136. }else{
  137. $tld = ".".$TLD['name'];
  138. }
  139. }
  140. $_POST['name'] = trim($_POST['name']);
  141. $hostname_labels = explode('.', $_POST['name'] . "." . $TLD['name']);
  142. $label_count = count($hostname_labels);
  143. //If reverse domain validate differently
  144. if ($hostname_labels[$label_count - 1] == "arpa" ) {
  145. $lookup_domain = $_POST['name'] . "." . $TLD['name'];
  146. if ($validate = is_valid_hostname_fqdn($lookup_domain, 0) ){
  147. $errors['name'] = $validate;
  148. }
  149. //If forward domain do our validation
  150. }elseif (!preg_match("/^(?!-)[a-z0-9-]{1,63}(?<!-)$/", $_POST['name'])) {
  151. $errors['name'] = "Please choose a valid domain name. Only lowercase alphanumeric characters are allowed and a dash (-). Domain cannot start or end with a dash.";
  152. }else{
  153. if (strlen($_POST['name']) > 62){
  154. $errors['name'] = "Please choose a shorter domain name.";
  155. }elseif (strlen($_POST['name']) < 2){
  156. $errors['name'] = "Please choose a bigger domain name.";
  157. }else{
  158. if (mysql_num_rows(mysql_query("SELECT 1 FROM `".$mysql_table."` WHERE `name` = '".mysql_escape_string($_POST['name'].$tld)."' ",$db))){
  159. $errors['name'] = "This domain name is already registered." ;
  160. }
  161. }
  162. }
  163. if ($_POST['hosted'] == "nohosted"){
  164. //CHECK NAMESERVERS
  165. for ($i = 0; $i <= count($_POST['nameserver'])-1; $i++) {
  166. $ns = trim($_POST['nameserver'][$i]);
  167. $glue = trim($_POST['glue'][$i]);
  168. $n = $i+1;
  169. if (!$ns){
  170. $errors['namesever'.$i] = "Please enter a valid Nameserver ".$n.".";
  171. }else{
  172. //check nameserver name
  173. if (mysql_num_rows(mysql_query("SELECT 1 FROM `".$mysql_table."` WHERE `name` = '".mysql_escape_string($ns)."' AND type = 'A' AND user_id > 0 ",$db)) || !getTLD(mysql_escape_string($ns)) ){
  174. //NS exists! We use this one!
  175. $nameserver[$i]['name'] = trim($ns);
  176. }else{
  177. //Check if the nameserver to be created is under a domain the user owns or under the newly created domain
  178. $new_domain = ".".$_POST['name'] . $tld;
  179. //echo $new_domain;
  180. $ns_domain_parts = explode(".", $ns);
  181. //print_r($ns_domain_parts);
  182. $ns_domain_parts[0] = false;
  183. $ns_domain = implode(".", $ns_domain_parts);
  184. $ns_domain = substr($ns_domain, 1);
  185. //$ns_domain_parts = array_reverse($ns_domain_parts);
  186. //$ns_domain = $ns_domain_parts[1] . "." . $ns_domain_parts[0] . $tld;
  187. //echo $ns_domain;
  188. if ( stristr($ns. $tld, $new_domain ) ||
  189. mysql_num_rows(mysql_query("SELECT 1 FROM `".$mysql_table."` WHERE `name` = '".mysql_escape_string($ns_domain)."' AND type = 'NS' " . $user_id ,$db))
  190. ) {
  191. //NS does not exist - so we check the A record to add them later on
  192. if ($glue){
  193. //check nameserver ip/glue
  194. if(filter_var($glue, FILTER_VALIDATE_IP)){
  195. if ($CONF['NAMESERVERS_IP_RANGE'] == 'any' || netMatch($CONF['NAMESERVERS_IP_RANGE'], $glue)){
  196. //IP VALIDATED! We prepare arrays for the new nameserver/glue record insert
  197. $nameserver[$i]['name'] = trim($ns);
  198. $nameserver[$i]['glue'] = trim($glue);
  199. }else{
  200. $errors['glue'.$i] = "The Nameserver ".$n." IP you entered is not within permitted range: ".$CONF['NAMESERVERS_IP_RANGE'].".";
  201. }
  202. }else{
  203. $errors['glue'.$i] = "The Nameserver ".$n." IP you entered is not valid.";
  204. }
  205. }else{
  206. $n = $i+1;
  207. $errors['glue'.$i] = "Please enter a valid Nameserver ".$n." IP.";
  208. }
  209. }else{
  210. $n = $i+1;
  211. $errors['namesever'.$i] = "Nameserver ".$n." parent domain is not owned by you. Cannot create Glue Record";
  212. }
  213. }
  214. }
  215. }
  216. //echo "<pre>";
  217. //print_r($nameserver);
  218. //echo "</pre>";
  219. }elseif ($_POST['hosted'] != 'hosted'){
  220. $errors['hosted'] = "Please select a Domain Hosting Method";
  221. }
  222. if (!$_POST['user_id']) {
  223. if ($_SESSION['admin_level'] != 'admin'){
  224. $_POST['user_id'] = $_SESSION['admin_id'];
  225. }else{
  226. $errors['user_id'] = "Please choose an owner for the domain.";
  227. }
  228. }elseif ($_POST['user_id'] == 'system'){
  229. $_POST['user_id'] = '0';
  230. }
  231. if (count($errors) == 0) {
  232. $insert_errors = array();
  233. $new_domain_time = time();
  234. //INSERT DOMAIN FOR SELF HOSTING
  235. if ($_POST['hosted'] == 'nohosted'){
  236. for ($i = 0; $i <= count($nameserver)-1; $i++) {
  237. $INSERT = mysql_query("INSERT INTO `".$mysql_table."` (name, user_id, domain_id, type, content, ttl, prio, change_date, disabled, auth, created) VALUES (
  238. '" . mysql_escape_string($_POST['name'].$tld) . "',
  239. '" . mysql_escape_string($_POST['user_id']) . "',
  240. '".$TLDID['domain_id']."',
  241. 'NS',
  242. '".mysql_escape_string($nameserver[$i]['name'])."',
  243. '".$CONF['RECORDS_TTL']."',
  244. '0',
  245. '".$new_domain_time."',
  246. '1',
  247. NULL,
  248. '".$new_domain_time."'
  249. )", $db);
  250. if (!$INSERT){
  251. $insert_errors[] = true;
  252. }
  253. if ($nameserver[$i]['glue']){
  254. $INSERT = mysql_query("INSERT INTO `".$mysql_table."` (name, content, type, domain_id, ttl, prio, change_date, created, user_id, auth, disabled ) VALUES (
  255. '" . mysql_escape_string($nameserver[$i]['name']) . "',
  256. '" . mysql_escape_string($nameserver[$i]['glue']) . "',
  257. 'A',
  258. '".$TLDID['domain_id']."',
  259. '".$CONF['RECORDS_TTL']."',
  260. '0',
  261. '".$new_domain_time."',
  262. '".$new_domain_time."',
  263. '".mysql_escape_string($_POST['user_id'])."',
  264. NULL,
  265. '0'
  266. )", $db);
  267. if (!$INSERT){
  268. $insert_errors[] = true;
  269. }
  270. }
  271. //$soa_update = update_soa_serial($tld);
  272. }
  273. }elseif ($_POST['hosted'] == 'hosted'){
  274. //INSERT DOMAIN FOR MANAGED HOSTING
  275. //Insert Domain record
  276. $INSERT_DOMAIN = mysql_query("INSERT INTO domains (name, type, notified_serial) VALUES ('". mysql_escape_string($_POST['name'].$tld)."', 'MASTER', '".get_soa_serial($CONF['DEFAULT_SOA'])."' ) ", $db);
  277. $new_domain_id = mysql_insert_id($db);
  278. if (!$INSERT_DOMAIN || !$new_domain_id){
  279. $insert_errors[] = true;
  280. }
  281. //Insert SOA record
  282. $INSERT_SOA = mysql_query("INSERT INTO `records` (`domain_id`, `name`, `type`, `content`, `ttl`, `prio`, `change_date`, `ordername`, `auth`, `disabled`, `created`, `user_id`) VALUES (
  283. '".$new_domain_id."',
  284. '".mysql_escape_string($_POST['name'].$tld)."',
  285. 'SOA',
  286. '".$CONF['DEFAULT_SOA']."',
  287. '".$CONF['RECORDS_TTL']."',
  288. '0',
  289. '".$new_domain_time."',
  290. NULL,
  291. NULL,
  292. '1',
  293. '".$new_domain_time."',
  294. '".mysql_escape_string($_POST['user_id'])."'
  295. )", $db);
  296. if (!$INSERT_SOA){
  297. $insert_errors[] = true;
  298. }
  299. //Insert Nameservers for new Domain
  300. $SELECT_ROOT_NS = mysql_query("SELECT `name`, `ip`, `id` FROM `root_ns` WHERE `active` = '1' ORDER BY `name` ASC ", $db);
  301. while($ROOT_NS = mysql_fetch_array($SELECT_ROOT_NS)){
  302. $INSERT_NS = mysql_query("INSERT INTO `records` (`domain_id`, `name`, `type`, `content`, `ttl`, `prio`, `change_date`, `ordername`, `auth`, `disabled`, `created`, `user_id`) VALUES (
  303. '".$new_domain_id."',
  304. '".mysql_escape_string($_POST['name'].$tld)."',
  305. 'NS',
  306. '".$ROOT_NS['name']."',
  307. '".$CONF['RECORDS_TTL']."',
  308. '0',
  309. '".$new_domain_time."',
  310. NULL,
  311. NULL,
  312. '1',
  313. '".$new_domain_time."',
  314. '".mysql_escape_string($_POST['user_id'])."'
  315. )", $db);
  316. if (!$INSERT_NS){
  317. $insert_errors[] = true;
  318. }
  319. //Insert the NS TSIG records for AXFR to slaves
  320. $INSERT_TSIG = mysql_query("INSERT INTO `domainmetadata` (`domain_id`, `kind`, `content` ) VALUES (
  321. '".$new_domain_id."',
  322. 'TSIG-ALLOW-AXFR',
  323. '".$ROOT_NS['name']."'
  324. )", $db);
  325. //Insert the ALSO-NOTIFY records with Unicast IPs to notify meta-slaves for automatic provision of the new zone on the slaves.
  326. $SELECT_UNICAST_NS = mysql_query("SELECT `ip` FROM root_ns_unicast WHERE parent_id = '".$ROOT_NS['id']."' ", $db);
  327. while ($UNICAST_NS = mysql_fetch_array($SELECT_UNICAST_NS)){
  328. mysql_query("INSERT INTO `domainmetadata` (`domain_id`, `kind`, `content` ) VALUES (
  329. '".$new_domain_id."',
  330. 'ALSO-NOTIFY',
  331. '".addslashes($UNICAST_NS['ip'])."'
  332. )", $db);
  333. mysql_query("INSERT INTO `domainmetadata` (`domain_id`, `kind`, `content` ) VALUES (
  334. '".$new_domain_id."',
  335. 'ALSO-NOTIFY',
  336. '".addslashes($UNICAST_NS['ip']).":".$CONF['META_SLAVE_PORT']."'
  337. )", $db);
  338. }
  339. if (!$INSERT_TSIG){
  340. $insert_errors[] = true;
  341. }
  342. }
  343. $soa_update = update_soa_serial($tld);
  344. $soa_update = update_soa_serial(mysql_escape_string($_POST['name'].$tld));
  345. }
  346. if (count($insert_errors) == 0){
  347. header("Location: index.php?section=".$SECTION."&saved_success=1");
  348. exit();
  349. }else{
  350. $error_occured = TRUE;
  351. }
  352. }
  353. }
  354. // DELETE RECORD
  355. if ($_GET['action'] == "delete" && $_POST['id']){
  356. $id = mysql_real_escape_string(str_replace ("tr-", "", $_POST['id']), $db);
  357. if ($_SESSION['admin_level'] == 'user'){
  358. $user_id = " AND user_id = '".$_SESSION['admin_id'] . "' ";
  359. }else{
  360. $user_id = '';
  361. }
  362. $SELECT_DOMAIN = mysql_query("SELECT name FROM `".$mysql_table."` WHERE id = '".$id."' ". $user_id, $db);
  363. $DOMAIN = mysql_fetch_array($SELECT_DOMAIN);
  364. $SELECT_ISHOSTED = mysql_query("SELECT id FROM domains WHERE name = '".$DOMAIN['name']."' ", $db);
  365. $HOSTEDID = mysql_fetch_array($SELECT_ISHOSTED);
  366. $ISHOSTED = mysql_num_rows($SELECT_ISHOSTED);
  367. if (mysql_num_rows($SELECT_DOMAIN)){
  368. $DELETE = mysql_query("DELETE FROM `".$mysql_table."` WHERE `name`= '".$DOMAIN['name']."' AND type = 'NS' ". $user_id ,$db);
  369. $DELETE = mysql_query("DELETE FROM `".$mysql_table."` WHERE `name` LIKE '%.".$DOMAIN['name']."' AND type = 'A' ". $user_id ,$db);
  370. $DELETE = mysql_query("DELETE FROM `users_notifications` WHERE `name`= '".$DOMAIN['name']."' ". $user_id ,$db);
  371. if ($ISHOSTED){
  372. $DELETE = mysql_query("DELETE FROM `domains` WHERE `id`= '".$HOSTEDID['id']."' ",$db);
  373. $DELETE = mysql_query("DELETE FROM `domainmetadata` WHERE `domain_id`= '".$HOSTEDID['id']."' ",$db);
  374. $DELETE = mysql_query("DELETE FROM `".$mysql_table."` WHERE `domain_id`= '".$HOSTEDID['id']."' ". $user_id ,$db);
  375. $soa_update = true;
  376. }
  377. $soa_update = update_soa_serial($DOMAIN['name'], true);
  378. if ($DELETE && $soa_update){
  379. ob_end_clean();
  380. echo "ok";
  381. } else {
  382. ob_end_clean();
  383. echo "An error has occured.";
  384. }
  385. }
  386. exit();
  387. }
  388. // NOTIFY ROOT NAMESERVERS
  389. if ($_GET['action'] == "notify" && $_POST['id'] && $_SESSION['admin_level'] == 'admin'){
  390. $id = mysql_real_escape_string(str_replace ("tr-", "", $_POST['id']), $db);
  391. $SELECT_DOMAINS = mysql_query("SELECT domain_id, name FROM `".$mysql_table."` WHERE id = '".$id."' ", $db);
  392. $DOMAIN = mysql_fetch_array($SELECT_DOMAINS);
  393. if ($DOMAIN['domain_id'] != '1' && $DOMAIN['name']){
  394. $soa_update = update_soa_serial_byid($DOMAIN['domain_id']);
  395. // Run pdns_control notify to push the new SOA update to our slaves immediately. Fire and forget.
  396. exec ($CONF['PDNS_CONTROL_PATH'] . " --remote-address=".$CONF['PDNS_CONTROL_IP']." --remote-port=".$CONF['PDNS_CONTROL_PORT']." --secret=".$CONF['PDNS_CONTROL_KEY']." notify " . $DOMAIN['name'] . " > /dev/null 2>/dev/null &" );
  397. }
  398. if ($DOMAIN['name'] && $soa_update){
  399. ob_end_clean();
  400. echo "ok";
  401. } else {
  402. ob_end_clean();
  403. echo "An error has occured.";
  404. }
  405. exit();
  406. }
  407. /*
  408. // ENABLE/DISABLE RECORD
  409. if ($_GET['action'] == "toggle_active" && $_POST['id'] && isset($_POST['option'])){
  410. $id = mysql_real_escape_string($_POST['id'], $db);
  411. $option = mysql_real_escape_string($_POST['option'], $db);
  412. if ($_SESSION['admin_level'] == 'user'){
  413. $user_id = " AND user_id = '".$_SESSION['admin_id'] . "' ";
  414. }else{
  415. $user_id = '';
  416. }
  417. $SELECT_DOMAIN = mysql_query("SELECT name, domain_id FROM `".$mysql_table."` WHERE id = '".$id."' ". $user_id, $db);
  418. if (mysql_num_rows($SELECT_DOMAIN)){
  419. $DOMAIN = mysql_fetch_array($SELECT_DOMAIN);
  420. $UPDATE = mysql_query("UPDATE `".$mysql_table."` SET `disabled` = '".$option."' WHERE `name` = '".$DOMAIN['name']."' ".$user_id,$db);
  421. $UPDATE = mysql_query("UPDATE `".$mysql_table."` SET `disabled` = '".$option."' WHERE `name` LIKE '%.".$DOMAIN['name']."' ".$user_id,$db);
  422. $soa_update = update_soa_serial_byid($DOMAIN['domain_id']);
  423. if ($UPDATE && $soa_update) {
  424. //print_r($_GET);
  425. ob_clean();
  426. echo "ok";
  427. } else {
  428. ob_clean();
  429. echo "An error has occured.";
  430. }
  431. }
  432. exit();
  433. }
  434. */
  435. // FIND NAMESERVER GLUE
  436. if ($_GET['action'] == "fetch_glue" && $_POST['nameserver']){
  437. $nameserver = addslashes($_POST['nameserver']);
  438. //Check if nameserver TLD belongs to us or a 3rd Party DNS Service
  439. if (!getTLD($nameserver)){
  440. ob_clean();
  441. echo "3rd Party TLD";
  442. exit();
  443. }
  444. $SELECT_GLUE = mysql_query("SELECT content FROM `".$mysql_table."` WHERE name = '".$nameserver."' AND type = 'A' AND user_id > 0", $db);
  445. $GLUE = mysql_fetch_array($SELECT_GLUE);
  446. if ($GLUE['content']){
  447. ob_clean();
  448. echo $GLUE['content'];
  449. } else {
  450. ob_clean();
  451. echo "Enter IP";
  452. }
  453. exit();
  454. }
  455. ?>
  456. <script>
  457. $(document).bind('cbox_closed', function(){
  458. location.reload();
  459. });
  460. $(function() {
  461. $(".validate_domain").colorbox({iframe:true, width:"85%", height:"90%", fastIframe:false, current: "Domain {current} of {total}" });
  462. // most effect types need no options passed by default
  463. var options = {};
  464. // Hide/Show the ADD Form
  465. $( "#button" ).click(function() {
  466. $( "#toggler" ).toggle( "blind", options, 500, function (){
  467. $('#name').focus();
  468. } );
  469. return false;
  470. });
  471. // Hide/Show the RESULTS Table
  472. $( "#button2" ).click(function() {
  473. $( "#toggler2" ).toggle( "blind", options, 500, function (){
  474. //if ( $('#toggle_state').val('1') )
  475. $('#toggle_state').val('1');
  476. } );
  477. return false;
  478. });
  479. //Init
  480. <?if ($_POST['action'] || $_GET['action'] == 'add'){?>
  481. $( "#toggler" ).show();
  482. <?}else{?>
  483. $( "#toggler" ).hide();
  484. <?}?>
  485. $( "#toggler2" ).show();
  486. <?if (staff_help()){?>
  487. //TIPSY for the ADD Form
  488. $('#name').tipsy({trigger: 'focus', gravity: 'n', fade: true});
  489. $('#tld').tipsy({trigger: 'focus', gravity: 'w', fade: true});
  490. $('#hosted').tipsy({trigger: 'focus', gravity: 'w', fade: true});
  491. $('#user_id').tipsy({trigger: 'focus', gravity: 'w', fade: true});
  492. $('#nameserver').tipsy({ gravity: 'e', fade: true, live: true, html: true });
  493. $('#glue').tipsy({ gravity: 'w', fade: true, live: true, html: true });
  494. <?}?>
  495. //DELETE RECORD
  496. $('a.delete').click(function () {
  497. var record_id = $(this).attr('rel');
  498. if(confirm('Are you sure you want to delete this domain?\n\rThis action cannot be undone!')){
  499. $.post("index.php?section=<?=$SECTION;?>&action=delete", {
  500. id: record_id
  501. }, function(response){
  502. if (response == "ok"){
  503. $('#'+record_id).hide();
  504. $("#notification_success_response").html('Record deleted successfully.');
  505. $('.notification_success').show();
  506. var total_records = $('span#total_records').html();
  507. total_records--;
  508. $('span#total_records').html(total_records);
  509. } else {
  510. $("#notification_fail_response").html('An error occured.' );
  511. $('.notification_fail').show();
  512. //alert(response);
  513. }
  514. });
  515. return false;
  516. }
  517. });
  518. //NOTIFY ROOT NS
  519. $('a.notify').click(function () {
  520. var record_id = $(this).attr('rel');
  521. if(confirm('Are you sure you want to notify all root nameservers for this domain?')){
  522. $.post("index.php?section=<?=$SECTION;?>&action=notify", {
  523. id: record_id
  524. }, function(response){
  525. if (response == "ok"){
  526. $("#notification_success_response").html('Root nameservers notified!');
  527. $('.notification_success').show();
  528. } else {
  529. $("#notification_fail_response").html('An error occured.' );
  530. $('.notification_fail').show();
  531. //alert(response);
  532. }
  533. });
  534. return false;
  535. }
  536. });
  537. <?/*
  538. //ENABLE/DISABLE
  539. $('a.toggle_active').click(function () {
  540. var dochange = '0';
  541. if ($(this).hasClass('activated')){
  542. if(confirm('Are you sure you want disable this domain?')){
  543. var option = '1';
  544. var dochange = '1';
  545. }
  546. } else if ($(this).hasClass('deactivated')){
  547. var option = '0';
  548. var dochange = '1';
  549. }
  550. if (dochange == '1'){
  551. var myItem = $(this);
  552. var record_id = $(this).attr('rel');
  553. $.post("index.php?section=<?=$SECTION;?>&action=toggle_active", {
  554. id: record_id,
  555. option: option
  556. }, function(response){
  557. if (response == "ok"){
  558. $(myItem).toggleClass('activated');
  559. $(myItem).toggleClass('deactivated');
  560. } else {
  561. $("#notification_fail_response").html('An error occured.' );
  562. $('.notification_fail').show();
  563. //alert(response);
  564. }
  565. });
  566. }
  567. return false;
  568. });
  569. */?>
  570. //CLOSE THE NOTIFICATION BAR
  571. $("a.close_notification").click(function() {
  572. var bar_class = $(this).attr('rel');
  573. //alert(bar_class);
  574. $('.'+bar_class).hide();
  575. return false;
  576. });
  577. //Get new domain name as being typed
  578. //$("#name").live('keyup', function() {
  579. // var userdomain = this.value;
  580. // $("#nameserver").val( this.value );
  581. //});
  582. // Add Nameserver fields to add form
  583. var MaxInputs = 9; //maximum input boxes allowed
  584. var InputsWrapper = $("#InputsWrapper"); //Input boxes wrapper ID
  585. var AddButton = $("#AddMoreFileBox"); //Add button ID
  586. <?
  587. if (count($_POST['nameserver'])){
  588. echo "var FieldCount=".count($_POST['nameserver']).";";
  589. echo "var x=FieldCount;";
  590. }else{
  591. echo "var FieldCount=1;";
  592. echo "var x=FieldCount;";
  593. }
  594. ?>
  595. $(AddButton).click(function (e) //on add input button click
  596. {
  597. if(x <= MaxInputs) //max input box allowed
  598. {
  599. x++; //text box increment
  600. FieldCount++; //text box added increment
  601. //add input box
  602. var content = '<div>'+
  603. '<label for="nameserver" class="required">Nameserver '+ FieldCount +'</label>'+
  604. '<input type="text" name="nameserver[]" id="nameserver" title="Enter nameserver name.<br />Eg: ns'+ FieldCount +'.domain.tld" value="ns'+ FieldCount +'.domain.tld"/> '+
  605. ' &nbsp; IP: <input type="text" name="glue[]" class="glue" id="glue" value="Enter IP"/> '+
  606. '<a href="javascript:void(0)" class="removeclass" title="Click here to remove this nameserver field"><img src="images/ico_remove.png" align="absmiddle"></a>'+
  607. '<br /><br /></div>';
  608. $(InputsWrapper).append(content);
  609. }
  610. return false;
  611. });
  612. $("body").on("click",".removeclass", function(e){ //user click on remove text
  613. if( x > 1 ) {
  614. $(this).parent('div').remove(); //remove text box
  615. x--; //decrement textbox
  616. FieldCount--; //text box decrement
  617. }
  618. return false;
  619. });
  620. //Auto clear input NS fields
  621. $("#nameserver").live('focus', function() {
  622. if( this.value.indexOf( "domain.tld" ) != -1 ){
  623. $(this).val('');
  624. }
  625. });
  626. //Auto clear input GLUE fields
  627. $("#glue").live('focus', function() {
  628. if( this.value.indexOf( "10.x.x." ) != -1 || this.value.indexOf( "Enter IP" ) != -1 ){
  629. $(this).val('');
  630. }
  631. });
  632. //Find Nameserver Glue and add it to the field
  633. $('#nameserver').live('keyup', function () {
  634. var nameserver = this.value;
  635. var field = $(this).next();
  636. if (nameserver.length > 3){
  637. $.post("index.php?section=<?=$SECTION;?>&action=fetch_glue", {
  638. nameserver: nameserver
  639. }, function(response){
  640. if (response){
  641. $(field).val(response);
  642. if( response == "3rd Party TLD" ){
  643. $(field).addClass('input_disabled');
  644. $(field).attr("disabled", true);
  645. }else if( response.indexOf( "Enter IP" ) != -1 ){
  646. $(field).removeClass('input_disabled');
  647. $(field).attr("disabled", false);
  648. }else {
  649. $(field).addClass('input_disabled');
  650. $(field).attr("disabled", true);
  651. }
  652. }
  653. });
  654. }
  655. return false;
  656. });
  657. //SHOW/HIDE INPUT FIELDS BASED ON DROPDOWN MENU SELECTION
  658. <?if (!$_POST['hosted'] || $_POST['hosted'] == 'hosted') {?>
  659. $('#Hosted').show();
  660. $('#NoHosted').hide();
  661. <?}elseif ($_POST['hosted'] == 'nohosted'){?>
  662. $('#Hosted').hide();
  663. $('#NoHosted').show();
  664. <?}?>
  665. $('#hosted').live('change', function(){
  666. var myval = $('option:selected',this).val();
  667. if (myval == 'hosted') {
  668. $('#NoHosted').hide();
  669. $('#Hosted').show();
  670. }else if(myval == 'nohosted') {
  671. $('#NoHosted').show();
  672. $('#Hosted').hide();
  673. }
  674. });
  675. //end
  676. });
  677. </script>
  678. <!-- DOMAINS SECTION START -->
  679. <div id="main_content">
  680. <div class="mainsubtitle_bg">
  681. <div class="mainsubtitle"><a href="javascript: void(0)" id="button2">List all my Domain Names</a> | <?if ($_GET['action'] == 'edit'){?><a href="index.php?section=<?=$SECTION;?>&action=add" class="add"><span>Register new Domain Name</span></a> | <a href="index.php?section=<?=$SECTION;?>">Back to My Domains List</a><?}else{?><a href="javascript: void(0)" id="button" class="add"><span>Register new Domain Name</span></a><?}?></div>
  682. </div>
  683. <br />
  684. <? if ($_GET['saved_success']) { ?>
  685. <p class="success"><span style="float: right;"><a href="javascript:void(0)" style="margin:0 auto" class="<?if (staff_help()){?>tip_east<?}?> close_notification" rel="success" title="Close notification bar"><span>Close Notification Bar</span></a></span>
  686. Record saved successfully. </p>
  687. <? } ?>
  688. <? if ($error_occured) { ?>
  689. <p class="error"><span style="float: right;"><a href="javascript:void(0)" style="margin:0 auto" class="<?if (staff_help()){?>tip_east<?}?> close_notification" rel="error" title="Close notification bar"><span>Close Notification Bar</span></a></span>An error occured.</p>
  690. <? } ?>
  691. <p class="notification_success"><span style="float: right;"><a href="javascript:void(0)" style="margin:0 auto" class="<?if (staff_help()){?>tip_east<?}?> close_notification" rel="notification_success" title="Close notification bar"><span>Close Notification Bar</span></a></span><span id="notification_success_response"></span></p>
  692. <p class="notification_fail"><span style="float: right;"><a href="javascript:void(0)" style="margin:0 auto" class="<?if (staff_help()){?>tip_east<?}?> close_notification" rel="notification_fail" title="Close notification bar"><span>Close Notification Bar</span></a></span><span id="notification_fail_response"></span></p>
  693. <div id="toggler">
  694. <!-- ADD DOMAIN START -->
  695. <? if (count($errors) > 0) { ?>
  696. <div id="errors">
  697. <p>Please check:</p>
  698. <ul>
  699. <? foreach ($errors as $key => $value) { echo "<li>" . $value . "</li>"; }?>
  700. </ul>
  701. </div>
  702. <? } ?>
  703. <form id="form" method="post" action="index.php?section=<?=$SECTION;?>&action=add">
  704. <fieldset>
  705. <legend>&raquo; Register Domain Name</legend>
  706. <div class="columns">
  707. <div class="colx2-left">
  708. <p>
  709. <label for="name" class="required">Domain Name</label>
  710. <input type="text" name="name" id="name" title="Enter the Domain Name" value="<?if($_POST['name']){ echo $_POST['name']; } ?>">
  711. <select name="tld" id="tld" title="Select TLD" >
  712. <option value="" selected="selected">--Select--</option>
  713. <?
  714. $SELECT_TLDs = mysql_query("SELECT name, `default`, `id` FROM tlds WHERE active ='1' ORDER BY name ASC", $db);
  715. while ($TLDs = mysql_fetch_array($SELECT_TLDs)){
  716. $SELECT_DOMAIN_ID = mysql_query("SELECT id FROM domains WHERE name = '".$TLDs['name']."' ", $db);
  717. $DOMAIN_ID = mysql_fetch_array($SELECT_DOMAIN_ID);
  718. //Check if domain is reverse or forward
  719. $hostname_labels = explode('.', $TLDs['name']);
  720. $label_count = count($hostname_labels);
  721. if ($hostname_labels[$label_count - 1] == "arpa" && ( $CONF['ALLOW_USERS_REVERSE'] == 'yes' || $_SESSION['admin_level'] == 'admin' )) {
  722. ?>
  723. <option value="<?=$TLDs['id'];?>" <? if ($DOMAIN_ID['id'] && $_POST['tld'] == $TLDs['id']){ echo "selected=\"selected\""; }elseif ($TLDs['default'] == '1' && !$_POST['tld']){echo "selected=\"selected\"";}?> >.<?=$TLDs['name'];?></option>
  724. <?}elseif($hostname_labels[$label_count - 1] != "arpa" ){?>
  725. <option value="<?=$TLDs['id'];?>" <? if ($DOMAIN_ID['id'] && $_POST['tld'] == $TLDs['id']){ echo "selected=\"selected\""; }elseif ($TLDs['default'] == '1' && !$_POST['tld']){echo "selected=\"selected\"";}?> >.<?=$TLDs['name'];?></option>
  726. <?}}?>
  727. </select>
  728. </p>
  729. <p>
  730. <label for="hosted" class="required">Domain Hosting Method</label>
  731. <select name="hosted" id="hosted" title="Select the domain hosting method" >
  732. <option value="hosted" <?if (!$_POST['hosted'] || $_POST['hosted'] == 'hosted'){ echo "selected=\"selected\"";}?> >Managed Hosting</option>
  733. <option value="nohosted" <?if ($_POST['hosted'] == 'nohosted'){ echo "selected=\"selected\"";}?> >Self Hosted</option>
  734. </select>
  735. </p>
  736. <div id="Hosted"><strong>This domain will be hosted on <span class="red">our</span> nameservers.</strong></div>
  737. <div id="NoHosted">
  738. <strong>This domain will be hosted on <span class="red">your</span> nameservers</strong>
  739. <br />
  740. <br />
  741. <label class="required">Nameserver 1</label>
  742. <div id="InputsWrapper">
  743. <div>
  744. <input type="text" name="nameserver[]" id="nameserver" title="Enter nameserver name<br />Eg: ns1.domain.tld" value="<?if($_POST['nameserver'][0]){ echo $_POST['nameserver'][0]; }else{?>ns1.domain.tld<?}?>" autocomplete="off" />
  745. &nbsp;
  746. <?
  747. //echo "<pre>";
  748. //print_r($_POST);
  749. //echo "</pre>";
  750. if ($_POST){
  751. $SELECT_GLUE = mysql_query("SELECT content FROM records WHERE name = '".mysql_real_escape_string($_POST['nameserver'][0])."' AND user_id > 0", $db);
  752. $GLUE = mysql_fetch_array($SELECT_GLUE);
  753. if ($GLUE['content']){
  754. $glue = $GLUE['content'];
  755. $disabled = ' class="input_disabled" ';
  756. }elseif ($_POST['glue'][0]){
  757. $glue = $_POST['glue'][0];
  758. $disabled = '';
  759. }else{
  760. $glue = 'Enter IP';
  761. $disabled = '';
  762. }
  763. }else{
  764. $glue = 'Enter IP';
  765. $disabled = '';
  766. }
  767. ?>
  768. IP: <input type="text" name="glue[]" id="glue" <?=$disabled;?> value="<?=$glue;?>"/><br /><br />
  769. </div>
  770. <?
  771. if ($_POST){
  772. for ($i = 1; $i <= count($_POST['nameserver'])-1; $i++) {
  773. $SELECT_GLUE = mysql_query("SELECT content FROM records WHERE name = '".mysql_real_escape_string($_POST['nameserver'][$i])."' AND user_id > 0", $db);
  774. $GLUE = mysql_fetch_array($SELECT_GLUE);
  775. if ($GLUE['content']){
  776. $glue = $GLUE['content'];
  777. $disabled = ' class="input_disabled" ';
  778. }elseif ($_POST['glue'][$i]){
  779. $glue = $_POST['glue'][$i];
  780. $disabled = '';
  781. }else{
  782. $glue = 'Enter IP';
  783. $disabled = '';
  784. }
  785. ?>
  786. <div>
  787. <label class="required">Nameserver <?=$i+1;?></label>
  788. <input type="text" name="nameserver[]" id="nameserver" title="Enter nameserver name<br />Eg: ns<?=$i;?>.domain.tld" value="<?if($_POST['nameserver'][$i]){ echo $_POST['nameserver'][$i]; }else{?>ns<?=$i;?>.domain.tld<?}?>"/>
  789. &nbsp;
  790. IP: <input type="text" name="glue[]" id="glue" <?=$disabled;?> value="<?=$glue;?>"/>
  791. <a href="javascript:void(0)" class="removeclass" title="Click here to remove this nameserver field"><img src="images/ico_remove.png" align="absmiddle"></a>
  792. <br /><br />
  793. </div>
  794. <?}}?>
  795. </div>
  796. <a href="javascript:void(0)" id="AddMoreFileBox">Add another Nameserver <img src="images/ico_add.png" align="absmiddle"></a>
  797. <br />
  798. </div>
  799. </div>
  800. <div class="colx2-right">
  801. <? if ($_SESSION['admin_level'] == 'admin'){?>
  802. <p>
  803. <label for="user_id" class="required">Domain Name Owner</label>
  804. <select name="user_id" id="user_id" title="Select an owner" >
  805. <option value="" selected="selected">--Select--</option>
  806. <?
  807. $SELECT_USERS = mysql_query("SELECT id, username, fullname FROM users WHERE active ='1' ORDER BY username ASC", $db);
  808. while ($USERS = mysql_fetch_array($SELECT_USERS)){
  809. ?>
  810. <option value="<?=$USERS['id'];?>" <? if ($_POST['user_id'] == $USERS['id']){ echo "selected=\"selected\""; }elseif ($_SESSION['admin_id'] == $USERS['id']){ echo "selected=\"selected\"";}?> ><?=$USERS['username'];?> <?if ($USERS['fullname']){?>(<?=$USERS['fullname'];?> )<?}?></option>
  811. <?}?>
  812. <?if ($_SESSION['admin_level'] == 'admin'){?>
  813. <option value="system" <? if ($_POST['user_id'] == "system"){ echo "selected=\"selected\""; }?> >----System Zone----</option>
  814. <?}?>
  815. </select>
  816. </p>
  817. <?}?>
  818. </div>
  819. </div>
  820. </fieldset>
  821. <fieldset>
  822. <legend>&raquo; Action</legend>
  823. <button type="submit" >Save</button>&nbsp; &nbsp;
  824. <button type="reset" id="button">Cancel</button>
  825. <input type="hidden" name="action" id="action" value="add" />
  826. </fieldset>
  827. </form>
  828. <!-- ADD DOMAIN END -->
  829. <br />
  830. </div>
  831. <div id="toggler2">
  832. <!-- LIST DOMAINS START -->
  833. <fieldset>
  834. <legend>&raquo; My Domains List</legend>
  835. <form name="search_form" action="index.php?section=<?=$SECTION;?>" method="get" class="search_form">
  836. <input type="hidden" name="section" value="<?=$SECTION;?>" />
  837. <table border="0" cellspacing="0" cellpadding="4">
  838. <tr>
  839. <td>Domain:</td>
  840. <td><input type="text" name="q" id="search_field_q" class="input_field" value="<?=$q?>" /></td>
  841. <?if ($_SESSION['admin_level'] == 'admin'){?>
  842. <td>Owner:</td>
  843. <td>
  844. <select name="search_user_id" class="select_box">
  845. <option value="">All Owners</option>
  846. <?
  847. $SELECT_USERS = mysql_query("SELECT id, username, fullname FROM users WHERE active ='1' ORDER BY username ASC", $db);
  848. while ($USERS = mysql_fetch_array($SELECT_USERS)){
  849. ?>
  850. <option value="<?=$USERS['id'];?>" <? if ($_GET['search_user_id'] == $USERS['id']){ echo "selected=\"selected\""; }?> ><?=$USERS['username'];?> <?if ($USERS['fullname']){?>(<?=$USERS['fullname'];?>)<?}?></option>
  851. <?}?>
  852. </select>
  853. </td>
  854. <td>Show System Domains:</td>
  855. <td>
  856. <select name="show_system_domains" class="select_box">
  857. <option value="0" <? if ($_GET['show_system_domains'] != '1' && $_GET['show_system_domains'] != '2'){ echo "selected=\"selected\""; }?> >No</option>
  858. <option value="1" <? if ($_GET['show_system_domains'] == '1'){ echo "selected=\"selected\""; }?> >Yes</option>
  859. <option value="2" <? if ($_GET['show_system_domains'] == '2'){ echo "selected=\"selected\""; }?> >Only</option>
  860. </select>
  861. </td>
  862. <?}?>
  863. <td><button type="submit" >Search</button></td>
  864. </tr>
  865. </table>
  866. </form>
  867. <table width="100%" border="0" cellspacing="0" cellpadding="0" style="margin-bottom:15px; margin-top: 15px;">
  868. <tr>
  869. <td width="36%" height="30">
  870. <h3 style="margin:0"><?=$action_title;?> <? if ($q) { ?><span style="font-size:12px"> (<a href="index.php?section=<?=$SECTION;?>">x</a>)</span><? } ?></h3>
  871. </td>
  872. <td width="28%" align="center">
  873. <? if ($items_number) { ?>
  874. Total Records: <span id="total_records"><?=$items_number?></span>
  875. <? } ?>
  876. </td>
  877. <td width="36%"><? if ($items_number) { include "includes/paging.php"; } ?></td>
  878. </tr>
  879. </table>
  880. <table width="100%" border="0" cellspacing="2" cellpadding="5">
  881. <tr>
  882. <th><?=create_sort_link("name","Domain Name");?></th>
  883. <th>Nameservers</th>
  884. <th>Total Records</th>
  885. <th><?=create_sort_link("created","Registered");?> / <?=create_sort_link("change_date","Updated");?></th>
  886. <th><?=create_sort_link("disabled","Domain Status");?></th>
  887. <?if ($_SESSION['admin_level'] == 'admin'){?>
  888. <th><a href="javascript:void(0)" <?if (staff_help()){?>class="tip_south"<?}?> title="Domain Owner">Owner</a></th>
  889. <?}?>
  890. <th><a href="javascript:void(0)" <?if (staff_help()){?>class="tip_south"<?}?> title="Use the icons bellow manage your Domain.">Actions</a></th>
  891. </tr>
  892. <!-- RESULTS START -->
  893. <?
  894. $i=-1;
  895. while($LISTING = mysql_fetch_array($SELECT_RESULTS)){
  896. $i++;
  897. if ($_SESSION['admin_level'] == 'admin'){
  898. if ($LISTING['user_id'] == 0){
  899. $DOMAIN_USE

Large files files are truncated, but you can click here to view the full file