PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/dead/usersearch.php

https://bitbucket.org/nexea/x00n
PHP | 900 lines | 745 code | 84 blank | 71 comment | 150 complexity | 2a023de1bdc6f382c739d7005959ff98 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?
  2. ob_start("ob_gzhandler");
  3. require "include/bittorrent.php";
  4. // 0 - No debug; 1 - Show and run SQL query; 2 - Show SQL query only
  5. $DEBUG_MODE = 0;
  6. /*
  7. function get_user_icons($arr, $big = false)
  8. {
  9. if ($big)
  10. {
  11. $donorpic = "starbig.gif";
  12. $warnedpic = "warnedbig.gif";
  13. $disabledpic = "disabledbig.gif";
  14. }
  15. else
  16. {
  17. $donorpic = "star.gif";
  18. $warnedpic = "warned.gif";
  19. $disabledpic = "disabled.gif";
  20. }
  21. $pics = $arr["donor"] == "yes" ? "<img src=images/$donorpic alt='Donor' border=0 style=\"margin-left: 2pt\">" : "";
  22. if ($arr["enabled"] == "yes")
  23. $pics .= $arr["warned"] == "yes" ? "<img src=images/$warnedpic alt=\"Warned\" border=0>" : "";
  24. else
  25. $pics .= "<img src=images/$disabledpic alt=\"Disabled\" border=0 style=\"margin-left: 2pt\">\n";
  26. return $pics;
  27. }
  28. */
  29. dbconn();
  30. loggedinorreturn();
  31. if (get_user_class() < UC_MODERATOR)
  32. stderr("Error", "Permission denied.");
  33. stdhead("Administrative User Search");
  34. echo "<h1>Administrative User Search</h1>\n";
  35. if ($_GET['h'])
  36. {
  37. echo "<table width=65% border=0 align=center><tr><td class=embedded bgcolor='#F5F4EA'><div align=left>\n
  38. Fields left blank will be ignored;\n
  39. Wildcards * and ? may be used in Name, Email and Comments, as well as multiple values\n
  40. separated by spaces (e.g. 'wyz Max*' in Name will list both users named\n
  41. 'wyz' and those whose names start by 'Max'. Similarly '~' can be used for\n
  42. negation, e.g. '~alfiest' in comments will restrict the search to users\n
  43. that do not have 'alfiest' in their comments).<br><br>\n
  44. The Ratio field accepts 'Inf' and '---' besides the usual numeric values.<br><br>\n
  45. The subnet mask may be entered either in dotted decimal or CIDR notation\n
  46. (e.g. 255.255.255.0 is the same as /24).<br><br>\n
  47. Uploaded and Downloaded should be entered in GB.<br><br>\n
  48. For search parameters with multiple text fields the second will be\n
  49. ignored unless relevant for the type of search chosen. <br><br>\n
  50. 'Active only' restricts the search to users currently leeching or seeding,\n
  51. 'Disabled IPs' to those whose IPs also show up in disabled accounts.<br><br>\n
  52. The 'p' columns in the results show partial stats, that is, those\n
  53. of the torrents in progress. <br><br>\n
  54. The History column lists the number of forum posts and torrent comments,\n
  55. respectively, as well as linking to the history page.\n
  56. </div></td></tr></table><br><br>\n";
  57. }
  58. else
  59. {
  60. echo "<p align=center>(<a href='".$_SERVER["PHP_SELF"]."?h=1'>Instructions</a>)";
  61. echo "&nbsp;-&nbsp;(<a href='".$_SERVER["PHP_SELF"]."'>Reset</a>)</p>\n";
  62. }
  63. $highlight = " bgcolor=#BBAF9B";
  64. ?>
  65. <form method=get action=<?=$_SERVER["PHP_SELF"]?>>
  66. <table border="1" cellspacing="0" cellpadding="5">
  67. <tr>
  68. <td valign="middle" class=rowhead>Name:</td>
  69. <td<?=$_GET['n']?$highlight:""?>><input name="n" type="text" value="<?=$_GET['n']?>" size=35></td>
  70. <td valign="middle" class=rowhead>Ratio:</td>
  71. <td<?=$_GET['r']?$highlight:""?>><select name="rt">
  72. <?
  73. $options = array("equal","above","below","between");
  74. for ($i = 0; $i < count($options); $i++){
  75. echo "<option value=$i ".(($_GET['rt']=="$i")?"selected":"").">".$options[$i]."</option>\n";
  76. }
  77. ?>
  78. </select>
  79. <input name="r" type="text" value="<?=$_GET['r']?>" size="5" maxlength="4">
  80. <input name="r2" type="text" value="<?=$_GET['r2']?>" size="5" maxlength="4"></td>
  81. <td valign="middle" class=rowhead>Member status:</td>
  82. <td<?=$_GET['st']?$highlight:""?>><select name="st">
  83. <?
  84. $options = array("(any)","confirmed","pending");
  85. for ($i = 0; $i < count($options); $i++){
  86. echo "<option value=$i ".(($_GET['st']=="$i")?"selected":"").">".$options[$i]."</option>\n";
  87. }
  88. ?>
  89. </select></td></tr>
  90. <tr><td valign="middle" class=rowhead>Email:</td>
  91. <td<?=$_GET['em']?$highlight:""?>><input name="em" type="text" value="<?=$_GET['em']?>" size="35"></td>
  92. <td valign="middle" class=rowhead>IP:</td>
  93. <td<?=$_GET['ip']?$highlight:""?>><input name="ip" type="text" value="<?=$_GET['ip']?>" maxlength="17"></td>
  94. <td valign="middle" class=rowhead>Account status:</td>
  95. <td<?=$_GET['as']?$highlight:""?>><select name="as">
  96. <?
  97. $options = array("(any)","enabled","disabled");
  98. for ($i = 0; $i < count($options); $i++){
  99. echo "<option value=$i ".(($_GET['as']=="$i")?"selected":"").">".$options[$i]."</option>\n";
  100. }
  101. ?>
  102. </select></td></tr>
  103. <tr>
  104. <td valign="middle" class=rowhead>Comment:</td>
  105. <td<?=$_GET['co']?$highlight:""?>><input name="co" type="text" value="<?=$_GET['co']?>" size="35"></td>
  106. <td valign="middle" class=rowhead>Mask:</td>
  107. <td<?=$_GET['ma']?$highlight:""?>><input name="ma" type="text" value="<?=$_GET['ma']?>" maxlength="17"></td>
  108. <td valign="middle" class=rowhead>Class:</td>
  109. <td<?=($_GET['c'] && $_GET['c'] != 1)?$highlight:""?>><select name="c"><option value='1'>(any)</option>
  110. <?
  111. $class = $_GET['c'];
  112. if (!is_valid_id($class))
  113. $class = '';
  114. for ($i = 2;;++$i) {
  115. if ($c = get_user_class_name($i-2))
  116. print("<option value=" . $i . ($class && $class == $i? " selected" : "") . ">$c</option>\n");
  117. else
  118. break;
  119. }
  120. ?>
  121. </select></td></tr>
  122. <tr>
  123. <td valign="middle" class=rowhead>Joined:</td>
  124. <td<?=$_GET['d']?$highlight:""?>><select name="dt">
  125. <?
  126. $options = array("on","before","after","between");
  127. for ($i = 0; $i < count($options); $i++){
  128. echo "<option value=$i ".(($_GET['dt']=="$i")?"selected":"").">".$options[$i]."</option>\n";
  129. }
  130. ?>
  131. </select>
  132. <input name="d" type="text" value="<?=$_GET['d']?>" size="12" maxlength="10">
  133. <input name="d2" type="text" value="<?=$_GET['d2']?>" size="12" maxlength="10"></td>
  134. <td valign="middle" class=rowhead>Uploaded:</td>
  135. <td<?=$_GET['ul']?$highlight:""?>><select name="ult" id="ult">
  136. <?
  137. $options = array("equal","above","below","between");
  138. for ($i = 0; $i < count($options); $i++){
  139. echo "<option value=$i ".(($_GET['ult']=="$i")?"selected":"").">".$options[$i]."</option>\n";
  140. }
  141. ?>
  142. </select>
  143. <input name="ul" type="text" id="ul" size="8" maxlength="7" value="<?=$_GET['ul']?>">
  144. <input name="ul2" type="text" id="ul2" size="8" maxlength="7" value="<?=$_GET['ul2']?>"></td>
  145. <td valign="middle" class="rowhead">Donor:</td>
  146. <td<?=$_GET['do']?$highlight:""?>><select name="do">
  147. <?
  148. $options = array("(any)","Yes","No");
  149. for ($i = 0; $i < count($options); $i++){
  150. echo "<option value=$i ".(($_GET['do']=="$i")?"selected":"").">".$options[$i]."</option>\n";
  151. }
  152. ?>
  153. </select></td></tr>
  154. <tr>
  155. <td valign="middle" class=rowhead>Last seen:</td>
  156. <td <?=$_GET['ls']?$highlight:""?>><select name="lst">
  157. <?
  158. $options = array("on","before","after","between");
  159. for ($i = 0; $i < count($options); $i++){
  160. echo "<option value=$i ".(($_GET['lst']=="$i")?"selected":"").">".$options[$i]."</option>\n";
  161. }
  162. ?>
  163. </select>
  164. <input name="ls" type="text" value="<?=$_GET['ls']?>" size="12" maxlength="10">
  165. <input name="ls2" type="text" value="<?=$_GET['ls2']?>" size="12" maxlength="10"></td>
  166. <td valign="middle" class=rowhead>Downloaded:</td>
  167. <td<?=$_GET['dl']?$highlight:""?>><select name="dlt" id="dlt">
  168. <?
  169. $options = array("equal","above","below","between");
  170. for ($i = 0; $i < count($options); $i++){
  171. echo "<option value=$i ".(($_GET['dlt']=="$i")?"selected":"").">".$options[$i]."</option>\n";
  172. }
  173. ?>
  174. </select>
  175. <input name="dl" type="text" id="dl" size="8" maxlength="7" value="<?=$_GET['dl']?>">
  176. <input name="dl2" type="text" id="dl2" size="8" maxlength="7" value="<?=$_GET['dl2']?>"></td>
  177. <td valign="middle" class=rowhead>Warned:</td>
  178. <td<?=$_GET['w']?$highlight:""?>><select name="w">
  179. <?
  180. $options = array("(any)","Yes","No");
  181. for ($i = 0; $i < count($options); $i++){
  182. echo "<option value=$i ".(($_GET['w']=="$i")?"selected":"").">".$options[$i]."</option>\n";
  183. }
  184. ?>
  185. </select></td></tr>
  186. <tr><td class="rowhead"></td><td></td>
  187. <td valign="middle" class=rowhead>Active only:</td>
  188. <td<?=$_GET['ac']?$highlight:""?>><input name="ac" type="checkbox" value="1" <?=($_GET['ac'])?"checked":"" ?>></td>
  189. <td valign="middle" class=rowhead>Disabled IP: </td>
  190. <td<?=$_GET['dip']?$highlight:""?>><input name="dip" type="checkbox" value="1" <?=($_GET['dip'])?"checked":"" ?>></td>
  191. </tr>
  192. <tr><td colspan="6" align=center><input name="submit" type=submit class=btn></td></tr>
  193. </table>
  194. <br><br>
  195. </form>
  196. <?
  197. // Validates date in the form [yy]yy-mm-dd;
  198. // Returns date if valid, 0 otherwise.
  199. function mkdate($date){
  200. if (strpos($date,'-'))
  201. $a = explode('-', $date);
  202. elseif (strpos($date,'/'))
  203. $a = explode('/', $date);
  204. else
  205. return 0;
  206. for ($i=0;$i<3;$i++)
  207. if (!is_numeric($a[$i]))
  208. return 0;
  209. if (checkdate($a[1], $a[2], $a[0]))
  210. return date ("Y-m-d", mktime (0,0,0,$a[1],$a[2],$a[0]));
  211. else
  212. return 0;
  213. }
  214. // ratio as a string
  215. function ratios($up,$down, $color = True)
  216. {
  217. if ($down > 0)
  218. {
  219. $r = number_format($up / $down, 2);
  220. if ($color)
  221. $r = "<font color=".get_ratio_color($r).">$r</font>";
  222. }
  223. else
  224. if ($up > 0)
  225. $r = "Inf.";
  226. else
  227. $r = "---";
  228. return $r;
  229. }
  230. // checks for the usual wildcards *, ? plus mySQL ones
  231. function haswildcard($text){
  232. if (strpos($text,'*') === False && strpos($text,'?') === False
  233. && strpos($text,'%') === False && strpos($text,'_') === False)
  234. return False;
  235. else
  236. return True;
  237. }
  238. ///////////////////////////////////////////////////////////////////////////////
  239. if (count($_GET) > 0 && !$_GET['h'])
  240. {
  241. // name
  242. $names = explode(' ',trim($_GET['n']));
  243. if ($names[0] !== "")
  244. {
  245. foreach($names as $name)
  246. {
  247. if (substr($name,0,1) == '~')
  248. {
  249. if ($name == '~') continue;
  250. $names_exc[] = substr($name,1);
  251. }
  252. else
  253. $names_inc[] = $name;
  254. }
  255. if (is_array($names_inc))
  256. {
  257. $where_is .= isset($where_is)?" AND (":"(";
  258. foreach($names_inc as $name)
  259. {
  260. if (!haswildcard($name))
  261. $name_is .= (isset($name_is)?" OR ":"")."u.username = ".sqlesc($name);
  262. else
  263. {
  264. $name = str_replace(array('?','*'), array('_','%'), $name);
  265. $name_is .= (isset($name_is)?" OR ":"")."u.username LIKE ".sqlesc($name);
  266. }
  267. }
  268. $where_is .= $name_is.")";
  269. unset($name_is);
  270. }
  271. if (is_array($names_exc))
  272. {
  273. $where_is .= isset($where_is)?" AND NOT (":" NOT (";
  274. foreach($names_exc as $name)
  275. {
  276. if (!haswildcard($name))
  277. $name_is .= (isset($name_is)?" OR ":"")."u.username = ".sqlesc($name);
  278. else
  279. {
  280. $name = str_replace(array('?','*'), array('_','%'), $name);
  281. $name_is .= (isset($name_is)?" OR ":"")."u.username LIKE ".sqlesc($name);
  282. }
  283. }
  284. $where_is .= $name_is.")";
  285. }
  286. $q .= ($q ? "&amp;" : "") . "n=".urlencode(trim($_GET['n']));
  287. }
  288. // email
  289. $emaila = explode(' ', trim($_GET['em']));
  290. if ($emaila[0] !== "")
  291. {
  292. $where_is .= isset($where_is)?" AND (":"(";
  293. foreach($emaila as $email)
  294. {
  295. if (strpos($email,'*') === False && strpos($email,'?') === False
  296. && strpos($email,'%') === False)
  297. {
  298. if (validemail($email) !== 1)
  299. {
  300. stdmsg("Error", "Bad email.");
  301. stdfoot();
  302. die();
  303. }
  304. $email_is .= (isset($email_is)?" OR ":"")."u.email =".sqlesc($email);
  305. }
  306. else
  307. {
  308. $sql_email = str_replace(array('?','*'), array('_','%'), $email);
  309. $email_is .= (isset($email_is)?" OR ":"")."u.email LIKE ".sqlesc($sql_email);
  310. }
  311. }
  312. $where_is .= $email_is.")";
  313. $q .= ($q ? "&amp;" : "") . "em=".urlencode(trim($_GET['em']));
  314. }
  315. //class
  316. // NB: the c parameter is passed as two units above the real one
  317. $class = $_GET['c'] - 2;
  318. if (is_valid_id($class + 1))
  319. {
  320. $where_is .= (isset($where_is)?" AND ":"")."u.class=$class";
  321. $q .= ($q ? "&amp;" : "") . "c=".($class+2);
  322. }
  323. // IP
  324. $ip = trim($_GET['ip']);
  325. if ($ip)
  326. {
  327. $regex = "/^(((1?\d{1,2})|(2[0-4]\d)|(25[0-5]))(\.\b|$)){4}$/";
  328. if (!preg_match($regex, $ip))
  329. {
  330. stdmsg("Error", "Bad IP.");
  331. stdfoot();
  332. die();
  333. }
  334. $mask = trim($_GET['ma']);
  335. if ($mask == "" || $mask == "255.255.255.255")
  336. $where_is .= (isset($where_is)?" AND ":"")."u.ip = '$ip'";
  337. else
  338. {
  339. if (substr($mask,0,1) == "/")
  340. {
  341. $n = substr($mask, 1, strlen($mask) - 1);
  342. if (!is_numeric($n) or $n < 0 or $n > 32)
  343. {
  344. stdmsg("Error", "Bad subnet mask.");
  345. stdfoot();
  346. die();
  347. }
  348. else
  349. $mask = long2ip(pow(2,32) - pow(2,32-$n));
  350. }
  351. elseif (!preg_match($regex, $mask))
  352. {
  353. stdmsg("Error", "Bad subnet mask.");
  354. stdfoot();
  355. die();
  356. }
  357. $where_is .= (isset($where_is)?" AND ":"")."INET_ATON(u.ip) & INET_ATON('$mask') = INET_ATON('$ip') & INET_ATON('$mask')";
  358. $q .= ($q ? "&amp;" : "") . "ma=$mask";
  359. }
  360. $q .= ($q ? "&amp;" : "") . "ip=$ip";
  361. }
  362. // ratio
  363. $ratio = trim($_GET['r']);
  364. if ($ratio)
  365. {
  366. if ($ratio == '---')
  367. {
  368. $ratio2 = "";
  369. $where_is .= isset($where_is)?" AND ":"";
  370. $where_is .= " u.uploaded = 0 and u.downloaded = 0";
  371. }
  372. elseif (strtolower(substr($ratio,0,3)) == 'inf')
  373. {
  374. $ratio2 = "";
  375. $where_is .= isset($where_is)?" AND ":"";
  376. $where_is .= " u.uploaded > 0 and u.downloaded = 0";
  377. }
  378. else
  379. {
  380. if (!is_numeric($ratio) || $ratio < 0)
  381. {
  382. stdmsg("Error", "Bad ratio.");
  383. stdfoot();
  384. die();
  385. }
  386. $where_is .= isset($where_is)?" AND ":"";
  387. $where_is .= " (u.uploaded/u.downloaded)";
  388. $ratiotype = $_GET['rt'];
  389. $q .= ($q ? "&amp;" : "") . "rt=$ratiotype";
  390. if ($ratiotype == "3")
  391. {
  392. $ratio2 = trim($_GET['r2']);
  393. if(!$ratio2)
  394. {
  395. stdmsg("Error", "Two ratios needed for this type of search.");
  396. stdfoot();
  397. die();
  398. }
  399. if (!is_numeric($ratio2) or $ratio2 < $ratio)
  400. {
  401. stdmsg("Error", "Bad second ratio.");
  402. stdfoot();
  403. die();
  404. }
  405. $where_is .= " BETWEEN $ratio and $ratio2";
  406. $q .= ($q ? "&amp;" : "") . "r2=$ratio2";
  407. }
  408. elseif ($ratiotype == "2")
  409. $where_is .= " < $ratio";
  410. elseif ($ratiotype == "1")
  411. $where_is .= " > $ratio";
  412. else
  413. $where_is .= " BETWEEN ($ratio - 0.004) and ($ratio + 0.004)";
  414. }
  415. $q .= ($q ? "&amp;" : "") . "r=$ratio";
  416. }
  417. // comment
  418. $comments = explode(' ',trim($_GET['co']));
  419. if ($comments[0] !== "")
  420. {
  421. foreach($comments as $comment)
  422. {
  423. if (substr($comment,0,1) == '~')
  424. {
  425. if ($comment == '~') continue;
  426. $comments_exc[] = substr($comment,1);
  427. }
  428. else
  429. $comments_inc[] = $comment;
  430. }
  431. if (is_array($comments_inc))
  432. {
  433. $where_is .= isset($where_is)?" AND (":"(";
  434. foreach($comments_inc as $comment)
  435. {
  436. if (!haswildcard($comment))
  437. $comment_is .= (isset($comment_is)?" OR ":"")."u.modcomment LIKE ".sqlesc("%".$comment."%");
  438. else
  439. {
  440. $comment = str_replace(array('?','*'), array('_','%'), $comment);
  441. $comment_is .= (isset($comment_is)?" OR ":"")."u.modcomment LIKE ".sqlesc($comment);
  442. }
  443. }
  444. $where_is .= $comment_is.")";
  445. unset($comment_is);
  446. }
  447. if (is_array($comments_exc))
  448. {
  449. $where_is .= isset($where_is)?" AND NOT (":" NOT (";
  450. foreach($comments_exc as $comment)
  451. {
  452. if (!haswildcard($comment))
  453. $comment_is .= (isset($comment_is)?" OR ":"")."u.modcomment LIKE ".sqlesc("%".$comment."%");
  454. else
  455. {
  456. $comment = str_replace(array('?','*'), array('_','%'), $comment);
  457. $comment_is .= (isset($comment_is)?" OR ":"")."u.modcomment LIKE ".sqlesc($comment);
  458. }
  459. }
  460. $where_is .= $comment_is.")";
  461. }
  462. $q .= ($q ? "&amp;" : "") . "co=".urlencode(trim($_GET['co']));
  463. }
  464. $unit = 1073741824; // 1GB
  465. // uploaded
  466. $ul = trim($_GET['ul']);
  467. if ($ul)
  468. {
  469. if (!is_numeric($ul) || $ul < 0)
  470. {
  471. stdmsg("Error", "Bad uploaded amount.");
  472. stdfoot();
  473. die();
  474. }
  475. $where_is .= isset($where_is)?" AND ":"";
  476. $where_is .= " u.uploaded ";
  477. $ultype = $_GET['ult'];
  478. $q .= ($q ? "&amp;" : "") . "ult=$ultype";
  479. if ($ultype == "3")
  480. {
  481. $ul2 = trim($_GET['ul2']);
  482. if(!$ul2)
  483. {
  484. stdmsg("Error", "Two uploaded amounts needed for this type of search.");
  485. stdfoot();
  486. die();
  487. }
  488. if (!is_numeric($ul2) or $ul2 < $ul)
  489. {
  490. stdmsg("Error", "Bad second uploaded amount.");
  491. stdfoot();
  492. die();
  493. }
  494. $where_is .= " BETWEEN ".$ul*$unit." and ".$ul2*$unit;
  495. $q .= ($q ? "&amp;" : "") . "ul2=$ul2";
  496. }
  497. elseif ($ultype == "2")
  498. $where_is .= " < ".$ul*$unit;
  499. elseif ($ultype == "1")
  500. $where_is .= " >". $ul*$unit;
  501. else
  502. $where_is .= " BETWEEN ".($ul - 0.004)*$unit." and ".($ul + 0.004)*$unit;
  503. $q .= ($q ? "&amp;" : "") . "ul=$ul";
  504. }
  505. // downloaded
  506. $dl = trim($_GET['dl']);
  507. if ($dl)
  508. {
  509. if (!is_numeric($dl) || $dl < 0)
  510. {
  511. stdmsg("Error", "Bad downloaded amount.");
  512. stdfoot();
  513. die();
  514. }
  515. $where_is .= isset($where_is)?" AND ":"";
  516. $where_is .= " u.downloaded ";
  517. $dltype = $_GET['dlt'];
  518. $q .= ($q ? "&amp;" : "") . "dlt=$dltype";
  519. if ($dltype == "3")
  520. {
  521. $dl2 = trim($_GET['dl2']);
  522. if(!$dl2)
  523. {
  524. stdmsg("Error", "Two downloaded amounts needed for this type of search.");
  525. stdfoot();
  526. die();
  527. }
  528. if (!is_numeric($dl2) or $dl2 < $dl)
  529. {
  530. stdmsg("Error", "Bad second downloaded amount.");
  531. stdfoot();
  532. die();
  533. }
  534. $where_is .= " BETWEEN ".$dl*$unit." and ".$dl2*$unit;
  535. $q .= ($q ? "&amp;" : "") . "dl2=$dl2";
  536. }
  537. elseif ($dltype == "2")
  538. $where_is .= " < ".$dl*$unit;
  539. elseif ($dltype == "1")
  540. $where_is .= " > ".$dl*$unit;
  541. else
  542. $where_is .= " BETWEEN ".($dl - 0.004)*$unit." and ".($dl + 0.004)*$unit;
  543. $q .= ($q ? "&amp;" : "") . "dl=$dl";
  544. }
  545. // date joined
  546. $date = trim($_GET['d']);
  547. if ($date)
  548. {
  549. if (!$date = mkdate($date))
  550. {
  551. stdmsg("Error", "Invalid date.");
  552. stdfoot();
  553. die();
  554. }
  555. $q .= ($q ? "&amp;" : "") . "d=$date";
  556. $datetype = $_GET['dt'];
  557. $q .= ($q ? "&amp;" : "") . "dt=$datetype";
  558. if ($datetype == "0")
  559. // For mySQL 4.1.1 or above use instead
  560. // $where_is .= (isset($where_is)?" AND ":"")."DATE(added) = DATE('$date')";
  561. $where_is .= (isset($where_is)?" AND ":"").
  562. "(UNIX_TIMESTAMP(added) - UNIX_TIMESTAMP('$date')) BETWEEN 0 and 86400";
  563. else
  564. {
  565. $where_is .= (isset($where_is)?" AND ":"")."u.added ";
  566. if ($datetype == "3")
  567. {
  568. $date2 = mkdate(trim($_GET['d2']));
  569. if ($date2)
  570. {
  571. if (!$date = mkdate($date))
  572. {
  573. stdmsg("Error", "Invalid date.");
  574. stdfoot();
  575. die();
  576. }
  577. $q .= ($q ? "&amp;" : "") . "d2=$date2";
  578. $where_is .= " BETWEEN '$date' and '$date2'";
  579. }
  580. else
  581. {
  582. stdmsg("Error", "Two dates needed for this type of search.");
  583. stdfoot();
  584. die();
  585. }
  586. }
  587. elseif ($datetype == "1")
  588. $where_is .= "< '$date'";
  589. elseif ($datetype == "2")
  590. $where_is .= "> '$date'";
  591. }
  592. }
  593. // date last seen
  594. $last = trim($_GET['ls']);
  595. if ($last)
  596. {
  597. if (!$last = mkdate($last))
  598. {
  599. stdmsg("Error", "Invalid date.");
  600. stdfoot();
  601. die();
  602. }
  603. $q .= ($q ? "&amp;" : "") . "ls=$last";
  604. $lasttype = $_GET['lst'];
  605. $q .= ($q ? "&amp;" : "") . "lst=$lasttype";
  606. if ($lasttype == "0")
  607. // For mySQL 4.1.1 or above use instead
  608. // $where_is .= (isset($where_is)?" AND ":"")."DATE(added) = DATE('$date')";
  609. $where_is .= (isset($where_is)?" AND ":"").
  610. "(UNIX_TIMESTAMP(last_access) - UNIX_TIMESTAMP('$last')) BETWEEN 0 and 86400";
  611. else
  612. {
  613. $where_is .= (isset($where_is)?" AND ":"")."u.last_access ";
  614. if ($lasttype == "3")
  615. {
  616. $last2 = mkdate(trim($_GET['ls2']));
  617. if ($last2)
  618. {
  619. $where_is .= " BETWEEN '$last' and '$last2'";
  620. $q .= ($q ? "&amp;" : "") . "ls2=$last2";
  621. }
  622. else
  623. {
  624. stdmsg("Error", "The second date is not valid.");
  625. stdfoot();
  626. die();
  627. }
  628. }
  629. elseif ($lasttype == "1")
  630. $where_is .= "< '$last'";
  631. elseif ($lasttype == "2")
  632. $where_is .= "> '$last'";
  633. }
  634. }
  635. // status
  636. $status = $_GET['st'];
  637. if ($status)
  638. {
  639. $where_is .= ((isset($where_is))?" AND ":"");
  640. if ($status == "1")
  641. $where_is .= "u.status = 'confirmed'";
  642. else
  643. $where_is .= "u.status = 'pending'";
  644. $q .= ($q ? "&amp;" : "") . "st=$status";
  645. }
  646. // account status
  647. $accountstatus = $_GET['as'];
  648. if ($accountstatus)
  649. {
  650. $where_is .= (isset($where_is))?" AND ":"";
  651. if ($accountstatus == "1")
  652. $where_is .= " u.enabled = 'yes'";
  653. else
  654. $where_is .= " u.enabled = 'no'";
  655. $q .= ($q ? "&amp;" : "") . "as=$accountstatus";
  656. }
  657. //donor
  658. $donor = $_GET['do'];
  659. if ($donor)
  660. {
  661. $where_is .= (isset($where_is))?" AND ":"";
  662. if ($donor == 1)
  663. $where_is .= " u.donor = 'yes'";
  664. else
  665. $where_is .= " u.donor = 'no'";
  666. $q .= ($q ? "&amp;" : "") . "do=$donor";
  667. }
  668. //warned
  669. $warned = $_GET['w'];
  670. if ($warned)
  671. {
  672. $where_is .= (isset($where_is))?" AND ":"";
  673. if ($warned == 1)
  674. $where_is .= " u.warned = 'yes'";
  675. else
  676. $where_is .= " u.warned = 'no'";
  677. $q .= ($q ? "&amp;" : "") . "w=$warned";
  678. }
  679. // disabled IP
  680. $disabled = $_GET['dip'];
  681. if ($disabled)
  682. {
  683. $distinct = "DISTINCT ";
  684. $join_is .= " JOIN users AS u2 ON u.ip = u2.ip";
  685. $where_is .= ((isset($where_is))?" AND ":"")."u2.enabled = 'no'";
  686. $q .= ($q ? "&amp;" : "") . "dip=$disabled";
  687. }
  688. // active
  689. $active = $_GET['ac'];
  690. if ($active == "1")
  691. {
  692. $distinct = "DISTINCT ";
  693. $join_is .= " JOIN peers AS p ON u.id = p.userid";
  694. $q .= ($q ? "&amp;" : "") . "ac=$active";
  695. }
  696. $from_is = "users AS u".$join_is;
  697. $distinct = isset($distinct)?$distinct:"";
  698. $queryc = "SELECT COUNT(".$distinct."u.id) FROM ".$from_is.
  699. (($where_is == "")?"":" WHERE $where_is ");
  700. $querypm = "FROM ".$from_is.(($where_is == "")?" ":" WHERE $where_is ");
  701. $select_is = "u.id, u.username, u.email, u.status, u.added, u.last_access, u.ip,
  702. u.class, u.uploaded, u.downloaded, u.donor, u.modcomment, u.enabled, u.warned";
  703. $query = "SELECT ".$distinct." ".$select_is." ".$querypm;
  704. // <temporary> /////////////////////////////////////////////////////
  705. if ($DEBUG_MODE > 0)
  706. {
  707. stdmsg("Count Query",$queryc);
  708. echo "<BR><BR>";
  709. stdmsg("Search Query",$query);
  710. echo "<BR><BR>";
  711. stdmsg("URL ",$q);
  712. if ($DEBUG_MODE == 2)
  713. die();
  714. echo "<BR><BR>";
  715. }
  716. // </temporary> /////////////////////////////////////////////////////
  717. $res = mysql_query($queryc) or mysql_error();
  718. $arr = mysql_fetch_row($res);
  719. $count = $arr[0];
  720. $q = isset($q)?($q."&amp;"):"";
  721. $perpage = 30;
  722. list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, $_SERVER["PHP_SELF"]."?".$q);
  723. $query .= $limit;
  724. $res = mysql_query($query) or mysql_error();
  725. if (mysql_num_rows($res) == 0)
  726. stdmsg("Warning","No user was found.");
  727. else
  728. {
  729. if ($count > $perpage)
  730. echo $pagertop;
  731. echo "<table border=1 cellspacing=0 cellpadding=5>\n";
  732. echo "<tr><td class=colhead align=left>Name</td>
  733. <td class=colhead align=left>Ratio</td>
  734. <td class=colhead align=left>IP</td>
  735. <td class=colhead align=left>Email</td>".
  736. "<td class=colhead align=left>Joined:</td>".
  737. "<td class=colhead align=left>Last seen:</td>".
  738. "<td class=colhead align=left>Status</td>".
  739. "<td class=colhead align=left>Enabled</td>".
  740. "<td class=colhead>pR</td>".
  741. "<td class=colhead>pUL</td>".
  742. "<td class=colhead>pDL</td>".
  743. "<td class=colhead>History</td></tr>";
  744. while ($user = mysql_fetch_array($res))
  745. {
  746. if ($user['added'] == '0000-00-00 00:00:00')
  747. $user['added'] = '---';
  748. if ($user['last_access'] == '0000-00-00 00:00:00')
  749. $user['last_access'] = '---';
  750. if ($user['ip'])
  751. {
  752. $nip = ip2long($user['ip']);
  753. $auxres = mysql_query("SELECT COUNT(*) FROM bans WHERE $nip >= first AND $nip <= last") or mysql_error();
  754. $array = mysql_fetch_row($auxres);
  755. if ($array[0] == 0)
  756. $ipstr = $user['ip'];
  757. else
  758. $ipstr = "<a href='/testip.php?ip=" . $user['ip'] . "'><font color='#FF0000'><b>" . $user['ip'] . "</b></font></a>";
  759. }
  760. else
  761. $ipstr = "---";
  762. $auxres = mysql_query("SELECT SUM(uploaded) AS pul, SUM(downloaded) AS pdl FROM peers WHERE userid = " . $user['id']) or mysql_error();
  763. $array = mysql_fetch_array($auxres);
  764. $pul = $array['pul'];
  765. $pdl = $array['pdl'];
  766. $auxres = mysql_query("SELECT COUNT(DISTINCT p.id) FROM posts AS p JOIN topics as t ON p.topicid = t.id
  767. JOIN forums AS f ON t.forumid = f.id WHERE p.userid = " . $user['id'] . " AND f.minclassread <= " .
  768. $CURUSER['class']) or mysql_error();
  769. $n = mysql_fetch_row($auxres);
  770. $n_posts = $n[0];
  771. $auxres = mysql_query("SELECT COUNT(id) FROM comments WHERE user = ".$user['id']) or mysql_error();
  772. // Use JOIN to exclude orphan comments
  773. // $auxres = mysql_query("SELECT COUNT(c.id) FROM comments AS c JOIN torrents as t ON c.torrent = t.id WHERE c.user = '".$user['id']."'") or mysql_error();
  774. $n = mysql_fetch_row($auxres);
  775. $n_comments = $n[0];
  776. echo "<tr><td><b><a href='userdetails.php?id=" . $user['id'] . "'>" .
  777. $user['username']."</a></b>" . get_user_icons($user) . "</td>" .
  778. // ($user["donor"] == "yes" ? "<img src=images/star.gif alt=\"Donor\">" : "") .
  779. // ($user["warned"] == "yes" ? "<img src=\"images/warned.gif\" alt=\"Warned\">" : "") . "</td>
  780. "<td>" . ratios($user['uploaded'], $user['downloaded']) . "</td>
  781. <td>" . $ipstr . "</td><td>" . $user['email'] . "</td>
  782. <td><div align=center>" . $user['added'] . "</div></td>
  783. <td><div align=center>" . $user['last_access'] . "</div></td>
  784. <td><div align=center>" . $user['status'] . "</div></td>
  785. <td><div align=center>" . $user['enabled']."</div></td>
  786. <td><div align=center>" . ratios($pul,$pdl) . "</div></td>" .
  787. "<td><div align=right>" . mksize($pul) . "</div></td>
  788. <td><div align=right>" . mksize($pdl) . "</div></td>
  789. <td><div align=center>".($n_posts?"<a href=/userhistory.php?action=viewposts&id=".$user['id'].">$n_posts</a>":$n_posts).
  790. "|".($n_comments?"<a href=/userhistory.php?action=viewcomments&id=".$user['id'].">$n_comments</a>":$n_comments).
  791. "</div></td></tr>\n";
  792. }
  793. echo "</table>";
  794. if ($count > $perpage)
  795. echo "$pagerbottom";
  796. /*
  797. <br><br>
  798. <form method=post action=/sendmessage.php>
  799. <table border="1" cellpadding="5" cellspacing="0">
  800. <tr>
  801. <td>
  802. <div align="center">
  803. <input name="pmees" type="hidden" value="<?echo $querypm?>" size=10>
  804. <input name="PM" type="submit" value="PM" class=btn>
  805. <input name="n_pms" type="hidden" value="<?echo $count?>" size=10>
  806. </div></td>
  807. </tr>
  808. </table>
  809. </form>
  810. */
  811. }
  812. }
  813. print("<p>$pagemenu<br>$browsemenu</p>");
  814. stdfoot();
  815. die;
  816. ?>