-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtorrent_info.php
113 lines (89 loc) · 3.25 KB
/
torrent_info.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
<?php
require "include/bittorrent.php";
use OurBits\Bencode;
function torrent_structure_builder($array, $parent = "")
{
$ret = '';
foreach ($array as $item => $value) {
$value_length = strlen(Bencode::encode($value));
if (is_iterable($value)) { // It may `dictionary` or `list`
$type = is_indexed_array($value) ? 'list' : 'dictionary';
$ret .= "<li><div align='left' class='" . $type . "'><a href='javascript:void(0);' onclick='$(this).parent().next(\"ul\").toggle()'> + <span class=title>[" . $item . "]</span> <span class='icon'>(" . ucfirst($type) . ")</span> <span class=length>[" . $value_length . "]</span></a></div>";
$ret .= "<ul style='display:none'>" . torrent_structure_builder($value, $item) . "</ul></li>";
} else { // It may `interger` or `string`
$type = is_integer($value) ? 'integer' : 'string';
$value = ($parent == 'info' && $item == 'pieces') ? "0x" . bin2hex(substr($value, 0, 25)) . "..." : $value; // Cut the info pieces....
$ret .= "<li><div align=left class=" . $type . "> - <span class=title>[" . $item . "]</span> <span class=icon>(" . ucfirst($type) . ")</span> <span class=length>[" . $value_length . "]</span>: <span class=value>" . $value . "</span></div></li>";
}
}
return $ret;
}
dbconn();
global $torrentstructure_class, $torrent_dir;
loggedinorreturn();
if (get_user_class() < $torrentstructure_class) {
permissiondenied();
}
$id = (int)$_GET["id"];
if (!$id)
httperr();
$res = sql_query("SELECT name FROM torrents WHERE id = " . sqlesc($id)) or sqlerr(__FILE__, __LINE__);
$row = mysql_fetch_assoc($res);
$fn = "$torrent_dir/$id.torrent";
if (!$row || !is_file($fn) || !is_readable($fn))
httperr();
$dict = Bencode::load($fn);
// Standard html headers
stdhead("Torrent Info");
?>
<style type="text/css">
#torrent-structure ul {
margin-left: 15px
}
#torrent-structure ul, li {
list-style-type: none;
color: #000;
padding-inline-start: 0px;
}
#torrent-structure li div.string {
padding: 3px
}
#torrent-structure li div.integer {
padding: 3px
}
#torrent-structure li div.dictionary {
padding: 3px
}
#torrent-structure li div.list {
padding: 3px
}
#torrent-structure li div.string span.icon {
color: #090;
padding: 2px
}
#torrent-structure li div.integer span.icon {
color: #990;
padding: 2px
}
#torrent-structure li div.dictionary span.icon {
color: #909;
padding: 2px
}
#torrent-structure li div.list span.icon {
color: #009;
padding: 2px
}
#torrent-structure li span.title {
font-weight: bold
}
</style>
<?php
begin_main_frame();
print("<div align=center><h1>$row[name]</h1>"); // Heading
print("<table width=750 border=1 cellspacing=0 cellpadding=5><td>"); // Start table
echo "<ul id='torrent-structure'>";
echo torrent_structure_builder(['root' => $dict]);
echo "</ul>";
print("</td></table>"); // End table
end_main_frame();
stdfoot();