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')); } } ?>