-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathviewpeerlist.php
263 lines (136 loc) · 8.64 KB
/
viewpeerlist.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<?php
require "include/bittorrent.php";
dbconn();
require_once(get_langfile_path());
//Send some headers to keep the user's browser from caching the response.
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
header("Content-Type: text/xml; charset=utf-8");
$id = 0 + $_GET['id'];
if (isset($CURUSER)) {
function dltable($name, $arr, $torrent)
{
global $lang_viewpeerlist, $viewanonymous_class, $userprofile_class, $enablelocation_tweak;
global $CURUSER;
$s = "<b>" . count($arr) . " $name</b>\n";
if (!count($arr))
return $s;
$s .= "\n";
$s .= "<table width=825 class=main border=1 cellspacing=0 cellpadding=3>\n";
$s .= "<tr><td class=colhead align=center width=1%>" . $lang_viewpeerlist['col_user_ip'] . "</td>" .
/* ($enablelocation_tweak == 'yes' || get_user_class() >= $userprofile_class ? "<td class=colhead align=center width=1%>".$lang_viewpeerlist['col_location']."</td>" : "<td class=colhead align=center width=1%>".$lang_viewpeerlist['ip_type']."</td>").*/
($enablelocation_tweak == 'yes' || get_user_class() >= $userprofile_class ? "<td class=colhead align=center width=1%>" . $lang_viewpeerlist['col_location'] . "</td>" : "") .
"<td class=colhead align=center width=1%>" . $lang_viewpeerlist['ip_type'] . "</td>".
"<td class=colhead align=center width=1%>" . $lang_viewpeerlist['col_uploaded'] . "</td>" .
"<td class=colhead align=center width=1%>" . $lang_viewpeerlist['col_rate'] . "</td>" .
"<td class=colhead align=center width=1%>" . $lang_viewpeerlist['col_downloaded'] . "</td>" .
"<td class=colhead align=center width=1%>" . $lang_viewpeerlist['col_rate'] . "</td>" .
"<td class=colhead align=center width=1%>" . $lang_viewpeerlist['col_ratio'] . "</td>" .
"<td class=colhead align=center width=1%>" . $lang_viewpeerlist['col_complete'] . "</td>" .
"<td class=colhead align=center width=1%>" . $lang_viewpeerlist['col_connected'] . "</td>" .
"<td class=colhead align=center width=1%>" . $lang_viewpeerlist['col_idle'] . "</td>" .
"<td class=colhead align=center width=1%>" . $lang_viewpeerlist['col_client'] . "</td></tr>\n";
$now = time();
$num = 0;
foreach ($arr as $e) {
$privacy = get_single_value("users", "privacy", "WHERE id=" . sqlesc($e['userid']));
++$num;
$highlight = $CURUSER["id"] == $e['userid'] ? " bgcolor=#BBAF9B" : "";
$s .= "<tr$highlight>\n";
if ($privacy == "strong" || ($torrent['anonymous'] == 'yes' && $e['userid'] == $torrent['owner'])) {
if (get_user_class() >= $viewanonymous_class || $e['userid'] == $CURUSER['id'])
$s .= "<td class=rowfollow align=left width=1%><i>" . $lang_viewpeerlist['text_anonymous'] . "</i><br />(" . get_username($e['userid']) . ")";
else
$s .= "<td class=rowfollow align=left width=1%><i>" . $lang_viewpeerlist['text_anonymous'] . "</i></a></td>\n";
} else
$s .= "<td class=rowfollow align=left width=1%>" . get_username($e['userid']);
$secs = max(1, ($e["la"] - $e["st"]));
if ($enablelocation_tweak == 'yes') {
list($loc_pub, $loc_mod) = get_ip_location($e["ip"]);
$location = get_user_class() >= $userprofile_class ? "<div title='" . $loc_mod . "'>" . $loc_pub . "</div>" : $loc_pub;
$s .= "<td class=rowfollow align=center width=1%><nobr>" . $location . "</nobr></td>\n";
} elseif (get_user_class() >= $userprofile_class) {
// $location = $e["ip"];
$location = $e["ipv4"] . ($e["ipv6"] ? ($e["ipv4"] ? "<br />[" . $e["ipv6"] . "]" : "[" . $e["ipv6"] . "]") : "");
$s .= "<td class=rowfollow width=1%><nobr>" . $location . "</nobr></td>\n";
}
/* else {
$location = ($e[ipv6]?($e[ipv4]?$lang_viewpeerlist['both']:"IPv6"):"IPv4");
$s .= "<td class=rowfollow align=center width=1%><nobr>" . $location . "</nobr></td>\n";
}*/
// 检测连通性,是否是校内IPV4/校外IPV4/IPV6
$arrConn = [];
if (!empty($e["ipv4"])){
if (check_tjuip(ip2long($e['ipv4']))){
$arrConn[] = '<span>' . $lang_viewpeerlist['text_ipv4_in'] . '</span>';
}else{
$arrConn[] = '<span style="color:red;">' . $lang_viewpeerlist['text_ipv4_out'] . '</span>';
}
}
if (!empty($e["ipv6"])){
$arrConn[] = '<span style="font-weight: bold">' . $lang_viewpeerlist['text_ipv6'] . '</span>';
}
empty($arrConn) && $arrConn[] = $lang_viewpeerlist['text_unknown'];
$s .= "<td class=rowfollow align=center width=1%><nobr>" . implode(' / ', $arrConn) . "</nobr></td>\n";
$s .= "<td class=rowfollow align=center width=1%><nobr>" . mksize($e["uploaded"]) . "</nobr></td>\n";
$s .= "<td class=rowfollow align=center width=1%><nobr>" . mksize(($e["uploaded"] - $e["uploadoffset"]) / $secs) . "/s</nobr></td>\n";
$s .= "<td class=rowfollow align=center width=1%><nobr>" . mksize($e["downloaded"]) . "</nobr></td>\n";
if ($e["seeder"] == "no")
$s .= "<td class=rowfollow align=center width=1%><nobr>" . mksize(($e["downloaded"] - $e["downloadoffset"]) / $secs) . "/s</nobr></td>\n";
else
$s .= "<td class=rowfollow align=center width=1%><nobr>" . mksize(($e["downloaded"] - $e["downloadoffset"]) / max(1, $e["finishedat"] - $e['st'])) . "/s</nobr></td>\n";
if ($e["downloaded"]) {
$ratio = floor(($e["uploaded"] / $e["downloaded"]) * 1000) / 1000;
$s .= "<td class=rowfollow align=\"center\" width=1%><font color=" . get_ratio_color($ratio) . "><nobr>" . number_format($ratio, 3) . "</nobr></font></td>\n";
} elseif ($e["uploaded"])
$s .= "<td class=rowfollow align=center width=1%>" . $lang_viewpeerlist['text_inf'] . "</td>\n";
else
$s .= "<td class=rowfollow align=center width=1%>---</td>\n";
$s .= "<td class=rowfollow align=center width=1%><nobr>" . sprintf("%.2f%%", 100 * (1 - ($e["to_go"] / $torrent["size"]))) . "</nobr></td>\n";
$s .= "<td class=rowfollow align=center width=1%><nobr>" . mkprettytime($now - $e["st"]) . "</nobr></td>\n";
$s .= "<td class=rowfollow align=center width=1%><nobr>" . mkprettytime($now - $e["la"]) . "</nobr></td>\n";
$s .= "<td class=rowfollow align=center width=1%><nobr>" . htmlspecialchars(get_agent($e["peer_id"], $e["agent"])) . "</nobr></td>\n";
$s .= "</tr>\n";
}
$s .= "</table>\n";
return $s;
}
$downloaders = array();
$seeders = array();
// $subres = sql_query("SELECT seeder, finishedat, downloadoffset, uploadoffset, ipv4, ipv6, port, uploaded, downloaded, to_go, UNIX_TIMESTAMP(started) AS st, connectable, agent, peer_id, UNIX_TIMESTAMP(last_action) AS la, userid FROM peers WHERE torrent = $id") or sqlerr();
$subres = sql_query("SELECT seeder, finishedat, downloadoffset, uploadoffset, ipv4, ipv6, port, uploaded, downloaded, to_go, UNIX_TIMESTAMP(started) AS st, agent, peer_id, UNIX_TIMESTAMP(last_action) AS la, userid FROM peers WHERE torrent = $id") or sqlerr();
while ($subrow = mysql_fetch_array($subres)) {
if ($subrow["seeder"] == "yes")
$seeders[] = $subrow;
else
$downloaders[] = $subrow;
}
function leech_sort($a, $b)
{
$x = $a["to_go"];
$y = $b["to_go"];
if ($x == $y)
return 0;
if ($x < $y)
return -1;
return 1;
}
function seed_sort($a, $b)
{
$x = $a["uploaded"];
$y = $b["uploaded"];
if ($x == $y)
return 0;
if ($x < $y)
return 1;
return -1;
}
$res = sql_query("SELECT torrents.id, torrents.owner, torrents.size, torrents.anonymous FROM torrents WHERE torrents.id = $id LIMIT 1") or sqlerr();
$row = mysql_fetch_array($res);
usort($seeders, "seed_sort");
usort($downloaders, "leech_sort");
print(dltable($lang_viewpeerlist['text_seeders'], $seeders, $row));
print(dltable($lang_viewpeerlist['text_leechers'], $downloaders, $row));
}