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
|
<?php
session_start();
$f3 = require('lib/base.php');
$f3->set('DEBUG', 3);
ini_set('display_errors', 1);
error_reporting(E_ALL);
$f3->set('AUTOLOAD', 'api/models/');
// set defaults
$f3->set('loggedin', (isset($f3->get('SESSION')['username']))?true:false);
$f3->set('username', (isset($f3->get('SESSION')['username']))?$f3->get('SESSION')['username']:'Guest');
$f3->set('message', '');
$f3->config('config/global.cfg');
require('config/mysql.php');
$f3->set('DB', new DB\SQL(
'mysql:host=localhost;port=3306;dbname='.$mysql_database,
$mysql_username,
$mysql_password
));
$f3->route('POST /do/@action',
function($f3, $params) {
$master = new Master;
if ($params['action'] === 'login') {
if (isset($_POST['user']) && isset($_POST['pass'])) {
$master->dologin($f3, $f3->get('POST')['user'], $f3->get('POST')['pass']);
}
} else if ($params['action'] === 'savesatellite') {
if(isset($_POST['organization']) && isset($_POST['address'])
&& isset($_POST['name']) && isset($_POST['prefix']) && isset($_POST['publickey'])) {
$master->saveSatellite($f3, $_POST['organization'], $_POST['address'], $_POST['name'], $_POST['prefix'], $_POST['publickey']);
}
} else if ($params['action'] === 'newsatellite') {
if(isset($_POST['organization']) && isset($_POST['address'])
&& isset($_POST['name']) && isset($_POST['prefix']) && isset($_POST['publickey'])) {
$master->newSatellite($f3, $_POST['organization'], $_POST['address'], $_POST['name'], $_POST['prefix'], $_POST['publickey']);
}
} else {
$f3->reroute('@module(@m=home)');
}
},
0,
512
);
// ^ sending files with a maximum rate of 64 KB/s --> slow responses to prevent attacks
$f3->route('GET @module: /site/@m',
function($f3, $params) {
$master = new Master;
if ($params['m'] === 'logout') {
$master->dologout($f3);
} else {
$master->parse($f3, $params);
}
}
);
$f3->route('GET /',
function($f3) {
$f3->reroute('@module(@m=home)');
}
);
/*
$f3->set('ONERROR',
function($f3) {
// recursively clear existing output buffers:
while (ob_get_level()) ob_end_clean();
echo $f3->get('ERROR.title');
}
);
*/
$f3->run();
?>
|