-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathts3stats.php
More file actions
59 lines (45 loc) · 1.62 KB
/
Copy pathts3stats.php
File metadata and controls
59 lines (45 loc) · 1.62 KB
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
<?php
set_error_handler(function($severity, $message, $file, $line) {
throw new ErrorException($message, 0, $severity, $file, $line);
});
require('api/io.php');
require('api/log.php');
require('api/http.php');
require('api/ts3stats/command.php');
require('api/ts3stats/client.php');
require('api/ts3stats/handler.php');
$root = realpath(__DIR__);
$base = getenv('BASE');
$username = getenv('USERNAME');
$password = getenv('PASSWORD');
$client = new TS3\Client('127.0.0.1', 10011);
$session = new TS3\Session($client);
$session->use($username, $password, 1);
$rootLogger = Log\ConsoleLogger::for('RootLogger');
$httpLogger = Log\ConsoleLogger::for('HttpLogger');
$request = Http\newRequest();
$response = Http\newResponse();
$router = new Http\Router($base, $httpLogger);
$router->add('GET', '/', Http\serveRedirect("{$base}/index.html"));
$router->add('GET', '/api/ts3/info', new Http\Handler\ServerInfo($session));
$router->add('GET', '/api/ts3/clients', new Http\Handler\ListClients($session));
foreach(array(
'/index.html' => 'app/ts3stats/index.html',
'/app/dom.js' => 'app/dom.js',
'/app/presenter.js' => 'app/ts3stats/presenter.js',
'/app/client.js' => 'app/ts3stats/client.js',
'/app/views.js' => 'app/ts3stats/views.js',
'/app/styles.css' => 'app/ts3stats/styles.css',
) as $path => $file) {
$router->add('GET', $path, Http\serveFile("{$root}/{$file}"));
}
try {
if (!$router->apply($request, $response)) {
$response->setStatus(404);
}
} catch (Throwable $e) {
$rootLogger->error('uncaught {exception}', ['exception' => $e]);
$response->setStatus(500);
$response->setBodyAsText($e->getMessage());
}
?>