BioTorrents.de’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.

take_edit.php 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <?php
  2. #declare(strict_types=1);
  3. /**
  4. * START CHECKS
  5. */
  6. authorize();
  7. $UserID = (int) $_REQUEST['userid'];
  8. Security::checkInt($UserID);
  9. // For this entire page, we should generally be using $UserID not $LoggedUser['ID'] and $U[] not $LoggedUser[]
  10. $U = Users::user_info($UserID);
  11. if (!$U) {
  12. error(404);
  13. }
  14. $Permissions = Permissions::get_permissions($U['PermissionID']);
  15. if ((int) $UserID !== $LoggedUser['ID'] && !check_perms('users_edit_profiles', $Permissions['Class'])) {
  16. send_irc(ADMIN_CHAN, 'User '.$LoggedUser['Username'].' ('.site_url().'user.php?id='.$LoggedUser['ID'].') just tried to edit the profile of '.site_url().'user.php?id='.$_REQUEST['userid']);
  17. error(403);
  18. }
  19. $Val->SetFields('stylesheet', 1, "number", "You forgot to select a stylesheet.");
  20. $Val->SetFields('styleurl', 0, "regex", "You did not enter a valid stylesheet URL.", ['regex' => '/^'.CSS_REGEX.'$/i']);
  21. // The next two are commented out because the drop-down menus were replaced with a check box and radio buttons
  22. //$Val->SetFields('disablegrouping', 0, "number", "You forgot to select your torrent grouping option.");
  23. //$Val->SetFields('torrentgrouping', 0, "number", "You forgot to select your torrent grouping option.");
  24. $Val->SetFields('postsperpage', 1, "number", "You forgot to select your posts per page option.", ['inarray' => [25, 50, 100]]);
  25. //$Val->SetFields('hidecollage', 1, "number", "You forgot to select your collage option.", ['minlength' => 0, 'maxlength' => 1]);
  26. $Val->SetFields('collagecovers', 1, "number", "You forgot to select your collage option.");
  27. $Val->SetFields('avatar', 0, "regex", "You did not enter a valid avatar URL.", ['regex' => "/^".IMAGE_REGEX."$/i"]);
  28. $Val->SetFields('email', 1, "email", "You did not enter a valid email address.");
  29. $Val->SetFields('irckey', 0, "string", "You did not enter a valid IRC key. An IRC key must be between 6 and 32 characters long.", ['minlength' => 6, 'maxlength' => 32]);
  30. $Val->SetFields('new_pass_1', 0, "regex", "You did not enter a valid password. A valid password is 15 characters or longer.", ['regex' => '/(?=^.{15,}$).*$/']);
  31. #$Val->SetFields('new_pass_1', 0, "regex", "You did not enter a valid password. A valid password is 6 characters or longer.", ['regex' => '/(?=^.{6,}$).*$/']);
  32. $Val->SetFields('new_pass_2', 1, "compare", "Your passwords do not match.", ['comparefield' => 'new_pass_1']);
  33. /*
  34. if (check_perms('site_advanced_search')) {
  35. $Val->SetFields('searchtype', 1, "number", "You forgot to select your default search preference.", ['minlength' => 0, 'maxlength' => 1]);
  36. }
  37. */
  38. $ValErr = $Val->ValidateForm($_POST);
  39. if ($ValErr) {
  40. error($ValErr);
  41. }
  42. if (!apcu_exists('DBKEY')) {
  43. error("Cannot edit profile until database fully decrypted");
  44. }
  45. /**
  46. * END CHECKS
  47. */
  48. // Begin building $Paranoia
  49. // Reduce the user's input paranoia until it becomes consistent
  50. if (isset($_POST['p_uniquegroups_l'])) {
  51. $_POST['p_uploads_l'] = 'on';
  52. $_POST['p_uploads_c'] = 'on';
  53. }
  54. if (isset($_POST['p_uploads_l'])) {
  55. $_POST['p_uniquegroups_l'] = 'on';
  56. $_POST['p_uniquegroups_c'] = 'on';
  57. $_POST['p_perfectflacs_l'] = 'on';
  58. $_POST['p_perfectflacs_c'] = 'on';
  59. $_POST['p_artistsadded'] = 'on';
  60. }
  61. if (isset($_POST['p_collagecontribs_l'])) {
  62. $_POST['p_collages_l'] = 'on';
  63. $_POST['p_collages_c'] = 'on';
  64. }
  65. if (isset($_POST['p_snatched_c']) && isset($_POST['p_seeding_c']) && isset($_POST['p_downloaded'])) {
  66. $_POST['p_requiredratio'] = 'on';
  67. }
  68. // if showing exactly 2 of stats, show all 3 of stats
  69. $StatsShown = 0;
  70. $Stats = ['downloaded', 'uploaded', 'ratio'];
  71. foreach ($Stats as $S) {
  72. if (isset($_POST["p_$S"])) {
  73. $StatsShown++;
  74. }
  75. }
  76. if ($StatsShown === 2) {
  77. foreach ($Stats as $S) {
  78. $_POST["p_$S"] = 'on';
  79. }
  80. }
  81. $Paranoia = [];
  82. $Checkboxes = ['downloaded', 'uploaded', 'ratio', 'lastseen', 'requiredratio', 'invitedcount', 'artistsadded', 'notifications'];
  83. foreach ($Checkboxes as $C) {
  84. if (!isset($_POST["p_$C"])) {
  85. $Paranoia[] = $C;
  86. }
  87. }
  88. $SimpleSelects = ['torrentcomments', 'collages', 'collagecontribs', 'uploads', 'uniquegroups', 'perfectflacs', 'seeding', 'leeching', 'snatched'];
  89. foreach ($SimpleSelects as $S) {
  90. if (!isset($_POST["p_$S".'_c']) && !isset($_POST["p_$S".'_l'])) {
  91. // Very paranoid - don't show count or list
  92. $Paranoia[] = "$S+";
  93. } elseif (!isset($_POST["p_$S".'_l'])) {
  94. // A little paranoid - show count, don't show list
  95. $Paranoia[] = $S;
  96. }
  97. }
  98. $Bounties = ['requestsfilled', 'requestsvoted'];
  99. foreach ($Bounties as $B) {
  100. if (isset($_POST["p_$B".'_list'])) {
  101. $_POST["p_$B".'_count'] = 'on';
  102. $_POST["p_$B".'_bounty'] = 'on';
  103. }
  104. if (!isset($_POST["p_$B".'_list'])) {
  105. $Paranoia[] = $B.'_list';
  106. }
  107. if (!isset($_POST["p_$B".'_count'])) {
  108. $Paranoia[] = $B.'_count';
  109. }
  110. if (!isset($_POST["p_$B".'_bounty'])) {
  111. $Paranoia[] = $B.'_bounty';
  112. }
  113. }
  114. if (!isset($_POST['p_donor_heart'])) {
  115. $Paranoia[] = 'hide_donor_heart';
  116. }
  117. if (isset($_POST['p_donor_stats'])) {
  118. Donations::show_stats($UserID);
  119. } else {
  120. Donations::hide_stats($UserID);
  121. }
  122. // End building $Paranoia
  123. $DB->query("
  124. SELECT Email, PassHash, IRCKey
  125. FROM users_main
  126. WHERE ID = ?", $UserID);
  127. list($CurEmail, $CurPassHash, $CurIRCKey) = $DB->next_record();
  128. function require_password($Setting = false)
  129. {
  130. global $CurPassHash;
  131. if (empty($_POST['cur_pass'])) {
  132. error('A setting you changed requires you to enter your current password'.($Setting ? ' (Setting: '.$Setting.')' : ''));
  133. }
  134. if (!Users::check_password($_POST['cur_pass'], $CurPassHash)) {
  135. error('The password you entered was incorrect'.($Setting ? ' (Required by setting: '.$Setting.')' : ''));
  136. }
  137. }
  138. // Email change
  139. $CurEmail = Crypto::decrypt($CurEmail);
  140. if ($CurEmail !== $_POST['email']) {
  141. // Non-admins have to authenticate to change email
  142. if (!check_perms('users_edit_profiles')) {
  143. require_password("Change Email");
  144. }
  145. }
  146. if (!empty($_POST['new_pass_1']) && !empty($_POST['new_pass_2'])) {
  147. require_password("Change Password");
  148. $ResetPassword = true;
  149. }
  150. if ($CurIRCKey != $_POST['irckey']) {
  151. require_password("Change IRC Key");
  152. }
  153. if (isset($_POST['resetpasskey'])) {
  154. require_password("Reset Passkey");
  155. }
  156. if ($LoggedUser['DisableAvatar'] && $_POST['avatar'] != $U['Avatar']) {
  157. error('Your avatar privileges have been revoked.');
  158. }
  159. if (!empty($LoggedUser['DefaultSearch'])) {
  160. $Options['DefaultSearch'] = $LoggedUser['DefaultSearch'];
  161. }
  162. $Options['DisableGrouping2'] = (!empty($_POST['disablegrouping']) ? 0 : 1);
  163. $Options['TorrentGrouping'] = (!empty($_POST['torrentgrouping']) ? 1 : 0);
  164. $Options['PostsPerPage'] = (int)$_POST['postsperpage'];
  165. $Options['CollageCovers'] = (empty($_POST['collagecovers']) ? 0 : $_POST['collagecovers']);
  166. $Options['ShowTorFilter'] = (empty($_POST['showtfilter']) ? 0 : 1);
  167. $Options['ShowTags'] = (!empty($_POST['showtags']) ? 1 : 0);
  168. $Options['AutoSubscribe'] = (!empty($_POST['autosubscribe']) ? 1 : 0);
  169. $Options['DisableSmileys'] = (!empty($_POST['disablesmileys']) ? 1 : 0);
  170. $Options['AutoloadCommStats'] = (check_perms('users_mod') && !empty($_POST['autoload_comm_stats']) ? 1 : 0);
  171. $Options['DisableAvatars'] = db_string($_POST['disableavatars']);
  172. $Options['Identicons'] = (!empty($_POST['identicons']) ? (int)$_POST['identicons'] : 0);
  173. $Options['DisablePMAvatars'] = (!empty($_POST['disablepmavatars']) ? 1 : 0);
  174. $Options['NotifyOnQuote'] = (!empty($_POST['notifications_Quotes_popup']) ? 1 : 0);
  175. $Options['ListUnreadPMsFirst'] = (!empty($_POST['list_unread_pms_first']) ? 1 : 0);
  176. $Options['ShowSnatched'] = (!empty($_POST['showsnatched']) ? 1 : 0);
  177. $Options['DisableAutoSave'] = (!empty($_POST['disableautosave']) ? 1 : 0);
  178. $Options['CoverArt'] = (int)!empty($_POST['coverart']);
  179. $Options['ShowExtraCovers'] = (int)!empty($_POST['show_extra_covers']);
  180. $Options['HideLolicon'] = (int)!empty($_POST['hide_lolicon']);
  181. $Options['HideScat'] = (int)!empty($_POST['hide_scat']);
  182. $Options['HideSnuff'] = (int)!empty($_POST['hide_snuff']);
  183. $Options['AutoComplete'] = (int)$_POST['autocomplete'];
  184. $Options['StyleAdditions'] = $_POST['style_additions'] ?? [];
  185. if (isset($LoggedUser['DisableFreeTorrentTop10'])) {
  186. $Options['DisableFreeTorrentTop10'] = $LoggedUser['DisableFreeTorrentTop10'];
  187. }
  188. if (!empty($_POST['sorthide'])) {
  189. $JSON = json_decode($_POST['sorthide']);
  190. foreach ($JSON as $J) {
  191. $E = explode('_', $J);
  192. $Options['SortHide'][$E[0]] = $E[1];
  193. }
  194. } else {
  195. $Options['SortHide'] = [];
  196. }
  197. if (check_perms('site_advanced_search')) {
  198. $Options['SearchType'] = $_POST['searchtype'];
  199. } else {
  200. unset($Options['SearchType']);
  201. }
  202. // todo: Remove the following after a significant amount of time
  203. unset($Options['ArtistNoRedirect']);
  204. unset($Options['ShowQueryList']);
  205. unset($Options['ShowCacheList']);
  206. $UnseededAlerts = isset($_POST['unseededalerts']) ? 1 : 0;
  207. Donations::update_rewards($UserID);
  208. NotificationsManager::save_settings($UserID);
  209. // Begin Badge settings
  210. if (!empty($_POST['badges'])) {
  211. $BadgeIDs = array_slice($_POST['badges'], 0, 5);
  212. } else {
  213. $BadgeIDs = [];
  214. }
  215. $NewBadges = [];
  216. $BadgesChanged = false;
  217. $Badges = Users::user_info($UserID)['Badges'];
  218. foreach ($Badges as $BadgeID => $OldDisplayed) {
  219. if (in_array($BadgeID, $BadgeIDs)) { // Is the current badge in the list of badges the user wants to display?
  220. $Displayed = true;
  221. $DisplayedBadgeIDs[] = $BadgeID;
  222. if ($OldDisplayed == 0) { // The user wants to display a badge that wasn't displayed before
  223. $BadgesChanged = true;
  224. }
  225. } else { // The user no longer wants to display a badge that was displayed before
  226. $Displayed = false;
  227. $BadgesChanged = true;
  228. }
  229. $NewBadges[$BadgeID] = $Displayed?'1':'0';
  230. }
  231. // End Badge settings
  232. $Cache->begin_transaction("user_info_$UserID");
  233. $Cache->update_row(false, [
  234. 'Avatar' => display_str($_POST['avatar']),
  235. 'Paranoia' => $Paranoia,
  236. 'Badges' => $NewBadges
  237. ]);
  238. $Cache->commit_transaction(0);
  239. $Cache->begin_transaction("user_info_heavy_$UserID");
  240. $Cache->update_row(false, [
  241. 'StyleID' => $_POST['stylesheet'],
  242. 'StyleURL' => display_str($_POST['styleurl'])
  243. ]);
  244. $Cache->update_row(false, $Options);
  245. $Cache->commit_transaction(0);
  246. $SQL = "
  247. UPDATE users_main AS m
  248. JOIN users_info AS i ON m.ID = i.UserID
  249. SET
  250. i.StyleID = '".db_string($_POST['stylesheet'])."',
  251. i.StyleURL = '".db_string($_POST['styleurl'])."',
  252. i.Avatar = '".db_string($_POST['avatar'])."',
  253. i.SiteOptions = '".db_string(json_encode($Options))."',
  254. i.NotifyOnQuote = '".db_string($Options['NotifyOnQuote'])."',
  255. i.Info = '".db_string($_POST['info'])."',
  256. i.InfoTitle = '".db_string($_POST['profile_title'])."',
  257. i.UnseededAlerts = '$UnseededAlerts',
  258. m.Email = '".Crypto::encrypt($_POST['email'])."',
  259. m.IRCKey = '".db_string($_POST['irckey'])."',
  260. m.Paranoia = '".db_string(json_encode($Paranoia))."'";
  261. if ($ResetPassword) {
  262. $ChangerIP = Crypto::encrypt($LoggedUser['IP']);
  263. $PassHash = Users::make_sec_hash($_POST['new_pass_1']);
  264. $SQL.= ",m.PassHash = '".db_string($PassHash)."'";
  265. }
  266. if (isset($_POST['resetpasskey'])) {
  267. $UserInfo = Users::user_heavy_info($UserID);
  268. $OldPassKey = $UserInfo['torrent_pass'];
  269. $NewPassKey = Users::make_secret();
  270. $ChangerIP = Crypto::encrypt($LoggedUser['IP']);
  271. $SQL .= ",m.torrent_pass = '$NewPassKey'";
  272. $Cache->begin_transaction("user_info_heavy_$UserID");
  273. $Cache->update_row(false, ['torrent_pass' => $NewPassKey]);
  274. $Cache->commit_transaction(0);
  275. $Cache->delete_value("user_$OldPassKey");
  276. Tracker::update_tracker('change_passkey', ['oldpasskey' => $OldPassKey, 'newpasskey' => $NewPassKey]);
  277. }
  278. $SQL .= "WHERE m.ID = '".db_string($UserID)."'";
  279. $DB->query($SQL);
  280. if ($BadgesChanged) {
  281. $DB->query("
  282. UPDATE users_badges
  283. SET Displayed = 0
  284. WHERE UserID = ?", $UserID);
  285. if (!empty($BadgeIDs)) {
  286. $DB->query("
  287. UPDATE users_badges
  288. SET Displayed = 1
  289. WHERE UserID = $UserID
  290. AND BadgeID IN (".db_string(implode(',', $BadgeIDs)).")");
  291. }
  292. }
  293. if ($ResetPassword) {
  294. logout_all_sessions();
  295. }
  296. header("Location: user.php?action=edit&userid=$UserID");