From ec1e287bf129b3c4b91b565e0334009b72f6e928 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Thu, 19 Jan 2023 19:58:57 +0300 Subject: lws: add ipcam_server stats --- localwebsite/config.php | 2 ++ localwebsite/handlers/MiscHandler.php | 15 +++++++++++++++ localwebsite/htdocs/index.php | 1 + localwebsite/templates-web/index.twig | 1 + 4 files changed, 19 insertions(+) diff --git a/localwebsite/config.php b/localwebsite/config.php index b1e7553..b54856d 100644 --- a/localwebsite/config.php +++ b/localwebsite/config.php @@ -86,5 +86,7 @@ return [ 'grafana_sensors_url' => '', 'grafana_inverter_url' => '', + 'ipcam_server_api_addr' => '', + 'dhcp_hostname_overrides' => [], ]; diff --git a/localwebsite/handlers/MiscHandler.php b/localwebsite/handlers/MiscHandler.php index 2c2eb76..4eeb9fb 100644 --- a/localwebsite/handlers/MiscHandler.php +++ b/localwebsite/handlers/MiscHandler.php @@ -108,6 +108,21 @@ class MiscHandler extends RequestHandler $this->tpl->render_page('cams.twig'); } + public function GET_cams_stat() { + global $config; + list($ip, $port) = explode(':', $config['ipcam_server_api_addr']); + $body = jsonDecode(file_get_contents('http://'.$ip.':'.$port.'/api/timestamp/all')); + + header('Content-Type: text/plain'); + $date_fmt = 'd.m.Y H:i:s'; + + foreach ($body['response'] as $cam => $data) { + $fix = date($date_fmt, $data['fix']); + $motion = date($date_fmt, $data['motion']); + echo "$cam:\n motion: $motion\n\n"; + } + } + public function GET_debug() { print_r($_SERVER); } diff --git a/localwebsite/htdocs/index.php b/localwebsite/htdocs/index.php index e249fc6..d6034e6 100644 --- a/localwebsite/htdocs/index.php +++ b/localwebsite/htdocs/index.php @@ -29,6 +29,7 @@ $router->add('pump/', 'Misc pump_page'); $router->add('phpinfo/', 'Misc phpinfo'); $router->add('cams/', 'Misc cams'); $router->add('cams/([\d,]+)/', 'Misc cams id=$(1)'); +$router->add('cams/stat/', 'Misc cams_stat'); $router->add('debug/', 'Misc debug'); // auth diff --git a/localwebsite/templates-web/index.twig b/localwebsite/templates-web/index.twig index 19cc367..bbf6802 100644 --- a/localwebsite/templates-web/index.twig +++ b/localwebsite/templates-web/index.twig @@ -30,5 +30,6 @@ {% for id, name in cameras %}
  • {{ name }} (HQ)
  • {% endfor %} +
  • Статистика
  • \ No newline at end of file -- cgit v1.2.3