37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
<?php
|
|
require_once __DIR__ . '/_v4/includes.php';
|
|
|
|
$minLevel = (int)filter_input(INPUT_GET, 'l', FILTER_SANITIZE_NUMBER_INT);
|
|
$includeComment = !empty($_GET['c']);
|
|
$json = !empty($_GET['j']);
|
|
|
|
header('Content-Type: ' . ($json ? 'application/json; charset=utf-8' : 'text/plain; charset=us-ascii'));
|
|
|
|
$keys = $pdo->prepare('SELECT *, UNIX_TIMESTAMP(`key_created`) AS `key_created` FROM `fm_public_keys` WHERE `key_deprecated` IS NULL AND `key_level` >= :level ORDER BY `key_level` DESC, `key_id`');
|
|
$keys->bindValue('level', $minLevel);
|
|
$keys->execute();
|
|
$keys = $keys->fetchAll(PDO::FETCH_OBJ);
|
|
|
|
if($json) {
|
|
$items = [];
|
|
|
|
foreach($keys as $key) {
|
|
$items[] = $item = new stdClass;
|
|
$item->algo = $key->key_algo;
|
|
$item->key = $key->key_body;
|
|
if($includeComment) {
|
|
$item->comment = $key->key_comment;
|
|
$item->created = date(DateTime::ATOM, $key->key_created);
|
|
$item->level = $key->key_level;
|
|
}
|
|
}
|
|
|
|
echo json_encode($items);
|
|
} else {
|
|
foreach($keys as $key) {
|
|
printf('ssh-%s %s', $key->key_algo, $key->key_body);
|
|
if($includeComment)
|
|
printf(' %s (%s)', $key->key_comment, date('M Y', $key->key_created));
|
|
echo "\n";
|
|
}
|
|
}
|