forked from eustasy/Phoenix
/
function.tracker.stats.php
80 lines (67 loc) · 2.34 KB
/
function.tracker.stats.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
<?php
function tracker_stats() {
global $connection, $settings;
require_once __DIR__.'/once.db.connect.php';
require_once __DIR__.'/function.mysqli.fetch.once.php';
// Statistics
$stats = mysqli_fetch_once(
// select seeders and leechers
'SELECT '.
'SUM(`state`=\'1\') AS `seeders`, '.
'SUM(`state`=\'0\') AS `leechers`, '.
// unique torrents
'COUNT(DISTINCT info_hash) AS `torrents` '.
// from peers
'FROM `'.$settings['db_prefix'].'peers`'
);
// Downloads
$downloads = mysqli_fetch_once(
'SELECT '.
'SUM(`downloads`) AS `downloads` '.
'FROM `'.$settings['db_prefix'].'torrents`'
);
if ( !$stats ) {
tracker_error('Unable to get stats.');
} else {
$phoenix_version = 'Phoenix Procedural 1.3 2015-02-16 20:44:00Z eustasy';
$stats['seeders'] = intval($stats['seeders']);
$stats['leechers'] = intval($stats['leechers']);
$stats['torrents'] = intval($stats['torrents']);
$stats['downloads'] = intval($downloads['downloads']);
$stats['peers'] = $stats['seeders']+$stats['leechers'];
// XML
if ( isset($_GET['xml']) ) {
header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'.
'<tracker version="$Id: '.$phoenix_version.' $">'.
'<peers>'.$stats['peers'].'</peers>'.
'<seeders>'.$stats['seeders'].'</seeders>'.
'<leechers>'.$stats['leechers'].'</leechers>'.
'<torrents>'.$stats['torrents'].'</torrents>'.
'<downloads>'.$stats['downloads'].'</downloads></tracker>';
// JSON
} else if ( isset($_GET['json']) ) {
header('Content-Type: application/json');
echo json_encode(
array(
'tracker' => array(
'version' => '$Id: '.$phoenix_version.' $,',
'peers' => $stats['peers'],
'seeders' => $stats['seeders'],
'leechers' => $stats['leechers'],
'torrents' => $stats['torrents'],
'downloads' => $stats['downloads'],
),
)
);
// HTML
} else {
echo '<!DocType html><html><head><meta charset="UTF-8">'.
'<title>Phoenix: $Id: '.$phoenix_version.' $</title>'.
'<body><pre>'.number_format($stats['peers']).
' peers ('.number_format($stats['seeders']).' seeders + '.number_format($stats['leechers']).
' leechers) in '.number_format($stats['torrents']).' torrents and'.
' '.number_format($stats['downloads']).' downloads completed.</pre></body></html>';
}
}
}