-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtorrents-upload.php
356 lines (267 loc) · 11.4 KB
/
torrents-upload.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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
<?php
//
// TorrentTrader v2.x
// $LastChangedDate: 2011-11-11 16:19:27 +0000 (Fri, 11 Nov 2011) $
// $LastChangedBy: dj-howarth1 $
//
// http://www.torrenttrader.org
//
//
require_once("backend/functions.php");
dbconn();
// check access and rights
loggedinonly();
if($CURUSER["can_upload"]=="no")
show_error_msg("Error","You do not have permission to upload",1);
if ($site_config["UPLOADERSONLY"] && $CURUSER["class"] < 4)
show_error_msg("Error", "Only uploaders can upload.",1);
$announce_urls = explode(",", strtolower($site_config["announce_list"])); //generate announce_urls[] from config.php
if ($_POST["takeupload"] == "yes") {
require_once("backend/parse.php");
//check form data
foreach(explode(":","type:name") as $v) {
if (!isset($_POST[$v]))
$message = T_("MISSING_FORM_DATA");
}
if (!isset($_FILES["torrent"]))
$message = T_("MISSING_FORM_DATA");
if (($num = $_FILES['torrent']['error']))
show_error_msg('Error', T_("UPLOAD_ERR[$num]"), 1);
$f = $_FILES["torrent"];
$fname = $f["name"];
if (empty($fname))
$message = T_("EMPTY_FILENAME");
if ($_FILES['nfo']['size'] != 0) {
$nfofile = $_FILES['nfo'];
if ($nfofile['name'] == '')
$message = T_("NO_NFO_UPLOADED");
if (!preg_match('/^(.+)\.nfo$/si', $nfofile['name'], $fmatches))
$message = T_("UPLOAD_NOT_NFO");
if ($nfofile['size'] == 0)
$message = T_("NO_NFO_SIZE");
if ($nfofile['size'] > 65535)
$message = T_("NFO_UPLOAD_SIZE");
$nfofilename = $nfofile['tmp_name'];
if (($num = $_FILES['nfo']['error']))
$message = T_("UPLOAD_ERR[$num]");
$nfo = 'yes';
}
$descr = $_POST["descr"];
if (!$descr)
$descr = T_("UPLOAD_NO_DESC");
$langid = (int) $_POST["lang"];
/*if (!is_valid_id($langid))
$message = "Please be sure to select a torrent language";*/
$catid = (int) $_POST["type"];
if (!is_valid_id($catid))
$message = T_("UPLOAD_NO_CAT");
if (!validfilename($fname))
$message = T_("UPLOAD_INVALID_FILENAME");
if (!preg_match('/^(.+)\.torrent$/si', $fname, $matches))
$message = T_("UPLOAD_INVALID_FILENAME_NOT_TORRENT");
$shortfname = $torrent = $matches[1];
if (!empty($_POST["name"]))
$torrent = $_POST["name"];
$tmpname = $f['tmp_name'];
//end check form data
if (!$message) {
//parse torrent file
$torrent_dir = $site_config["torrent_dir"];
$nfo_dir = $site_config["nfo_dir"];
//if(!copy($f, "$torrent_dir/$fname"))
if(!move_uploaded_file($tmpname, "$torrent_dir/$fname"))
show_error_msg(T_("ERROR"), T_("ERROR"). ": " . T_("UPLOAD_COULD_NOT_BE_COPIED")." $tmpname - $torrent_dir - $fname",1);
$TorrentInfo = array();
$TorrentInfo = ParseTorrent("$torrent_dir/$fname");
$announce = $TorrentInfo[0];
$infohash = $TorrentInfo[1];
$creationdate = $TorrentInfo[2];
$internalname = $TorrentInfo[3];
$torrentsize = $TorrentInfo[4];
$filecount = $TorrentInfo[5];
$annlist = $TorrentInfo[6];
$comment = $TorrentInfo[7];
$filelist = $TorrentInfo[8];
/*
//for debug...
print ("<br /><br />announce: ".$announce."");
print ("<br /><br />infohash: ".$infohash."");
print ("<br /><br />creationdate: ".$creationdate."");
print ("<br /><br />internalname: ".$internalname."");
print ("<br /><br />torrentsize: ".$torrentsize."");
print ("<br /><br />filecount: ".$filecount."");
print ("<br /><br />annlist: ".$annlist."");
print ("<br /><br />comment: ".$comment."");
*/
//check announce url is local or external
if (!in_array($announce, $announce_urls, 1)){
$external='yes';
}else{
$external='no';
}
//if externals is turned off
if (!$site_config["ALLOWEXTERNAL"] && $external == 'yes')
$message = T_("UPLOAD_NO_TRACKER_ANNOUNCE");
}
if ($message) {
@unlink("$torrent_dir/$fname");
@unlink($tmpname);
@unlink("$nfo_dir/$nfofilename");
show_error_msg(T_("UPLOAD_FAILED"), $message,1);
}
//release name check and adjust
if ($name ==""){
$name = $internalname;
}
$name = str_replace(".torrent","",$name);
$name = str_replace("_", " ", $name);
//upload images
$allowed_types = &$site_config["allowed_image_types"];
$inames = array();
for ($x=0; $x < 2; $x++) {
if (!($_FILES[image.$x]['name'] == "")) {
$y = $x + 1;
//if (!preg_match('/^(.+)\.(jpg|gif|png)$/si', $_FILES[image.$x]['name']))
// show_error_msg(T_("INVAILD_IMAGE"), T_("THIS_FILETYPE_NOT_IMAGE"), 1);
if ($_FILES['image$x']['size'] > $site_config['image_max_filesize'])
show_error_msg(T_("ERROR"), T_("INVAILD_FILE_SIZE_IMAGE"), 1);
$uploaddir = $site_config["torrent_dir"]."/images/";
$ifile = $_FILES[image.$x]['tmp_name'];
$im = getimagesize($ifile);
if (!$im[2])
show_error_msg(T_("ERROR"), sprintf(T_("INVALID_IMAGE"), $y), 1);
if (!array_key_exists($im['mime'], $allowed_types))
show_error_msg(T_("ERROR"), T_("INVALID_FILETYPE_IMAGE"), 1);
$ret = SQL_Query_exec("SHOW TABLE STATUS LIKE 'torrents'");
$row = mysql_fetch_array($ret);
$next_id = $row['Auto_increment'];
$ifilename = $next_id . $x . $allowed_types[$im['mime']];
$copy = copy($ifile, $uploaddir.$ifilename);
if (!$copy)
show_error_msg(T_("ERROR"), sprintf(T_("IMAGE_UPLOAD_FAILED"), $y), 1);
$inames[] = $ifilename;
}
}
//end upload images
//anonymous upload
$anonyupload = $_POST["anonycheck"];
if ($anonyupload == "yes") {
$anon = "yes";
}else{
$anon = "no";
}
$ret = SQL_Query_exec("INSERT INTO torrents (filename, owner, name, descr, image1, image2, category, added, info_hash, size, numfiles, save_as, announce, external, nfo, torrentlang, anon, last_action) VALUES (".sqlesc($fname).", '".$CURUSER['id']."', ".sqlesc($name).", ".sqlesc($descr).", '".$inames[0]."', '".$inames[1]."', '".$catid."', '" . get_date_time() . "', '".$infohash."', '".$torrentsize."', '".$filecount."', ".sqlesc($fname).", '".$announce."', '".$external."', '".$nfo."', '".$langid."','$anon', '".get_date_time()."')");
$id = mysql_insert_id();
if (mysql_errno() == 1062)
show_error_msg(T_("UPLOAD_FAILED"), T_("UPLOAD_ALREADY_UPLOADED"), 1);
//Update the members uploaded torrent count
/*if ($ret){
SQL_Query_exec("UPDATE users SET torrents = torrents + 1 WHERE id = $userid");*/
if($id == 0){
unlink("$torrent_dir/$fname");
$message = T_("UPLOAD_NO_ID");
show_error_msg(T_("UPLOAD_FAILED"), $message, 1);
}
rename("$torrent_dir/$fname", "$torrent_dir/$id.torrent");
if (count($filelist)) {
foreach ($filelist as $file) {
$dir = '';
$size = $file["length"];
$count = count($file["path"]);
for ($i=0; $i<$count;$i++) {
if (($i+1) == $count)
$fname = $dir.$file["path"][$i];
else
$dir .= $file["path"][$i]."/";
}
SQL_Query_exec("INSERT INTO `files` (`torrent`, `path`, `filesize`) VALUES($id, ".sqlesc($fname).", $size)");
}
} else {
SQL_Query_exec("INSERT INTO `files` (`torrent`, `path`, `filesize`) VALUES($id, ".sqlesc($TorrentInfo[3]).", $torrentsize)");
}
if (!count($annlist)) {
$annlist = array(array($announce));
}
foreach ($annlist as $ann) {
foreach ($ann as $val) {
if (strtolower(substr($val, 0, 4)) != "udp:") {
SQL_Query_exec("INSERT INTO `announce` (`torrent`, `url`) VALUES($id, ".sqlesc($val).")");
}
}
}
if ($nfo == 'yes') {
move_uploaded_file($nfofilename, "$nfo_dir/$id.nfo");
}
//EXTERNAL SCRAPE
if ($external=='yes' && $site_config['UPLOADSCRAPE']){
$tracker=str_replace("/announce","/scrape",$announce);
$stats = torrent_scrape_url($tracker, $infohash);
$seeders = strip_tags($stats['seeds']);
$leechers = strip_tags($stats['peers']);
$downloaded = strip_tags($stats['downloaded']);
SQL_Query_exec("UPDATE torrents SET leechers='".$leechers."', seeders='".$seeders."',times_completed='".$downloaded."',last_action= '".get_date_time()."',visible='yes' WHERE id='".$id."'");
}
//END SCRAPE
write_log("Torrent $id (".htmlspecialchars($name).") was Uploaded by $CURUSER[username]");
//insert email notif, irc, req notif, etc here
//Uploaded ok message (update later)
if ($external=='no')
$message = sprintf( T_("TORRENT_UPLOAD_LOCAL"), $name, $id, $id );
else
$message = sprintf( T_("TORRENT_UPLOAD_EXTERNAL"), $name, $id );
show_error_msg(T_("UPLOAD_COMPLETE"), $message, 1);
die();
}//takeupload
///////////////////// FORMAT PAGE ////////////////////////
stdhead(T_("UPLOAD"));
begin_frame(T_("UPLOAD_RULES"));
echo "<b>".stripslashes($site_config["UPLOADRULES"])."</b>";
echo "<br />";
end_frame();
begin_frame(T_("UPLOAD"));
?>
<form name="upload" enctype="multipart/form-data" action="torrents-upload.php" method="post">
<input type="hidden" name="takeupload" value="yes" />
<table border="0" cellspacing="0" cellpadding="6" align="center">
<?php
print ("<tr><td align='right' valign='top'>" . T_("ANNOUNCE_URL") . ": </td><td align='left'>");
while (list($key,$value) = each($announce_urls)) {
echo "<b>$value</b><br />";
}
if ($site_config["ALLOWEXTERNAL"]){
echo "<br /><b>".T_("THIS_SITE_ACCEPTS_EXTERNAL")."</b>";
}
print ("</td></tr>");
print ("<tr><td align='right'>" . T_("TORRENT_FILE") . ": </td><td align='left'> <input type='file' name='torrent' size='50' value='" . $_FILES['torrent']['name'] . "' />\n</td></tr>");
print ("<tr><td align='right'>" .T_("NFO"). ": </td><td align='left'> <input type='file' name='nfo' size='50' value='" . $_FILES['nfo']['name'] . "' /><br />\n</td></tr>");
print ("<tr><td align='right'>" . T_("TORRENT_NAME") . ": </td><td align='left'><input type='text' name='name' size='60' value='" . $_POST['name'] . "' /><br />".T_("THIS_WILL_BE_TAKEN_TORRENT")." \n</td></tr>");
print ("<tr><td colspan='2' align='center'>".T_("MAX_FILE_SIZE").": ".mksize($site_config['image_max_filesize'])."<br />".T_("ACCEPTED_FORMATS").": ".implode(", ", array_unique($site_config["allowed_image_types"]))."<br /></td></tr><tr><td align='right'>".T_("IMAGE")." 1: </td><td><input type='file' name='image0' size='50' /></td></tr><tr><td align='right'>".T_("IMAGE")." 2: </td><td><input type='file' name='image1' size='50' /></td></tr>");
$category = "<select name=\"type\">\n<option value=\"0\">" . T_("CHOOSE_ONE") . "</option>\n";
$cats = genrelist();
foreach ($cats as $row)
$category .= "<option value=\"" . $row["id"] . "\">" . htmlspecialchars($row["parent_cat"]) . ": " . htmlspecialchars($row["name"]) . "</option>\n";
$category .= "</select>\n";
print ("<tr><td align='right'>" . T_("CATEGORY") . ": </td><td align='left'>".$category."</td></tr>");
$language = "<select name=\"lang\">\n<option value=\"0\">".T_("UNKNOWN_NA")."</option>\n";
$langs = langlist();
foreach ($langs as $row)
$language .= "<option value=\"" . $row["id"] . "\">" . htmlspecialchars($row["name"]) . "</option>\n";
$language .= "</select>\n";
print ("<tr><td align='right'>".T_("Idioma").": </td><td align='left'>".$language."</td></tr>");
if ($site_config['ANONYMOUSUPLOAD'] && $site_config["MEMBERSONLY"] ){ ?>
<tr><td align="right"><?php echo T_("UPLOAD_ANONY");?>: </td><td><?php printf("<input name='anonycheck' value='yes' type='radio' " . ($anonycheck ? " checked='checked'" : "") . " />Yes <input name='anonycheck' value='no' type='radio' " . (!$anonycheck ? " checked='checked'" : "") . " />No"); ?> <i><?php echo T_("UPLOAD_ANONY_MSG");?></i>
</td></tr>
<?php
}
print ("<tr><td align='center' colspan='2'>" . T_("DESCRIPTION") . "</td></tr></table>");
require_once("backend/bbcode.php");
print textbbcode("upload","descr","$descr");
?>
<br /><br /><center><input type="submit" value="<?php echo T_("UPLOAD_TORRENT"); ?>" /><br />
<i><?php echo T_("CLICK_ONCE_IMAGE");?></i>
</center>
</form>
<?php
end_frame();
stdfoot();
?>