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.

editsite.php 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?PHP
  2. require_once('lib/dashboard.php');
  3. require_once('lib/account.php');
  4. checkAccess(HAS_HOSTING);
  5. if (isset($_POST['site'])) { $_GET['n'] = $_POST['site']; }
  6. $errors = array();
  7. function foo () {
  8. global $errors;
  9. if (!isset($_POST['task'])) { return; }
  10. if (isset($_POST['site']) && preg_match('/^[0-9]+$/', $_POST['site'])) {
  11. $sql = 'SELECT user_name, users.user_id FROM sites NATURAL JOIN users ';
  12. $sql .= 'WHERE site_id = '.$_POST['site'];
  13. $res = mysql_query($sql) or mf(__FILE__, __LINE__, $sql);
  14. $row = mysql_fetch_array($res);
  15. if ($row['user_id'] != UID && !defined('ADMIN')) {
  16. $errors[] = 'You do not control that site.';
  17. return;
  18. }
  19. if ($row['user_id'] != UID && defined('ADMIN') && ADMIN) {
  20. define('SUID', $row['user_id']);
  21. define('SUSER', $row['user_name']);
  22. }
  23. if ($_POST['task'] == 'domains') {
  24. $sql = 'DELETE FROM records WHERE record_type = \'UTD\' AND ';
  25. $sql .= 'record_value = '.$_POST['site'];
  26. mysql_query($sql) or mf(__FILE__, __LINE__, $sql);
  27. foreach ($_POST as $key => $val) {
  28. if (substr($key,0,6) == 'domain') {
  29. $dom = (int)substr($key,6);
  30. $sql = 'SELECT domain_name, user_id FROM domains WHERE domain_id = '.$dom;
  31. $res = mysql_query($sql) or mf(__FILE__, __LINE__, $sql);
  32. $row = mysql_fetch_array($res);
  33. if ($row['user_id'] != UID && !defined('ADMIN')) {
  34. $errors[] = 'You do not control the domain \''.$row['domain_name'].'\'';
  35. continue;
  36. }
  37. $sql = 'SELECT * FROM records WHERE record_type = \'UTD\' AND domain_id = '.$dom;
  38. $res = mysql_query($sql) or mf(__FILE__, __LINE__, $sql);
  39. if (mysql_num_rows($res) > 0) {
  40. $errors[] = 'The domain \''.$row['domain_name'].'\' is already associated with another site.';
  41. continue;
  42. }
  43. $sql = 'INSERT INTO records (domain_id, record_type, record_value) VALUES ('.$dom.', \'UTD\', \''.$_POST['site'].'\')';
  44. mysql_query($sql) or mf(__FILE__, __LINE__, $sql);
  45. }
  46. }
  47. $sql = 'INSERT INTO actions (user_id, action_type, action_value) VALUES (';
  48. $sql .= UID . ', \'updateconf\', \'bind\')';
  49. mysql_query($sql) or mf(__FILE__, __LINE__, $sql);
  50. } elseif ($_POST['task'] == 'webserver') {
  51. $update = false;
  52. $sql = 'SELECT site_php, site_index, site_htaccess FROM sites';
  53. $sql .= ' WHERE site_id = ' . $_POST['site'];
  54. $res = mysql_query($sql) or mf(__FILE__, __LINE__, $sql);
  55. $row = mysql_fetch_assoc($res);
  56. if ($row['site_php'] != $_POST['phpversion']) {
  57. $update = true;
  58. $sql = 'UPDATE sites SET site_php = \''. m($_POST['phpversion']);
  59. $sql .= '\' WHERE site_id = ' . $_POST['site'];
  60. mysql_query($sql) or mf(__FILE__, __LINE__, $sql);
  61. }
  62. $index = isset($_POST['index']) ? '1' : '0';
  63. $htaccess = isset($_POST['htaccess']) ? '1': '0';
  64. if ($row['site_index'] != $index || $row['site_htaccess'] != $htaccess) {
  65. $update = true;
  66. $sql = 'UPDATE sites SET site_index = '.$index.', site_htaccess = ';
  67. $sql .= $htaccess.' WHERE site_id = '.$_POST['site'];
  68. mysql_query($sql) or mf(__FILE__, __LINE__, $sql);
  69. }
  70. if ($update) {
  71. $sql = 'INSERT INTO actions (user_id, action_type, action_value) ';
  72. $sql .= 'VALUES (' . UID . ', \'updateconf\', \'apache\')';
  73. mysql_query($sql) or mf(__FILE__, __LINE__, $sql);
  74. }
  75. } else {
  76. return;
  77. }
  78. }
  79. }
  80. foo();
  81. if (count($errors) > 0) {
  82. $error = 'The following errors were encountered:<ul><li>'.implode('<li>',$errors).'</ul>';
  83. define('TITLE', 'Error');
  84. } elseif (!isset($_GET['n']) || !preg_match('/^[0-9]+$/',$_GET['n'])) {
  85. $error = 'Invalid site ID!';
  86. define('TITLE', 'Error');
  87. } else {
  88. $site = $_GET['n'];
  89. $sql = 'SELECT site_id, users.user_id, user_name, site_name, site_docroot FROM sites NATURAL JOIN users WHERE site_id = '.$site;
  90. $res = mysql_query($sql) or mf(__FILE__, __LINE__, $sql);
  91. if (mysql_num_rows($res) == 0) {
  92. $error = 'There is no such site with that ID.';
  93. define('TITLE', 'Error');
  94. } else {
  95. $row = mysql_fetch_array($res);
  96. if ($row['user_id'] != UID && !defined('ADMIN')) {
  97. $error = 'You do not own this site.';
  98. define('TITLE', 'Error');
  99. } else {
  100. if ($row['user_id'] != UID && defined('ADMIN') && ADMIN) {
  101. define('SUID', $row['user_id']);
  102. define('SUSER', $row['user_name']);
  103. }
  104. define('SITE_ID', $row['site_id']);
  105. define('SITE_NAME', $row['site_name']);
  106. define('SITE_DOCROOT', $row['site_docroot']);
  107. define('TITLE', 'Edit site: '.$row['site_name']);
  108. }
  109. }
  110. }
  111. addDashboardItem('Useful links', 'Support center', 'support');
  112. addDashboardItem('Useful links', 'Site overview', 'sites');
  113. addDashboardItem('Frequently asked questions', 'What do I do if my site isn\'t working?', 'support/002');
  114. addDashboardItem('Frequently asked questions', 'What does \'document root\' mean?', 'support/015');
  115. addDashboardItem('Frequently asked questions', 'What does KiB/MiB/GiB mean?', 'support/003');
  116. addDashboardItem('Frequently asked questions', 'How do I configure PHP for my site?', 'support/001');
  117. if (isset($error)) {
  118. define('MESSAGE', $error);
  119. }
  120. require_once('lib/header.php');
  121. if (!defined('SUSER')) { define('SUSER', USER); define('SUID', UID); }
  122. if (!isset($error)) {
  123. require_once('pages/editsite.overview.php');
  124. require_once('pages/editsite.webserver.php');
  125. require_once('pages/editsite.domains.php');
  126. require_once('pages/editsite.errors.php');
  127. }
  128. require_once('lib/footer.php');
  129. ?>