-
Notifications
You must be signed in to change notification settings - Fork 29
/
takeedit.php
315 lines (263 loc) · 10.7 KB
/
takeedit.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
<?
/*
// +--------------------------------------------------------------------------+
// | Project: TBDevYSE - TBDev Yuna Scatari Edition |
// +--------------------------------------------------------------------------+
// | This file is part of TBDevYSE. TBDevYSE is based on TBDev, |
// | originally by RedBeard of TorrentBits, extensively modified by |
// | Gartenzwerg. |
// | |
// | TBDevYSE is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation; either version 2 of the License, or |
// | (at your option) any later version. |
// | |
// | TBDevYSE is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with TBDevYSE; if not, write to the Free Software Foundation, |
// | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
// +--------------------------------------------------------------------------+
// | Do not remove above lines! |
// +--------------------------------------------------------------------------+
*/
require_once("include/BDecode.php");
require_once("include/BEncode.php");
require_once("include/bittorrent.php");
function bark($msg) {
stderr("Îøèáêà", $msg);
}
////////////////////////////////////////////////
function uploadimage($x, $imgname, $tid) {
global $max_image_size;
$maxfilesize = $max_image_size; // default 1mb
$allowed_types = array(
"image/gif" => "gif",
"image/pjpeg" => "jpg",
"image/jpeg" => "jpg",
"image/jpg" => "jpg",
"image/png" => "png"
// Add more types here if you like
);
if (!($_FILES['image'.$x]['name'] == "")) {
if ($imgname != "") {
// Make sure is same as in takeedit.php (except for the $imgname bit)
$img = "torrents/images/$imgname";
$del = unlink($img);
}
$y = $x + 1;
// Is valid filetype?
if (!array_key_exists($_FILES['image'.$x]['type'], $allowed_types))
bark("Invalid file type! Image $y (".htmlspecialchars_uni($_FILES['image'.$x]['type']).")");
if (!preg_match('/^(.+)\.(jpg|jpeg|png|gif)$/si', $_FILES['image'.$x]['name']))
bark("Íåâåðíîå èìÿ ôàéëà (íå êàðòèíêà).");
// Is within allowed filesize?
if ($_FILES['image'.$x]['size'] > $maxfilesize)
bark("Ïðåâûøåí ðàçìåð ôàéëà! Êàðòèíêà $y - Äîëæíà áûòü ìåíüøå ".mksize($maxfilesize));
// Where to upload?
// Make sure is same as on takeupload.php
$uploaddir = "torrents/images/";
// What is the temporary file name?
$ifile = $_FILES['image'.$x]['tmp_name'];
// By what filename should the tracker associate the image with?
//$ifilename = $tid . $x . substr($_FILES['image'.$x]['name'], strlen($_FILES['image'.$x]['name'])-4, 4);
$ifilename = $tid . $x . '.' . end(explode('.', $_FILES['image'.$x]['name']));
// Upload the file
$copy = copy($ifile, $uploaddir.$ifilename);
if (!$copy)
bark("Error occured uploading image! - Image $y");
return $ifilename;
}
}
////////////////////////////////////////////////
function dict_check($d, $s) {
if ($d["type"] != "dictionary")
bark("not a dictionary");
$a = explode(":", $s);
$dd = $d["value"];
$ret = array();
foreach ($a as $k) {
unset($t);
if (preg_match('/^(.*)\((.*)\)$/', $k, $m)) {
$k = $m[1];
$t = $m[2];
}
if (!isset($dd[$k]))
bark("dictionary is missing key(s)");
if (isset($t)) {
if ($dd[$k]["type"] != $t)
bark("invalid entry in dictionary");
$ret[] = $dd[$k]["value"];
}
else
$ret[] = $dd[$k];
}
return $ret;
}
function dict_get($d, $k, $t) {
if ($d["type"] != "dictionary")
bark("not a dictionary");
$dd = $d["value"];
if (!isset($dd[$k]))
return;
$v = $dd[$k];
if ($v["type"] != $t)
bark("invalid dictionary entry type");
return $v["value"];
}
dbconn();
loggedinorreturn();
if (!mkglobal("id:name:descr:type"))
bark("missing form data");
$id = intval($id);
if (!$id)
die();
$res = sql_query("SELECT owner, filename, save_as, image1, image2, image3, image4, image5 FROM torrents WHERE id = $id");
$row = mysql_fetch_array($res);
if (!$row)
die();
if ($CURUSER["id"] != $row["owner"] && get_user_class() < UC_MODERATOR)
bark("You're not the owner! How did that happen?\n");
$updateset = array();
$fname = $row["filename"];
preg_match('/^(.+)\.torrent$/si', $fname, $matches);
$shortfname = $matches[1];
$dname = $row["save_as"];
// picturemod
for ($x=1; $x <= 5; $x++) {
$_GLOBALS['img'.$x.'action'] = $_POST['img'.$x.'action'];
if ($_GLOBALS['img'.$x.'action'] == 'update')
$updateset[] = 'image' . $x . ' = ' .sqlesc(uploadimage($x - 1, $row['image' . $x], $id));
if ($_GLOBALS['img'.$x.'action'] == 'delete') {
if ($row['image' . $x]) {
$del = unlink('torrents/images/' . $row['image' . $x]);
$updateset[] = 'image' . $x . ' = ""';
}
}
}
// picturemod
if (isset($_FILES["tfile"]) && !empty($_FILES["tfile"]["name"]))
$update_torrent = true;
if ($update_torrent) {
$f = $_FILES["tfile"];
$fname = unesc($f["name"]);
if (empty($fname))
bark("Ôàéë íå çàãðóæåí. Ïóñòîå èìÿ ôàéëà!");
if (!validfilename($fname))
bark("Íåâåðíîå èìÿ ôàéëà!");
if (!preg_match('/^(.+)\.torrent$/si', $fname, $matches))
bark("Íåâåðíîå èìÿ ôàéëà (íå .torrent).");
$tmpname = $f["tmp_name"];
if (!is_uploaded_file($tmpname))
bark("eek");
if (!filesize($tmpname))
bark("Ïóñòîé ôàéë!");
$dict = bdecode(file_get_contents($tmpname));
if (!isset($dict))
bark("×òî çà õðåíü òû çàãðóæàåøü? Ýòî íå áèíàðíî-êîäèðîâàíûé ôàéë!");
$info = $dict['info'];
list($dname, $plen, $pieces, $totallen) = array($info['name'], $info['piece length'], $info['pieces'], $info['length']);
if (strlen($pieces) % 20 != 0)
bark("invalid pieces");
$filelist = array();
if (isset($totallen)) {
$filelist[] = array($dname, $totallen);
$torrent_type = "single";
} else {
$flist = $info['files'];
if (!isset($flist))
bark("missing both length and files");
if (!count($flist))
bark("no files");
$totallen = 0;
foreach ($flist as $fn) {
list($ll, $ff) = array($fn['length'], $fn['path']);
$totallen += $ll;
$ffa = array();
foreach ($ff as $ffe) {
$ffa[] = $ffe;
}
if (!count($ffa))
bark("filename error");
$ffe = implode("/", $ffa);
$filelist[] = array($ffe, $ll);
if ($ffe == 'Thumbs.db')
{
stderr("Îøèáêà", "Â òîððåíòàõ çàïðåùåíî äåðæàòü ôàéëû Thumbs.db!");
die;
}
}
$torrent_type = "multi";
}
$dict['announce'] = $announce_urls[0]; // change announce url to local
$dict['info']['private'] = 1; // add private tracker flag
$dict['info']['source'] = "[$DEFAULTBASEURL] $SITENAME"; // add link for bitcomet users
unset($dict['announce-list']); // remove multi-tracker capability
unset($dict['nodes']); // remove cached peers (Bitcomet & Azareus)
unset($dict['info']['crc32']); // remove crc32
unset($dict['info']['ed2k']); // remove ed2k
unset($dict['info']['md5sum']); // remove md5sum
unset($dict['info']['sha1']); // remove sha1
unset($dict['info']['tiger']); // remove tiger
unset($dict['azureus_properties']); // remove azureus properties
$dict = BDecode(BEncode($dict)); // double up on the becoding solves the occassional misgenerated infohash
$dict['comment'] = "Òîððåíò ñîçäàí äëÿ '$SITENAME'"; // change torrent comment
$dict['created by'] = "$CURUSER[username]"; // change created by
$dict['publisher'] = "$CURUSER[username]"; // change publisher
$dict['publisher.utf-8'] = "$CURUSER[username]"; // change publisher.utf-8
$dict['publisher-url'] = "$DEFAULTBASEURL/userdetails.php?id=$CURUSER[id]"; // change publisher-url
$dict['publisher-url.utf-8'] = "$DEFAULTBASEURL/userdetails.php?id=$CURUSER[id]"; // change publisher-url.utf-8
$infohash = sha1(BEncode($dict['info']));
move_uploaded_file($tmpname, "$torrent_dir/$id.torrent");
$fp = fopen("$torrent_dir/$id.torrent", "w");
if ($fp) {
$dict_str = BEncode($dict);
@fwrite($fp, $dict_str, strlen($dict_str));
fclose($fp);
}
$updateset[] = "info_hash = " . sqlesc($infohash);
$updateset[] = "filename = " . sqlesc($fname);
$updateset[] = "save_as = " . sqlesc($dname);
$updateset[] = "size = " . sqlesc($totallen);
$updateset[] = "type = " . sqlesc($torrent_type);
$updateset[] = "numfiles = " . count($filelist);
@sql_query("DELETE FROM files WHERE torrent = $id");
foreach ($filelist as $file) {
@sql_query("INSERT INTO files (torrent, filename, size) VALUES ($id, ".sqlesc($file[0]).", ".$file[1].")");
}
}
$name = html_uni($name);
$descr = unesc($_POST["descr"]);
if (!$descr)
bark("Âû äîëæíû ââåñòè îïèñàíèå!");
$updateset[] = "name = " . sqlesc($name);
$updateset[] = "descr = " . sqlesc($descr);
$updateset[] = "ori_descr = " . sqlesc($descr);
sql_query('REPLACE INTO torrents_descr (tid, descr_hash, descr_parsed) VALUES ('.implode(', ', array_map('sqlesc', array($id, md5($descr), format_comment($descr)))).')') or sqlerr(__FILE__,__LINE__);
$updateset[] = "category = " . (intval($type));
if (get_user_class() >= UC_ADMINISTRATOR) {
if ($_POST["banned"]) {
$updateset[] = "banned = 'yes'";
$_POST["visible"] = 0;
} else
$updateset[] = "banned = 'no'";
if ($_POST["not_sticky"] == "no")
$updateset[] = "not_sticky = 'no'";
else
$updateset[] = "not_sticky = 'yes'";
}
if(get_user_class() >= UC_ADMINISTRATOR && in_array($_POST['free'], array('yes', 'silver', 'no')))
$updateset[] = "free = " . sqlesc($_POST['free']);
$updateset[] = "visible = '" . ($_POST["visible"] ? "yes" : "no") . "'";
$updateset[] = "moderated = 'yes'";
$updateset[] = "moderatedby = ".sqlesc($CURUSER["id"]);
sql_query("UPDATE torrents SET " . join(", ", $updateset) . " WHERE id = $id") or sqlerr(__FILE__,__LINE__);
write_log("Òîððåíò '$name' áûë îòðåäàêòèðîâàí ïîëüçîâàòåëåì {$CURUSER['username']}", "F25B61", "torrent");
$returl = "details.php?id=$id";
if (isset($_POST["returnto"]))
$returl .= "&returnto=" . urlencode($_POST["returnto"]);
header("Refresh: 0; url=$returl");
?>