* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with PHP Server Monitor. If not, see <http://www.gnu.org/licenses/>. * * @package phpservermon * @author Pepijn Over <*****@*****.**> * @copyright Copyright (c) 2008-2015 Pepijn Over <*****@*****.**> * @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3 * @version Release: @package_version@ * @link http://www.phpservermonitor.org/ **/ require __DIR__ . '/src/bootstrap.php'; psm_no_cache(); if (isset($_GET["logout"])) { $router->getService('user')->doLogout(); // logged out, redirect to login header('Location: ' . psm_build_url()); die; } $mod = psm_GET('mod', PSM_MODULE_DEFAULT); try { $router->run($mod); } catch (\InvalidArgumentException $e) { // invalid module, try the default one // it that somehow also doesnt exist, we have a bit of an issue // and we really have no reason catch it $router->run(PSM_MODULE_DEFAULT); }
/** * Create HTML code for the menu * @return string */ protected function createHTMLMenu() { $ulvl = $this->getUser()->getUserLevel(); $tpl_data = array('label_help' => psm_get_lang('menu', 'help'), 'label_profile' => psm_get_lang('users', 'profile'), 'label_logout' => psm_get_lang('login', 'logout'), 'url_profile' => psm_build_url(array('mod' => 'user_profile')), 'url_logout' => psm_build_url(array('logout' => 1))); switch ($ulvl) { case PSM_USER_ADMIN: $items = array('server_status', 'server', 'server_log', 'user', 'config', 'server_update'); break; case PSM_USER_USER: $items = array('server_status', 'server', 'server_log', 'server_update'); break; default: $items = array(); break; } $tpl_data['menu'] = array(); foreach ($items as $key) { $tpl_data['menu'][] = array('active' => $key == psm_GET('mod') ? 'active' : '', 'url' => psm_build_url(array('mod' => $key)), 'label' => psm_get_lang('menu', $key)); } if ($ulvl != PSM_USER_ANONYMOUS) { $user = $this->getUser()->getUser(); $tpl_data['label_usermenu'] = str_replace('%user_name%', $user->name, psm_get_lang('login', 'welcome_usermenu')); } return $this->twig->render('main/menu.tpl.html', $tpl_data); }
/** * Run. * * The $mod param is in the format $module_$controller. * If the "_$controller" part is omitted, it will attempt to load * the controller with the same name as the module. * If no mod is given it will attempt to load the default module. * @param string $mod if empty, the mod getvar will be used, or fallback to default * @throws \InvalidArgumentException * @throws \LogicException */ public function run($mod = null) { if (!psm_is_cli() && isset($_GET["logout"])) { $this->services['user']->doLogout(); // logged out, redirect to login header('Location: ' . psm_build_url()); die; } if ($mod === null) { $mod = psm_GET('mod', $this->default_module); } try { $controller = $this->getController($mod); } catch (\InvalidArgumentException $e) { // invalid module, try the default one // it that somehow also doesnt exist, we have a bit of an issue // and we really have no reason catch it $controller = $this->getController($this->default_module); } // get min required level for this controller and make sure the user matches $min_lvl = $controller->getMinUserLevelRequired(); $action = null; if ($min_lvl < PSM_USER_ANONYMOUS) { // if user is not logged in, load login module if (!$this->services['user']->isUserLoggedIn()) { $controller = $this->getController('user_login'); } elseif ($this->services['user']->getUserLevel() > $min_lvl) { $controller = $this->getController('error'); $action = '401'; } } $controller->setUser($this->services['user']); $response = $controller->initialize($action); if (!$response instanceof Response) { throw new \LogicException('Controller did not return a Response object.'); } $response->send(); }