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

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