Gazelle/sections/userhistory/ip_history.php

264 lines
7.7 KiB
PHP
Raw Normal View History

2013-05-28 08:01:02 +00:00
<?php
2011-03-28 14:21:28 +00:00
/************************************************************************
||------------|| User IP history page ||---------------------------||
This page lists previous IPs a user has connected to the site with. It
gets called if $_GET['action'] == 'ips'.
It also requires $_GET['userid'] in order to get the data for the correct
user.
************************************************************************/
define('IPS_PER_PAGE', 25);
$UserID = $_GET['userid'];
2013-04-20 08:01:01 +00:00
if (!is_number($UserID)) {
error(404);
}
2011-03-28 14:21:28 +00:00
2013-04-20 08:01:01 +00:00
$DB->query("
SELECT
um.Username,
p.Level AS Class
FROM users_main AS um
LEFT JOIN permissions AS p ON p.ID=um.PermissionID
WHERE um.ID = ".$UserID);
list($Username, $Class) = $DB->next_record();
2013-04-20 08:01:01 +00:00
if (!check_perms('users_view_ips', $Class)) {
error(403);
}
$UsersOnly = $_GET['usersonly'];
2011-03-28 14:21:28 +00:00
2013-04-20 08:01:01 +00:00
if (isset($_POST['ip'])) {
2012-08-23 08:00:17 +00:00
$SearchIP = db_string($_POST['ip']);
$SearchIPQuery = " AND h1.IP = '$SearchIP' ";
}
2013-05-16 16:15:57 +00:00
View::show_header("IP address history for $Username");
2011-03-28 14:21:28 +00:00
?>
2013-02-07 08:00:47 +00:00
<script type="text/javascript">//<![CDATA[
2011-03-28 14:21:28 +00:00
function ShowIPs(rowname) {
2013-06-17 08:01:02 +00:00
$('tr[name="'+rowname+'"]').gtoggle();
2012-07-22 08:00:16 +00:00
}
function Ban(ip, id, elemID) {
2013-02-22 08:00:24 +00:00
var notes = prompt("Enter notes for this ban");
2013-04-20 08:01:01 +00:00
if (notes != null && notes.length > 0) {
2012-07-22 08:00:16 +00:00
var xmlhttp;
if (window.XMLHttpRequest) {
2013-02-07 08:00:47 +00:00
xmlhttp=new XMLHttpRequest();
} else {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
2012-07-22 08:00:16 +00:00
xmlhttp.onreadystatechange=function() {
2013-05-16 16:15:57 +00:00
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
2012-07-22 08:00:16 +00:00
document.getElementById(elemID).innerHTML = "<strong>[Banned]</strong>";
}
2013-02-07 08:00:47 +00:00
}
2012-07-22 08:00:16 +00:00
xmlhttp.open("GET","tools.php?action=quick_ban&perform=create&ip=" + ip + "&notes=" + notes,true);
xmlhttp.send();
}
}
/*
function UnBan(ip, id, elemID) {
var xmlhttp;
if (window.XMLHttpRequest) {
2013-02-07 08:00:47 +00:00
xmlhttp=new XMLHttpRequest();
} else {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
2012-07-22 08:00:16 +00:00
xmlhttp.onreadystatechange=function() {
2013-05-16 16:15:57 +00:00
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
2012-07-22 08:00:16 +00:00
document.getElementById(elemID).innerHTML = "Ban";
2013-05-16 16:15:57 +00:00
document.getElementById(elemID).onclick = function() { Ban(ip, id, elemID); return false; };
2012-07-22 08:00:16 +00:00
}
}
2013-02-07 08:00:47 +00:00
xmlhttp.open("GET","tools.php?action=quick_ban&perform=delete&id=" + id + "&ip=" + ip,true);
2012-07-22 08:00:16 +00:00
xmlhttp.send();
2011-03-28 14:21:28 +00:00
}
2013-02-07 08:00:47 +00:00
*/
//]]>
2011-03-28 14:21:28 +00:00
</script>
<?
2013-05-28 08:01:02 +00:00
list($Page, $Limit) = Format::page_limit(IPS_PER_PAGE);
2011-03-28 14:21:28 +00:00
if ($UsersOnly == 1) {
2013-04-20 08:01:01 +00:00
$RS = $DB->query("
2013-05-29 08:00:51 +00:00
SELECT
SQL_CALC_FOUND_ROWS
2013-02-07 08:00:47 +00:00
h1.IP,
h1.StartTime,
h1.EndTime,
GROUP_CONCAT(h2.UserID SEPARATOR '|'),
GROUP_CONCAT(h2.StartTime SEPARATOR '|'),
GROUP_CONCAT(IFNULL(h2.EndTime,0) SEPARATOR '|'),
GROUP_CONCAT(um2.Username SEPARATOR '|'),
GROUP_CONCAT(um2.Enabled SEPARATOR '|'),
GROUP_CONCAT(ui2.Donor SEPARATOR '|'),
GROUP_CONCAT(ui2.Warned SEPARATOR '|')
2013-04-20 08:01:01 +00:00
FROM users_history_ips AS h1
2013-02-07 08:00:47 +00:00
LEFT JOIN users_history_ips AS h2 ON h2.IP=h1.IP AND h2.UserID!=$UserID
LEFT JOIN users_main AS um2 ON um2.ID=h2.UserID
LEFT JOIN users_info AS ui2 ON ui2.UserID=h2.UserID
2011-03-28 14:21:28 +00:00
WHERE h1.UserID='$UserID'
2013-04-20 08:01:01 +00:00
AND h2.UserID>0 $SearchIPQuery
GROUP BY h1.IP, h1.StartTime
ORDER BY h1.StartTime DESC
LIMIT $Limit");
2011-03-28 14:21:28 +00:00
} else {
2013-04-20 08:01:01 +00:00
$RS = $DB->query("
2013-05-29 08:00:51 +00:00
SELECT
SQL_CALC_FOUND_ROWS
2013-04-20 08:01:01 +00:00
h1.IP,
h1.StartTime,
h1.EndTime,
GROUP_CONCAT(h2.UserID SEPARATOR '|'),
GROUP_CONCAT(h2.StartTime SEPARATOR '|'),
GROUP_CONCAT(IFNULL(h2.EndTime,0) SEPARATOR '|'),
GROUP_CONCAT(um2.Username SEPARATOR '|'),
GROUP_CONCAT(um2.Enabled SEPARATOR '|'),
GROUP_CONCAT(ui2.Donor SEPARATOR '|'),
GROUP_CONCAT(ui2.Warned SEPARATOR '|')
2011-03-28 14:21:28 +00:00
FROM users_history_ips AS h1
2013-04-20 08:01:01 +00:00
LEFT JOIN users_history_ips AS h2 ON h2.IP=h1.IP AND h2.UserID!=$UserID
LEFT JOIN users_main AS um2 ON um2.ID=h2.UserID
LEFT JOIN users_info AS ui2 ON ui2.UserID=h2.UserID
2012-08-23 08:00:17 +00:00
WHERE h1.UserID='$UserID' $SearchIPQuery
2011-03-28 14:21:28 +00:00
GROUP BY h1.IP, h1.StartTime
2013-04-20 08:01:01 +00:00
ORDER BY h1.StartTime DESC
LIMIT $Limit");
2011-03-28 14:21:28 +00:00
}
$DB->query("SELECT FOUND_ROWS()");
list($NumResults) = $DB->next_record();
$DB->set_query_id($RS);
2013-04-20 08:01:01 +00:00
$Pages = Format::get_pages($Page, $NumResults, IPS_PER_PAGE, 9);
2011-03-28 14:21:28 +00:00
?>
2012-08-19 08:00:19 +00:00
<div class="thin">
<div class="header">
2013-02-07 08:00:47 +00:00
<h2>IP address history for <a href="/user.php?id=<?=$UserID?>"><?=$Username?></a></h2>
2013-05-21 08:01:09 +00:00
<div class="linkbox">
2013-04-20 08:01:01 +00:00
<? if ($UsersOnly) { ?>
2013-05-21 08:01:09 +00:00
<a href="userhistory.php?action=ips&amp;userid=<?=$UserID?>" class="brackets">View all IP addresses</a>
2013-04-20 08:01:01 +00:00
<? } else { ?>
2013-05-21 08:01:09 +00:00
<a href="userhistory.php?action=ips&amp;userid=<?=$UserID?>&amp;usersonly=1" class="brackets">View IP addresses with users</a>
<? } ?>
</div>
<? if ($Pages) { ?>
<div class="linkbox pager"><?=$Pages?></div>
2013-04-20 08:01:01 +00:00
<? } ?>
2012-08-23 08:00:17 +00:00
</div>
2011-03-28 14:21:28 +00:00
<table>
2012-08-23 08:00:17 +00:00
<tr class="colhead">
2013-02-09 08:01:01 +00:00
<td>IP address search</td>
2012-08-23 08:00:17 +00:00
</tr>
2013-02-22 08:00:24 +00:00
2012-08-23 08:00:17 +00:00
<tr><td>
2012-09-15 08:00:25 +00:00
<form class="search_form" name="ip_log" method="post" action="">
2012-09-19 08:00:35 +00:00
<input type="text" name="ip" />
<input type="submit" value="Search" />
</form>
2013-02-22 08:00:24 +00:00
</td></tr>
2012-08-23 08:00:17 +00:00
</table>
2013-05-07 08:00:23 +00:00
<table id="iphistory">
2011-03-28 14:21:28 +00:00
<tr class="colhead">
<td>IP address</td>
2013-06-17 08:01:02 +00:00
<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>
<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>
2011-03-28 14:21:28 +00:00
<td>Ended</td>
2013-05-07 08:00:23 +00:00
<td class="hidden">Ended</td>
2011-03-28 14:21:28 +00:00
<td>Elapsed</td>
</tr>
<?
2012-07-22 08:00:16 +00:00
$counter = 0;
$IPs = array();
2011-03-28 14:21:28 +00:00
$Results = $DB->to_array();
2012-07-25 08:00:15 +00:00
$CanManageIPBans = check_perms('admin_manage_ipbans');
2013-04-20 08:01:01 +00:00
foreach ($Results as $Index => $Result) {
2011-03-28 14:21:28 +00:00
list($IP, $StartTime, $EndTime, $UserIDs, $UserStartTimes, $UserEndTimes, $Usernames, $UsersEnabled, $UsersDonor, $UsersWarned) = $Result;
$HasDupe = false;
$UserIDs = explode('|', $UserIDs);
2013-04-20 08:01:01 +00:00
if (!$EndTime) {
$EndTime = sqltime();
}
if ($UserIDs[0] != 0) {
2011-03-28 14:21:28 +00:00
$HasDupe = true;
$UserStartTimes = explode('|', $UserStartTimes);
$UserEndTimes = explode('|', $UserEndTimes);
$Usernames = explode('|', $Usernames);
$UsersEnabled = explode('|', $UsersEnabled);
$UsersDonor = explode('|', $UsersDonor);
$UsersWarned = explode('|', $UsersWarned);
}
?>
<tr class="rowa">
<td>
2013-04-20 08:01:01 +00:00
<?=$IP?> (<?=Tools::get_country_code_by_ajax($IP)?>)<?
if ($CanManageIPBans) {
2013-05-07 08:00:23 +00:00
if (!isset($IPs[$IP])) {
$sql = "SELECT ID, FromIP, ToIP FROM ip_bans WHERE '".Tools::ip_to_unsigned($IP)."' BETWEEN FromIP AND ToIP LIMIT 1";
2012-07-22 08:00:16 +00:00
$DB->query($sql);
2013-02-22 08:00:24 +00:00
2013-04-20 08:01:01 +00:00
if ($DB->record_count() > 0) {
2013-05-07 08:00:23 +00:00
$IPs[$IP] = true;
?>
<strong>[Banned]</strong>
<?
} else {
$IPs[$IP] = false;
?>
2013-02-09 08:01:01 +00:00
<a id="<?=$counter?>" href="#" onclick="Ban('<?=$IP?>', '<?=$ID?>', '<?=$counter?>'); this.onclick=null;return false;" class="brackets">Ban</a>
2013-05-07 08:00:23 +00:00
<?
}
2012-07-22 08:00:16 +00:00
$counter++;
2013-02-22 08:00:24 +00:00
}
}
2012-07-22 08:00:16 +00:00
?>
2013-05-07 08:00:23 +00:00
<br />
<?=Tools::get_host_by_ajax($IP)?>
<?=($HasDupe ? '<a href="#" onclick="ShowIPs('.$Index.'); return false;">('.count($UserIDs).')</a>' : '(0)')?>
</td>
2011-03-28 14:21:28 +00:00
<td><?=time_diff($StartTime)?></td>
2013-05-07 08:00:23 +00:00
<td class="hidden"><?=$StartTime?></td>
2011-03-28 14:21:28 +00:00
<td><?=time_diff($EndTime)?></td>
2013-05-07 08:00:23 +00:00
<td class="hidden"><?=$EndTime?></td>
2011-03-28 14:21:28 +00:00
<td><?//time_diff(strtotime($StartTime), strtotime($EndTime)); ?></td>
</tr>
<?
2013-04-20 08:01:01 +00:00
if ($HasDupe) {
2011-03-28 14:21:28 +00:00
$HideMe = (count($UserIDs) > 10);
foreach ($UserIDs as $Key => $Val) {
2013-05-07 08:00:23 +00:00
if (!$UserEndTimes[$Key]) {
$UserEndTimes[$Key] = sqltime();
}
2011-03-28 14:21:28 +00:00
?>
<tr class="rowb<?=($HideMe ? ' hidden' : '')?>" name="<?=$Index?>">
2012-10-11 08:00:15 +00:00
<td>&nbsp;&nbsp;&#187;&nbsp;<?=Users::format_username($Val, true, true, true)?></td>
2011-03-28 14:21:28 +00:00
<td><?=time_diff($UserStartTimes[$Key])?></td>
2013-05-07 08:00:23 +00:00
<td class="hidden"><?=$UserStartTimes[$Key]?></td>
2011-03-28 14:21:28 +00:00
<td><?=time_diff($UserEndTimes[$Key])?></td>
2013-05-07 08:00:23 +00:00
<td class="hidden"><?=$UserEndTimes[$Key]?></td>
2011-03-28 14:21:28 +00:00
<td><?//time_diff(strtotime($UserStartTimes[$Key]), strtotime($UserEndTimes[$Key])); ?></td>
</tr>
<?
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
}
}
}
?>
</table>
<div class="linkbox">
<?=$Pages?>
</div>
</div>
2013-05-07 08:00:23 +00:00
<?
View::show_footer();