This repository has been archived by the owner on May 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
ipsearch.php
170 lines (151 loc) · 5.85 KB
/
ipsearch.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
require "include/bittorrent.php";
dbconn();
require_once(get_langfile_path());
loggedinorreturn();
if (get_user_class() < $userprofile_class)
permissiondenied();
else
{
$ip = trim($_GET['ip']);
if ($ip)
{
$regex = "/^(((1?\d{1,2})|(2[0-4]\d)|(25[0-5]))(\.\b|$)){4}$/";
if (!preg_match($regex, $ip))
{
stderr($lang_ipsearch['std_error'], $lang_ipsearch['std_invalid_ip']);
}
}
$mask = trim($_GET['mask']);
if ($mask == "" || $mask == "255.255.255.255")
{
$where1 = "u.ip = '$ip'";
$where2 = "iplog.ip = '$ip'";
$dom = @gethostbyaddr($ip);
if ($dom == $ip || @gethostbyname($dom) != $ip)
$addr = "";
else
$addr = $dom;
}
else
{
if (substr($mask,0,1) == "/")
{
$n = substr($mask, 1, strlen($mask) - 1);
if (!is_numeric($n) or $n < 0 or $n > 32)
{
stderr($lang_ipsearch['std_error'], $lang_ipsearch['std_invalid_subnet_mask']);
}
else
$mask = long2ip(pow(2,32) - pow(2,32-$n));
}
elseif (!preg_match($regex, $mask))
{
stderr($lang_ipsearch['std_error'], $lang_ipsearch['std_invalid_subnet_mask']);
}
$where1 = "INET_ATON(u.ip) & INET_ATON('$mask') = INET_ATON('$ip') & INET_ATON('$mask')";
$where2 = "INET_ATON(iplog.ip) & INET_ATON('$mask') = INET_ATON('$ip') & INET_ATON('$mask')";
$addr = "Mask: $mask";
}
stdhead($lang_ipsearch['head_search_ip_history']);
begin_main_frame();
print("<h1 align=\"center\">".$lang_ipsearch['text_search_ip_history']."</h1>\n");
print("<form method=\"get\" action=\"\">");
print("<table align=center border=1 cellspacing=0 width=115 cellpadding=5>\n");
tr($lang_ipsearch['row_ip']."<font color=red>*</font>", "<input type=\"text\" name=\"ip\" size=\"40\" value=\"".htmlspecialchars($ip)."\" />", 1);
tr("<nobr>".$lang_ipsearch['row_subnet_mask']."</nobr>", "<input type=\"text\" name=\"mask\" size=\"40\" value=\"" . htmlspecialchars($mask) . "\" />", 1);
print("<tr><td align=\"right\" colspan=\"2\"><input type=\"submit\" value=\"".$lang_ipsearch['submit_search']."\"/></td></tr>");
print("</table></form>\n");
if ($ip)
{
$queryc = "SELECT COUNT(*) FROM
(
SELECT u.id FROM users AS u WHERE $where1
UNION SELECT u.id FROM users AS u RIGHT JOIN iplog ON u.id = iplog.userid WHERE $where2
GROUP BY u.id
) AS ipsearch";
$res = sql_query($queryc) or sqlerr(__FILE__, __LINE__);
$row = mysql_fetch_array($res);
$count = $row[0];
if ($count == 0)
{
print("<p align=\"center\">".$lang_ipsearch['text_no_users_found']."</p>\n");
end_main_frame();
stdfoot();
die;
}
$order = $_GET['order'];
$page = 0 + $_GET["page"];
$perpage = 20;
list($pagertop, $pagerbottom, $limit) = pager($perpage, $count, "$_SERVER[PHP_SELF]?ip=$ip&mask=$mask&order=$order&");
if ($order == "added")
$orderby = "added DESC";
elseif ($order == "username")
$orderby = "UPPER(username) ASC";
elseif ($order == "email")
$orderby = "email ASC";
elseif ($order == "last_ip")
$orderby = "last_ip ASC";
elseif ($order == "last_access")
$orderby = "last_ip ASC";
else
$orderby = "access DESC";
$query = "SELECT * FROM (
SELECT u.id, u.username, u.ip AS ip, u.ip AS last_ip, u.last_access, u.last_access AS access, u.email, u.invited_by, u.added, u.class, u.uploaded, u.downloaded, u.donor, u.enabled, u.warned
FROM users AS u
WHERE $where1
UNION SELECT u.id, u.username, iplog.ip AS ip, u.ip as last_ip, u.last_access, max(iplog.access) AS access, u.email, u.invited_by, u.added, u.class, u.uploaded, u.downloaded, u.donor, u.enabled, u.warned
FROM users AS u
RIGHT JOIN iplog ON u.id = iplog.userid
WHERE $where2
GROUP BY u.id ) as ipsearch
GROUP BY id
ORDER BY $orderby
$limit";
$res = sql_query($query) or sqlerr(__FILE__, __LINE__);
print("<h1 align=\"center\">".$count.$lang_ipsearch['text_users_used_the_ip'].$ip."</h1>");
print("<table width=940 border=1 cellspacing=0 cellpadding=5 align=center>\n");
print("<tr><td class=colhead align=center><a class=colhead href=\"?ip=$ip&mask=$mask&order=username\">".$lang_ipsearch['col_username']."</a></td>".
"<td class=colhead align=center><a class=colhead href=\"?ip=$ip&mask=$mask&order=last_ip\">".$lang_ipsearch['col_last_ip']."</a></td>".
"<td class=colhead align=center><a class=colhead href=\"?ip=$ip&mask=$mask&order=last_access\">".$lang_ipsearch['col_last_access']."</a></td>".
"<td class=colhead align=center>".$lang_ipsearch['col_ip_num']."</td>".
"<td class=colhead align=center><a class=colhead href=\"?ip=$ip&mask=$mask\">".$lang_ipsearch['col_last_access_on']."</a></td>".
"<td class=colhead align=center><a class=colhead href=\"?ip=$ip&mask=$mask&order=added\">".$lang_ipsearch['col_added']."</a></td>".
"<td class=colhead align=center>".$lang_ipsearch['col_invited_by']."</td>");
while ($user = mysql_fetch_array($res))
{
if ($user['added'] == '0000-00-00 00:00:00')
$added = $lang_ipsearch['text_not_available'];
else $added = gettime($user['added']);
if ($user['last_access'] == '0000-00-00 00:00:00')
$lastaccess = $lang_ipsearch['text_not_available'];
else $lastaccess = gettime($user['last_access']);
if ($user['last_ip'])
$ipstr = $user['last_ip'];
else
$ipstr = $lang_ipsearch['text_not_available'];
$resip = sql_query("SELECT ip FROM iplog WHERE userid=" . sqlesc($user['id']) . " GROUP BY iplog.ip") or sqlerr(__FILE__, __LINE__);
$iphistory = mysql_num_rows($resip);
if ($user["invited_by"] > 0)
{
$invited_by = get_username($user['invited_by']);
}
else
$invited_by = $lang_ipsearch['text_not_available'];
echo "<tr><td align=\"center\">" .
get_username($user['id'])."</td>".
"<td align=\"center\">" . $ipstr . "</td>
<td align=\"center\">" . $lastaccess . "</td>
<td align=\"center\"><a href=\"iphistory.php?id=" . $user['id'] . "\">" . $iphistory. "</a></td>
<td align=\"center\">" . gettime($user['access']) . "</td>
<td align=\"center\">" . gettime($user['added']) . "</td>
<td align=\"center\">" . $invited_by . "</td>
</tr>\n";
}
echo "</table>";
echo $pagerbottom;
}
end_main_frame();
stdfoot();
}
?>