|
|
@@ -13,41 +13,40 @@ if (!isset($_REQUEST['authkey']) || !isset($_REQUEST['torrent_pass'])) {
|
|
13
|
13
|
$UserInfo = $Cache->get_value('user_'.$_REQUEST['torrent_pass']);
|
|
14
|
14
|
if (!is_array($UserInfo)) {
|
|
15
|
15
|
$DB->query("
|
|
16
|
|
- SELECT ID, la.UserID
|
|
17
|
|
- FROM users_main AS m
|
|
|
16
|
+ SELECT ID, la.UserID
|
|
|
17
|
+ FROM users_main AS m
|
|
18
|
18
|
INNER JOIN users_info AS i ON i.UserID = m.ID
|
|
19
|
19
|
LEFT JOIN locked_accounts AS la ON la.UserID = m.ID
|
|
20
|
|
- WHERE m.torrent_pass = '".db_string($_REQUEST['torrent_pass'])."'
|
|
21
|
|
- AND m.Enabled = '1'");
|
|
|
20
|
+ WHERE m.torrent_pass = '".db_string($_REQUEST['torrent_pass'])."'
|
|
|
21
|
+ AND m.Enabled = '1'");
|
|
22
|
22
|
$UserInfo = $DB->next_record();
|
|
23
|
23
|
$Cache->cache_value('user_'.$_REQUEST['torrent_pass'], $UserInfo, 3600);
|
|
24
|
24
|
}
|
|
25
|
|
-
|
|
26
|
25
|
$UserInfo = array($UserInfo);
|
|
27
|
26
|
list($UserID, $Locked) = array_shift($UserInfo);
|
|
28
|
27
|
if (!$UserID) {
|
|
29
|
28
|
error(0);
|
|
30
|
29
|
}
|
|
31
|
|
-
|
|
32
|
30
|
$TorrentPass = $_REQUEST['torrent_pass'];
|
|
33
|
31
|
$AuthKey = $_REQUEST['authkey'];
|
|
34
|
32
|
|
|
35
|
|
- if ($Locked === $UserID) {
|
|
|
33
|
+ if ($Locked == $UserID) {
|
|
36
|
34
|
header('HTTP/1.1 403 Forbidden');
|
|
37
|
35
|
die();
|
|
38
|
36
|
}
|
|
39
|
37
|
}
|
|
40
|
38
|
|
|
41
|
39
|
$TorrentID = $_REQUEST['id'];
|
|
|
40
|
+
|
|
42
|
41
|
if (!is_number($TorrentID)) {
|
|
43
|
42
|
error(0);
|
|
44
|
43
|
}
|
|
45
|
44
|
|
|
46
|
45
|
/*
|
|
47
|
|
- * uTorrent Remote and various scripts redownload .torrent files periodically.
|
|
48
|
|
- * To prevent this retardation from blowing bandwidth etc., let's block it
|
|
49
|
|
- * if the .torrent file has been downloaded four times before
|
|
50
|
|
-*/
|
|
|
46
|
+ uTorrent Remote and various scripts redownload .torrent files periodically.
|
|
|
47
|
+ To prevent this retardation from blowing bandwidth etc., let's block it
|
|
|
48
|
+ if the .torrent file has been downloaded four times before
|
|
|
49
|
+ */
|
|
51
|
50
|
$ScriptUAs = array('BTWebClient*', 'Python-urllib*', 'python-requests*');
|
|
52
|
51
|
if (Misc::in_array_partial($_SERVER['HTTP_USER_AGENT'], $ScriptUAs)) {
|
|
53
|
52
|
$DB->query("
|
|
|
@@ -56,7 +55,6 @@ if (Misc::in_array_partial($_SERVER['HTTP_USER_AGENT'], $ScriptUAs)) {
|
|
56
|
55
|
WHERE UserID = $UserID
|
|
57
|
56
|
AND TorrentID = $TorrentID
|
|
58
|
57
|
LIMIT 4");
|
|
59
|
|
-
|
|
60
|
58
|
if ($DB->record_count() === 4) {
|
|
61
|
59
|
error('You have already downloaded this torrent file four times. If you need to download it again, please do so from your browser.', true);
|
|
62
|
60
|
die();
|
|
|
@@ -75,36 +73,29 @@ if (!is_array($Info) || !array_key_exists('PlainArtists', $Info) || empty($Info[
|
|
75
|
73
|
COALESCE(NULLIF(tg.Name,''), NULLIF(tg.NameRJ,''), tg.NameJP) AS Name,
|
|
76
|
74
|
tg.WikiImage,
|
|
77
|
75
|
tg.CategoryID,
|
|
78
|
|
- tm.Resource,
|
|
79
|
76
|
t.Size,
|
|
80
|
77
|
t.FreeTorrent,
|
|
81
|
78
|
HEX(t.info_hash)
|
|
82
|
79
|
FROM torrents AS t
|
|
83
|
80
|
INNER JOIN torrents_group AS tg ON tg.ID = t.GroupID
|
|
84
|
|
- LEFT JOIN torrents_mirrors AS tm ON tm.ID = t.GroupID
|
|
85
|
81
|
WHERE t.ID = '".db_string($TorrentID)."'");
|
|
86
|
|
-
|
|
87
|
82
|
if (!$DB->has_results()) {
|
|
88
|
83
|
error(404);
|
|
89
|
84
|
}
|
|
90
|
|
-
|
|
91
|
85
|
$Info = array($DB->next_record(MYSQLI_NUM, array(4, 5, 6, 10)));
|
|
92
|
86
|
$Artists = Artists::get_artist($Info[0][4], false);
|
|
93
|
87
|
$Info['Artists'] = Artists::display_artists($Artists, false, true);
|
|
94
|
88
|
$Info['PlainArtists'] = Artists::display_artists($Artists, false, true, false);
|
|
95
|
89
|
$Cache->cache_value("torrent_download_$TorrentID", $Info, 0);
|
|
96
|
90
|
}
|
|
97
|
|
-
|
|
98
|
91
|
if (!is_array($Info[0])) {
|
|
99
|
92
|
error(404);
|
|
100
|
93
|
}
|
|
101
|
|
-
|
|
102
|
|
-list($Media, $Format, $Encoding, $Year, $GroupID, $Name, $Image, $CategoryID, $Resources, $Size, $FreeTorrent, $InfoHash) = array_shift($Info); // Used for generating the filename
|
|
|
94
|
+list($Media, $Format, $Encoding, $Year, $GroupID, $Name, $Image, $CategoryID, $Size, $FreeTorrent, $InfoHash) = array_shift($Info); // used for generating the filename
|
|
103
|
95
|
$Artists = $Info['Artists'];
|
|
104
|
96
|
|
|
105
|
97
|
// If he's trying use a token on this, we need to make sure he has one,
|
|
106
|
98
|
// deduct it, add this to the FLs table, and update his cache key.
|
|
107
|
|
-// todo: Make sure strict equality works
|
|
108
|
99
|
if ($_REQUEST['usetoken'] && $FreeTorrent == '0') {
|
|
109
|
100
|
if (isset($LoggedUser)) {
|
|
110
|
101
|
$FLTokens = $LoggedUser['FLTokens'];
|
|
|
@@ -135,16 +126,16 @@ if ($_REQUEST['usetoken'] && $FreeTorrent == '0') {
|
|
135
|
126
|
|
|
136
|
127
|
if (!Torrents::has_token($TorrentID)) {
|
|
137
|
128
|
$DB->query("
|
|
138
|
|
- INSERT INTO users_freeleeches (UserID, TorrentID, Time)
|
|
139
|
|
- VALUES ($UserID, $TorrentID, NOW())
|
|
140
|
|
- ON DUPLICATE KEY UPDATE
|
|
141
|
|
- Time = VALUES(Time),
|
|
142
|
|
- Expired = FALSE,
|
|
143
|
|
- Uses = Uses + 1");
|
|
|
129
|
+ INSERT INTO users_freeleeches (UserID, TorrentID, Time)
|
|
|
130
|
+ VALUES ($UserID, $TorrentID, NOW())
|
|
|
131
|
+ ON DUPLICATE KEY UPDATE
|
|
|
132
|
+ Time = VALUES(Time),
|
|
|
133
|
+ Expired = FALSE,
|
|
|
134
|
+ Uses = Uses + 1");
|
|
144
|
135
|
$DB->query("
|
|
145
|
|
- UPDATE users_main
|
|
146
|
|
- SET FLTokens = FLTokens - 1
|
|
147
|
|
- WHERE ID = $UserID");
|
|
|
136
|
+ UPDATE users_main
|
|
|
137
|
+ SET FLTokens = FLTokens - 1
|
|
|
138
|
+ WHERE ID = $UserID");
|
|
148
|
139
|
|
|
149
|
140
|
// Fix for downloadthemall messing with the cached token count
|
|
150
|
141
|
$UInfo = Users::user_heavy_info($UserID);
|
|
|
@@ -159,7 +150,7 @@ if ($_REQUEST['usetoken'] && $FreeTorrent == '0') {
|
|
159
|
150
|
}
|
|
160
|
151
|
}
|
|
161
|
152
|
|
|
162
|
|
-// Stupid Recent Snatches on User Page
|
|
|
153
|
+// Stupid Recent Snatches On User Page
|
|
163
|
154
|
if ($Image != '') {
|
|
164
|
155
|
$RecentSnatches = $Cache->get_value("recent_snatches_$UserID");
|
|
165
|
156
|
if (!empty($RecentSnatches)) {
|
|
|
@@ -191,16 +182,15 @@ $FileName = TorrentsDL::construct_file_name($Info['PlainArtists'], $Name, $Year,
|
|
191
|
182
|
header('Content-Type: application/x-bittorrent; charset=utf-8');
|
|
192
|
183
|
header('Content-disposition: attachment; filename="'.$FileName.'"');
|
|
193
|
184
|
|
|
194
|
|
-function add_passkey($Ann)
|
|
|
185
|
+function add_passkey($ann)
|
|
195
|
186
|
{
|
|
196
|
187
|
global $TorrentPass;
|
|
197
|
|
- return (is_array($Ann)) ? array_map('add_passkey', $Ann) : $Ann.'/'.$TorrentPass.'/announce';
|
|
|
188
|
+ return (is_array($ann)) ? array_map("add_passkey", $ann) : $ann."/".$TorrentPass."/announce";
|
|
198
|
189
|
}
|
|
199
|
|
-
|
|
200
|
|
-$UserAnnounceURL = ANNOUNCE_URLS[0][0].'/'.$TorrentPass.'/announce';
|
|
|
190
|
+$UserAnnounceURL = ANNOUNCE_URLS[0][0]."/".$TorrentPass."/announce";
|
|
201
|
191
|
$UserAnnounceList = (sizeof(ANNOUNCE_URLS) === 1 && sizeof(ANNOUNCE_URLS[0]) === 1) ? [] : array(array_map('add_passkey', ANNOUNCE_URLS[0]), ANNOUNCE_URLS[1]);
|
|
202
|
|
-#$UserAnnounceList = (sizeof(ANNOUNCE_URLS) === 1 && sizeof(ANNOUNCE_URLS[0]) === 1) ? [] : array_map('add_passkey', ANNOUNCE_URLS);
|
|
|
192
|
+#$UserAnnounceList = (sizeof(ANNOUNCE_URLS) == 1 && sizeof(ANNOUNCE_URLS[0]) == 1) ? [] : array_map("add_passkey", ANNOUNCE_URLS);
|
|
203
|
193
|
|
|
204
|
|
-echo TorrentsDL::get_file($Contents, $UserAnnounceURL, $UserAnnounceList, $Resources);
|
|
|
194
|
+echo TorrentsDL::get_file($Contents, $UserAnnounceURL, $UserAnnounceList);
|
|
205
|
195
|
|
|
206
|
196
|
define('SKIP_NO_CACHE_HEADERS', 1);
|