Unsupported scripts and control panel web app for a hosting company
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

domains.php 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?PHP
  2. require_once('lib/dashboard.php');
  3. require_once('lib/account.php');
  4. require_once('lib/database.php');
  5. checkAccess(HAS_HOSTING || HAS_DNS);
  6. function meep() {
  7. if (isset($_POST['action'])) {
  8. if ($_POST['action'] == 'deldom' && isset($_POST['domain']) && preg_match('/^[0-9]+$/',$_POST['domain'])) {
  9. $sql = 'SELECT user_id, domain_name FROM domains WHERE domain_id = '.$_POST['domain'];
  10. $res = mysql_query($sql) or mf(__FILE__, __LINE__, $sql);
  11. if (mysql_num_rows($res) == 0) {
  12. define('MESSAGE', 'No such domain!');
  13. return;
  14. }
  15. $row = mysql_fetch_array($res);
  16. $dn = $row['domain_name'];
  17. if (!defined('ADMIN') && $row['user_id'] != UID) {
  18. define('MESSAGE', 'You do not control that domain.');
  19. return;
  20. }
  21. $sql = 'SELECT s.site_name FROM sites AS s, records AS r WHERE r.domain_id = '.m($_POST['domain']).' AND r.record_type = \'UTD\' AND s.site_id = r.record_value';
  22. $res = mysql_query($sql) or mf(__FILE__, __LINE__, $sql);
  23. if (mysql_num_rows($res) > 0) {
  24. $row = mysql_fetch_array($res);
  25. define('MESSAGE', 'That domain is associated with the site '.$row['site_name'].' and thus cannot be deleted.');
  26. return;
  27. }
  28. $sql = 'SELECT domain_parent FROM domains WHERE domain_id = '.$_POST['domain'];
  29. $res = mysql_query($sql) or mf(__FILE__, __LINE__, $sql);
  30. $row = mysql_fetch_assoc($res);
  31. $sql = 'UPDATE domains SET domain_parent = '.$row['domain_parent'].' WHERE';
  32. $sql .= ' domain_parent = '.$_POST['domain'];
  33. mysql_query($sql) or mf(__FILE__, __LINE__, $sql);
  34. $sql = 'DELETE FROM domains WHERE domain_id = '.$_POST['domain'];
  35. mysql_query($sql) or mf(__FILE__, __LINE__, $sql);
  36. $sql = 'DELETE FROM records WHERE domain_id = '.$_POST['domain'];
  37. mysql_query($sql) or mf(__FILE__, __LINE__, $sql);
  38. define('MESSAGE', 'The domain \''.$dn.'\' has been deleted.');
  39. logger::log('Domain deleted: '.$dn,logger::information);
  40. } elseif ($_POST['action'] == 'add' && isset($_POST['domain'])) {
  41. if (!preg_match('/^[a-z][a-z0-9\-\.]*\.[a-z]{2,}$/i', $_POST['domain'])) {
  42. define('MESSAGE', 'Invalid domain name. Must start with a letter and contain only letters, numbers, hyphens and periods.');
  43. return;
  44. }
  45. $parts = explode('.', $_POST['domain']);
  46. $string = '';
  47. while (count($parts) > 0) {
  48. if ($string != '') { $string = '.'.$string; }
  49. $string = array_pop($parts).$string;
  50. $sql = 'SELECT domain_name FROM domains WHERE domain_name = \''.m(strtolower($string)).'\'';
  51. $res = mysql_query($sql) or mf(__FILE__, __LINE__, $sql);
  52. if (mysql_num_rows($res) > 0) {
  53. define('MESSAGE', 'That domain, or a parent domain, is already registered. Please contact UTD-Hosting support.');
  54. return;
  55. }
  56. }
  57. $sql = 'INSERT INTO domains (user_id, domain_name, domain_enabled) VALUES ('.UID.', \'';
  58. $sql .= m($_POST['domain']).'\', 0)';
  59. $res = mysql_query($sql) or mf(__FILE__, __LINE__, $sql);
  60. logger::log('Added domain: '.$_POST['domain'],logger::information);
  61. // Hacky!
  62. $_POST['subject'] = 'New domain: '.$_POST['domain'];
  63. $_POST['body'] = 'The user has requested to have the domain name '.$_POST['domain'].' associated with their account.';
  64. require('doticket.php');
  65. exit;
  66. // Add ticket
  67. } elseif ($_POST['action'] == 'addsub' && isset($_POST['subdomain']) && isset($_POST['subdomaind'])) {
  68. if (!preg_match('/^[0-9]+$/',$_POST['subdomaind'])) { return; }
  69. $sql = 'SELECT user_id, domain_name, domain_enabled FROM domains WHERE domain_id = '.m($_POST['subdomaind']);
  70. $res = mysql_query($sql) or mf(__FILE__, __LINE__, $sql);
  71. if (mysql_num_rows($res) == 0) {
  72. define('MESSAGE', 'Invalid domain');
  73. return;
  74. }
  75. $row = mysql_fetch_array($res);
  76. $dn = $row['domain_name'];
  77. if ($row['domain_enabled'] == '0') {
  78. define('MESSAGE', 'That domain hasn\'t been enabled yet.');
  79. return;
  80. }
  81. if (!defined('ADMIN') && $row['user_id'] != UID) {
  82. define('MESSAGE', 'You do not control that domain.');
  83. return;
  84. }
  85. if (!preg_match('/^[a-z][a-z0-9\-]*$/i', $_POST['subdomain'])) {
  86. define('MESSAGE', 'Invalid subdomain. Must start with a letter and contain only letters, numbers and \'-\'.');
  87. return;
  88. }
  89. $target = strtolower($_POST['subdomain'].'.'.$dn);
  90. $sql = 'SELECT domain_name FROM domains WHERE domain_name = \''.$target.'\'';
  91. $res = mysql_query($sql) or mf(__FILE__, __LINE__, $sql);
  92. if (mysql_num_rows($res) != 0) {
  93. define('MESSAGE', 'That domain already exists!');
  94. return;
  95. }
  96. $sql = 'INSERT INTO domains (user_id, domain_name, domain_enabled';
  97. $sql .= ', domain_parent) VALUES ('.UID.',\''.$target.'\',1,'.m($_POST['subdomaind']).')';
  98. mysql_query($sql) or mf(__FILE__, __LINE__, $sql);
  99. logger::log('Added subdomain: '.$target, logger::information);
  100. define('MESSAGE', 'Added new domain \''.$target.'\'');
  101. }
  102. }
  103. }
  104. meep();
  105. define('TITLE', 'Domains');
  106. addDashboardItem('Frequently asked questions', 'How do I register a domain name?', 'support/200');
  107. addDashboardItem('Useful links', 'Create a new site', 'addsite');
  108. require_once('lib/header.php');
  109. require_once('pages/domains.list.php');
  110. require_once('pages/domains.addsubdomain.php');
  111. require_once('pages/domains.adddomain.php');
  112. require_once('lib/footer.php');
  113. ?>