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

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