get('/ssh.php', function() { $query = ''; $minLevel = (int)filter_input(INPUT_GET, 'l', FILTER_SANITIZE_NUMBER_INT); if($minLevel > 0) $query .= sprintf('l=%d&', $minLevel); if(!empty($_GET['c'])) $query .= 'c=1&'; if(!empty($_GET['j'])) $query .= 'j=1&'; if($query !== '') $query = '?' . substr($query, 0, -1); header('Location: /ssh_keys' . $query); return 302; }); $router->get('/ssh_keys', function() use ($db) { $minLevel = (int)filter_input(INPUT_GET, 'l', FILTER_SANITIZE_NUMBER_INT); $includeComment = !empty($_GET['c']); $json = !empty($_GET['j']); $keys = (new SSHKeys($db))->getKeys($minLevel); if($json) { $items = []; foreach($keys as $key) { $items[] = $item = new \stdClass; $item->algo = $key->getAlgorithm(); $item->key = $key->getBody(); if($includeComment) { $item->comment = (string)$key->getComment(); $item->created = $key->getCreatedAt()->format(\DateTime::ATOM); $item->level = $key->getLevel(); } } return $items; } header('Content-Type: text/plain; charset=us-ascii'); $body = ''; foreach($keys as $key) $body .= $key->toString($includeComment) . "\n"; return $body; }); $router->get('/authorized_keys', function() use ($db) { $keys = (new SSHKeys($db))->getKeys(500); header('Content-Type: text/plain; charset=us-ascii'); $body = ''; foreach($keys as $key) $body .= $key->toString(true) . "\n"; return $body; }); $router->get('/git_keys_ro', function() use ($db) { $keys = (new SSHKeys($db))->getKeys(100); header('Content-Type: text/plain; charset=us-ascii'); $body = ''; foreach($keys as $key) $body .= $key->toString(false) . "\n"; return $body; }); $router->get('/git_keys_rw', function() use ($db) { $keys = (new SSHKeys($db))->getKeys(200); header('Content-Type: text/plain; charset=us-ascii'); $body = ''; foreach($keys as $key) $body .= $key->toString(false) . "\n"; return $body; });