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);
|
|
|
|
}
|
2015-01-28 08:00:26 +00:00
|
|
|
$UserInfo = Users::user_info($UserID);
|
|
|
|
if (!check_perms('users_view_ips', $UserInfo['Class'])) {
|
2011-06-23 08:00:06 +00:00
|
|
|
error(403);
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:00:26 +00:00
|
|
|
$UsersOnly = !empty($_GET['usersonly']);
|
2011-03-28 14:21:28 +00:00
|
|
|
|
2015-01-28 08:00:26 +00:00
|
|
|
if (!empty($_GET['ip']) && trim($_GET['ip']) != '') {
|
|
|
|
$SearchIP = db_string(str_replace("*", "%", trim($_GET['ip'])));
|
|
|
|
$SearchIPQuery = "AND IP LIKE '$SearchIP'";
|
|
|
|
} else {
|
|
|
|
$SearchIPQuery = "";
|
2012-08-23 08:00:17 +00:00
|
|
|
}
|
|
|
|
|
2015-01-28 08:00:26 +00:00
|
|
|
View::show_header("IP address history for $UserInfo[Username]");
|
2011-03-28 14:21:28 +00:00
|
|
|
?>
|
2013-02-07 08:00:47 +00:00
|
|
|
<script type="text/javascript">//<![CDATA[
|
2015-01-28 08:00:26 +00:00
|
|
|
function Ban(ip, 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-07-04 08:00:56 +00:00
|
|
|
xmlhttp = new XMLHttpRequest();
|
2013-02-07 08:00:47 +00:00
|
|
|
} else {
|
2013-07-04 08:00:56 +00:00
|
|
|
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
|
2013-02-07 08:00:47 +00:00
|
|
|
}
|
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
|
|
|
}
|
2013-07-04 08:00:56 +00:00
|
|
|
xmlhttp.open("GET", "tools.php?action=quick_ban&perform=create&ip=" + ip + "¬es=" + notes, true);
|
2012-07-22 08:00:16 +00:00
|
|
|
xmlhttp.send();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
function UnBan(ip, id, elemID) {
|
|
|
|
var xmlhttp;
|
|
|
|
if (window.XMLHttpRequest) {
|
2013-07-04 08:00:56 +00:00
|
|
|
xmlhttp = new XMLHttpRequest();
|
2013-02-07 08:00:47 +00:00
|
|
|
} else {
|
2013-07-04 08:00:56 +00:00
|
|
|
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
|
2013-02-07 08:00:47 +00:00
|
|
|
}
|
2013-07-04 08:00:56 +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";
|
2015-01-28 08:00:26 +00:00
|
|
|
document.getElementById(elemID).onclick = function() { Ban(ip, elemID); return false; };
|
2012-07-22 08:00:16 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-04 08:00:56 +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
|
|
|
|
2015-01-28 08:00:26 +00:00
|
|
|
if ($UsersOnly) {
|
|
|
|
$DB->query("
|
|
|
|
SELECT DISTINCT IP
|
|
|
|
FROM users_history_ips
|
|
|
|
WHERE UserID = '$UserID'
|
|
|
|
$SearchIPQuery");
|
|
|
|
|
|
|
|
if ($DB->has_results()) {
|
|
|
|
$UserIPs = db_array($DB->collect('IP'), array(), true);
|
|
|
|
$DB->query("
|
|
|
|
SELECT DISTINCT IP
|
|
|
|
FROM users_history_ips
|
|
|
|
WHERE UserID != '$UserID'
|
|
|
|
AND IP IN (" . implode(',', $UserIPs) . ")");
|
|
|
|
unset($UserIPs);
|
|
|
|
|
|
|
|
if ($DB->has_results()) {
|
|
|
|
$OtherIPs = db_array($DB->collect('IP'), array(), true);
|
|
|
|
$QueryID = $DB->query("
|
|
|
|
SELECT
|
|
|
|
SQL_CALC_FOUND_ROWS
|
|
|
|
IP,
|
|
|
|
StartTime,
|
|
|
|
EndTime
|
|
|
|
FROM users_history_ips
|
|
|
|
WHERE UserID = '$UserID'
|
|
|
|
AND IP IN (" . implode(',', $OtherIPs) . ")
|
|
|
|
ORDER BY StartTime DESC
|
|
|
|
LIMIT $Limit");
|
|
|
|
unset($OtherIPs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$QueryID = $DB->query("
|
2013-05-29 08:00:51 +00:00
|
|
|
SELECT
|
|
|
|
SQL_CALC_FOUND_ROWS
|
2015-01-28 08:00:26 +00:00
|
|
|
IP,
|
|
|
|
StartTime,
|
|
|
|
EndTime
|
|
|
|
FROM users_history_ips
|
|
|
|
WHERE UserID = '$UserID'
|
|
|
|
$SearchIPQuery
|
|
|
|
ORDER BY StartTime DESC
|
2013-04-20 08:01:01 +00:00
|
|
|
LIMIT $Limit");
|
2015-01-28 08:00:26 +00:00
|
|
|
}
|
|
|
|
|
2015-09-11 08:00:26 +00:00
|
|
|
|
2015-01-28 08:00:26 +00:00
|
|
|
if (isset($QueryID)) {
|
|
|
|
$DB->query('SELECT FOUND_ROWS()');
|
|
|
|
list($NumResults) = $DB->next_record();
|
|
|
|
$DB->set_query_id($QueryID);
|
|
|
|
$Results = $DB->to_array(false, MYSQLI_ASSOC);
|
|
|
|
$IPMatches = $IPMatchesUser = $IPMatchesIgnored = array();
|
2011-03-28 14:21:28 +00:00
|
|
|
} else {
|
2015-01-28 08:00:26 +00:00
|
|
|
$NumResults = 0;
|
|
|
|
$Results = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($Results)) {
|
|
|
|
$IPs = db_array($DB->collect('IP'), array(), true);
|
|
|
|
$DB->query("
|
2013-05-29 08:00:51 +00:00
|
|
|
SELECT
|
2015-01-28 08:00:26 +00:00
|
|
|
UserID,
|
|
|
|
IP,
|
|
|
|
StartTime,
|
|
|
|
EndTime
|
|
|
|
FROM users_history_ips
|
|
|
|
WHERE IP IN (" . implode(',', $IPs) . ")
|
|
|
|
AND UserID != '$UserID'
|
|
|
|
AND UserID != 0
|
|
|
|
ORDER BY StartTime DESC");
|
|
|
|
unset($IPs);
|
|
|
|
|
|
|
|
while ($Match = $DB->next_record(MYSQLI_ASSOC)) {
|
|
|
|
$OtherIP = $Match['IP'];
|
|
|
|
$OtherUserID = $Match['UserID'];
|
|
|
|
if (!isset($IPMatchesUser[$OtherIP][$OtherUserID])) {
|
|
|
|
$IPMatchesUser[$OtherIP][$OtherUserID] = 0;
|
|
|
|
}
|
|
|
|
if ($IPMatchesUser[$OtherIP][$OtherUserID] < 500) {
|
|
|
|
$IPMatches[$OtherIP][] = $Match;
|
|
|
|
} else {
|
|
|
|
if (!isset($IPMatchesIgnored[$OtherIP][$OtherUserID])) {
|
|
|
|
$IPMatchesIgnored[$OtherIP][$OtherUserID] = 0;
|
|
|
|
}
|
|
|
|
$IPMatchesIgnored[$OtherIP][$OtherUserID]++;
|
|
|
|
}
|
|
|
|
$IPMatchesUser[$OtherIP][$OtherUserID]++;
|
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
|
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">
|
2015-01-28 08:00:26 +00:00
|
|
|
<h2>IP address history for <a href="user.php?id=<?=$UserID?>"><?=$UserInfo['Username']?></a></h2>
|
2013-05-21 08:01:09 +00:00
|
|
|
<div class="linkbox">
|
2015-09-11 08:00:26 +00:00
|
|
|
<?
|
|
|
|
if ($UsersOnly) { ?>
|
2015-01-28 08:00:26 +00:00
|
|
|
<a href="userhistory.php?<?=Format::get_url(array('usersonly'))?>" class="brackets">View all IP addresses</a>
|
2013-04-20 08:01:01 +00:00
|
|
|
<? } else { ?>
|
2015-01-28 08:00:26 +00:00
|
|
|
<a href="userhistory.php?<?=Format::get_url()?>&usersonly=1" class="brackets">View IP addresses with users</a>
|
2013-05-21 08:01:09 +00:00
|
|
|
<? } ?>
|
|
|
|
</div>
|
2015-09-11 08:00:26 +00:00
|
|
|
<?
|
|
|
|
if ($Pages) { ?>
|
2013-05-21 08:01:09 +00:00
|
|
|
<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>
|
2015-01-28 08:00:26 +00:00
|
|
|
<form class="search_form" name="ip_log" method="get" action="">
|
|
|
|
<input type="hidden" name="action" value="<?=$_GET['action']?>" />
|
|
|
|
<input type="hidden" name="userid" value="<?=$UserID?>" />
|
|
|
|
<? if ($UsersOnly) { ?>
|
|
|
|
<input type="hidden" name="usersonly" value="1" />
|
|
|
|
<? } ?>
|
|
|
|
<input type="text" name="ip" value="<?=Format::form('ip')?>" />
|
2012-09-19 08:00:35 +00:00
|
|
|
<input type="submit" value="Search" />
|
2014-01-05 08:00:35 +00:00
|
|
|
Wildcard (*) search examples: 127.0.* or 1*2.0.*.1 or *.*.*.*
|
2012-09-19 08:00:35 +00:00
|
|
|
</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>
|
2015-01-28 08:00:26 +00:00
|
|
|
<td>Started <a href="#" onclick="$('#iphistory .reltime').gtoggle(); $('#iphistory .abstime').gtoggle(); 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>
|
|
|
|
<?
|
2015-01-28 08:00:26 +00:00
|
|
|
$Counter = 0;
|
|
|
|
$IPBanChecks = array();
|
|
|
|
$PrintedIPs = 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) {
|
2015-01-28 08:00:26 +00:00
|
|
|
$IP = $Result['IP'];
|
|
|
|
$StartTime = $Result['StartTime'];
|
|
|
|
$EndTime = $Result['EndTime'];
|
|
|
|
if (!$Result['EndTime']) {
|
2013-04-20 08:01:01 +00:00
|
|
|
$EndTime = sqltime();
|
|
|
|
}
|
2015-01-28 08:00:26 +00:00
|
|
|
$OtherUsers = isset($IPMatches[$IP]) ? $IPMatches[$IP] : array();
|
|
|
|
$ElementID = 'ip_' . strtr($IP, '.', '-');
|
|
|
|
$FirstOccurrence = !isset($IPIndexes[$IP]);
|
|
|
|
if ($FirstOccurrence) {
|
|
|
|
$IPIndexes[$IP] = $Index;
|
2011-03-28 14:21:28 +00:00
|
|
|
}
|
|
|
|
?>
|
2015-01-28 08:00:26 +00:00
|
|
|
<tr class="rowa" <?=$FirstOccurrence ? "id=\"$ElementID\"" : ''?>>
|
2011-05-24 08:00:09 +00:00
|
|
|
<td>
|
2013-04-20 08:01:01 +00:00
|
|
|
<?=$IP?> (<?=Tools::get_country_code_by_ajax($IP)?>)<?
|
|
|
|
if ($CanManageIPBans) {
|
2015-01-28 08:00:26 +00:00
|
|
|
if (!isset($IPBanChecks[$IP])) {
|
|
|
|
if (Tools::site_ban_ip($IP)) {
|
|
|
|
$IPBanChecks[$IP] = true;
|
2013-05-07 08:00:23 +00:00
|
|
|
?>
|
|
|
|
<strong>[Banned]</strong>
|
|
|
|
<?
|
|
|
|
} else {
|
2015-01-28 08:00:26 +00:00
|
|
|
$IPBanChecks[$IP] = false;
|
2013-05-07 08:00:23 +00:00
|
|
|
?>
|
2015-01-28 08:00:26 +00:00
|
|
|
<a id="<?=$Counter?>" href="#" onclick="Ban('<?=$IP?>', '<?=$Counter?>'); this.onclick = null; return false;" class="brackets">Ban</a>
|
2013-05-07 08:00:23 +00:00
|
|
|
<?
|
|
|
|
}
|
2015-01-28 08:00:26 +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)?>
|
2015-01-28 08:00:26 +00:00
|
|
|
<?
|
|
|
|
if (!empty($OtherUsers)) {
|
|
|
|
if ($FirstOccurrence || count($OtherUsers) <= 100) {
|
|
|
|
?>
|
|
|
|
<a href="#" onclick="$('.otherusers' + <?=$Index?>).gtoggle(); return false;">(<?=count($OtherUsers)?>)</a>
|
|
|
|
<?
|
|
|
|
} else {
|
|
|
|
?>
|
|
|
|
<a href="#<?=$ElementID?>" onclick="$('.otherusers' + <?=$IPIndexes[$IP]?>).gshow();">(<?=count($OtherUsers)?>)</a>
|
|
|
|
<?
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
?>
|
|
|
|
(0)
|
|
|
|
<?
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<span class="reltime"><?=time_diff($StartTime)?></span>
|
|
|
|
<span class="abstime hidden"><?=$StartTime?></span>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<span class="reltime"><?=time_diff($EndTime)?></span>
|
|
|
|
<span class="abstime hidden"><?=$EndTime?></span>
|
2013-05-07 08:00:23 +00:00
|
|
|
</td>
|
2011-03-28 14:21:28 +00:00
|
|
|
<td><?//time_diff(strtotime($StartTime), strtotime($EndTime)); ?></td>
|
|
|
|
</tr>
|
|
|
|
<?
|
2015-01-28 08:00:26 +00:00
|
|
|
if (!empty($OtherUsers) && ($FirstOccurrence || count($OtherUsers) < 100)) {
|
|
|
|
$HideMe = (count($OtherUsers) > 10);
|
|
|
|
foreach ($OtherUsers as $OtherUser) {
|
|
|
|
if (!$OtherUser['EndTime']) {
|
|
|
|
$OtherUser['EndTime'] = sqltime();
|
2013-05-07 08:00:23 +00:00
|
|
|
}
|
2011-03-28 14:21:28 +00:00
|
|
|
?>
|
2015-01-28 08:00:26 +00:00
|
|
|
<tr class="rowb otherusers<?=$Index?><?=($HideMe ? ' hidden' : '')?>">
|
|
|
|
<td> » <?=Users::format_username($OtherUser['UserID'], true, true, true)?></td>
|
|
|
|
<td>
|
|
|
|
<span class="reltime"><?=time_diff($OtherUser['StartTime'])?></span>
|
|
|
|
<span class="hidden abstime"><?=$OtherUser['StartTime']?></span>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<span class="reltime"><?=time_diff($OtherUser['EndTime'])?></span>
|
|
|
|
<span class="hidden abstime"><?=$OtherUser['EndTime']?></span>
|
|
|
|
</td>
|
|
|
|
<td><?//time_diff(strtotime($OtherUser['StartTime']), strtotime($OtherUser['EndTime'])); ?></td>
|
2011-03-28 14:21:28 +00:00
|
|
|
</tr>
|
|
|
|
<?
|
2015-01-28 08:00:26 +00:00
|
|
|
}
|
|
|
|
if (isset($IPMatchesIgnored[$IP])) {
|
|
|
|
foreach ($IPMatchesIgnored[$IP] as $OtherUserID => $MatchCount) {
|
|
|
|
?>
|
|
|
|
<tr class="rowb otherusers<?=$Index?><?=($HideMe ? ' hidden' : '')?>">
|
|
|
|
<td colspan="4"> » <?=$MatchCount?> matches skipped for <?=Users::format_username($OtherUserID, false, false, false)?></td>
|
|
|
|
</tr>
|
|
|
|
<?
|
|
|
|
}
|
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();
|