This repository has been archived by the owner on Oct 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
announce.php
78 lines (68 loc) · 2.72 KB
/
announce.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
<?php
/*
* Bitstorm 2 - A small and fast BitTorrent tracker
* Copyright 2011 Peter Caprioli
* Copyright 2015 Wilhelm Svenselius
*
* This program 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
require('includes/_config.php');
require(__INCLUDES.'_util.php');
require(__INCLUDES.'_data.php');
header("Content-Type: text/plain");
dbConnect();
dbSettings();
if (
$_set['download_only_user'] &&
(
!isset($_GET['usrid'])
|| !isset($_GET['dltkn'])
|| !isset($_GET['trid'])
|| !is_numeric($_GET['usrid'])
|| !$_sql->query("SELECT 1 FROM users WHERE id = $_GET[usrid]")->num_rows
|| $_GET['dltkn'] != tokenGenerator($_GET['usrid'].$_GET['trid'])
)
)
die('d14:failure reason29:Invalid usere');
$peerId = validateFixedLengthString('peer_id');
$port = validateConstrainedInt('port', 1, 65535);
$infoHash = validateFixedLengthString('info_hash');
$key = validateString('key', true);
$downloaded = validateInt('downloaded', true);
$uploaded = validateInt('uploaded', true);
$left = validateInt('left', true);
$numWant = validateInt('numwant', true);
$noPeerId = isset($_GET['no_peer_id']);
if($numWant <= 0 || $numWant > __MAX_PPR) {
$numWant = __MAX_PPR;
}
if(__WHITELIST_ENABLED && !isWhitelisted($infoHash)) {
actionReport('not_allowed_torrent');
die(trackError('Torrent not allowed on this tracker'));
}
$peerPk = dbUpdatePeer($peerId, $_SERVER['HTTP_USER_AGENT'], $_SERVER['REMOTE_ADDR'], $key, $port, $_GET['usrid']);
$torrentPk = dbUpdateTorrent($infoHash);
$peerTorrentPk = dbUpdatePeerTorrent($peerPk, $uploaded, $downloaded, $left, $infoHash);
if(isset($_GET['event']) && $_GET['event'] === 'stopped') {
actionReport('stopped');
dbStoppedPeer($peerTorrentPk);
// The RFC says its OK to return an empty string when stopping a torrent however some clients will whine about it so we return an empty dictionary
die(trackPeers(array(), 0, 0, $noPeerId));
}
actionReport('run');
$reply = dbGetPeers($torrentPk, $peerPk, $_SERVER['REMOTE_ADDR'], $numWant);
list($seeders, $leechers) = dbGetCounts($torrentPk);
$result = trackPeers($reply, $seeders, $leechers, $noPeerId);
mydebug($result);
die($result);