1
0
mirror of https://github.com/PurpleI2P/regi2p.git synced 2025-01-15 13:59:56 +00:00
regi2p/views/alive.php
r4sas e79d2bb28e
add autojump, update css, add host disabling
Signed-off-by: r4sas <r4sas@i2pmail.org>
2021-06-13 04:55:08 +00:00

42 lines
1.8 KiB
PHP

<?php
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../config.php';
/* Initialize Twig engine */
$loader = new \Twig\Loader\FilesystemLoader(__DIR__ . '/../templates');
$twig = new \Twig\Environment($loader, [
'cache' => __DIR__ . '/../cache',
'auto_reload' => true,
]);
$offset = $options["tableitems"] * ($page - 1);
$newregoffs = date ("Y-m-d H:i:s", strtotime ("-7 day"));
$newseenlim = date ("Y-m-d H:i:s", strtotime ("-3 day"));
$oldseenlim = date ("Y-m-d H:i:s", strtotime ("-7 day"));
$pdo = (new App\DB($options))->pdo;
/* Get records amount */
$STH = $pdo->query ("SELECT COUNT(*) as `count` FROM `hosts` " .
"WHERE `approved` = 1 AND `disabled` = 0 AND `hidden` = 0 AND (" .
" (`add_date` < '" . $newregoffs . "' AND `last_seen` > '" . $oldseenlim . "') OR" .
" (`add_date` > '" . $newregoffs . "' AND `last_seen` > '" . $newseenlim . "')" .
")");
$STH->setFetchMode (PDO::FETCH_ASSOC);
$records = $STH->fetch()["count"];
$pages = intdiv($records, $options["tableitems"]) + 1;
/* Get records with limit */
$STH = $pdo->query ("SELECT `host`, `base64`, `base32`, `last_seen` FROM `hosts` " .
"WHERE `approved` = 1 AND `disabled` = 0 AND `hidden` = 0 AND (" .
" (`add_date` < '" . $newregoffs . "' AND `last_seen` > '" . $oldseenlim . "') OR" .
" (`add_date` > '" . $newregoffs . "' AND `last_seen` > '" . $newseenlim . "')" .
") LIMIT " . $offset . ", " . $options["tableitems"]);
$STH->setFetchMode(PDO::FETCH_ASSOC);
$rows = $STH->fetchAll();
$template = $twig->load('alive.twig');
echo $template->render(['current' => $page, 'total' => $pages, 'hosts' => $rows]);