-
Notifications
You must be signed in to change notification settings - Fork 4
/
peerlist.php
150 lines (126 loc) · 6.92 KB
/
peerlist.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
<?php
/**
* http://btdev.net:1337/svn/test/Installer09_Beta
* Licence Info: GPL
* Copyright (C) 2010 BTDev Installer v.1
* A bittorrent tracker source based on TBDev.net/tbsource/bytemonsoon.
* Project Leaders: Mindless,putyn.
**/
require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'include'.DIRECTORY_SEPARATOR.'bittorrent.php');
require_once(INCL_DIR.'user_functions.php');
require_once(INCL_DIR.'bt_client_functions.php');
require_once(INCL_DIR.'html_functions.php');
dbconn(false);
loggedinorreturn();
$lang = array_merge( load_language('global'), load_language('peerlist') );
$id = (int)$_GET['id'];
if (!isset($id) || !is_valid_id($id))
stderr($lang['peerslist_user_error'], $lang['peerslist_invalid_id']);
$HTMLOUT = '';
function dltable($name, $arr, $torrent)
{
global $CURUSER, $lang;
$htmlout = '';
if (!count($arr))
return $htmlout = "<div align='left'><b>{$lang['peerslist_no']} $name {$lang['peerslist_data_available']}</b></div>\n";
$htmlout = "\n";
$htmlout .= "<table width='100%' class='main' border='1' cellspacing='0' cellpadding='5'>\n";
$htmlout .= "<tr><td colspan='11' class='colhead'>" . count($arr) . " $name</td></tr>" .
"<tr><td class='colhead'>{$lang['peerslist_user_ip']}</td>" .
"<td class='colhead' align='center'>{$lang['peerslist_connectable']}</td>".
"<td class='colhead' align='right'>{$lang['peerslist_uploaded']}</td>".
"<td class='colhead' align='right'>{$lang['peerslist_rate']}</td>".
"<td class='colhead' align='right'>{$lang['peerslist_downloaded']}</td>" .
"<td class='colhead' align='right'>{$lang['peerslist_rate']}</td>" .
"<td class='colhead' align='right'>{$lang['peerslist_ratio']}</td>" .
"<td class='colhead' align='right'>{$lang['peerslist_complete']}</td>" .
"<td class='colhead' align='right'>{$lang['peerslist_connected']}</td>" .
"<td class='colhead' align='right'>{$lang['peerslist_idle']}</td>" .
"<td class='colhead' align='left'>{$lang['peerslist_client']}</td></tr>\n";
$now = time();
$mod = $CURUSER['class'] >= UC_MODERATOR;
foreach ($arr as $e) {
//if ($e["paranoia"] == 0) continue;
$htmlout .= "<tr>\n";
if($e['username']){
if(($e['tanonymous'] == 'yes' && $e['owner'] == $e['userid'] || $e['anonymous'] == 'yes' && $CURUSER['id'] != $e['userid']) && $CURUSER['class'] < UC_MODERATOR)
$htmlout .= "<td><b>Anonymous</b></td>\n";
else
$htmlout .= "<td><a href='userdetails.php?id=".$e['userid']."'><b>".$e['username']."</b></a></td>\n";
}
else
$htmlout .= "<td>" . ($mod ? $e["ip"] : preg_replace('/\.\d+$/', ".xxx", $e["ip"])) . "</td>\n";
$secs = max(1, ($now - $e["st"]) - ($now - $e["la"]));
$htmlout .= "<td align='center'>" . ($e['connectable'] == "yes" ? "{$lang['peerslist_yes']}" : "<font color='red'>{$lang['peerslist_no']}</font>") . "</td>\n";
$htmlout .= "<td align='right'>" . mksize($e["uploaded"]) . "</td>\n";
$htmlout .= "<td align='right'><span style=\"white-space: nowrap;\">" . mksize(($e["uploaded"] - $e["uploadoffset"]) / $secs) . "/s</span></td>\n";
$htmlout .= "<td align='right'>" . mksize($e["downloaded"]) . "</td>\n";
if ($e["seeder"] == "no")
$htmlout .= "<td align='right'><span style=\"white-space: nowrap;\">" . mksize(($e["downloaded"] - $e["downloadoffset"]) / $secs) . "/s</span></td>\n";
else
$htmlout .= "<td align='right'><span style=\"white-space: nowrap;\">" . mksize(($e["downloaded"] - $e["downloadoffset"]) / max(1, $e["finishedat"] - $e['st'])) . "/s</span></td>\n";
if ($e["downloaded"])
{
$ratio = floor(($e["uploaded"] / $e["downloaded"]) * 1000) / 1000;
$htmlout .= "<td align=\"right\"><font color='" . get_ratio_color($ratio) . "'>" . number_format($ratio, 3) . "</font></td>\n";
}
else
if ($e["uploaded"])
$htmlout .= "<td align='right'>{$lang['peerslist_inf']}</td>\n";
else
$htmlout .= "<td align='right'>---</td>\n";
$htmlout .= "<td align='right'>" . sprintf("%.2f%%", 100 * (1 - ($e["to_go"] / $torrent["size"]))) . "</td>\n";
$htmlout .= "<td align='right'>" . mkprettytime($now - $e["st"]) . "</td>\n";
$htmlout .= "<td align='right'>" . mkprettytime($now - $e["la"]) . "</td>\n";
$htmlout .= "<td align='left'>" . htmlspecialchars(getagent($e["agent"], $e['peer_id'])) . "</td>\n";
$htmlout .= "</tr>\n";
}
$htmlout .= "</table>\n";
return $htmlout;
}
$res = sql_query("SELECT * FROM torrents WHERE id = $id")
or sqlerr();
if(mysql_num_rows($res) == 0)
stderr("{$lang['peerslist_error']}", "{$lang['peerslist_nothing']}");
$row = mysql_fetch_assoc($res);
$downloaders = array();
$seeders = array();
$subres = sql_query("SELECT u.username,u.anonymous, u.paranoia, t.owner, t.anonymous as tanonymous, p.seeder, p.finishedat, p.downloadoffset, p.uploadoffset, p.ip, p.port, p.uploaded, p.downloaded, p.to_go, p.started AS st, p.connectable, p.agent, p.last_action AS la, p.userid, p.peer_id
FROM peers p
LEFT JOIN users u ON p.userid = u.id
LEFT JOIN torrents as t on t.id = p.torrent
WHERE p.torrent = $id") or sqlerr();
if(mysql_num_rows($subres) == 0)
stderr("{$lang['peerslist_warning']}", "{$lang['peerslist_no_data']}");
while ($subrow = mysql_fetch_assoc($subres)) {
if ($subrow["seeder"] == "yes")
$seeders[] = $subrow;
else
$downloaders[] = $subrow;
}
function leech_sort($a,$b) {
if ( isset( $_GET["usort"] ) ) return seed_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;
}
usort($seeders, "seed_sort");
usort($downloaders, "leech_sort");
$HTMLOUT .= "<h1>Peerlist for <a href='{$TBDEV['baseurl']}/details.php?id=$id'>".htmlentities($row['name'])."</a></h1>";
$HTMLOUT .= dltable("{$lang['peerslist_seeders']}<a name='seeders'></a>", $seeders, $row);
$HTMLOUT .= '<br />' . dltable("{$lang['peerslist_leechers']}<a name='leechers'></a>", $downloaders, $row);
print stdhead("{$lang['peerslist_stdhead']}") . $HTMLOUT . stdfoot();
?>