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 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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."', '1073741824', '$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. // Award invite badge to inviter if they don't have it
  108. if (Badges::award_badge($InviterID, 136)) {
  109. Misc::send_pm($InviterID, 0, 'You have received a badge!', "You have received a badge for inviting a user to the site.\n\nIt can be enabled from your user settings.");
  110. $Cache->delete_value('user_badges_'.$InviterID);
  111. }
  112. $DB->query("
  113. SELECT ID
  114. FROM stylesheets
  115. WHERE `Default` = '1'");
  116. list($StyleID) = $DB->next_record();
  117. $AuthKey = Users::make_secret();
  118. if ($InviteReason !== '') {
  119. $InviteReason = db_string(sqltime()." - $InviteReason");
  120. }
  121. $DB->query("
  122. INSERT INTO users_info
  123. (UserID, StyleID, AuthKey, Inviter, JoinDate, AdminComment)
  124. VALUES
  125. ('$UserID', '$StyleID', '".db_string($AuthKey)."', '$InviterID', '".sqltime()."', '$InviteReason')");
  126. $DB->query("
  127. INSERT INTO users_history_ips
  128. (UserID, IP, StartTime)
  129. VALUES
  130. ('$UserID', '".DBCrypt::encrypt($_SERVER['REMOTE_ADDR'])."', '".sqltime()."')");
  131. $DB->query("
  132. INSERT INTO users_notifications_settings
  133. (UserID)
  134. VALUES
  135. ('$UserID')");
  136. $DB->query("
  137. INSERT INTO users_history_emails
  138. (UserID, Email, Time, IP)
  139. VALUES
  140. ('$UserID', '".DBCrypt::encrypt($_REQUEST['email'])."', '0000-00-00 00:00:00', '".DBCrypt::encrypt($_SERVER['REMOTE_ADDR'])."')");
  141. if ($_REQUEST['email'] != $InviteEmail) {
  142. $DB->query("
  143. INSERT INTO users_history_emails
  144. (UserID, Email, Time, IP)
  145. VALUES
  146. ('$UserID', '".DBCrypt::encrypt($InviteEmail)."', '".sqltime()."', '".DBCrypt::encrypt($_SERVER['REMOTE_ADDR'])."')");
  147. }
  148. // Manage invite trees, delete invite
  149. if ($InviterID !== null) {
  150. $DB->query("
  151. SELECT TreePosition, TreeID, TreeLevel
  152. FROM invite_tree
  153. WHERE UserID = '$InviterID'");
  154. list($InviterTreePosition, $TreeID, $TreeLevel) = $DB->next_record();
  155. // If the inviter doesn't have an invite tree
  156. // Note: This should never happen unless you've transferred from another database, like What.CD did
  157. if (!$DB->has_results()) {
  158. $DB->query("
  159. SELECT MAX(TreeID) + 1
  160. FROM invite_tree");
  161. list($TreeID) = $DB->next_record();
  162. $DB->query("
  163. INSERT INTO invite_tree
  164. (UserID, InviterID, TreePosition, TreeID, TreeLevel)
  165. VALUES ('$InviterID', '0', '1', '$TreeID', '1')");
  166. $TreePosition = 2;
  167. $TreeLevel = 2;
  168. } else {
  169. $DB->query("
  170. SELECT TreePosition
  171. FROM invite_tree
  172. WHERE TreePosition > '$InviterTreePosition'
  173. AND TreeLevel <= '$TreeLevel'
  174. AND TreeID = '$TreeID'
  175. ORDER BY TreePosition
  176. LIMIT 1");
  177. list($TreePosition) = $DB->next_record();
  178. if ($TreePosition) {
  179. $DB->query("
  180. UPDATE invite_tree
  181. SET TreePosition = TreePosition + 1
  182. WHERE TreeID = '$TreeID'
  183. AND TreePosition >= '$TreePosition'");
  184. } else {
  185. $DB->query("
  186. SELECT TreePosition + 1
  187. FROM invite_tree
  188. WHERE TreeID = '$TreeID'
  189. ORDER BY TreePosition DESC
  190. LIMIT 1");
  191. list($TreePosition) = $DB->next_record();
  192. }
  193. $TreeLevel++;
  194. // Create invite tree record
  195. $DB->query("
  196. INSERT INTO invite_tree
  197. (UserID, InviterID, TreePosition, TreeID, TreeLevel)
  198. VALUES
  199. ('$UserID', '$InviterID', '$TreePosition', '$TreeID', '$TreeLevel')");
  200. }
  201. } else { // No inviter (open registration)
  202. $DB->query("
  203. SELECT MAX(TreeID)
  204. FROM invite_tree");
  205. list($TreeID) = $DB->next_record();
  206. $TreeID++;
  207. $InviterID = 0;
  208. $TreePosition = 1;
  209. $TreeLevel = 1;
  210. }
  211. include(SERVER_ROOT.'/classes/templates.class.php');
  212. $TPL = NEW TEMPLATE;
  213. $TPL->open(SERVER_ROOT.'/templates/new_registration.tpl');
  214. $TPL->set('Username', $_REQUEST['username']);
  215. $TPL->set('TorrentKey', $torrent_pass);
  216. $TPL->set('SITE_NAME', SITE_NAME);
  217. $TPL->set('SITE_DOMAIN', SITE_DOMAIN);
  218. Misc::send_email($_REQUEST['email'], 'New account confirmation at '.SITE_NAME, $TPL->get(), 'noreply');
  219. Tracker::update_tracker('add_user', array('id' => $UserID, 'passkey' => $torrent_pass));
  220. $Sent = 1;
  221. }
  222. } elseif ($_GET['invite']) {
  223. // If they haven't submitted the form, check to see if their invite is good
  224. $DB->query("
  225. SELECT InviteKey
  226. FROM invites
  227. WHERE InviteKey = '".db_string($_GET['invite'])."'");
  228. if (!$DB->has_results()) {
  229. error('Invite not found!');
  230. }
  231. }
  232. include('step1.php');
  233. } elseif (!OPEN_REGISTRATION) {
  234. if (isset($_GET['welcome'])) {
  235. include('code.php');
  236. } else {
  237. include('closed.php');
  238. }
  239. }
  240. ?>