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
83
84
85
86
87
88
89
90
|
<?php
class Master {
public $view;
public function __construct() {
$this->view = new View;
}
public function parse($f3, $params) {
$f3->set('_title', $f3->get('title'));
// set view if item exists
if (in_array($params['m'], $f3->get('item'))) {
if (!file_exists('views/' . $params['m'] . '.htm')) {
// if file does not exists, create a template
copy('views/template.htm', 'views/' . $params['m'] . '.htm');
}
$f3->set('_module', $params['m']);
} elseif ($params['m'] === 'login') {
$f3->set('_module', 'login');
} else {
$f3->set('_module', 'home');
}
echo $this->view->render('template/header.php');
echo $this->view->render('views/menu.php');
if (!empty($f3->get('message'))) {
echo $this->view->render('template/message.php');
}
// if we want to list the users:
if ($f3->get('_module') === 'users') {
$this->tabUsers($f3);
} else if($f3->get('_module') === 'home') {
$this->tabHome($f3);
} else if ($f3->get('_module') === 'satellites') {
$this->tabSatellite($f3);
}
echo Template::instance()->render('views/' . $f3->get('_module') . '.htm');
echo $this->view->render('template/footer.php');
}
public function dologin($f3, $username, $password) {
if (isset($f3->get('user')[$username]) && $f3->get('user')[$username] == sha1($password)) {
$_SESSION['username'] = $username;
$f3->set('loggedin', true);
$f3->set('username', $username);
$f3->reroute('@module(@m=home)');
} else {
$f3->set('message', 'Login invalid.');
$f3->reroute('@module(@m=home)');
}
}
public function dologout($f3) {
$_SESSION = array();
$f3->set('message', 'Logout successful');
$f3->set('loggedin', false);
$f3->set('username', 'Guest');
$this->parse($f3, array('m' => 'login'));
}
private function tabUsers($f3) {
$f3->set('result',$f3->get('DB')->exec('SELECT userid, username, organization, firstname, lastname, email, lastlogin FROM user'));
}
private function tabHome($f3) {
// one command is 'sh -c' and the other command is 'grep'
// so we need more than two commands to find the server
if (shell_exec('ps aux | grep "org.openslx.imagemaster.App" | wc -l') > 2) {
$f3->set('serverstatus', true);
} else {
$f3->set('serverstatus', false);
}
}
private function tabSatellite($f3) {
$f3->set('result', $f3->get('DB')->exec('SELECT organization, address, name, prefix, publickey FROM satellite'));
}
}
?>
|