Contributing back some bug fixes
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 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. <?
  2. /*****************************************************************
  3. Tools switch center
  4. This page acts as a switch for the tools pages.
  5. *****************************************************************/
  6. if (isset($argv[1])) {
  7. $_REQUEST['action'] = $argv[1];
  8. } else {
  9. if (empty($_REQUEST['action']) || ($_REQUEST['action'] != 'public_sandbox' && $_REQUEST['action'] != 'ocelot')) {
  10. // if set, do not enforce login so we can set the encryption key w/o an account
  11. if (!FEATURE_SET_ENC_KEY_PUBLIC) {
  12. enforce_login();
  13. }
  14. }
  15. }
  16. if (!isset($_REQUEST['action'])) {
  17. include(SERVER_ROOT.'/sections/tools/tools.php');
  18. die();
  19. }
  20. if (substr($_REQUEST['action'], 0, 7) == 'sandbox' && !isset($argv[1])) {
  21. if (!check_perms('site_debug')) {
  22. error(403);
  23. }
  24. }
  25. if (substr($_REQUEST['action'], 0, 12) == 'update_geoip' && !isset($argv[1])) {
  26. if (!check_perms('site_debug')) {
  27. error(403);
  28. }
  29. }
  30. if (substr($_REQUEST['action'],0,16) == 'rerender_gallery' && !isset($argv[1])) {
  31. if (!check_perms('site_debug')) {
  32. error(403);
  33. }
  34. }
  35. include(SERVER_ROOT.'/classes/validate.class.php');
  36. $Val = new VALIDATE;
  37. include(SERVER_ROOT.'/classes/feed.class.php');
  38. $Feed = new FEED;
  39. switch ($_REQUEST['action']) {
  40. case 'phpinfo':
  41. if (!check_perms('site_debug')) {
  42. error(403);
  43. }
  44. phpinfo();
  45. break;
  46. //Services
  47. case 'get_host':
  48. include(SERVER_ROOT.'/sections/tools/services/get_host.php');
  49. break;
  50. case 'get_cc':
  51. include(SERVER_ROOT.'/sections/tools/services/get_cc.php');
  52. break;
  53. //Managers
  54. case 'forum':
  55. include(SERVER_ROOT.'/sections/tools/managers/forum_list.php');
  56. break;
  57. case 'forum_alter':
  58. include(SERVER_ROOT.'/sections/tools/managers/forum_alter.php');
  59. break;
  60. case 'whitelist':
  61. include(SERVER_ROOT.'/sections/tools/managers/whitelist_list.php');
  62. break;
  63. case 'whitelist_alter':
  64. include(SERVER_ROOT.'/sections/tools/managers/whitelist_alter.php');
  65. break;
  66. case 'enable_requests':
  67. include(SERVER_ROOT.'/sections/tools/managers/enable_requests.php');
  68. break;
  69. case 'expunge_requests':
  70. include(SERVER_ROOT.'/sections/tools/managers/expunge_requests.php');
  71. break;
  72. case 'ajax_take_enable_request':
  73. if (FEATURE_EMAIL_REENABLE) {
  74. include(SERVER_ROOT.'/sections/tools/managers/ajax_take_enable_request.php');
  75. } else {
  76. // Prevent post requests to the ajax page
  77. header("Location: tools.php");
  78. die();
  79. }
  80. break;
  81. case 'login_watch':
  82. include(SERVER_ROOT.'/sections/tools/managers/login_watch.php');
  83. break;
  84. case 'email_blacklist':
  85. include(SERVER_ROOT.'/sections/tools/managers/email_blacklist.php');
  86. break;
  87. case 'email_blacklist_alter':
  88. include(SERVER_ROOT.'/sections/tools/managers/email_blacklist_alter.php');
  89. break;
  90. case 'email_blacklist_search':
  91. include(SERVER_ROOT.'/sections/tools/managers/email_blacklist_search.php');
  92. break;
  93. case 'dnu':
  94. include(SERVER_ROOT.'/sections/tools/managers/dnu_list.php');
  95. break;
  96. case 'dnu_alter':
  97. include(SERVER_ROOT.'/sections/tools/managers/dnu_alter.php');
  98. break;
  99. case 'editnews':
  100. case 'news':
  101. include(SERVER_ROOT.'/sections/tools/managers/news.php');
  102. break;
  103. case 'edit_tags':
  104. include(SERVER_ROOT.'/sections/tools/misc/tags.php');
  105. break;
  106. case 'takeeditnews':
  107. if (!check_perms('admin_manage_news')) {
  108. error(403);
  109. }
  110. if (is_number($_POST['newsid'])) {
  111. $DB->query("
  112. UPDATE news
  113. SET Title = '".db_string($_POST['title'])."',
  114. Body = '".db_string($_POST['body'])."'
  115. WHERE ID = '".db_string($_POST['newsid'])."'");
  116. $Cache->delete_value('news');
  117. $Cache->delete_value('feed_news');
  118. }
  119. header('Location: index.php');
  120. break;
  121. case 'deletenews':
  122. if (!check_perms('admin_manage_news')) {
  123. error(403);
  124. }
  125. if (is_number($_GET['id'])) {
  126. authorize();
  127. $DB->query("
  128. DELETE FROM news
  129. WHERE ID = '".db_string($_GET['id'])."'");
  130. $Cache->delete_value('news');
  131. $Cache->delete_value('feed_news');
  132. // Deleting latest news
  133. $LatestNews = $Cache->get_value('news_latest_id');
  134. if ($LatestNews !== false && $LatestNews == $_GET['id']) {
  135. $Cache->delete_value('news_latest_id');
  136. $Cache->delete_value('news_latest_title');
  137. }
  138. }
  139. header('Location: index.php');
  140. break;
  141. case 'takenewnews':
  142. if (!check_perms('admin_manage_news')) {
  143. error(403);
  144. }
  145. $DB->query("
  146. INSERT INTO news (UserID, Title, Body, Time)
  147. VALUES ('$LoggedUser[ID]', '".db_string($_POST['title'])."', '".db_string($_POST['body'])."', NOW())");
  148. $Cache->delete_value('news_latest_id');
  149. $Cache->delete_value('news_latest_title');
  150. $Cache->delete_value('news');
  151. header('Location: index.php');
  152. break;
  153. case 'tokens':
  154. include(SERVER_ROOT.'/sections/tools/managers/tokens.php');
  155. break;
  156. case 'multiple_freeleech':
  157. include(SERVER_ROOT.'/sections/tools/managers/multiple_freeleech.php');
  158. break;
  159. case 'ocelot':
  160. include(SERVER_ROOT.'/sections/tools/managers/ocelot.php');
  161. break;
  162. case 'ocelot_info':
  163. include(SERVER_ROOT.'/sections/tools/data/ocelot_info.php');
  164. break;
  165. case 'official_tags':
  166. include(SERVER_ROOT.'/sections/tools/managers/official_tags.php');
  167. break;
  168. case 'freeleech':
  169. include(SERVER_ROOT.'/sections/tools/managers/sitewide_freeleech.php');
  170. break;
  171. case 'tag_aliases':
  172. include(SERVER_ROOT.'/sections/tools/managers/tag_aliases.php');
  173. break;
  174. case 'label_aliases':
  175. include(SERVER_ROOT.'/sections/tools/managers/label_aliases.php');
  176. break;
  177. case 'change_log':
  178. include(SERVER_ROOT.'/sections/tools/managers/change_log.php');
  179. break;
  180. case 'global_notification':
  181. include(SERVER_ROOT.'/sections/tools/managers/global_notification.php');
  182. break;
  183. case 'take_global_notification':
  184. include(SERVER_ROOT.'/sections/tools/managers/take_global_notification.php');
  185. break;
  186. case 'permissions':
  187. if (!check_perms('admin_manage_permissions')) {
  188. error(403);
  189. }
  190. if (!empty($_REQUEST['id'])) {
  191. $Val->SetFields('name', true, 'string', 'You did not enter a valid name for this permission set.');
  192. $Val->SetFields('level', true, 'number', 'You did not enter a valid level for this permission set.');
  193. $Val->SetFields('maxcollages', true, 'number', 'You did not enter a valid number of personal collages.');
  194. //$Val->SetFields('test', true, 'number', 'You did not enter a valid level for this permission set.');
  195. if (is_numeric($_REQUEST['id'])) {
  196. $DB->query("
  197. SELECT p.ID, p.Name, p.Abbreviation, p.Level, p.Secondary, p.PermittedForums, p.Values, p.DisplayStaff, COUNT(u.ID)
  198. FROM permissions AS p
  199. LEFT JOIN users_main AS u ON u.PermissionID = p.ID
  200. WHERE p.ID = '".db_string($_REQUEST['id'])."'
  201. GROUP BY p.ID");
  202. list($ID, $Name, $Abbreviation, $Level, $Secondary, $Forums, $Values, $DisplayStaff, $UserCount) = $DB->next_record(MYSQLI_NUM, array(6));
  203. if ($Level > $LoggedUser['EffectiveClass'] || (isset($_REQUEST['level']) && $_REQUEST['level'] > $LoggedUser['EffectiveClass'])) {
  204. error(403);
  205. }
  206. $Values = unserialize($Values);
  207. }
  208. if (!empty($_POST['submit'])) {
  209. $Err = $Val->ValidateForm($_POST);
  210. if (!is_numeric($_REQUEST['id'])) {
  211. $DB->query("
  212. SELECT ID
  213. FROM permissions
  214. WHERE Level = '".db_string($_REQUEST['level'])."'");
  215. list($DupeCheck)=$DB->next_record();
  216. if ($DupeCheck) {
  217. $Err = 'There is already a permission class with that level.';
  218. }
  219. }
  220. $Values = [];
  221. foreach ($_REQUEST as $Key => $Perms) {
  222. if (substr($Key, 0, 5) == 'perm_') {
  223. $Values[substr($Key, 5)] = (int)$Perms;
  224. }
  225. }
  226. $Name = $_REQUEST['name'];
  227. $Level = $_REQUEST['level'];
  228. $Abbreviation = $_REQUEST['abbreviation'];
  229. $Secondary = empty($_REQUEST['secondary']) ? 0 : 1;
  230. $Forums = $_REQUEST['forums'];
  231. $DisplayStaff = isset($_REQUEST['displaystaff']) ? $_REQUEST['displaystaff']: 0;
  232. $Values['MaxCollages'] = $_REQUEST['maxcollages'];
  233. if (!$Err) {
  234. if (!is_numeric($_REQUEST['id'])) {
  235. $DB->query("
  236. INSERT INTO permissions (Level, Name, Abbreviation, Secondary, PermittedForums, `Values`, DisplayStaff)
  237. VALUES ('".db_string($Level)."',
  238. '".db_string($Name)."',
  239. '".db_string($Abbreviation)."',
  240. $Secondary,
  241. '".db_string($Forums)."',
  242. '".db_string(serialize($Values))."',
  243. '".db_string($DisplayStaff)."')");
  244. } else {
  245. $DB->query("
  246. UPDATE permissions
  247. SET Level = '".db_string($Level)."',
  248. Name = '".db_string($Name)."',
  249. Abbreviation = '".db_string($Abbreviation)."',
  250. Secondary = $Secondary,
  251. PermittedForums = '".db_string($Forums)."',
  252. `Values` = '".db_string(serialize($Values))."',
  253. DisplayStaff = '".db_string($DisplayStaff)."'
  254. WHERE ID = '".db_string($_REQUEST['id'])."'");
  255. $Cache->delete_value('perm_'.$_REQUEST['id']);
  256. if ($Secondary) {
  257. $DB->query("
  258. SELECT DISTINCT UserID
  259. FROM users_levels
  260. WHERE PermissionID = ".db_string($_REQUEST['id']));
  261. while (list($UserID) = $DB->next_record()) {
  262. $Cache->delete_value("user_info_heavy_$UserID");
  263. }
  264. }
  265. }
  266. $Cache->delete_value('classes');
  267. } else {
  268. error($Err);
  269. }
  270. }
  271. include(SERVER_ROOT.'/sections/tools/managers/permissions_alter.php');
  272. } else {
  273. if (!empty($_REQUEST['removeid'])) {
  274. $DB->query("
  275. DELETE FROM permissions
  276. WHERE ID = '".db_string($_REQUEST['removeid'])."'");
  277. $DB->query("
  278. SELECT UserID
  279. FROM users_levels
  280. WHERE PermissionID = '".db_string($_REQUEST['removeid'])."'");
  281. while (list($UserID) = $DB->next_record()) {
  282. $Cache->delete_value("user_info_$UserID");
  283. $Cache->delete_value("user_info_heavy_$UserID");
  284. }
  285. $DB->query("
  286. DELETE FROM users_levels
  287. WHERE PermissionID = '".db_string($_REQUEST['removeid'])."'");
  288. $DB->query("
  289. SELECT ID
  290. FROM users_main
  291. WHERE PermissionID = '".db_string($_REQUEST['removeid'])."'");
  292. while (list($UserID) = $DB->next_record()) {
  293. $Cache->delete_value("user_info_$UserID");
  294. $Cache->delete_value("user_info_heavy_$UserID");
  295. }
  296. $DB->query("
  297. UPDATE users_main
  298. SET PermissionID = '".USER."'
  299. WHERE PermissionID = '".db_string($_REQUEST['removeid'])."'");
  300. $Cache->delete_value('classes');
  301. }
  302. include(SERVER_ROOT.'/sections/tools/managers/permissions_list.php');
  303. }
  304. break;
  305. case 'ip_ban':
  306. //TODO: Clean up DB table ip_bans.
  307. include(SERVER_ROOT.'/sections/tools/managers/bans.php');
  308. break;
  309. case 'quick_ban':
  310. include(SERVER_ROOT.'/sections/tools/misc/quick_ban.php');
  311. break;
  312. //Data
  313. case 'registration_log':
  314. include(SERVER_ROOT.'/sections/tools/data/registration_log.php');
  315. break;
  316. case 'donation_log':
  317. include(SERVER_ROOT.'/sections/tools/finances/donation_log.php');
  318. break;
  319. case 'bitcoin_unproc':
  320. include(SERVER_ROOT.'/sections/tools/finances/bitcoin_unproc.php');
  321. break;
  322. case 'bitcoin_balance':
  323. include(SERVER_ROOT.'/sections/tools/finances/bitcoin_balance.php');
  324. break;
  325. case 'donor_rewards':
  326. include(SERVER_ROOT.'/sections/tools/finances/donor_rewards.php');
  327. break;
  328. case 'upscale_pool':
  329. include(SERVER_ROOT.'/sections/tools/data/upscale_pool.php');
  330. break;
  331. case 'invite_pool':
  332. include(SERVER_ROOT.'/sections/tools/data/invite_pool.php');
  333. break;
  334. case 'torrent_stats':
  335. include(SERVER_ROOT.'/sections/tools/data/torrent_stats.php');
  336. break;
  337. case 'user_flow':
  338. include(SERVER_ROOT.'/sections/tools/data/user_flow.php');
  339. break;
  340. case 'economic_stats':
  341. include(SERVER_ROOT.'/sections/tools/data/economic_stats.php');
  342. break;
  343. case 'service_stats':
  344. include(SERVER_ROOT.'/sections/tools/development/service_stats.php');
  345. break;
  346. case 'database_specifics':
  347. include(SERVER_ROOT.'/sections/tools/data/database_specifics.php');
  348. break;
  349. case 'special_users':
  350. include(SERVER_ROOT.'/sections/tools/data/special_users.php');
  351. break;
  352. case 'browser_support':
  353. include(SERVER_ROOT.'/sections/tools/data/browser_support.php');
  354. break;
  355. //END Data
  356. //Misc
  357. case 'update_geoip':
  358. include(SERVER_ROOT.'/sections/tools/development/update_geoip.php');
  359. break;
  360. case 'dupe_ips':
  361. include(SERVER_ROOT.'/sections/tools/misc/dupe_ip.php');
  362. break;
  363. case 'clear_cache':
  364. include(SERVER_ROOT.'/sections/tools/development/clear_cache.php');
  365. break;
  366. case 'create_user':
  367. include(SERVER_ROOT.'/sections/tools/misc/create_user.php');
  368. break;
  369. case 'manipulate_tree':
  370. include(SERVER_ROOT.'/sections/tools/misc/manipulate_tree.php');
  371. break;
  372. case 'misc_values':
  373. include(SERVER_ROOT.'/sections/tools/development/misc_values.php');
  374. break;
  375. case 'recommendations':
  376. include(SERVER_ROOT.'/sections/tools/misc/recommendations.php');
  377. break;
  378. case 'analysis':
  379. include(SERVER_ROOT.'/sections/tools/misc/analysis.php');
  380. break;
  381. case 'database_key':
  382. include(SERVER_ROOT.'/sections/tools/misc/database_key.php');
  383. break;
  384. case 'process_info':
  385. include(SERVER_ROOT.'/sections/tools/development/process_info.php');
  386. break;
  387. case 'rerender_gallery':
  388. include(SERVER_ROOT.'/sections/tools/development/rerender_gallery.php');
  389. break;
  390. case 'sandbox1':
  391. include(SERVER_ROOT.'/sections/tools/sandboxes/sandbox1.php');
  392. break;
  393. case 'sandbox2':
  394. include(SERVER_ROOT.'/sections/tools/sandboxes/sandbox2.php');
  395. break;
  396. case 'sandbox3':
  397. include(SERVER_ROOT.'/sections/tools/sandboxes/sandbox3.php');
  398. break;
  399. case 'public_sandbox':
  400. include(SERVER_ROOT.'/sections/tools/sandboxes/public_sandbox.php');
  401. break;
  402. case 'mod_sandbox':
  403. if (check_perms('users_mod')) {
  404. include(SERVER_ROOT.'/sections/tools/sandboxes/mod_sandbox.php');
  405. } else {
  406. error(403);
  407. }
  408. break;
  409. case 'bbcode_sandbox':
  410. include(SERVER_ROOT.'/sections/tools/sandboxes/bbcode_sandbox.php');
  411. break;
  412. case 'calendar':
  413. include(SERVER_ROOT.'/sections/tools/managers/calendar.php');
  414. break;
  415. case 'get_calendar_event':
  416. include(SERVER_ROOT.'/sections/tools/managers/ajax_get_calendar_event.php');
  417. break;
  418. case 'take_calendar_event':
  419. include(SERVER_ROOT.'/sections/tools/managers/ajax_take_calendar_event.php');
  420. break;
  421. case 'mass_pm':
  422. include(SERVER_ROOT.'/sections/tools/managers/mass_pm.php');
  423. break;
  424. case 'take_mass_pm':
  425. include(SERVER_ROOT.'/sections/tools/managers/take_mass_pm.php');
  426. break;
  427. default:
  428. include(SERVER_ROOT.'/sections/tools/tools.php');
  429. }
  430. ?>