| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- require_once '../vendor/autoload.php';
- require_once __DIR__ . '/../src/controllers/user.php';
- require_once __DIR__ . '/../src/controllers/ssh.php';
- function get_view($view_name) {
- try {
- $loader = new Twig\Loader\FilesystemLoader('../templates');
- $twig = new Twig\Environment($loader);
- $twig->addGlobal('session', $_SESSION);
-
- return $twig->load($view_name . '.html.twig');
- } catch (Exception $e) {
- die ('ERROR: ' . $e->getMessage());
- }
- }
- $dispatcher = FastRoute\simpleDispatcher(function(FastRoute\RouteCollector $r) {
- $r->addRoute('GET', '/', 'signin');
- $r->addRoute('POST', '/auth', 'auth');
- $r->addRoute('GET', '/home', 'home');
- $r->addRoute('GET', '/changepassword', 'form_password');
- $r->addRoute('POST', '/changepassword', 'change_password');
- $r->addRoute('GET', '/signout', 'signout');
- $r->addRoute('GET', '/ssh', 'form_ssh');
- $r->addRoute('GET', '/getsshkeys', 'get_ssh_keys');
- $r->addRoute('POST', '/addsshkey', 'add_ssh_key');
- $r->addRoute('POST', '/delsshkey', 'del_ssh_key');
- });
- // Fetch method and URI from somewhere
- $httpMethod = $_SERVER['REQUEST_METHOD'];
- $uri = $_SERVER['REQUEST_URI'];
- // Strip query string (?foo=bar) and decode URI
- if (false !== $pos = strpos($uri, '?')) {
- $uri = substr($uri, 0, $pos);
- }
- $uri = rawurldecode($uri);
- $routeInfo = $dispatcher->dispatch($httpMethod, $uri);
- switch ($routeInfo[0]) {
- case FastRoute\Dispatcher::NOT_FOUND:
- // ... 404 Not Found
- break;
- case FastRoute\Dispatcher::METHOD_NOT_ALLOWED:
- $allowedMethods = $routeInfo[1];
- // ... 405 Method Not Allowed
- break;
- case FastRoute\Dispatcher::FOUND:
- $handler = $routeInfo[1];
- $handler();
- break;
- }
|