Oppaitime's version of Gazelle
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.

index.php 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <?
  2. /*
  3. if (isset($LoggedUser)) {
  4. //Silly user, what are you doing here!
  5. header('Location: index.php');
  6. die();
  7. }
  8. */
  9. include(SERVER_ROOT.'/classes/validate.class.php');
  10. $Val = NEW VALIDATE;
  11. if (!empty($_REQUEST['confirm'])) {
  12. // Confirm registration
  13. $DB->query("
  14. SELECT ID
  15. FROM users_main
  16. WHERE torrent_pass = '".db_string($_REQUEST['confirm'])."'
  17. AND Enabled = '0'");
  18. list($UserID) = $DB->next_record();
  19. if ($UserID) {
  20. $DB->query("
  21. UPDATE users_main
  22. SET Enabled = '1'
  23. WHERE ID = '$UserID'");
  24. $Cache->increment('stats_user_count');
  25. include('step2.php');
  26. }
  27. } elseif (OPEN_REGISTRATION || !empty($_REQUEST['invite'])) {
  28. $Val->SetFields('username', true, 'regex', 'You did not enter a valid username.', array('regex' => USERNAME_REGEX));
  29. $Val->SetFields('email', true, 'email', 'You did not enter a valid email address.');
  30. $Val->SetFields('password', true, 'regex', 'Your password must be at least 6 characters long.', array('regex'=>'/(?=^.{6,}$).*$/'));
  31. $Val->SetFields('confirm_password', true, 'compare', 'Your passwords do not match.', array('comparefield' => 'password'));
  32. $Val->SetFields('readrules', true, 'checkbox', 'You did not select the box that says you will read the rules.');
  33. $Val->SetFields('readwiki', true, 'checkbox', 'You did not select the box that says you will read the wiki.');
  34. $Val->SetFields('agereq', true, 'checkbox', 'You did not select the box that says you are 18 years of age or older.');
  35. //$Val->SetFields('captcha', true, 'string', 'You did not enter a captcha code.', array('minlength' => 6, 'maxlength' => 6));
  36. if (!apc_exists('DBKEY')) {
  37. $Err = "Registration temporarily disabled due to degraded database access (security measure)";
  38. }
  39. if (!empty($_POST['submit'])) {
  40. // User has submitted registration form
  41. $Err = $Val->ValidateForm($_REQUEST);
  42. /*
  43. if (!$Err && strtolower($_SESSION['captcha']) != strtolower($_REQUEST['captcha'])) {
  44. $Err = 'You did not enter the correct captcha code.';
  45. }
  46. */
  47. if (!$Err) {
  48. // Don't allow a username of "0" or "1" due to PHP's type juggling
  49. if (trim($_POST['username']) == '0' || trim($_POST['username']) == '1') {
  50. $Err = 'You cannot have a username of "0" or "1".';
  51. }
  52. $DB->query("
  53. SELECT COUNT(ID)
  54. FROM users_main
  55. WHERE Username LIKE '".db_string(trim($_POST['username']))."'");
  56. list($UserCount) = $DB->next_record();
  57. if ($UserCount) {
  58. $Err = 'There is already someone registered with that username.';
  59. $_REQUEST['username'] = '';
  60. }
  61. if ($_REQUEST['invite']) {
  62. $DB->query("
  63. SELECT InviterID, Email, Reason
  64. FROM invites
  65. WHERE InviteKey = '".db_string($_REQUEST['invite'])."'");
  66. if (!$DB->has_results()) {
  67. $Err = 'Invite does not exist.';
  68. $InviterID = 0;
  69. } else {
  70. list($InviterID, $InviteEmail, $InviteReason) = $DB->next_record(MYSQLI_NUM, false);
  71. $InviteEmail = DBCrypt::decrypt($InviteEmail);
  72. }
  73. } else {
  74. $InviterID = 0;
  75. $InviteEmail = $_REQUEST['email'];
  76. $InviteReason = '';
  77. }
  78. }
  79. if (!$Err) {
  80. $torrent_pass = Users::make_secret();
  81. // Previously SELECT COUNT(ID) FROM users_main, which is a lot slower.
  82. $DB->query("
  83. SELECT ID
  84. FROM users_main
  85. LIMIT 1");
  86. $UserCount = $DB->record_count();
  87. if ($UserCount == 0) {
  88. $NewInstall = true;
  89. $Class = SYSOP;
  90. $Enabled = '1';
  91. } else {
  92. $NewInstall = false;
  93. $Class = USER;
  94. $Enabled = '0';
  95. }
  96. $IPcc = Tools::geoip($_SERVER['REMOTE_ADDR']);
  97. $DB->query("
  98. INSERT INTO users_main
  99. (Username, Email, PassHash, torrent_pass, IP, PermissionID, Enabled, Invites, Uploaded, ipcc)
  100. VALUES
  101. ('".db_string(trim($_POST['username']))."', '".DBCrypt::encrypt($_POST['email'])."', '".db_string(Users::make_sec_hash($_POST['password']))."', '".db_string($torrent_pass)."', '".DBCrypt::encrypt($_SERVER['REMOTE_ADDR'])."', '$Class', '$Enabled', '".STARTING_INVITES."', '524288000', '$IPcc')");
  102. $UserID = $DB->inserted_id();
  103. // User created, delete invite. If things break after this point, then it's better to have a broken account to fix than a 'free' invite floating around that can be reused
  104. $DB->query("
  105. DELETE FROM invites
  106. WHERE InviteKey = '".db_string($_REQUEST['invite'])."'");
  107. $DB->query("
  108. SELECT ID
  109. FROM stylesheets
  110. WHERE `Default` = '1'");
  111. list($StyleID) = $DB->next_record();
  112. $AuthKey = Users::make_secret();
  113. if ($InviteReason !== '') {
  114. $InviteReason = db_string(sqltime()." - $InviteReason");
  115. }
  116. $DB->query("
  117. INSERT INTO users_info
  118. (UserID, StyleID, AuthKey, Inviter, JoinDate, AdminComment)
  119. VALUES
  120. ('$UserID', '$StyleID', '".db_string($AuthKey)."', '$InviterID', '".sqltime()."', '$InviteReason')");
  121. $DB->query("
  122. INSERT INTO users_history_ips
  123. (UserID, IP, StartTime)
  124. VALUES
  125. ('$UserID', '".DBCrypt::encrypt($_SERVER['REMOTE_ADDR'])."', '".sqltime()."')");
  126. $DB->query("
  127. INSERT INTO users_notifications_settings
  128. (UserID)
  129. VALUES
  130. ('$UserID')");
  131. $DB->query("
  132. INSERT INTO users_history_emails
  133. (UserID, Email, Time, IP)
  134. VALUES
  135. ('$UserID', '".DBCrypt::encrypt($_REQUEST['email'])."', '0000-00-00 00:00:00', '".DBCrypt::encrypt($_SERVER['REMOTE_ADDR'])."')");
  136. if ($_REQUEST['email'] != $InviteEmail) {
  137. $DB->query("
  138. INSERT INTO users_history_emails
  139. (UserID, Email, Time, IP)
  140. VALUES
  141. ('$UserID', '".DBCrypt::encrypt($InviteEmail)."', '".sqltime()."', '".DBCrypt::encrypt($_SERVER['REMOTE_ADDR'])."')");
  142. }
  143. // Manage invite trees, delete invite
  144. if ($InviterID !== null) {
  145. $DB->query("
  146. SELECT TreePosition, TreeID, TreeLevel
  147. FROM invite_tree
  148. WHERE UserID = '$InviterID'");
  149. list($InviterTreePosition, $TreeID, $TreeLevel) = $DB->next_record();
  150. // If the inviter doesn't have an invite tree
  151. // Note: This should never happen unless you've transferred from another database, like What.CD did
  152. if (!$DB->has_results()) {
  153. $DB->query("
  154. SELECT MAX(TreeID) + 1
  155. FROM invite_tree");
  156. list($TreeID) = $DB->next_record();
  157. $DB->query("
  158. INSERT INTO invite_tree
  159. (UserID, InviterID, TreePosition, TreeID, TreeLevel)
  160. VALUES ('$InviterID', '0', '1', '$TreeID', '1')");
  161. $TreePosition = 2;
  162. $TreeLevel = 2;
  163. } else {
  164. $DB->query("
  165. SELECT TreePosition
  166. FROM invite_tree
  167. WHERE TreePosition > '$InviterTreePosition'
  168. AND TreeLevel <= '$TreeLevel'
  169. AND TreeID = '$TreeID'
  170. ORDER BY TreePosition
  171. LIMIT 1");
  172. list($TreePosition) = $DB->next_record();
  173. if ($TreePosition) {
  174. $DB->query("
  175. UPDATE invite_tree
  176. SET TreePosition = TreePosition + 1
  177. WHERE TreeID = '$TreeID'
  178. AND TreePosition >= '$TreePosition'");
  179. } else {
  180. $DB->query("
  181. SELECT TreePosition + 1
  182. FROM invite_tree
  183. WHERE TreeID = '$TreeID'
  184. ORDER BY TreePosition DESC
  185. LIMIT 1");
  186. list($TreePosition) = $DB->next_record();
  187. }
  188. $TreeLevel++;
  189. // Create invite tree record
  190. $DB->query("
  191. INSERT INTO invite_tree
  192. (UserID, InviterID, TreePosition, TreeID, TreeLevel)
  193. VALUES
  194. ('$UserID', '$InviterID', '$TreePosition', '$TreeID', '$TreeLevel')");
  195. }
  196. } else { // No inviter (open registration)
  197. $DB->query("
  198. SELECT MAX(TreeID)
  199. FROM invite_tree");
  200. list($TreeID) = $DB->next_record();
  201. $TreeID++;
  202. $InviterID = 0;
  203. $TreePosition = 1;
  204. $TreeLevel = 1;
  205. }
  206. include(SERVER_ROOT.'/classes/templates.class.php');
  207. $TPL = NEW TEMPLATE;
  208. $TPL->open(SERVER_ROOT.'/templates/new_registration.tpl');
  209. $TPL->set('Username', $_REQUEST['username']);
  210. $TPL->set('TorrentKey', $torrent_pass);
  211. $TPL->set('SITE_NAME', SITE_NAME);
  212. $TPL->set('SITE_URL', SITE_URL);
  213. Misc::send_email($_REQUEST['email'], 'New account confirmation at '.SITE_NAME, $TPL->get(), 'noreply');
  214. Tracker::update_tracker('add_user', array('id' => $UserID, 'passkey' => $torrent_pass));
  215. $Sent = 1;
  216. }
  217. } elseif ($_GET['invite']) {
  218. // If they haven't submitted the form, check to see if their invite is good
  219. $DB->query("
  220. SELECT InviteKey
  221. FROM invites
  222. WHERE InviteKey = '".db_string($_GET['invite'])."'");
  223. if (!$DB->has_results()) {
  224. error('Invite not found!');
  225. }
  226. }
  227. include('step1.php');
  228. } elseif (!OPEN_REGISTRATION) {
  229. if (isset($_GET['welcome'])) {
  230. include('code.php');
  231. } else {
  232. include('closed.php');
  233. }
  234. }
  235. ?>