flash.moe/public/ssh.php

38 lines
1.2 KiB
PHP
Raw Normal View History

2021-07-07 01:13:50 +00:00
<?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'));
2022-02-04 04:25:57 +00:00
$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`');
2021-07-07 01:13:50 +00:00
$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";
}
}