| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,311 @@ |
| 1 |
+<?php |
|
| 2 |
+require_once("config.php");
|
|
| 3 |
+require_once("funcsv2.php");
|
|
| 4 |
+//Check session |
|
| 5 |
+session_start(); |
|
| 6 |
+ |
|
| 7 |
+if (!$_SESSION['admin_logged_in'] && !$_SESSION['upload_logged_in']) |
|
| 8 |
+{
|
|
| 9 |
+ //check fails |
|
| 10 |
+ header("Location: authenticate.php?status=error");
|
|
| 11 |
+ exit(); |
|
| 12 |
+} |
|
| 13 |
+?> |
|
| 14 |
+ |
|
| 15 |
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
|
| 16 |
+<html> |
|
| 17 |
+<head> |
|
| 18 |
+ <title>Add Torrent to Tracker</title> |
|
| 19 |
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> |
|
| 20 |
+ <link rel="stylesheet" type="text/css" href="./css/style.css" /> |
|
| 21 |
+</head> |
|
| 22 |
+<body> |
|
| 23 |
+ |
|
| 24 |
+<?php |
|
| 25 |
+$tracker_url = $website_url . substr($_SERVER['PHP_SELF'], 0, -15) . $announceurl; |
|
| 26 |
+ |
|
| 27 |
+if (isset($_FILES["torrent"])) |
|
| 28 |
+ addTorrent(); |
|
| 29 |
+ |
|
| 30 |
+ |
|
| 31 |
+endOutput(); |
|
| 32 |
+ |
|
| 33 |
+ |
|
| 34 |
+function addTorrent() |
|
| 35 |
+{
|
|
| 36 |
+ require ("config.php");
|
|
| 37 |
+ $tracker_url = $website_url . substr($_SERVER['PHP_SELF'], 0, -15) . $announceurl; |
|
| 38 |
+ |
|
| 39 |
+ $hash = strtolower($_POST["hash"]); |
|
| 40 |
+ |
|
| 41 |
+ $db = mysql_connect($dbhost, $dbuser, $dbpass) or die(errorMessage() . "Couldn't connect to the database, contact the administrator</p>"); |
|
| 42 |
+ mysql_select_db($database) or die(errorMessage() . "Can't open the database.</p>"); |
|
| 43 |
+ |
|
| 44 |
+ require_once ("funcsv2.php");
|
|
| 45 |
+ require_once ("BDecode.php");
|
|
| 46 |
+ require_once ("BEncode.php");
|
|
| 47 |
+ |
|
| 48 |
+ if ($_FILES["torrent"]["error"] != 4) |
|
| 49 |
+ {
|
|
| 50 |
+ $fd = fopen($_FILES["torrent"]["tmp_name"], "rb") or die(errorMessage() . "File upload error 1</p>\n"); |
|
| 51 |
+ is_uploaded_file($_FILES["torrent"]["tmp_name"]) or die(errorMessage() . "File upload error 2</p>\n"); |
|
| 52 |
+ $alltorrent = fread($fd, filesize($_FILES["torrent"]["tmp_name"])); |
|
| 53 |
+ |
|
| 54 |
+ $array = BDecode($alltorrent); |
|
| 55 |
+ if (!$array) |
|
| 56 |
+ {
|
|
| 57 |
+ echo errorMessage() . "Error: The parser was unable to load your torrent. Please re-create and re-upload the torrent.</p>\n"; |
|
| 58 |
+ endOutput(); |
|
| 59 |
+ exit; |
|
| 60 |
+ } |
|
| 61 |
+ |
|
| 62 |
+ if (isset($array["announce-list"])) {
|
|
| 63 |
+ //multiple trackers are listed |
|
| 64 |
+ $found_tracker = false; |
|
| 65 |
+ for ($i = 0; $i < count($array["announce-list"]); $i++) {
|
|
| 66 |
+ if (strtolower($array["announce-list"][$i][0]) == $tracker_url) {
|
|
| 67 |
+ $found_tracker = true; |
|
| 68 |
+ break; |
|
| 69 |
+ } |
|
| 70 |
+ } |
|
| 71 |
+ if ($found_tracker == false) |
|
| 72 |
+ {
|
|
| 73 |
+ echo errorMessage() . "Error: Multiple trackers were found but none of them match the |
|
| 74 |
+ announce URL:<br>$tracker_url<br>Please re-create and re-upload the torrent.</p>\n"; |
|
| 75 |
+ endOutput(); |
|
| 76 |
+ exit; |
|
| 77 |
+ } |
|
| 78 |
+ } else {
|
|
| 79 |
+ //a single tracker is listed |
|
| 80 |
+ if (strtolower($array["announce"]) != $tracker_url) {
|
|
| 81 |
+ echo errorMessage() . "Error: The tracker announce URL does not match this:<br>$tracker_url<br>Please re-create and re-upload the torrent.</p>\n"; |
|
| 82 |
+ endOutput(); |
|
| 83 |
+ exit; |
|
| 84 |
+ } |
|
| 85 |
+ } |
|
| 86 |
+ |
|
| 87 |
+ if (isset($_POST["httpseed"]) && $_POST["httpseed"] == "enabled" && $_POST["relative_path"] == "") |
|
| 88 |
+ {
|
|
| 89 |
+ echo errorMessage() . "Error: HTTP seeding was checked however no relative path was given.</p>\n"; |
|
| 90 |
+ endOutput(); |
|
| 91 |
+ exit; |
|
| 92 |
+ } |
|
| 93 |
+ if (isset($_POST["httpseed"]) && $_POST["httpseed"] == "enabled" && $_POST["relative_path"] != "") |
|
| 94 |
+ {
|
|
| 95 |
+ if (Substr($_POST["relative_path"], -1) == "/") |
|
| 96 |
+ {
|
|
| 97 |
+ if (!is_dir($_POST["relative_path"])) |
|
| 98 |
+ {
|
|
| 99 |
+ echo errorMessage() . "Error: HTTP seeding relative path ends in / but is not a valid directory.</p>\n"; |
|
| 100 |
+ endOutput(); |
|
| 101 |
+ exit; |
|
| 102 |
+ } |
|
| 103 |
+ } |
|
| 104 |
+ else |
|
| 105 |
+ {
|
|
| 106 |
+ if (!is_file($_POST["relative_path"])) |
|
| 107 |
+ {
|
|
| 108 |
+ echo errorMessage() . "Error: HTTP seeding relative path is not a valid file.</p>\n"; |
|
| 109 |
+ endOutput(); |
|
| 110 |
+ exit; |
|
| 111 |
+ } |
|
| 112 |
+ } |
|
| 113 |
+ } |
|
| 114 |
+ if (isset($_POST["getrightseed"]) && $_POST["getrightseed"] == "enabled" && $_POST["httpftplocation"] == "") |
|
| 115 |
+ {
|
|
| 116 |
+ echo errorMessage() . "Error: GetRight HTTP seeding was checked however no URL was given.</p>\n"; |
|
| 117 |
+ endOutput(); |
|
| 118 |
+ exit; |
|
| 119 |
+ } |
|
| 120 |
+ if (isset($_POST["getrightseed"]) && $_POST["getrightseed"] == "enabled" && |
|
| 121 |
+ (Substr($_POST["httpftplocation"], 0, 7) != "http://" && Substr($_POST["httpftplocation"], 0, 6) != "ftp://") |
|
| 122 |
+ ) |
|
| 123 |
+ {
|
|
| 124 |
+ echo errorMessage() . "Error: GetRight HTTP seeding URL must start with http:// or ftp://</p>\n"; |
|
| 125 |
+ endOutput(); |
|
| 126 |
+ exit; |
|
| 127 |
+ } |
|
| 128 |
+ $hash = @sha1(BEncode($array["info"])); |
|
| 129 |
+ fclose($fd); |
|
| 130 |
+ |
|
| 131 |
+ $target_path = "torrents/"; |
|
| 132 |
+ $target_path = $target_path . basename( clean($_FILES['torrent']['name'])); |
|
| 133 |
+ $move_torrent = move_uploaded_file($_FILES["torrent"]["tmp_name"], $target_path); |
|
| 134 |
+ if ($move_torrent == false) |
|
| 135 |
+ {
|
|
| 136 |
+ echo errorMessage() . "Unable to move " . $_FILES["torrent"]["tmp_name"] . " to torrents/</p>\n"; |
|
| 137 |
+ } |
|
| 138 |
+ } |
|
| 139 |
+ |
|
| 140 |
+ |
|
| 141 |
+ if (isset($_POST["title"])) |
|
| 142 |
+ $title = clean($_POST["title"]); |
|
| 143 |
+ else |
|
| 144 |
+ $title = ""; |
|
| 145 |
+ |
|
| 146 |
+ if (isset($_POST["filename"])) |
|
| 147 |
+ $filename = clean($_POST["filename"]); |
|
| 148 |
+ else |
|
| 149 |
+ $filename = ""; |
|
| 150 |
+ |
|
| 151 |
+ if (isset($_POST["url"])) |
|
| 152 |
+ $url = clean($_POST["url"]); |
|
| 153 |
+ else |
|
| 154 |
+ $url = ""; |
|
| 155 |
+ |
|
| 156 |
+ if (isset($_POST["autoset"])) |
|
| 157 |
+ if (strcmp($_POST["autoset"], "enabled") == 0) |
|
| 158 |
+ {
|
|
| 159 |
+ if (strlen($filename) == 0 && isset($array["info"]["name"])) |
|
| 160 |
+ $filename = $array["info"]["name"]; |
|
| 161 |
+ } |
|
| 162 |
+ |
|
| 163 |
+ |
|
| 164 |
+ //figure out total size of all files in torrent |
|
| 165 |
+ $info = $array["info"]; |
|
| 166 |
+ $total_size = 0; |
|
| 167 |
+ if (isset($info["files"])) |
|
| 168 |
+ {
|
|
| 169 |
+ foreach ($info["files"] as $file) |
|
| 170 |
+ {
|
|
| 171 |
+ $total_size = $total_size + $file["length"]; |
|
| 172 |
+ } |
|
| 173 |
+ } |
|
| 174 |
+ else |
|
| 175 |
+ {
|
|
| 176 |
+ $total_size = $info["length"]; |
|
| 177 |
+ } |
|
| 178 |
+ |
|
| 179 |
+ //Validate torrent file, make sure everything is correct |
|
| 180 |
+ |
|
| 181 |
+ $filename = mysql_real_escape_string($filename); |
|
| 182 |
+ $filename = stripslashes($filename); |
|
| 183 |
+ $filename = htmlspecialchars(clean($filename)); |
|
| 184 |
+ $url = htmlspecialchars(mysql_real_escape_string($url)); |
|
| 185 |
+ |
|
| 186 |
+ if ((strlen($hash) != 40) || !verifyHash($hash)) |
|
| 187 |
+ {
|
|
| 188 |
+ echo errorMessage() . "Error: Info hash must be exactly 40 hex bytes.</p>\n"; |
|
| 189 |
+ endOutput(); |
|
| 190 |
+ } |
|
| 191 |
+ |
|
| 192 |
+ if (Substr($url, 0, 7) != "http://" && $url != "") |
|
| 193 |
+ {
|
|
| 194 |
+ echo errorMessage() . "Error: The Torrent URL does not start with http:// Make sure you entered a correct URL.</p>\n"; |
|
| 195 |
+ endOutput(); |
|
| 196 |
+ } |
|
| 197 |
+ |
|
| 198 |
+ if ($GLOBALS["customtitle"] == "true") |
|
| 199 |
+ $query = "INSERT INTO ".$prefix."namemap (info_hash, title, filename, url, size, pubDate) VALUES (\"$hash\", \"$title\", \"$filename\", \"$url\", \"$total_size\", \"" . date("$dateformat") . "\")";
|
|
| 200 |
+ else $query = "INSERT INTO ".$prefix."namemap (info_hash, title, filename, url, size, pubDate) VALUES (\"$hash\", \"$filename\", \"$filename\", \"$url\", \"$total_size\", \"" . date("$dateformat") . "\")";
|
|
| 201 |
+ $status = makeTorrent($hash, true); |
|
| 202 |
+ quickQuery($query); |
|
| 203 |
+ if ($status) |
|
| 204 |
+ {
|
|
| 205 |
+ echo "<p class=\"success\">Torrent was added successfully.</p>\n"; |
|
| 206 |
+ 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"; |
|
| 207 |
+ //rename torrent file to match filename |
|
| 208 |
+ rename("torrents/" . clean($_FILES['torrent']['name']), "torrents/" . $filename . ".torrent");
|
|
| 209 |
+ //make torrent file readable by all |
|
| 210 |
+ chmod("torrents/" . $filename . ".torrent", 0644);
|
|
| 211 |
+ |
|
| 212 |
+ //run RSS generator |
|
| 213 |
+ require_once("rss_generator.php");
|
|
| 214 |
+ //Display information from DumpTorrentCGI.php |
|
| 215 |
+ require_once("torrent_functions.php");
|
|
| 216 |
+ } |
|
| 217 |
+ else |
|
| 218 |
+ {
|
|
| 219 |
+ echo errorMessage() . "There were some errors. Check if this torrent has been added previously.</p>\n"; |
|
| 220 |
+ //delete torrent file if it doesn't exist in database |
|
| 221 |
+ $query = "SELECT COUNT(*) FROM ".$prefix."summary WHERE info_hash = '$hash'"; |
|
| 222 |
+ $results = mysql_query($query) or die(errorMessage() . "Can't do SQL query - " . mysql_error() . "</p>"); |
|
| 223 |
+ $data = mysql_fetch_row($results); |
|
| 224 |
+ if ($data[0] == 0) |
|
| 225 |
+ {
|
|
| 226 |
+ if (file_exists("torrents/" . $_FILES['torrent']['name']))
|
|
| 227 |
+ unlink("torrents/" . $_FILES['torrent']['name']);
|
|
| 228 |
+ } |
|
| 229 |
+ //make torrent file readable by all |
|
| 230 |
+ chmod("torrents/" . $filename . ".torrent", 0644);
|
|
| 231 |
+ endOutput(); |
|
| 232 |
+ } |
|
| 233 |
+} |
|
| 234 |
+ |
|
| 235 |
+function endOutput() |
|
| 236 |
+{
|
|
| 237 |
+ require ("config.php");
|
|
| 238 |
+ $tracker_url = $website_url . substr($_SERVER['PHP_SELF'], 0, -15) . $announceurl; |
|
| 239 |
+ ?> |
|
| 240 |
+ <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> |
|
| 241 |
+ <div class="center"> |
|
| 242 |
+ <h1>Add Torrent to Tracker Database</h1> |
|
| 243 |
+ <h3>Tracker URL: <?php echo $tracker_url;?></h3> |
|
| 244 |
+ <form enctype="multipart/form-data" method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> |
|
| 245 |
+ <table> |
|
| 246 |
+ <tr> |
|
| 247 |
+ <?php |
|
| 248 |
+ if ($GLOBALS["customtitle"] == "true") |
|
| 249 |
+ echo "<td class=\"right\">Title:</td> |
|
| 250 |
+ <td class=\"left\"><input type=\"title\" name=\"title\" size=\"50\"/></td>"; |
|
| 251 |
+ else ($GLOBALS["customtitle"] != "true"); |
|
| 252 |
+ ?> |
|
| 253 |
+ </tr> |
|
| 254 |
+ <tr> |
|
| 255 |
+ <td class="right">Torrent file:</td> |
|
| 256 |
+ <td class="left"><?php |
|
| 257 |
+ if (function_exists("sha1"))
|
|
| 258 |
+ echo "<input type=\"file\" name=\"torrent\" size=\"50\"/>"; |
|
| 259 |
+ else |
|
| 260 |
+ echo '<i>File uploading not available - no SHA1 function.</i>'; |
|
| 261 |
+ ?></td> |
|
| 262 |
+ </tr> |
|
| 263 |
+ <tr><td colspan="2"><hr></td></tr> |
|
| 264 |
+ <tr> |
|
| 265 |
+ <td class="center" colspan="2"><input type="checkbox" name="httpseed" value="enabled">Use BitTornado HTTP seeding specification (optional)</td> |
|
| 266 |
+ </tr> |
|
| 267 |
+ <tr> |
|
| 268 |
+ <td class="right">Relative location of file or directory:<br>e.g. ../../files/file.zip</td> |
|
| 269 |
+ <td class="left"><input type="text" name="relative_path" size="70"/></td> |
|
| 270 |
+ </tr> |
|
| 271 |
+ <tr><td colspan="2"><hr></td></tr> |
|
| 272 |
+ <tr> |
|
| 273 |
+ <td class="center" colspan="2"><input type="checkbox" name="getrightseed" value="enabled">Use GetRight HTTP seeding specification (optional)</td> |
|
| 274 |
+ </tr> |
|
| 275 |
+ <tr> |
|
| 276 |
+ <td class="right">FTP/HTTP URL of file or directory:<br>e.g. http://yourwebsite.com/file.zip</td> |
|
| 277 |
+ <td class="left"><input type="text" name="httpftplocation" size="70"/></td> |
|
| 278 |
+ </tr> |
|
| 279 |
+ <tr><td colspan="2"><hr></td></tr> |
|
| 280 |
+ <?php if (function_exists("sha1"))
|
|
| 281 |
+ 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"; |
|
| 282 |
+ ?> |
|
| 283 |
+ <tr> |
|
| 284 |
+ <td class="right">Info Hash:</td> |
|
| 285 |
+ <td class="left"><input type="text" name="hash" size="40"/></td> |
|
| 286 |
+ </tr> |
|
| 287 |
+ <tr> |
|
| 288 |
+ <td class="right">File name (optional): </td> |
|
| 289 |
+ <td class="left"><input type="text" name="filename" size="60" maxlength="200"/></td> |
|
| 290 |
+ </tr> |
|
| 291 |
+ <tr> |
|
| 292 |
+ <td class="right">Torrent's URL (optional): </td> |
|
| 293 |
+ <td class="left"><input type="text" name="url" size="60" maxlength="200"/></td> |
|
| 294 |
+ </tr> |
|
| 295 |
+ <tr><td colspan="2"><hr></td></tr> |
|
| 296 |
+ <tr> |
|
| 297 |
+ <td class="center" colspan="2"><input type="submit" value="Add Torrent to Database"/> - <input type="reset" value="Clear Settings"/></td> |
|
| 298 |
+ </tr> |
|
| 299 |
+ </table> |
|
| 300 |
+ <br> |
|
| 301 |
+ <input type="hidden" name="username" value="<?php echo $_POST['username']; ?>"/> |
|
| 302 |
+ <input type="hidden" name="password" value="<?php echo $_POST['password']; ?>"/> |
|
| 303 |
+ </form> |
|
| 304 |
+ <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> |
|
| 305 |
+ </div> |
|
| 306 |
+ </body></html> |
|
| 307 |
+ <?php |
|
| 308 |
+ // Still in function endOutput() |
|
| 309 |
+ exit; |
|
| 310 |
+} |
|
| 311 |
+?> |
|
| 0 | 312 |
\ No newline at end of file |