1
0
mirror of https://github.com/PurpleI2P/regi2p.git synced 2025-01-15 18:09:57 +00:00
regi2p/views/api.php
r4sas 57b6299440
push recent updates
Signed-off-by: r4sas <r4sas@i2pmail.org>
2022-06-06 17:57:49 +00:00

31 lines
825 B
PHP

<?php
require_once __DIR__ . '/../config.php';
$all = false;
$pdo = (new App\DB($options))->pdo;
header('Content-Type: application/json');
if (isset($_GET["all"]))
$all = true;
if(!$command || !in_array($command, ['all', 'status']))
exit(json_encode(["status" => "error", "message" => "Incorrect request"]));
if($command == "all") {
$STH = $pdo->query ("SELECT `base32`, UNIX_TIMESTAMP(`last_seen`) as `last_seen` FROM `hosts` " .
"WHERE `approved` = 1 AND `disabled` = 0" .
($all ? " " : " AND `blacklisted` = 0 "));
$STH->setFetchMode(PDO::FETCH_ASSOC);
$rows = $STH->fetchAll();
$data = [];
foreach($rows as $row) {
$data[$row["base32"] . ".b32.i2p"] = $row["last_seen"];
}
exit(json_encode($data, JSON_PRETTY_PRINT));
}