Oppaitime'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 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <?
  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. die();
  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])) { $_GET[$S] = NULL; }
  13. }
  14. View::show_header("Enable Requests", 'enable_requests');
  15. // Pagination
  16. $RequestsPerPage = 25;
  17. list($Page, $Limit) = Format::page_limit($RequestsPerPage);
  18. // How can things be ordered?
  19. $OrderBys = array(
  20. 'submitted_timestamp' => 'uer.Timestamp',
  21. 'outcome' => 'uer.Outcome',
  22. 'handled_timestamp' => 'uer.HandledTimestamp');
  23. $Where = [];
  24. $Joins = [];
  25. // Default orderings
  26. $OrderBy = "uer.Timestamp";
  27. $OrderWay = "DESC";
  28. // Build query for different views
  29. // TODO: Work with encrypted values
  30. if (!isset($_GET['view'])) {
  31. $_GET['view'] = 'main';
  32. }
  33. if ($_GET['view'] == 'perfect') {
  34. $Where[] = "um.Email = uer.Email";
  35. $Joins[] = "JOIN users_main um ON um.ID = uer.UserID";
  36. $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))";
  37. $Where[] = "(SELECT 1 FROM users_history_ips uhi WHERE uhi.IP = uer.IP AND uhi.UserID != uer.UserID) IS NULL";
  38. $Where[] = "ui.BanReason = '3'";
  39. } else if ($_GET['view'] == 'minus_ip') {
  40. $Where[] = "um.Email = uer.Email";
  41. $Joins[] = "JOIN users_main um ON um.ID = uer.UserID";
  42. $Where[] = "ui.BanReason = '3'";
  43. } else if ($_GET['view'] == 'invalid_email') {
  44. $Joins[] = "JOIN users_main um ON um.ID = uer.UserID";
  45. $Where[] = "um.Email != uer.Email";
  46. } else if ($_GET['view'] == 'ip_overlap') {
  47. $Joins[] = "JOIN users_history_ips uhi ON uhi.IP = uer.IP AND uhi.UserID != uer.UserID";
  48. } else if ($_GET['view'] == 'manual_disable') {
  49. $Where[] = "ui.BanReason != '3'";
  50. } else {
  51. $Joins[] = '';
  52. }
  53. // End views
  54. // Build query further based on search
  55. if (isset($_GET['search'])) {
  56. $Username = db_string($_GET['username']);
  57. $IP = db_string($_GET['ip']);
  58. $SubmittedBetween = db_string($_GET['submitted_between']);
  59. $SubmittedTimestamp1 = db_string($_GET['submitted_timestamp1']);
  60. $SubmittedTimestamp2 = db_string($_GET['submitted_timestamp2']);
  61. $HandledUsername = db_string($_GET['handled_username']);
  62. $HandledBetween = db_string($_GET['handled_between']);
  63. $HandledTimestamp1 = db_string($_GET['handled_timestamp1']);
  64. $HandledTimestamp2 = db_string($_GET['handled_timestamp2']);
  65. $OutcomeSearch = (int) $_GET['outcome_search'];
  66. $Checked = (isset($_GET['show_checked']));
  67. if (array_key_exists($_GET['order'], $OrderBys)) {
  68. $OrderBy = $OrderBys[$_GET['order']];
  69. }
  70. if ($_GET['way'] == "asc" || $_GET['way'] == "desc") {
  71. $OrderWay = $_GET['way'];
  72. }
  73. if (!empty($Username)) {
  74. $Joins[] = "JOIN users_main um1 ON um1.ID = uer.UserID";
  75. }
  76. if (!empty($HandledUsername)) {
  77. $Joins[] = "JOIN users_main um2 ON um2.ID = uer.CheckedBy";
  78. }
  79. $Where = array_merge($Where, AutoEnable::build_search_query($Username,
  80. $IP, $SubmittedBetween, $SubmittedTimestamp1, $SubmittedTimestamp2, $HandledUsername,
  81. $HandledBetween, $HandledTimestamp1, $HandledTimestamp2, $OutcomeSearch, $Checked));
  82. }
  83. // End search queries
  84. $ShowChecked = (isset($Checked) && $Checked) || !empty($HandledUsername) || !empty($HandledTimestamp1) || !empty($OutcomeSearch);
  85. if (!$ShowChecked || count($Where) == 0) {
  86. // If no search is entered, add this to the query to only show unchecked requests
  87. $Where[] = 'Outcome IS NULL';
  88. }
  89. $QueryID = $DB->query("
  90. SELECT SQL_CALC_FOUND_ROWS
  91. uer.ID,
  92. uer.UserID,
  93. uer.Email,
  94. uer.IP,
  95. uer.UserAgent,
  96. uer.Timestamp,
  97. ui.BanReason,
  98. uer.CheckedBy,
  99. uer.HandledTimestamp,
  100. uer.Outcome
  101. FROM users_enable_requests AS uer
  102. JOIN users_info ui ON ui.UserID = uer.UserID
  103. ".implode(' ', $Joins)."
  104. WHERE
  105. ".implode(' AND ', $Where)."
  106. ORDER BY $OrderBy $OrderWay
  107. LIMIT $Limit");
  108. $DB->query("SELECT FOUND_ROWS()");
  109. list($NumResults) = $DB->next_record();
  110. $DB->set_query_id($QueryID);
  111. ?>
  112. <div class="header">
  113. <h2>Auto-Enable Requests</h2>
  114. </div>
  115. <div align="center">
  116. <a class="brackets tooltip" href="tools.php?action=enable_requests" title="Default view">Main</a>
  117. <a class="brackets tooltip" href="tools.php?action=enable_requests&amp;view=perfect&amp;<?=Format::get_url(array('view', 'action'))?>" title="Valid username, matching email, current IP with no matches, and inactivity disabled">Perfect</a>
  118. <a class="brackets tooltip" href="tools.php?action=enable_requests&amp;view=minus_ip&amp;<?=Format::get_url(array('view', 'action'))?>" title="Valid username, matching email, and inactivity disabled">Perfect Minus IP</a>
  119. <a class="brackets tooltip" href="tools.php?action=enable_requests&amp;view=invalid_email&amp;<?=Format::get_url(array('view', 'action'))?>" title="Non-matching email address">Invalid Email</a>
  120. <a class="brackets tooltip" href="tools.php?action=enable_requests&amp;view=ip_overlap&amp;<?=Format::get_url(array('view', 'action'))?>" title="Requests with IP matches to other accounts">IP Overlap</a>
  121. <a class="brackets tooltip" href="tools.php?action=enable_requests&amp;view=manual_disable&amp;<?=Format::get_url(array('view', 'action'))?>" title="Requests for accounts that were not disabled for inactivity">Manual Disable</a>
  122. <a class="brackets tooltip" title="Show/Hide Search" data-toggle-target="#search_form">Search</a>
  123. <a class="brackets tooltip" title="Show/Hide Search" data-toggle-target="#scores">Scores</a>
  124. </div><br />
  125. <div class="thin">
  126. <table id="scores" class="hidden" style="width: 50%; margin: 0 auto;">
  127. <tr>
  128. <th>Username</th>
  129. <th>Checked</th>
  130. </tr>
  131. <? $DB->query("
  132. SELECT COUNT(CheckedBy), CheckedBy
  133. FROM users_enable_requests
  134. WHERE CheckedBy IS NOT NULL
  135. GROUP BY CheckedBy
  136. ORDER BY COUNT(CheckedBy) DESC
  137. LIMIT 50");
  138. while (list($Checked, $UserID) = $DB->next_record()) { ?>
  139. <tr>
  140. <td><?=Users::format_username($UserID)?></td>
  141. <td><?=$Checked?></td>
  142. </tr>
  143. <? }
  144. $DB->set_query_id($QueryID); ?>
  145. </table>
  146. <form action="" method="GET" id="search_form" <?=!isset($_GET['search']) ? 'class="hidden"' : ''?>>
  147. <input type="hidden" name="action" value="enable_requests" />
  148. <input type="hidden" name="view" value="<?=$_GET['view']?>" />
  149. <input type="hidden" name="search" value="1" />
  150. <table>
  151. <tr>
  152. <td class="label">Username</td>
  153. <td><input type="text" name="username" value="<?=$_GET['username']?>" /></td>
  154. </tr>
  155. <tr>
  156. <td class="label">IP Address</td>
  157. <td><input type="text" name="ip" value="<?=$_GET['ip']?>" /></td>
  158. </tr>
  159. <tr>
  160. <td class="label tooltip" title="This will search between the entered date and 24 hours after it">Submitted Timestamp</td>
  161. <td>
  162. <select name="submitted_between" onchange="ChangeDateSearch(this.value, 'submitted_timestamp2');">
  163. <option value="on" <?=$_GET['submitted_between'] == 'on' ? 'selected' : ''?>>On</option>
  164. <option value="before" <?=$_GET['submitted_between'] == 'before' ? 'selected' : ''?>>Before</option>
  165. <option value="after" <?=$_GET['submitted_between'] == 'after' ? 'selected' : ''?>>After</option>
  166. <option value="between" <?=$_GET['submitted_between'] == 'between' ? 'selected' : ''?>>Between</option>
  167. </select>&nbsp;
  168. <input type="date" name="submitted_timestamp1" value="<?=$_GET['submitted_timestamp1']?>" />
  169. <input type="date" id="submitted_timestamp2" name="submitted_timestamp2" value="<?=$_GET['submitted_timestamp2']?>" <?=$_GET['submitted_between'] != 'between' ? 'style="display: none;"' : ''?>/>
  170. </td>
  171. </tr>
  172. <tr>
  173. <td class="label">Handled By Username</td>
  174. <td><input type="text" name="handled_username" value="<?=$_GET['handled_username']?>" /></td>
  175. </tr>
  176. <tr>
  177. <td class="label tooltip" title="This will search between the entered date and 24 hours after it">Handled Timestamp</td>
  178. <td>
  179. <select name="handled_between" onchange="ChangeDateSearch(this.value, 'handled_timestamp2');">
  180. <option value="on" <?=$_GET['handled_between'] == 'on' ? 'selected' : ''?>>On</option>
  181. <option value="before" <?=$_GET['handled_between'] == 'before' ? 'selected' : ''?>>Before</option>
  182. <option value="after" <?=$_GET['handled_between'] == 'after' ? 'selected' : ''?>>After</option>
  183. <option value="between" <?=$_GET['handled_between'] == 'between' ? 'selected' : ''?>>Between</option>
  184. </select>&nbsp;
  185. <input type="date" name="handled_timestamp1" value="<?=$_GET['handled_timestamp1']?>" />
  186. <input type="date" id="handled_timestamp2" name="handled_timestamp2" value="<?=$_GET['handled_timestamp2']?>" <?=$_GET['handled_between'] != 'between' ? 'style="display: none;"' : ''?>/>
  187. </td>
  188. </tr>
  189. <tr>
  190. <td class="label">Outcome</td>
  191. <td>
  192. <select name="outcome_search">
  193. <option value="">---</option>
  194. <option value="<?=AutoEnable::APPROVED?>" <?=$_GET['outcome_search'] == AutoEnable::APPROVED ? 'selected' : ''?>>Approved</option>
  195. <option value="<?=AutoEnable::DENIED?>" <?=$_GET['outcome_search'] == AutoEnable::DENIED ? 'selected' : ''?>>Denied</option>
  196. <option value="<?=AutoEnable::DISCARDED?>" <?=$_GET['outcome_search'] == AutoEnable::DISCARDED ? 'selected' : ''?>>Discarded</option>
  197. </select>
  198. </td>
  199. </tr>
  200. <tr>
  201. <td class="label">Include Checked</td>
  202. <td><input type="checkbox" name="show_checked" <?=isset($_GET['show_checked']) ? 'checked' : ''?> /></td>
  203. </tr>
  204. <tr>
  205. <td class="label">Order By</td>
  206. <td>
  207. <select name="order">
  208. <option value="submitted_timestamp" <?=$_GET['order'] == 'submitted_timestamp' ? 'selected' : '' ?>>Submitted Timestamp</option>
  209. <option value="outcome" <?=$_GET['order'] == 'outcome' ? 'selected' : '' ?>>Outcome</option>
  210. <option value="handled_timestamp" <?=$_GET['order'] == 'handled_timestamp' ? 'selected' : '' ?>>Handled Timestamp</option>
  211. </select>&nbsp;
  212. <select name="way">
  213. <option value="asc" <?=$_GET['way'] == 'asc' ? 'selected' : '' ?>>Ascending</option>
  214. <option value="desc" <?=!isset($_GET['way']) || $_GET['way'] == 'desc' ? 'selected' : '' ?>>Descending</option>
  215. </select>
  216. </td>
  217. </tr>
  218. <tr>
  219. <td colspan=2><input type="submit" value="Search" /></td>
  220. </tr>
  221. </table>
  222. </form>
  223. </div>
  224. <?
  225. if ($NumResults > 0) { ?>
  226. <div class="linkbox">
  227. <?
  228. $Pages = Format::get_pages($Page, $NumResults, $RequestsPerPage);
  229. echo $Pages;
  230. ?>
  231. </div>
  232. <table width="100%">
  233. <tr class="colhead">
  234. <td class="center"><input type="checkbox" id="check_all" /></td>
  235. <td>Username</td>
  236. <td>Email Address</td>
  237. <td>IP Address</td>
  238. <td>User Agent</td>
  239. <td>Age</td>
  240. <td>Ban Reason</td>
  241. <td>Comment<?=$ShowChecked ? '/Checked By' : ''?></td>
  242. <td>Submit<?=$ShowChecked ? '/Checked Date' : ''?></td>
  243. <? if ($ShowChecked) { ?>
  244. <td>Outcome</td>
  245. <? } ?>
  246. </tr>
  247. <?
  248. while (list($ID, $UserID, $Email, $IP, $UserAgent, $Timestamp, $BanReason, $CheckedBy, $HandledTimestamp, $Outcome) = $DB->next_record()) {
  249. ?>
  250. <tr class="row" id="row_<?=$ID?>">
  251. <td class="center">
  252. <? if (!$HandledTimestamp) { ?>
  253. <input type="checkbox" id="multi" data-id="<?=$ID?>" />
  254. <? } ?>
  255. </td>
  256. <td><?=Users::format_username($UserID)?></td>
  257. <td><?=display_str(Crypto::decrypt($Email))?></td>
  258. <td><?=display_str(Crypto::decrypt($IP))?></td>
  259. <td><?=display_str($UserAgent)?></td>
  260. <td><?=time_diff($Timestamp)?></td>
  261. <td><?=($BanReason == 3) ? '<b>Inactivity</b>' : 'Other'?></td>
  262. <? if (!$HandledTimestamp) { ?>
  263. <td><input class="inputtext" type="text" id="comment<?=$ID?>" placeholder="Comment" /></td>
  264. <td>
  265. <input type="submit" id="outcome" value="Approve" data-id="<?=$ID?>" />
  266. <input type="submit" id="outcome" value="Reject" data-id="<?=$ID?>" />
  267. <input type="submit" id="outcome" value="Discard" data-id="<?=$ID?>" />
  268. </td>
  269. <? } else { ?>
  270. <td><?=Users::format_username($CheckedBy);?></td>
  271. <td><?=$HandledTimestamp?></td>
  272. <? }
  273. if ($ShowChecked) { ?>
  274. <td><?=AutoEnable::get_outcome_string($Outcome)?>
  275. <? if ($Outcome == AutoEnable::DISCARDED) { ?>
  276. <a href="" id="unresolve" onclick="return false;" class="brackets" data-id="<?=$ID?>">Unresolve</a>
  277. <? } ?>
  278. </td>
  279. <? } ?>
  280. </tr>
  281. <?
  282. }
  283. ?>
  284. </table>
  285. <div class="linkbox">
  286. <?
  287. $Pages = Format::get_pages($Page, $NumResults, $RequestsPerPage);
  288. echo $Pages;
  289. ?>
  290. </div>
  291. <div style="padding-bottom: 11px;">
  292. <input type="submit" id="outcome" value="Approve Selected" />
  293. <input type="submit" id="outcome" value="Reject Selected" />
  294. <input type="submit" id="outcome" value="Discard Selected" />
  295. </div>
  296. <? } else { ?>
  297. <h2 align="center">No new pending auto enable requests<?=($_GET['view'] == 'main') ? '' : ' in this view'?></h2>
  298. <? }
  299. View::show_footer();