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.

account.php 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?PHP
  2. require_once('lib/common.php');
  3. require_once('lib/profiler.php');
  4. require_once('lib/database.php');
  5. // Check IP bans
  6. $sql = 'SELECT ipban_message, ipban_expires FROM ipbans WHERE ipban_ip = \'';
  7. $sql .= m($_SERVER['REMOTE_ADDR']).'\' AND ipban_expires > '.time();
  8. $res = mq($sql, __FILE__, __LINE__);
  9. if (mysql_num_rows($res) > 0) {
  10. if (!defined('FORBIDDEN')) {
  11. header('Location: '.CP_PATH.'403');
  12. exit;
  13. } else {
  14. $row = mysql_fetch_array($res);
  15. define('REASON', $row['ipban_message']);
  16. define('EXPIRES', $row['ipban_expires']);
  17. }
  18. }
  19. // Check to see if they're logged in
  20. if (!isset($_COOKIE['utdsid']) && !defined('NOLOGINREF')) {
  21. header('Location: '.CP_PATH.'login');
  22. exit;
  23. }
  24. // Prune old sessions
  25. $sql = 'DELETE FROM sessions WHERE session_last < '.(time()-60*60);
  26. $sql .= ' OR session_start < '.(time()-60*60*24);
  27. mq($sql, __FILE__, __LINE__);
  28. // Select the user's session
  29. $sql = 'SELECT user_id, user_pass, user_name, user_admin, user_tac, ';
  30. $sql .= 'session_spoof FROM sessions NATURAL JOIN users WHERE session_ident ';
  31. $sql .= '= \''.m($_COOKIE['utdsid']).'\'';
  32. $res = mq($sql, __FILE__, __LINE__);
  33. // Make sure it exists
  34. if (mysql_num_rows($res) <> 1 && !defined('NOLOGINREF')) {
  35. header('Location: '.CP_PATH.'login');
  36. exit;
  37. } elseif (mysql_num_rows($res) == 1) {
  38. $row = mysql_fetch_array($res);
  39. // Read the first line of the T&C (the version number)
  40. $fh = fopen('/home/utd/common/tac.txt','r');
  41. $tac = trim(fgets($fh));
  42. fclose($fh);
  43. // Check they've agreed to it
  44. if ((int)$tac > (int)$row['user_tac'] && !defined('NOTACREF')) {
  45. header('Location: '.CP_PATH.'tac');
  46. exit;
  47. }
  48. // Check to see if it's an admin spoofing a user
  49. if ($row['session_spoof'] != '0' && $row['user_admin'] == '1') {
  50. $sql = 'SELECT user_id, user_pass, user_name, user_admin, user_tac FROM ';
  51. $sql .= 'users WHERE user_id = '.m($row['session_spoof']);
  52. $res = mq($sql, __FILE__, __LINE__);
  53. define('SPOOF', $row['user_id']);
  54. $row = mysql_fetch_array($res);
  55. }
  56. // Define some nice constants
  57. define('USER', $row[2]);
  58. define('PASS', $row[1]);
  59. define('UID', $row[0]);
  60. define('TAC', $row[4]);
  61. if ($row[3] == '1') { define('ADMIN', True); }
  62. // Let's see what packages they have access to
  63. $sql = 'SELECT package_type FROM userpackages NATURAL JOIN packages WHERE ';
  64. $sql .= 'user_id = '.UID.' AND up_active = 1';
  65. $res = mq($sql, __FILE__, __LINE__);
  66. $packages = array('hosting'=>false,'dns'=>false,'backup'=>false,'ssh'=>false);
  67. while ($row = mysql_fetch_array($res)) {
  68. $packages[($row['package_type'])] = true;
  69. }
  70. foreach ($packages as $key=>$value) {
  71. define('HAS_'.strtoupper($key),$value);
  72. }
  73. }
  74. // Function to change a user's password
  75. function changePass ($uid, $newpass) {
  76. $sql = 'SELECT user_name FROM users WHERE user_id = '.m($uid);
  77. $res = mq($sql, __FILE__, __LINE__);
  78. $row = mysql_fetch_array($res);
  79. $uname = $row[0];
  80. $sql = 'UPDATE users SET user_pass = \''.md5($uname.$newpass).'\' WHERE ';
  81. $sql .= 'user_name = \''.m($uname).'\'';
  82. mq($sql) or mf(__FILE__, __LINE__, $sql);
  83. $sql = 'SET PASSWORD FOR \''.m($uname).'\'@\'localhost\' = PASSWORD(\'';
  84. $sql .= md5($uname.$newpass).'\')';
  85. $l = mysql_connect('localhost', 'root', 'mysql32159');;
  86. mysql_select_db('admin', $l);
  87. mq($sql,$l) or mf(__FILE__, __LINE__, $sql);
  88. mysql_close($l);
  89. $_redodb = true; require('/home/utd/control/lib/database.php'); unset($_redodb);
  90. $sql = 'INSERT INTO actions (user_id, action_type, action_value) VALUES (';
  91. $sql .= m($uid).', \'pass\', \''.m($newpass).'\')';
  92. mq($sql) or mf(__FILE__, __LINE__, $sql);
  93. }
  94. function addUser ($username, $email, $pass, $tac, $slots = 1) {
  95. if (!ctype_digit($slots) || $slots < 1 || $slots > 3) {
  96. $slots = 1;
  97. }
  98. $sql = 'INSERT INTO users (user_name, user_pass, user_email, user_tac, ';
  99. $sql .= 'band_total, hdd_total) VALUES (\''.m($username).'\', \'invalid\'';
  100. $sql .= ', \''.m($email).'\', '.((int)$tac).', '.(50000000000*$slots).', ';
  101. $sql .= (3500000000*$slots).')';
  102. mq($sql) or mf(__FILE__, __LINE__, $sql);
  103. $uid = mysql_insert_id();
  104. $sql = 'GRANT USAGE ON *.* TO \''.m($username).'\'@\'localhost\' IDENTIFIED';
  105. $sql .= 'BY \'dummypass123445\'';
  106. $l = mysql_connect('localhost', 'root', 'mysql32159');;
  107. mysql_select_db('admin', $l);
  108. mq($sql,$l) or mf(__FILE__, __LINE__, $sql);
  109. mysql_close($l);
  110. $_redodb = true; require('/home/utd/control/lib/database.php'); unset($_redodb);
  111. $fqdn = m($username.'.utd-hosting.com');
  112. $sql = 'INSERT INTO domains (user_id, domain_name, domain_enabled, domain_parent) VALUES (';
  113. $sql .= (int)$uid.', \''.$fqdn.'\', 1, 16)';
  114. mq($sql) or mf(__FILE__, __LINE__, $sql);
  115. $domain = mysql_insert_id();
  116. $docroot = m('/home/'.$username.'/public_html');
  117. $sql = 'INSERT INTO sites (user_id, site_name, site_docroot, ';
  118. $sql .= 'site_curdocroot) VALUES ('.(int)$uid.', \''.$fqdn;
  119. $sql .= '\', \''.$docroot.'\', \''.$docroot.'\')';
  120. mq($sql) or mf(__FILE__, __LINE__, $sql);
  121. $site = mysql_insert_id();
  122. $sql = 'INSERT INTO records (domain_id, record_type, record_value) VALUES (';
  123. $sql .= (int)$domain.', \'UTD\', \''.(int)$site.'\')';
  124. mq($sql) or mf(__FILE__, __LINE__, $sql);
  125. $sql = 'INSERT INTO billing (bill_due, user_id, bill_paid, bill_amount) ';
  126. $sql .= ' VALUES ('.time().', '.(int)$uid.', 1, '.(3500*$slots).')';
  127. mq($sql) or mf(__FILE__, __LINE__, $sql);
  128. $sql = 'INSERT INTO actions (user_id, action_type, action_value) VALUES (';
  129. $sql .= (int)$uid.', \'create\', \'...\')';
  130. mq($sql) or mf(__FILE__, __LINE__, $sql);
  131. changePass($uid, $pass);
  132. }
  133. // Returns true if $pass is complex enough, or an error message if not
  134. function validPass ($pass) {
  135. if (preg_match('/[a-z]/',$pass)) {
  136. if (preg_match('/[A-Z]/',$pass)) {
  137. if (preg_match('/[0-9]/', $pass)) {
  138. if (strlen($pass) < 5 || strlen($pass) > 20) {
  139. return 'Please ensure your password is 5-20 characters long';
  140. } else {
  141. return true;
  142. }
  143. } else {
  144. return 'Please ensure your password includes some numbers';
  145. }
  146. } else {
  147. return 'Please ensure your password includes some uppercase letters';
  148. }
  149. } else {
  150. return 'Please ensure your password includes some lowercase letters';
  151. }
  152. }
  153. function checkAccess($conditions) {
  154. if ($conditions !== true) {
  155. define('REASON', 'Insufficient access');
  156. require('403.php');
  157. exit();
  158. }
  159. }
  160. define('LIB_ACCOUNT', true);
  161. ?>