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.

index.php 14KB

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