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.

ip_history.php 8.4KB

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