forked from malletfils/xbtit-3.1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdownload.php
114 lines (98 loc) · 4.53 KB
/
download.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
<?php
/////////////////////////////////////////////////////////////////////////////////////
// xbtit - Bittorrent tracker/frontend
//
// Copyright (C) 2004 - 2020 Btiteam
//
// This file is part of xbtit.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// 3. The name of the author may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
////////////////////////////////////////////////////////////////////////////////////
$THIS_BASEPATH = __DIR__;
require_once "$THIS_BASEPATH/include/functions.php";
require_once "$THIS_BASEPATH/include/BDecode.php";
require_once "$THIS_BASEPATH/include/BEncode.php";
dbconn();
if (!$CURUSER || $CURUSER['can_download'] == 'no') {
require load_language('lang_main.php');
die($language['NOT_AUTH_DOWNLOAD']);
}
if (ini_get('zlib.output_compression')) {
ini_set('zlib.output_compression', 'Off');
}
$infohash = mysqli_real_escape_string($GLOBALS['conn'], $_GET['id']);
$filepath = $TORRENTSDIR.'/'.$infohash.'.btf';
if (!is_file($filepath) || !is_readable($filepath)) {
require load_language('lang_main.php');
die($language['CANT_FIND_TORRENT']);
}
$f = rawurlencode(html_entity_decode($_GET['f']));
// pid code begin
$row = get_result("SELECT pid FROM {$TABLE_PREFIX}users WHERE id=".$CURUSER['uid'], true, $btit_settings['cache_duration']);
$pid = $row[0]['pid'];
if (!$pid) {
$pid = md5(uniqid(rand(), true));
do_sqlquery("UPDATE {$TABLE_PREFIX}users SET pid='".$pid."' WHERE id='".$CURUSER['uid']."'");
if ($XBTT_USE) {
do_sqlquery("UPDATE xbt_users SET torrent_pass='".$pid."' WHERE uid='".$CURUSER['uid']."'");
}
}
$result = get_result("SELECT * FROM {$TABLE_PREFIX}files WHERE info_hash='".$infohash."'", true, $btit_settings['cache_duration']);
$row = $result[0];
if ($row['external'] == 'yes' || !$PRIVATE_ANNOUNCE) {
$fd = fopen($filepath, 'rb');
$alltorrent = fread($fd, filesize($filepath));
fclose($fd);
header('Content-Type: application/x-bittorrent');
header('Content-Disposition: attachment; filename="'.$f.'"');
echo $alltorrent;
} else {
$fd = fopen($filepath, 'rb');
$alltorrent = fread($fd, filesize($filepath));
$array = BDecode($alltorrent);
fclose($fd);
if ($XBTT_USE) {
$array['announce'] = $XBTT_URL."/$pid/announce";
} else {
$array['announce'] = $BASEURL."/announce.php?pid=$pid";
}
if (isset($array['announce-list']) && is_array($array['announce-list'])) {
for ($i = 0; $i < count($array['announce-list']); $i++) {
for ($j = 0; $j < count($array['announce-list'][$i]); $j++) {
if (in_array($array['announce-list'][$i][$j], $TRACKER_ANNOUNCEURLS)) {
if (strpos($array['announce-list'][$i][$j], 'announce.php') === false) {
$array['announce-list'][$i][$j] = trim(str_replace('/announce', "/$pid/announce", $array['announce-list'][$i][$j]));
} else {
$array['announce-list'][$i][$j] = trim(str_replace('/announce.php', "/announce.php?pid=$pid", $array['announce-list'][$i][$j]));
}
}
}
}
}
$alltorrent = BEncode($array);
header('Content-Type: application/x-bittorrent');
header('Content-Disposition: attachment; filename="'.$f.'"');
echo $alltorrent;
}
?>