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.

enable_requests.php 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. <?php
  2. if (!check_perms('users_mod')) {
  3. error(403);
  4. }
  5. if (!FEATURE_EMAIL_REENABLE) {
  6. // This feature is disabled
  7. header('Location: tools.php');
  8. error();
  9. }
  10. // Silence undefined variable warnings
  11. foreach (array('username', 'ip', 'submitted_between', 'submitted_between', 'submitted_timestamp1', 'submitted_timestamp2', 'handled_username', 'handled_between', 'handled_timestamp1', 'handled_timestamp2', 'outcome_search', 'order', 'way') as $S) {
  12. if (!isset($_GET[$S])) {
  13. $_GET[$S] = null;
  14. }
  15. }
  16. View::show_header('Enable Requests', 'enable_requests');
  17. // Pagination
  18. $RequestsPerPage = 25;
  19. list($Page, $Limit) = Format::page_limit($RequestsPerPage);
  20. // How can things be ordered?
  21. $OrderBys = array(
  22. 'submitted_timestamp' => 'uer.`Timestamp`',
  23. 'outcome' => 'uer.`Outcome`',
  24. 'handled_timestamp' => 'uer.`HandledTimestamp`');
  25. $Where = [];
  26. $Joins = [];
  27. // Default orderings
  28. $OrderBy = "uer.`Timestamp`";
  29. $OrderWay = "DESC";
  30. // Build query for different views
  31. // TODO: Work with encrypted values
  32. if (!isset($_GET['view'])) {
  33. $_GET['view'] = 'main';
  34. }
  35. switch ($_GET['view']) {
  36. case 'perfect':
  37. $Where[] = "um.`Email` = uer.`Email`";
  38. $Joins[] = "JOIN `users_main` um ON um.`ID` = uer.`UserID`";
  39. $Where[] = "uer.`IP` = (SELECT `IP` FROM `users_history_ips` uhi1 WHERE uhi1.`StartTime` = (SELECT MAX(`StartTime`) FROM `users_history_ips` uhi2 WHERE uhi2.`UserID` = uer.`UserID` ORDER BY `StartTime` DESC LIMIT 1))";
  40. $Where[] = "(SELECT 1 FROM `users_history_ips` uhi WHERE uhi.`IP` = uer.`IP` AND uhi.`UserID` != uer.`UserID`) IS NULL";
  41. $Where[] = "ui.`BanReason` = '3'";
  42. break;
  43. case 'minus_ip':
  44. $Where[] = "um.`Email` = uer.`Email`";
  45. $Joins[] = "JOIN `users_main` um ON um.`ID` = uer.`UserID`";
  46. $Where[] = "ui.`BanReason` = '3'";
  47. break;
  48. case 'invalid_email':
  49. $Joins[] = "JOIN `users_main` um ON um.`ID` = uer.`UserID`";
  50. $Where[] = "um.`Email` != uer.`Email`";
  51. break;
  52. case 'ip_overlap':
  53. $Joins[] = "JOIN `users_history_ips` uhi ON uhi.`IP` = uer.`IP` AND uhi.`UserID` != uer.`UserID`";
  54. break;
  55. case 'manual_disable':
  56. $Where[] = "ui.`BanReason` != '3'";
  57. break;
  58. default:
  59. $Joins[] = '';
  60. break;
  61. }
  62. // End views
  63. // Build query further based on search
  64. if (isset($_GET['search'])) {
  65. $Username = db_string($_GET['username']);
  66. $IP = db_string($_GET['ip']);
  67. $SubmittedBetween = db_string($_GET['submitted_between']);
  68. $SubmittedTimestamp1 = db_string($_GET['submitted_timestamp1']);
  69. $SubmittedTimestamp2 = db_string($_GET['submitted_timestamp2']);
  70. $HandledUsername = db_string($_GET['handled_username']);
  71. $HandledBetween = db_string($_GET['handled_between']);
  72. $HandledTimestamp1 = db_string($_GET['handled_timestamp1']);
  73. $HandledTimestamp2 = db_string($_GET['handled_timestamp2']);
  74. $OutcomeSearch = (int) $_GET['outcome_search'];
  75. $Checked = (isset($_GET['show_checked']));
  76. if (array_key_exists($_GET['order'], $OrderBys)) {
  77. $OrderBy = $OrderBys[$_GET['order']];
  78. }
  79. if ($_GET['way'] === 'asc' || $_GET['way'] === 'desc') {
  80. $OrderWay = $_GET['way'];
  81. }
  82. if (!empty($Username)) {
  83. $Joins[] = "JOIN `users_main` um1 ON um1.`ID` = uer.`UserID`";
  84. }
  85. if (!empty($HandledUsername)) {
  86. $Joins[] = "JOIN `users_main` um2 ON um2.`ID` = uer.`CheckedBy`";
  87. }
  88. $Where = array_merge($Where, AutoEnable::build_search_query(
  89. $Username,
  90. $IP,
  91. $SubmittedBetween,
  92. $SubmittedTimestamp1,
  93. $SubmittedTimestamp2,
  94. $HandledUsername,
  95. $HandledBetween,
  96. $HandledTimestamp1,
  97. $HandledTimestamp2,
  98. $OutcomeSearch,
  99. $Checked
  100. ));
  101. }
  102. // End search queries
  103. $ShowChecked = (isset($Checked) && $Checked) || !empty($HandledUsername) || !empty($HandledTimestamp1) || !empty($OutcomeSearch);
  104. if (!$ShowChecked || count($Where) === 0) {
  105. // If no search is entered, add this to the query to only show unchecked requests
  106. $Where[] = '`Outcome` IS NULL';
  107. }
  108. $QueryID = $DB->query("
  109. SELECT SQL_CALC_FOUND_ROWS
  110. uer.`ID`,
  111. uer.`UserID`,
  112. uer.`Email`,
  113. uer.`IP`,
  114. uer.`UserAgent`,
  115. uer.`Timestamp`,
  116. ui.`BanReason`,
  117. uer.`CheckedBy`,
  118. uer.`HandledTimestamp`,
  119. uer.`Outcome`
  120. FROM
  121. `users_enable_requests` AS uer
  122. JOIN `users_info` ui ON
  123. ui.`UserID` = uer.`UserID` ".implode(' ', $Joins)."
  124. WHERE
  125. ".implode(' AND ', $Where)."
  126. ORDER BY
  127. $OrderBy $OrderWay
  128. LIMIT
  129. $Limit
  130. ");
  131. $DB->query("SELECT FOUND_ROWS()");
  132. list($NumResults) = $DB->next_record();
  133. $DB->set_query_id($QueryID);
  134. ?>
  135. <div class="header">
  136. <h2>Auto-Enable Requests</h2>
  137. </div>
  138. <div align="center">
  139. <a class="brackets tooltip" href="tools.php?action=enable_requests" title="Default view">Main</a>
  140. <a class="brackets tooltip"
  141. href="tools.php?action=enable_requests&amp;view=perfect&amp;<?=Format::get_url(array('view', 'action'))?>"
  142. title="Valid username, matching email, current IP with no matches, and inactivity disabled">Perfect</a>
  143. <a class="brackets tooltip"
  144. href="tools.php?action=enable_requests&amp;view=minus_ip&amp;<?=Format::get_url(array('view', 'action'))?>"
  145. title="Valid username, matching email, and inactivity disabled">Perfect Minus IP</a>
  146. <a class="brackets tooltip"
  147. href="tools.php?action=enable_requests&amp;view=invalid_email&amp;<?=Format::get_url(array('view', 'action'))?>"
  148. title="Non-matching email address">Invalid Email</a>
  149. <a class="brackets tooltip"
  150. href="tools.php?action=enable_requests&amp;view=ip_overlap&amp;<?=Format::get_url(array('view', 'action'))?>"
  151. title="Requests with IP matches to other accounts">IP Overlap</a>
  152. <a class="brackets tooltip"
  153. href="tools.php?action=enable_requests&amp;view=manual_disable&amp;<?=Format::get_url(array('view', 'action'))?>"
  154. title="Requests for accounts that were not disabled for inactivity">Manual Disable</a>
  155. <a class="brackets tooltip" title="Show/Hide Search" data-toggle-target="#search_form">Search</a>
  156. <a class="brackets tooltip" title="Show/Hide Search" data-toggle-target="#scores">Scores</a>
  157. </div>
  158. <div>
  159. <table id="scores" class="hidden" style="width: 50%; margin: 0 auto;">
  160. <tr>
  161. <th>Username</th>
  162. <th>Checked</th>
  163. </tr>
  164. <?php
  165. $DB->query("
  166. SELECT
  167. COUNT(`CheckedBy`),
  168. `CheckedBy`
  169. FROM
  170. `users_enable_requests`
  171. WHERE
  172. `CheckedBy` IS NOT NULL
  173. GROUP BY
  174. `CheckedBy`
  175. ORDER BY
  176. COUNT(`CheckedBy`)
  177. DESC
  178. LIMIT 50
  179. ");
  180. while (list($Checked, $UserID) = $DB->next_record()) { ?>
  181. <tr>
  182. <td>
  183. <?=Users::format_username($UserID)?>
  184. </td>
  185. <td>
  186. <?=$Checked?>
  187. </td>
  188. </tr>
  189. <?php
  190. }
  191. $DB->set_query_id($QueryID); ?>
  192. </table>
  193. <form action="" method="GET" id="search_form" <?=!isset($_GET['search']) ? 'class="hidden"' : ''?>>
  194. <input type="hidden" name="action" value="enable_requests" />
  195. <input type="hidden" name="view"
  196. value="<?=$_GET['view']?>" />
  197. <input type="hidden" name="search" value="1" />
  198. <table>
  199. <tr>
  200. <td class="label">Username</td>
  201. <td>
  202. <input type="text" name="username"
  203. value="<?=$_GET['username']?>" />
  204. </td>
  205. </tr>
  206. <tr>
  207. <td class="label">IP Address</td>
  208. <td>
  209. <input type="text" name="ip"
  210. value="<?=$_GET['ip']?>" />
  211. </td>
  212. </tr>
  213. <tr>
  214. <td class="label tooltip" title="This will search between the entered date and 24 hours after it">
  215. Submitted Timestamp
  216. </td>
  217. <td>
  218. <select name="submitted_between" onchange="ChangeDateSearch(this.value, 'submitted_timestamp2');">
  219. <option value="on" <?=$_GET['submitted_between'] === 'on' ? 'selected' : ''?>>On
  220. </option>
  221. <option value="before" <?=$_GET['submitted_between'] === 'before' ? 'selected' : ''?>>Before
  222. </option>
  223. <option value="after" <?=$_GET['submitted_between'] === 'after' ? 'selected' : ''?>>After
  224. </option>
  225. <option value="between" <?=$_GET['submitted_between'] === 'between' ? 'selected' : ''?>>Between
  226. </option>
  227. </select>&nbsp;
  228. <input type="date" name="submitted_timestamp1"
  229. value="<?=$_GET['submitted_timestamp1']?>" />
  230. <input type="date" id="submitted_timestamp2" name="submitted_timestamp2"
  231. value="<?=$_GET['submitted_timestamp2']?>"
  232. <?=$_GET['submitted_between'] !== 'between' ? 'style="display: none;"' : ''?>
  233. />
  234. </td>
  235. </tr>
  236. <tr>
  237. <td class="label">Handled By Username</td>
  238. <td>
  239. <input type="text" name="handled_username"
  240. value="<?=$_GET['handled_username']?>" />
  241. </td>
  242. </tr>
  243. <tr>
  244. <td class="label tooltip" title="This will search between the entered date and 24 hours after it">
  245. Handled Timestamp
  246. </td>
  247. <td>
  248. <select name="handled_between" onchange="ChangeDateSearch(this.value, 'handled_timestamp2');">
  249. <option value="on" <?=$_GET['handled_between'] === 'on' ? 'selected' : ''?>>On
  250. </option>
  251. <option value="before" <?=$_GET['handled_between'] === 'before' ? 'selected' : ''?>>Before
  252. </option>
  253. <option value="after" <?=$_GET['handled_between'] === 'after' ? 'selected' : ''?>>After
  254. </option>
  255. <option value="between" <?=$_GET['handled_between'] === 'between' ? 'selected' : ''?>>Between
  256. </option>
  257. </select>&nbsp;
  258. <input type="date" name="handled_timestamp1"
  259. value="<?=$_GET['handled_timestamp1']?>" />
  260. <input type="date" id="handled_timestamp2" name="handled_timestamp2"
  261. value="<?=$_GET['handled_timestamp2']?>"
  262. <?=$_GET['handled_between'] !== 'between' ? 'style="display: none;"' : ''?>
  263. />
  264. </td>
  265. </tr>
  266. <tr>
  267. <td class="label">Outcome</td>
  268. <td>
  269. <select name="outcome_search">
  270. <option value="">---</option>
  271. <option value="<?=AutoEnable::APPROVED?>"
  272. <?=$_GET['outcome_search'] === AutoEnable::APPROVED ? 'selected' : ''?>>Approved
  273. </option>
  274. <option value="<?=AutoEnable::DENIED?>"
  275. <?=$_GET['outcome_search'] === AutoEnable::DENIED ? 'selected' : ''?>>Denied
  276. </option>
  277. <option value="<?=AutoEnable::DISCARDED?>"
  278. <?=$_GET['outcome_search'] === AutoEnable::DISCARDED ? 'selected' : ''?>>Discarded
  279. </option>
  280. </select>
  281. </td>
  282. </tr>
  283. <tr>
  284. <td class="label">Include Checked</td>
  285. <td>
  286. <input type="checkbox" name="show_checked" <?=isset($_GET['show_checked']) ? 'checked' : ''?>
  287. />
  288. </td>
  289. </tr>
  290. <tr>
  291. <td class="label">Order By</td>
  292. <td>
  293. <select name="order">
  294. <option value="submitted_timestamp" <?=$_GET['order'] === 'submitted_timestamp' ? 'selected' : '' ?>>Submitted
  295. Timestamp</option>
  296. <option value="outcome" <?=$_GET['order'] === 'outcome' ? 'selected' : '' ?>>Outcome
  297. </option>
  298. <option value="handled_timestamp" <?=$_GET['order'] === 'handled_timestamp' ? 'selected' : '' ?>>Handled
  299. Timestamp</option>
  300. </select>&nbsp;
  301. <select name="way">
  302. <option value="asc" <?=$_GET['way'] === 'asc' ? 'selected' : '' ?>>Ascending
  303. </option>
  304. <option value="desc" <?=!isset($_GET['way']) || $_GET['way'] === 'desc' ? 'selected' : '' ?>>Descending
  305. </option>
  306. </select>
  307. </td>
  308. </tr>
  309. <tr>
  310. <td colspan=2>
  311. <input type="submit" value="Search" />
  312. </td>
  313. </tr>
  314. </table>
  315. </form>
  316. </div>
  317. <?php
  318. if ($NumResults > 0) { ?>
  319. <div class="linkbox">
  320. <?php
  321. $Pages = Format::get_pages($Page, $NumResults, $RequestsPerPage);
  322. echo $Pages;
  323. ?>
  324. </div>
  325. <table width="100%">
  326. <tr class="colhead">
  327. <td class="center"><input type="checkbox" id="check_all" /></td>
  328. <td>
  329. Username
  330. </td>
  331. <td>
  332. Email Address
  333. </td>
  334. <td>
  335. IP Address
  336. </td>
  337. <td>
  338. User Agent
  339. </td>
  340. <td>
  341. Age
  342. </td>
  343. <td>
  344. Ban Reason
  345. </td>
  346. <td>
  347. Comment<?=$ShowChecked ? '/Checked By' : ''?>
  348. </td>
  349. <td>
  350. Submit<?=$ShowChecked ? '/Checked Date' : ''?>
  351. </td>
  352. <?php if ($ShowChecked) { ?>
  353. <td>
  354. Outcome
  355. </td>
  356. <?php } ?>
  357. </tr>
  358. <?php
  359. while (list($ID, $UserID, $Email, $IP, $UserAgent, $Timestamp, $BanReason, $CheckedBy, $HandledTimestamp, $Outcome) = $DB->next_record()) {
  360. ?>
  361. <tr class="row" id="row_<?=$ID?>">
  362. <td class="center">
  363. <?php if (!$HandledTimestamp) { ?>
  364. <input type="checkbox" id="multi" data-id="<?=$ID?>" />
  365. <?php } ?>
  366. </td>
  367. <td>
  368. <?=Users::format_username($UserID)?>
  369. </td>
  370. <td>
  371. <?=display_str(Crypto::decrypt($Email))?>
  372. </td>
  373. <td>
  374. <?=display_str(Crypto::decrypt($IP))?>
  375. </td>
  376. <td>
  377. <?=display_str($UserAgent)?>
  378. </td>
  379. <td>
  380. <?=time_diff($Timestamp)?>
  381. </td>
  382. <td>
  383. <?=($BanReason == 3) ? '<b>Inactivity</b>' : 'Other'?>
  384. </td>
  385. <?php if (!$HandledTimestamp) { ?>
  386. <td>
  387. <input class="inputtext" type="text" id="comment<?=$ID?>"
  388. placeholder="Comment" />
  389. </td>
  390. <td>
  391. <input type="submit" id="outcome" value="Approve"
  392. data-id="<?=$ID?>" />
  393. <input type="submit" id="outcome" value="Reject"
  394. data-id="<?=$ID?>" />
  395. <input type="submit" id="outcome" value="Discard"
  396. data-id="<?=$ID?>" />
  397. </td>
  398. <?php } else { ?>
  399. <td>
  400. <?=Users::format_username($CheckedBy);?>
  401. </td>
  402. <td>
  403. <?=$HandledTimestamp?>
  404. </td>
  405. <?php }
  406. if ($ShowChecked) { ?>
  407. <td>
  408. <?=AutoEnable::get_outcome_string($Outcome)?>
  409. <?php if ($Outcome === AutoEnable::DISCARDED) { ?>
  410. <a href="" id="unresolve" onclick="return false;" class="brackets"
  411. data-id="<?=$ID?>">Unresolve</a>
  412. <?php } ?>
  413. </td>
  414. <?php } ?>
  415. </tr>
  416. <?php
  417. }
  418. ?>
  419. </table>
  420. <div class="linkbox">
  421. <?php
  422. $Pages = Format::get_pages($Page, $NumResults, $RequestsPerPage);
  423. echo $Pages;
  424. ?>
  425. </div>
  426. <div style="padding-bottom: 11px;">
  427. <input type="submit" id="multi" value="Approve Selected" />
  428. <input type="submit" id="multi" value="Reject Selected" />
  429. <input type="submit" id="multi" value="Discard Selected" />
  430. </div>
  431. <?php } else { ?>
  432. <h2>
  433. No new pending auto enable requests <?=($_GET['view'] === 'main') ? '' : ' in this view' ?>
  434. </h2>
  435. <?php }
  436. View::show_footer();