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.

ip_history.php 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <?php
  2. #declare(strict_types=1);
  3. /************************************************************************
  4. ||------------|| User IP history page ||---------------------------||
  5. This page lists previous IPs a user has connected to the site with. It
  6. gets called if $_GET['action'] == 'ips'.
  7. It also requires $_GET['userid'] in order to get the data for the correct
  8. user.
  9. ************************************************************************/
  10. define('IPS_PER_PAGE', 25);
  11. $UserID = $_GET['userid'];
  12. if (!is_number($UserID)) {
  13. error(404);
  14. }
  15. $DB->query("
  16. SELECT
  17. um.Username,
  18. p.Level AS Class
  19. FROM users_main AS um
  20. LEFT JOIN permissions AS p ON p.ID = um.PermissionID
  21. WHERE um.ID = $UserID");
  22. list($Username, $Class) = $DB->next_record();
  23. if (!check_perms('users_view_ips', $Class)) {
  24. error(403);
  25. }
  26. $UsersOnly = isset($_GET['usersonly']) ? $_GET['usersonly'] : 0;
  27. if (isset($_POST['ip'])) {
  28. $SearchIP = db_string(str_replace("*", "%", trim($_POST['ip'])));
  29. $SearchIPQuery = " AND h1.IP LIKE '$SearchIP' ";
  30. } else {
  31. $SearchIPQuery = "";
  32. }
  33. View::show_header("IP address history for $Username");
  34. ?>
  35. <script type="text/javascript">
  36. //<![CDATA[
  37. function ShowIPs(rowname) {
  38. $('tr[name="' + rowname + '"]').gtoggle();
  39. }
  40. function Ban(ip, id, elemID) {
  41. var notes = prompt("Enter notes for this ban");
  42. if (notes != null && notes.length > 0) {
  43. var xmlhttp;
  44. if (window.XMLHttpRequest) {
  45. xmlhttp = new XMLHttpRequest();
  46. } else {
  47. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  48. }
  49. xmlhttp.onreadystatechange = function() {
  50. if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  51. document.getElementById(elemID).innerHTML = "<strong>[Banned]</strong>";
  52. }
  53. }
  54. xmlhttp.open("GET", "tools.php?action=quick_ban&perform=create&ip=" + ip + "&notes=" + notes, true);
  55. xmlhttp.send();
  56. }
  57. }
  58. /*
  59. function UnBan(ip, id, elemID) {
  60. var xmlhttp;
  61. if (window.XMLHttpRequest) {
  62. xmlhttp = new XMLHttpRequest();
  63. } else {
  64. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  65. }
  66. xmlhttp.onreadystatechange = function() {
  67. if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  68. document.getElementById(elemID).innerHTML = "Ban";
  69. document.getElementById(elemID).onclick = function() { Ban(ip, id, elemID); return false; };
  70. }
  71. }
  72. xmlhttp.open("GET","tools.php?action=quick_ban&perform=delete&id=" + id + "&ip=" + ip, true);
  73. xmlhttp.send();
  74. }
  75. */
  76. //]]>
  77. </script>
  78. <?php
  79. list($Page, $Limit) = Format::page_limit(IPS_PER_PAGE);
  80. if ($UsersOnly == 1) {
  81. $RS = $DB->query("
  82. SELECT
  83. SQL_CALC_FOUND_ROWS
  84. h1.IP,
  85. h1.StartTime,
  86. h1.EndTime,
  87. GROUP_CONCAT(h2.UserID SEPARATOR '|'),
  88. GROUP_CONCAT(h2.StartTime SEPARATOR '|'),
  89. GROUP_CONCAT(IFNULL(h2.EndTime,0) SEPARATOR '|'),
  90. GROUP_CONCAT(um2.Username SEPARATOR '|'),
  91. GROUP_CONCAT(um2.Enabled SEPARATOR '|'),
  92. GROUP_CONCAT(ui2.Donor SEPARATOR '|'),
  93. GROUP_CONCAT(ui2.Warned SEPARATOR '|')
  94. FROM users_history_ips AS h1
  95. LEFT JOIN users_history_ips AS h2 ON h2.IP = h1.IP AND h2.UserID != $UserID
  96. LEFT JOIN users_main AS um2 ON um2.ID = h2.UserID
  97. LEFT JOIN users_info AS ui2 ON ui2.UserID = h2.UserID
  98. WHERE h1.UserID = '$UserID'
  99. AND h2.UserID > 0 $SearchIPQuery
  100. GROUP BY h1.IP, h1.StartTime
  101. ORDER BY h1.StartTime DESC
  102. LIMIT $Limit");
  103. } else {
  104. $RS = $DB->query("
  105. SELECT
  106. SQL_CALC_FOUND_ROWS
  107. h1.IP,
  108. h1.StartTime,
  109. h1.EndTime,
  110. GROUP_CONCAT(h2.UserID SEPARATOR '|'),
  111. GROUP_CONCAT(h2.StartTime SEPARATOR '|'),
  112. GROUP_CONCAT(IFNULL(h2.EndTime,0) SEPARATOR '|'),
  113. GROUP_CONCAT(um2.Username SEPARATOR '|'),
  114. GROUP_CONCAT(um2.Enabled SEPARATOR '|'),
  115. GROUP_CONCAT(ui2.Donor SEPARATOR '|'),
  116. GROUP_CONCAT(ui2.Warned SEPARATOR '|')
  117. FROM users_history_ips AS h1
  118. LEFT JOIN users_history_ips AS h2 ON h2.IP = h1.IP AND h2.UserID != $UserID
  119. LEFT JOIN users_main AS um2 ON um2.ID = h2.UserID
  120. LEFT JOIN users_info AS ui2 ON ui2.UserID = h2.UserID
  121. WHERE h1.UserID = '$UserID' $SearchIPQuery
  122. GROUP BY h1.IP, h1.StartTime
  123. ORDER BY h1.StartTime DESC
  124. LIMIT $Limit");
  125. }
  126. $DB->query('SELECT FOUND_ROWS()');
  127. list($NumResults) = $DB->next_record();
  128. $DB->set_query_id($RS);
  129. $Pages = Format::get_pages($Page, $NumResults, IPS_PER_PAGE, 9);
  130. ?>
  131. <div>
  132. <div class="header">
  133. <h2>IP address history for <a
  134. href="user.php?id=<?=$UserID?>"><?=$Username?></a></h2>
  135. <div class="linkbox">
  136. <?php if ($UsersOnly) { ?>
  137. <a href="userhistory.php?action=ips&amp;userid=<?=$UserID?>"
  138. class="brackets">View all IP addresses</a>
  139. <?php } else { ?>
  140. <a href="userhistory.php?action=ips&amp;userid=<?=$UserID?>&amp;usersonly=1"
  141. class="brackets">View IP addresses with users</a>
  142. <?php } ?>
  143. </div>
  144. <?php if ($Pages) { ?>
  145. <div class="linkbox pager"><?=$Pages?>
  146. </div>
  147. <?php } ?>
  148. </div>
  149. <table>
  150. <tr class="colhead">
  151. <td>IP address search</td>
  152. </tr>
  153. <tr>
  154. <td>
  155. <form class="search_form" name="ip_log" method="post" action="">
  156. <input type="text" name="ip" />
  157. <input type="submit" value="Search" />
  158. Wildcard (*) search examples: 127.0.* or 1*2.0.*.1 or *.*.*.*
  159. </form>
  160. </td>
  161. </tr>
  162. </table>
  163. <table id="iphistory">
  164. <tr class="colhead">
  165. <td>IP address</td>
  166. <td>Started <a href="#"
  167. onclick="$('#iphistory td:nth-child(2), #iphistory td:nth-child(4)').ghide(); $('#iphistory td:nth-child(3), #iphistory td:nth-child(5)').gshow(); return false;"
  168. class="brackets">Toggle</a></td>
  169. <td class="hidden">Started <a href="#"
  170. onclick="$('#iphistory td:nth-child(2), #iphistory td:nth-child(4)').gshow(); $('#iphistory td:nth-child(3), #iphistory td:nth-child(5)').ghide(); return false;"
  171. class="brackets">Toggle</a></td>
  172. <td>Ended</td>
  173. <td class="hidden">Ended</td>
  174. <td>Elapsed</td>
  175. </tr>
  176. <?php
  177. $counter = 0;
  178. $IPs = [];
  179. $Results = $DB->to_array();
  180. $CanManageIPBans = check_perms('admin_manage_ipbans');
  181. foreach ($Results as $Index => $Result) {
  182. list($IP, $StartTime, $EndTime, $UserIDs, $UserStartTimes, $UserEndTimes, $Usernames, $UsersEnabled, $UsersDonor, $UsersWarned) = $Result;
  183. $IP = apcu_exists('DBKEY') ? Crypto::decrypt($IP) : '[Encrypted]';
  184. $HasDupe = false;
  185. $UserIDs = explode('|', $UserIDs);
  186. if (!$EndTime) {
  187. $EndTime = sqltime();
  188. }
  189. if ($UserIDs[0] != 0) {
  190. $HasDupe = true;
  191. $UserStartTimes = explode('|', $UserStartTimes);
  192. $UserEndTimes = explode('|', $UserEndTimes);
  193. $Usernames = explode('|', $Usernames);
  194. $UsersEnabled = explode('|', $UsersEnabled);
  195. $UsersDonor = explode('|', $UsersDonor);
  196. $UsersWarned = explode('|', $UsersWarned);
  197. } ?>
  198. <tr class="row">
  199. <td>
  200. <?=$IP?>
  201. <?php
  202. if ($CanManageIPBans) {
  203. if (!isset($IPs[$IP])) {
  204. $sql = "
  205. SELECT ID, FromIP, ToIP
  206. FROM ip_bans
  207. WHERE '".Tools::ip_to_unsigned($IP)."' BETWEEN FromIP AND ToIP
  208. LIMIT 1";
  209. $DB->query($sql);
  210. if ($DB->has_results()) {
  211. $IPs[$IP] = true; ?>
  212. <strong>[Banned]</strong>
  213. <?php
  214. } else {
  215. $IPs[$IP] = false; ?>
  216. <a id="<?=$counter?>" href="#"
  217. onclick="Ban('<?=$IP?>', '', '<?=$counter?>'); this.onclick = null; return false;"
  218. class="brackets">Ban</a>
  219. <?php
  220. }
  221. $counter++;
  222. }
  223. } ?>
  224. <br />
  225. <?=Tools::get_host_by_ajax($IP)?>
  226. <?=($HasDupe ? '<a href="#" onclick="ShowIPs('.$Index.'); return false;">('.count($UserIDs).')</a>' : '(0)')?>
  227. </td>
  228. <td><?=time_diff($StartTime)?>
  229. </td>
  230. <td class="hidden"><?=$StartTime?>
  231. </td>
  232. <td><?=time_diff($EndTime)?>
  233. </td>
  234. <td class="hidden"><?=$EndTime?>
  235. </td>
  236. <td>
  237. <?//time_diff(strtotime($StartTime), strtotime($EndTime));?>
  238. </td>
  239. </tr>
  240. <?php
  241. if ($HasDupe) {
  242. $HideMe = (count($UserIDs) > 10);
  243. foreach ($UserIDs as $Key => $Val) {
  244. if (!$UserEndTimes[$Key]) {
  245. $UserEndTimes[$Key] = sqltime();
  246. } ?>
  247. <tr
  248. class="row<?=($HideMe ? ' hidden' : '')?>"
  249. name="<?=$Index?>">
  250. <td>&nbsp;&nbsp;&#187;&nbsp;<?=Users::format_username($Val, true, true, true)?>
  251. </td>
  252. <td><?=time_diff($UserStartTimes[$Key])?>
  253. </td>
  254. <td class="hidden"><?=$UserStartTimes[$Key]?>
  255. </td>
  256. <td><?=time_diff($UserEndTimes[$Key])?>
  257. </td>
  258. <td class="hidden"><?=$UserEndTimes[$Key]?>
  259. </td>
  260. <td>
  261. <?//time_diff(strtotime($UserStartTimes[$Key]), strtotime($UserEndTimes[$Key]));?>
  262. </td>
  263. </tr>
  264. <?php
  265. }
  266. }
  267. }
  268. ?>
  269. </table>
  270. <div class="linkbox">
  271. <?=$Pages?>
  272. </div>
  273. </div>
  274. <?php View::show_footer();