This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnewtorrents.php
317 lines (287 loc) · 11 KB
/
newtorrents.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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<?php
require_once("config.php");
require_once("funcsv2.php");
//Check session
session_start();
if (!$_SESSION['admin_logged_in'] && !$_SESSION['upload_logged_in'])
{
//check fails
header("Location: authenticate.php?status=error");
exit();
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Add Torrent to Tracker</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="./css/style.css" />
</head>
<body>
<?php
$tracker_url = $announce_url0 OR $announce_url1 OR $announce_url2 OR $announce_url3 OR $announce_url4;
if (isset($_FILES["torrent"]))
addTorrent();
endOutput();
function addTorrent()
{
require ("config.php");
$tracker_url = $announce_url0 OR $announce_url1 OR $announce_url2 OR $announce_url3 OR $announce_url4;
$hash = strtolower(htmlentities($_POST["hash"], ENT_QUOTES, "UTF-8"));
$db = mysql_connect($dbhost, $dbuser, $dbpass) or die(errorMessage() . "Couldn't connect to the database, contact the administrator</p>");
mysql_select_db($database) or die(errorMessage() . "Can't open the database.</p>");
require_once ("funcsv2.php");
require_once ("BDecode.php");
require_once ("BEncode.php");
if ($_FILES["torrent"]["error"] != 4)
{
$fd = fopen($_FILES["torrent"]["tmp_name"], "rb") or die(errorMessage() . "File upload error 1</p>\n");
is_uploaded_file($_FILES["torrent"]["tmp_name"]) or die(errorMessage() . "File upload error 2</p>\n");
$alltorrent = fread($fd, filesize($_FILES["torrent"]["tmp_name"]));
$array = BDecode($alltorrent);
if (!$array)
{
echo errorMessage() . "Error: The parser was unable to load your torrent. Please re-create and re-upload the torrent.</p>\n";
endOutput();
exit;
}
if (isset($array["announce-list"])) {
//multiple trackers are listed
$found_tracker = false;
for ($i = 0; $i < count($array["announce-list"]); $i++) {
if (strtolower($array["announce-list"][$i][0]) == $tracker_url) {
$found_tracker = true;
break;
}
}
if ($found_tracker == false)
{
echo errorMessage() . "Error: Multiple trackers were found but none of them match the primary
announce URL:<br>$tracker_url<br><br>or any alternate URLs:<br>$announce_url1<br>$announce_url2<br>$announce_url3<br>$announce_url4<br><br>Please re-create and re-upload the torrent.</p>\n";
endOutput();
exit;
}
} else {
//a single tracker is listed
if (strtolower($array["announce"]) != $tracker_url) {
echo errorMessage() . "Error: The tracker announce URL does not match the primary
announce URL:<br>$tracker_url<br><br>or any alternate URLs:<br>$announce_url1<br>$announce_url2<br>$announce_url3<br>$announce_url4<br><br>Please re-create and re-upload the torrent.</p>\n";
endOutput();
exit;
}
}
if (isset($_POST["httpseed"]) && $_POST["httpseed"] == "enabled" && $_POST["relative_path"] == "")
{
echo errorMessage() . "Error: HTTP seeding was checked however no relative path was given.</p>\n";
endOutput();
exit;
}
if (isset($_POST["httpseed"]) && $_POST["httpseed"] == "enabled" && $_POST["relative_path"] != "")
{
if (Substr($_POST["relative_path"], -1) == "/")
{
if (!is_dir($_POST["relative_path"]))
{
echo errorMessage() . "Error: HTTP seeding relative path ends in / but is not a valid directory.</p>\n";
endOutput();
exit;
}
}
else
{
if (!is_file($_POST["relative_path"]))
{
echo errorMessage() . "Error: HTTP seeding relative path is not a valid file.</p>\n";
endOutput();
exit;
}
}
}
if (isset($_POST["getrightseed"]) && $_POST["getrightseed"] == "enabled" && $_POST["httpftplocation"] == "")
{
echo errorMessage() . "Error: GetRight HTTP seeding was checked however no URL was given.</p>\n";
endOutput();
exit;
}
if (isset($_POST["getrightseed"]) && $_POST["getrightseed"] == "enabled" &&
(Substr($_POST["httpftplocation"], 0, 7) != "http://" && Substr($_POST["httpftplocation"], 0, 6) != "ftp://")
)
{
echo errorMessage() . "Error: GetRight HTTP seeding URL must start with http:// or ftp://</p>\n";
endOutput();
exit;
}
$hash = @sha1(BEncode($array["info"]));
fclose($fd);
$target_path = "torrents/";
$target_path = $target_path . basename( clean($_FILES['torrent']['name']));
$move_torrent = move_uploaded_file($_FILES["torrent"]["tmp_name"], $target_path);
if ($move_torrent == false)
{
echo errorMessage() . "Unable to move " . $_FILES["torrent"]["tmp_name"] . " to torrents/</p>\n";
}
}
if (isset($_POST["title"]))
$title = clean($_POST["title"]);
else
$title = "";
if (isset($_POST["filename"]))
$filename = clean($_POST["filename"]);
else
$filename = "";
if (isset($_POST["url"]))
$url = clean($_POST["url"]);
else
$url = "";
if (isset($_POST["autoset"]))
if (strcmp($_POST["autoset"], "enabled") == 0)
{
if (strlen($filename) == 0 && isset($array["info"]["name"]))
$filename = $array["info"]["name"];
}
//figure out total size of all files in torrent
$info = $array["info"];
$total_size = 0;
if (isset($info["files"]))
{
foreach ($info["files"] as $file)
{
$total_size = $total_size + $file["length"];
}
}
else
{
$total_size = $info["length"];
}
//Validate torrent file, make sure everything is correct
$filename = mysql_real_escape_string($filename);
$filename = stripslashes($filename);
$filename = htmlspecialchars(clean($filename));
$url = htmlspecialchars(mysql_real_escape_string($url));
if ((strlen($hash) != 40) || !verifyHash($hash))
{
echo errorMessage() . "Error: Info hash must be exactly 40 hex bytes.</p>\n";
endOutput();
}
if (Substr($url, 0, 7) != "http://" && $url != "")
{
echo errorMessage() . "Error: The Torrent URL does not start with http:// Make sure you entered a correct URL.</p>\n";
endOutput();
}
if ($GLOBALS["customtitle"] == "true")
$query = "INSERT INTO ".$prefix."namemap (info_hash, title, filename, url, size, pubDate) VALUES (\"$hash\", \"$title\", \"$filename\", \"$url\", \"$total_size\", \"" . date("$dateformat") . "\")";
else $query = "INSERT INTO ".$prefix."namemap (info_hash, title, filename, url, size, pubDate) VALUES (\"$hash\", \"$filename\", \"$filename\", \"$url\", \"$total_size\", \"" . date("$dateformat") . "\")";
$status = makeTorrent($hash, true);
quickQuery($query);
if ($status)
{
echo "<p class=\"success\">Torrent was added successfully.</p>\n";
echo "<a href=\"newtorrents.php\"><img src=\"images/add.png\" border=\"0\" class=\"icon\" alt=\"Add Torrent\" title=\"Add Torrent\" /></a><a href=\"newtorrents.php\">Add Another Torrent</a><br>\n";
//rename torrent file to match filename
rename("torrents/" . clean($_FILES['torrent']['name']), "torrents/" . $filename . ".torrent");
//make torrent file readable by all
chmod("torrents/" . $filename . ".torrent", 0644);
//run RSS generator
require_once("rss_generator.php");
//Display information from DumpTorrentCGI.php
require_once("torrent_functions.php");
}
else
{
echo errorMessage() . "There were some errors. Check if this torrent has been added previously.</p>\n";
//delete torrent file if it doesn't exist in database
$query = "SELECT COUNT(*) FROM ".$prefix."summary WHERE info_hash = '$hash'";
$results = mysql_query($query) or die(errorMessage() . "Can't do SQL query - " . mysql_error() . "</p>");
$data = mysql_fetch_row($results);
if ($data[0] == 0)
{
if (file_exists("torrents/" . $_FILES['torrent']['name']))
unlink("torrents/" . $_FILES['torrent']['name']);
}
//make torrent file readable by all
chmod("torrents/" . $filename . ".torrent", 0644);
endOutput();
}
}
function endOutput()
{
require ("config.php");
$tracker_url = $announce_url0;
$alt_tracker_url1 = $announce_url1;
$alt_tracker_url2 = $announce_url2;
$alt_tracker_url3 = $announce_url3;
$alt_tracker_url4 = $announce_url4;
?>
<p align="right"><a href="./docs/help.html"><img src="images/help.png" border="0" class="icon" alt="Help" title="Help" /></a><a href="./docs/help.html">Help</a></p>
<div class="center">
<h1>Add Torrent to Tracker Database</h1>
<h3>Tracker URL: <br> <?php echo $tracker_url;?></h3>
<h4>Alternate Tracker URLs: <br> <?php echo $alt_tracker_url1;?> <br> <?php echo $alt_tracker_url2;?> <br> <?php echo $alt_tracker_url3;?> <br> <?php echo $alt_tracker_url4; ?> </h4>
<form enctype="multipart/form-data" method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<table>
<tr>
<?php
if ($GLOBALS["customtitle"] == "true")
echo "<td class=\"right\">Title:</td>
<td class=\"left\"><input type=\"title\" name=\"title\" size=\"50\"/></td>";
else ($GLOBALS["customtitle"] != "true");
?>
</tr>
<tr>
<td class="right">Torrent file:</td>
<td class="left"><?php
if (function_exists("sha1"))
echo "<input type=\"file\" name=\"torrent\" size=\"50\"/>";
else
echo '<i>File uploading not available - no SHA1 function.</i>';
?></td>
</tr>
<tr><td colspan="2"><hr></td></tr>
<tr>
<td class="center" colspan="2"><input type="checkbox" name="httpseed" value="enabled">Use BitTornado HTTP seeding specification (optional)</td>
</tr>
<tr>
<td class="right">Relative location of file or directory:<br>e.g. ../../files/file.zip</td>
<td class="left"><input type="text" name="relative_path" size="70"/></td>
</tr>
<tr><td colspan="2"><hr></td></tr>
<tr>
<td class="center" colspan="2"><input type="checkbox" name="getrightseed" value="enabled">Use GetRight HTTP seeding specification (optional)</td>
</tr>
<tr>
<td class="right">FTP/HTTP URL of file or directory:<br>e.g. http://yourwebsite.com/file.zip</td>
<td class="left"><input type="text" name="httpftplocation" size="70"/></td>
</tr>
<tr><td colspan="2"><hr></td></tr>
<?php if (function_exists("sha1"))
echo "<tr><td class=\"center\" colspan=\"2\"><input type=\"checkbox\" name=\"autoset\" value=\"enabled\" checked=\"checked\" /> Fill in fields below automatically using data from the torrent file.</td></tr>\n";
?>
<tr>
<td class="right">Info Hash:</td>
<td class="left"><input type="text" name="hash" size="40"/></td>
</tr>
<tr>
<td class="right">File name (optional): </td>
<td class="left"><input type="text" name="filename" size="60" maxlength="200"/></td>
</tr>
<tr>
<td class="right">Torrent's URL (optional): </td>
<td class="left"><input type="text" name="url" size="60" maxlength="200"/></td>
</tr>
<tr><td colspan="2"><hr></td></tr>
<tr>
<td class="center" colspan="2"><input type="submit" value="Add Torrent to Database"/> - <input type="reset" value="Clear Settings"/></td>
</tr>
</table>
<br>
<input type="hidden" name="username" value="<?php echo $_POST['username']; ?>"/>
<input type="hidden" name="password" value="<?php echo $_POST['password']; ?>"/>
</form>
<a href="index.php"><img src="images/stats.png" border="0" class="icon" alt="Tracker Statistics" title="Tracker Statistics" /></a><a href="index.php">Return to Statistics Page</a><br>
</div>
</body></html>
<?php
// Still in function endOutput()
exit;
}
?>