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.

addsite.php 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?PHP
  2. require_once('lib/dashboard.php');
  3. require_once('lib/common.php');
  4. require_once('lib/account.php');
  5. checkAccess(HAS_HOSTING);
  6. define('TITLE', 'Add site');
  7. addDashboardItem('Useful links', 'Support center', 'support');
  8. function meep () {
  9. if (!isset($_POST['docroot']) || !isset($_POST['domain'])) {
  10. return;
  11. }
  12. if (!ctype_digit($_POST['domain'])) {
  13. define('MESSAGE', 'Invalid domain name');
  14. return;
  15. }
  16. $path = '/home/'.USER.'/'.$_POST['docroot'];
  17. $path = preg_replace('#/(.*?)/\.\./#','/',$path);
  18. $path = preg_replace('#//+#','/',$path);
  19. $path = preg_replace('#/\./#', '/', $path);
  20. if (substr($path, 0, strlen('/home/'.USER.'/')) != '/home/'.USER.'/') {
  21. logger::log('Potential attack; attempted to create site with doc root "'.$_POST['docroot'].'"',logger::normal);
  22. define('MESSAGE', 'Invalid document root');
  23. return;
  24. }
  25. if (substr($path,-1) == '/') { $path = substr($path,0,-1); }
  26. $sql = 'SELECT user_id, domain_name FROM domains WHERE domain_id = '.m($_POST['domain']);
  27. $res = mq($sql, __FILE__, __LINE__);
  28. if (mysql_num_rows($res) == 0) {
  29. define('MESSAGE', 'No such domain name');
  30. return;
  31. }
  32. $row = mysql_fetch_array($res);
  33. if ($row['user_id'] != UID) {
  34. logger::log('Potential attack; attempted to create site with domain name "'.$row['domain_name'].'" (belongs to another user)', logger::normal);
  35. define('MESSAGE', 'No such domain name');
  36. return;
  37. }
  38. $sql = 'SELECT record_value FROM records WHERE domain_id = '.m($_POST['domain']).' AND record_type = \'UTD\'';
  39. $re2 = mq($sql, __FILE__, __LINE__);
  40. if (mysql_num_rows($re2) > 0) {
  41. define('MESSAGE', 'Domain name is already associated with another site.');
  42. return;
  43. }
  44. $sql = 'INSERT INTO sites (user_id, site_name, site_docroot, site_curdocroot) VALUES ('.UID.', \''.m($row['domain_name']).'\',\''.m($path).'\',\''.m($path).'\')';
  45. $res = mysql_query($sql) or mf(__FILE__, __LINE__, $sql);
  46. $id = mysql_insert_id();
  47. $sql = 'INSERT INTO records (record_type, domain_id, record_value) VALUES (\'UTD\', '.m($_POST['domain']).', \''.m($id).'\')';
  48. mysql_query($sql) or mf(__FILE__, __LINE__, $sql);
  49. $sql = 'INSERT INTO actions (user_id, action_type, action_value) VALUES (';
  50. $sql .= UID . ', \'updateconf\', \'bind\')';
  51. mysql_query($sql) or mf(__FILE__, __LINE__, $sql);
  52. logger::log('Added site: '.$row['domain_name'].' ['.$path.']', logger::info);
  53. header('Location: '.CP_PATH.'editsite/'.$id);
  54. exit;
  55. }
  56. meep();
  57. require_once('lib/header.php');
  58. require_once('pages/addsite.php');
  59. require_once('lib/footer.php');
  60. ?>