PageRenderTime 25ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/takemultiupload.php

https://github.com/Bigjoos/U-232-V2
PHP | 350 lines | 323 code | 16 blank | 11 comment | 55 complexity | 632e5f3d11f9785a3396ff7bb8d2cbb9 MD5 | raw file
  1. <?php
  2. /**
  3. * https://09source.kicks-ass.net:8443/svn/installer09/
  4. * Licence Info: GPL
  5. * Copyright (C) 2010 Installer09 v.2
  6. * A bittorrent tracker source based on TBDev.net/tbsource/bytemonsoon.
  7. * Project Leaders: Mindless,putyn,kidvision.
  8. **/
  9. require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'include'.DIRECTORY_SEPARATOR.'bittorrent.php');
  10. require_once(INCL_DIR.'benc.php');
  11. require_once(INCL_DIR.'user_functions.php');
  12. require_once(CLASS_DIR.'page_verify.php');
  13. dbconn();
  14. loggedinorreturn();
  15. $lang = array_merge( load_language('global'), load_language('takeupload') );
  16. $newpage = new page_verify();
  17. $newpage->check('tamud');
  18. if ($CURUSER['class'] < UC_UPLOADER OR $CURUSER["uploadpos"] == 0 || $CURUSER["uploadpos"] > 1 || $CURUSER['suspended'] == 'yes')
  19. header( "Location: {$INSTALLER09['baseurl']}/multiupload.php" );
  20. $nfofilename = array();
  21. $matches = array();
  22. $fname = array();
  23. if (!isset($_FILES["file1"]) && !isset($_FILES["file2"]) && !isset($_FILES["file3"]) && !isset($_FILES["file4"]) && !isset($_FILES["file5"])) {
  24. stderr("Ooops", "You didn't specify a filename!");
  25. } else {
  26. $f1 = $_FILES["file1"];
  27. $nfofile1 = $_FILES['nfo1'];
  28. $fname[] = unesc($f1["name"]);
  29. if ($nfofile1['size'] > 65535)
  30. stderr("Oops", "No NFO! for #1 torrent OR NFO #1 is too big! Max 65,535 bytes.");
  31. $f2 = $_FILES["file2"];
  32. $nfofile2 = $_FILES['nfo2'];
  33. $fname[] = unesc($f2["name"]);
  34. if ($nfofile2['size'] > 65535)
  35. stderr("Error", "No NFO! for #2 torrent OR NFO #2 is too big! Max 65,535 bytes.");
  36. $f3 = $_FILES["file3"];
  37. $nfofile3 = $_FILES['nfo3'];
  38. $fname[] = unesc($f3["name"]);
  39. if ($nfofile3['size'] > 65535)
  40. stderr("Oops", "No NFO! for #3 torrent OR NFO #3 is too big! Max 65,535 bytes.");
  41. $f4 = $_FILES["file4"];
  42. $nfofile4 = $_FILES['nfo4'];
  43. $fname[] = unesc($f4["name"]);
  44. if ($nfofile4['size'] > 65535)
  45. stderr("Oops", "No NFO! for #4 torrent OR NFO #4 is too big! Max 65,535 bytes.");
  46. $f5 = $_FILES["file5"];
  47. $nfofile5 = $_FILES['nfo5'];
  48. $fname[] = unesc($f5["name"]);
  49. if ($nfofile5['size'] > 65535)
  50. stderr("Oops", "No NFO! #5 torrent OR NFO #5 is too big! Max 65,535 bytes.");
  51. function dict_check($d, $s)
  52. {
  53. // echo $d["type"];
  54. // print_r($d);
  55. if ($d["type"] != "dictionary")
  56. stderr("Oops", "not a dictionary");
  57. $a = explode(":", $s);
  58. $dd = $d["value"];
  59. $ret = array();
  60. foreach ($a as $k) {
  61. unset($t);
  62. if (preg_match('/^(.*)\((.*)\)$/', $k, $m)) {
  63. $k = $m[1];
  64. $t = $m[2];
  65. }
  66. if (!isset($dd[$k]))
  67. stderr("Oops", "dictionary is missing key(s)");
  68. if (isset($t)) {
  69. if ($dd[$k]["type"] != $t)
  70. stderr("Oops", "invalid entry in dictionary");
  71. $ret[] = $dd[$k]["value"];
  72. } else
  73. $ret[] = $dd[$k];
  74. }
  75. return $ret;
  76. }
  77. function dict_get($d, $k, $t)
  78. {
  79. if ($d["type"] != "dictionary")
  80. stderr("Oops", "not a dictionary");
  81. $dd = $d["value"];
  82. if (!isset($dd[$k]))
  83. return;
  84. $v = $dd[$k];
  85. if ($v["type"] != $t)
  86. stderr("Oops", "invalid dictionary entry type");
  87. return $v["value"];
  88. }
  89. //== Some crucial checks
  90. if (!validfilename($fname[0]) || !validfilename($fname[1]) || !validfilename($fname[2]) || !validfilename($fname[3]) || !validfilename($fname[4]))
  91. stderr("Oops", "One of the filenames was invalid!");
  92. if (!preg_match('/^(.+)\.torrent$/si', $fname[0], $matches[0]))
  93. stderr("Oops", "Invalid filename 1(not a .torrent).");
  94. if (!preg_match('/^(.+)\.torrent$/si', $fname[1], $matches[1]))
  95. stderr("Oops", "Invalid filename 2(not a .torrent).");
  96. if (!preg_match('/^(.+)\.torrent$/si', $fname[2], $matches[2]))
  97. stderr("Oops", "Invalid filename 3(not a .torrent).");
  98. if (!preg_match('/^(.+)\.torrent$/si', $fname[3], $matches[3]))
  99. stderr("Oops", "Invalid filename 4(not a .torrent).");
  100. if (!preg_match('/^(.+)\.torrent$/si', $fname[4], $matches[4]))
  101. stderr("Oops", "Invalid filename 5(not a .torrent).");
  102. //== very important check in terms of security
  103. if ($nfofile1['name'] != '')
  104. $nfofilename[] = $nfofile1['tmp_name'];
  105. if (@!is_uploaded_file($nfofilename[0]))
  106. stderr("Oops", "NFO1 upload failed");
  107. if ($nfofile2['name'] != '')
  108. $nfofilename[] = $nfofile2['tmp_name'];
  109. if (@!is_uploaded_file($nfofilename[1]))
  110. stderr("Oops", "NFO2 upload failed");
  111. if ($nfofile3['name'] != '')
  112. $nfofilename[] = $nfofile3['tmp_name'];
  113. if (@!is_uploaded_file($nfofilename[2]))
  114. stderr("Oops", "NFO3 upload failed");
  115. if ($nfofile4['name'] != '')
  116. $nfofilename[] = $nfofile4['tmp_name'];
  117. if (@!is_uploaded_file($nfofilename[3]))
  118. stderr("Oops", "NFO4 upload failed");
  119. if ($nfofile5['name'] != '')
  120. $nfofilename[] = $nfofile5['tmp_name'];
  121. if (@!is_uploaded_file($nfofilename[4]))
  122. stderr("oOPS", "NFO5 upload failed");
  123. }
  124. $descr = unesc($_POST["description"]);
  125. if (!$descr) {
  126. stderr("Oops", "Please select either 'Take description from its respective NFO' OR enter a custom description to go with all torrents'");
  127. }
  128. $cat = array();
  129. $catid = (0 + $_POST["alltype"]);
  130. if (!is_valid_id($catid))
  131. stderr("Oops", "You must select a category to put ALL the torrent in!");
  132. //== Use the posted type category first -- if not set then just apply from settings
  133. if (isset($_POST["type1"])) {
  134. $cat[0] = 0 + $_POST["type1"];
  135. if (!is_valid_id($cat[0]))
  136. $cat[0] = 0 + $_POST["alltype"];
  137. }
  138. if (isset($_POST["type2"])) {
  139. $cat[1] = 0 + $_POST["type2"];
  140. if (!is_valid_id($cat[1]))
  141. $cat[1] = 0 + $_POST["alltype"];
  142. }
  143. if (isset($_POST["type3"])) {
  144. $cat[2] = 0 + $_POST["type3"];
  145. if (!is_valid_id($cat[2]))
  146. $cat[2] = 0 + $_POST["alltype"];
  147. }
  148. if (isset($_POST["type4"])) {
  149. $cat[3] = 0 + $_POST["type4"];
  150. if (!is_valid_id($cat[3]))
  151. $cat[3] = 0 + $_POST["alltype"];
  152. }
  153. if (isset($_POST["type5"])) {
  154. $cat[4] = 0 + $_POST["type5"];
  155. if (!is_valid_id($cat[4]))
  156. $cat[4] = 0 + $_POST["alltype"];
  157. }
  158. if(isset($_POST['uplver1']) && $_POST['uplver1'] == 'yes') {
  159. $anonymous = "yes";
  160. $anon = "Anonymous";
  161. } else {
  162. $anonymous = "no";
  163. $anon = $CURUSER["username"];
  164. }
  165. if(isset($_POST['uplver2']) && $_POST['uplver2'] == 'yes') {
  166. $anonymous = "yes";
  167. $anon = "Anonymous";
  168. } else {
  169. $anonymous = "no";
  170. $anon = $CURUSER["username"];
  171. }
  172. if(isset($_POST['uplver3']) && $_POST['uplver3'] == 'yes') {
  173. $anonymous = "yes";
  174. $anon = "Anonymous";
  175. } else {
  176. $anonymous = "no";
  177. $anon = $CURUSER["username"];
  178. }
  179. if(isset($_POST['uplver4']) && $_POST['uplver4'] == 'yes') {
  180. $anonymous = "yes";
  181. $anon = "Anonymous";
  182. } else {
  183. $anonymous = "no";
  184. $anon = $CURUSER["username"];
  185. }
  186. if(isset($_POST['uplver5']) && $_POST['uplver5'] == 'yes') {
  187. $anonymous = "yes";
  188. $anon = "Anonymous";
  189. } else {
  190. $anonymous = "no";
  191. $anon = $CURUSER["username"];
  192. }
  193. //== Arrays
  194. $shortname = array();
  195. $tmpname = array();
  196. $dict = array();
  197. $ann = array();
  198. $info = array();
  199. $dbname = array();
  200. $plen = array();
  201. $pieces = array();
  202. $filelist = array();
  203. $totallen = array();
  204. $infohash = array();
  205. $torrent = array();
  206. $nfo = array();
  207. $ids = array();
  208. $tmpname[] = $f1["tmp_name"];
  209. $tmpname[] = $f2["tmp_name"];
  210. $tmpname[] = $f3["tmp_name"];
  211. $tmpname[] = $f4["tmp_name"];
  212. $tmpname[] = $f5["tmp_name"];
  213. $i = 0;
  214. foreach($tmpname as $value) {
  215. $shortfname[$i] = $torrent[$i] = $matches[$i];
  216. if (!is_uploaded_file($value))
  217. stderr("Opps", "Bad filename found on file no #$i");
  218. if (!filesize($value))
  219. stderr("Oops", "Empty file! $value");
  220. $dict[] = bdec_file($value, $INSTALLER09['max_torrent_size']);
  221. if (!isset($dict[$i]))
  222. stderr("Oops", "What the hell did you upload? This is not a bencoded file 1!");
  223. list($ann[$i], $info[$i]) = dict_check($dict[$i], "announce(string):info");
  224. list($dname[$i], $plen[$i], $pieces[$i]) = dict_check($info[$i], "name(string):piece length(integer):pieces(string)");
  225. if (!in_array($ann[$i], $INSTALLER09['announce_urls'], 1))
  226. stderr("Oops", "invalid announce url! in file no #$i must be {$INSTALLER09['announce_urls'][0]} - Make sure its exactly like that even the port number should be in there like '80'");
  227. if (strlen($pieces[$i]) % 20 != 0)
  228. stderr("Oops", "invalid pieces in file $i");
  229. $totallen = dict_get($info[$i], "length", "integer");
  230. if (isset($totallen)) {
  231. $filelist[] = array($dname[$i], $totallen);
  232. $type = "single";
  233. } else {
  234. $flist = dict_get($info[$i], "files", "list");
  235. if (!isset($flist)) {
  236. stderr("Oops", "missing both length and files in #$i torrent");
  237. }
  238. if (!count($flist)) {
  239. stderr("Oops", "Missing files in torrent #$i");
  240. }
  241. $totallen = 0;
  242. foreach ($flist as $fn) {
  243. list($ll, $ff) = dict_check($fn, "length(integer):path(list)");
  244. $totallen += $ll;
  245. $ffa = array();
  246. foreach ($ff as $ffe) {
  247. if ($ffe["type"] != "string")
  248. stderr("Oops", "filename error on torrent #$i");
  249. $ffa[] = $ffe["value"];
  250. }
  251. if (!count($ffa))
  252. stderr("Oops", "filename error");
  253. $ffe = implode("/", $ffa);
  254. $filelist[] = array($ffe, $ll);
  255. }
  256. $type = "multi";
  257. }
  258. /* Private Tracker mod code */
  259. $info[$i]['value']['source']['type'] = "string";
  260. $info[$i]['value']['source']['value'] = $INSTALLER09['site_name'];
  261. $info[$i]['value']['source']['strlen'] = strlen($info[$i]['value']['source']['value']);
  262. $info[$i]['value']['private']['type'] = "integer";
  263. $info[$i]['value']['private']['value'] = 1;
  264. $dict[$i]['value']['info'] = $info[$i];
  265. $dict[$i] = benc($dict[$i]);
  266. $dict[$i] = bdec($dict[$i]);
  267. list($ann[$i], $info[$i]) = dict_check($dict[$i], "announce(string):info");
  268. $tmaker = (isset($dict['value']['created by']) && !empty($dict['value']['created by']['value'])) ? sqlesc($dict['value']['created by']['value']) : sqlesc("Unknown");
  269. unset($dict['value']['created by']);
  270. $infohash[$i] = sha1($info[$i]["string"]);
  271. /* ...... end of Private Tracker mod */
  272. $torrent[$i] = str_replace("_", " ", $torrent[$i]);
  273. $torrent[$i] = str_replace("'", " ", $torrent[$i]);
  274. $torrent[$i] = str_replace("\"", " ", $torrent[$i]);
  275. $torrent[$i] = str_replace(",", " ", $torrent[$i]);
  276. $nfo[$i] = sqlesc(str_replace("\x0d\x0d\x0a", "\x0d\x0a", @file_get_contents($nfofilename[$i])));
  277. $first = $shortfname[$i][1];
  278. $second = $dname[$i];
  279. $third = $torrent[$i][1];
  280. $vip = (isset($_POST["vip1"]) ? "1" : "0");
  281. $vip = (isset($_POST["vip2"]) ? "1" : "0");
  282. $vip = (isset($_POST["vip3"]) ? "1" : "0");
  283. $vip = (isset($_POST["vip4"]) ? "1" : "0");
  284. $vip = (isset($_POST["vip5"]) ? "1" : "0");
  285. $ret = mysql_query("INSERT INTO torrents (search_text, filename, owner, visible, anonymous, vip, info_hash, name, size, numfiles, type, descr, ori_descr, category, save_as, added, last_action, nfo) VALUES (" . implode(",", array_map("sqlesc", array(searchfield("$first $second $third"), $fname[$i], $CURUSER["id"], "no", $anonymous, $vip, $infohash[$i], $torrent[$i][1], $totallen, count($filelist[$i]), $type, $descr, $descr, $cat[$i], $dname[$i]))) . ", '" . time() . "', '" . time() . "', $nfo[$i])");
  286. if (!$ret) {
  287. if (mysql_errno() == 1062)
  288. stderr("Oops", "#$i torrent was already uploaded!");
  289. stderr("Oops", "mysql puked: " . mysql_error());
  290. }
  291. $id = mysql_insert_id();
  292. $ids[] = $id;
  293. $mc1->delete_value('MyPeers_'.$CURUSER['id']);
  294. $mc1->delete_value('lastest_tor_');
  295. sql_query("DELETE FROM files WHERE torrent = $id");
  296. foreach ($filelist as $file) {
  297. sql_query("INSERT INTO files (torrent, filename, size) VALUES ($id, " . sqlesc($file[0]) . "," . $file[1] . ")");
  298. }
  299. $fp = fopen("{$INSTALLER09['torrent_dir']}/$id.torrent", "w");
  300. if ($fp) {
  301. @fwrite($fp, benc($dict[$i]), strlen(benc($dict[$i])));
  302. fclose($fp);
  303. }
  304. $i++;
  305. }
  306. //unset($filelist);
  307. //unset($flist);
  308. // ===add karma
  309. sql_query("UPDATE users SET seedbonus = seedbonus+75.0 WHERE id =".sqlesc($CURUSER['id'])."") or sqlerr(__FILE__, __LINE__);
  310. // ===end
  311. ////////new torrent upload detail sent to shoutbox//////////
  312. if ($CURUSER["anonymous"] == 'yes')
  313. $message = "[url={$INSTALLER09['baseurl']}/multidetails.php?id1=$ids[0]&id2=$ids[1]&id3=$ids[2]&id4=$ids[3]&id5=$ids[4]]Multiple Torrents were just uploaded! Click here to see them[/url] - Anonymous User";
  314. else
  315. $message = "[url={$INSTALLER09['baseurl']}/multidetails.php?id1=$ids[0]&id2=$ids[1]&id3=$ids[2]&id4=$ids[3]&id5=$ids[4]]Multiple Torrents were just uploaded! Click here to see them[/url] Uploaded by ".htmlspecialchars($CURUSER["username"])."";
  316. // ///////////////////////////END///////////////////////////////////
  317. // //////new torrent upload detail sent to shoutbox//////////
  318. autoshout($message);
  319. // ///////////////////////////end///////////////////////////////////
  320. header("Location: {$INSTALLER09['baseurl']}/multidetails.php?id1=$ids[0]&id2=$ids[1]&id3=$ids[2]&id4=$ids[3]&id5=$ids[4]&uploaded=1");
  321. ?>