diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2023-01-19 19:58:57 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2023-01-19 19:58:57 +0300 |
commit | ec1e287bf129b3c4b91b565e0334009b72f6e928 (patch) | |
tree | c34051d6268f16fc04f53a1f74b2cfe43e05fc76 | |
parent | a58f4ef5880f37c0e873a06a927d24cecb1efbe2 (diff) |
lws: add ipcam_server stats
-rw-r--r-- | localwebsite/config.php | 2 | ||||
-rw-r--r-- | localwebsite/handlers/MiscHandler.php | 15 | ||||
-rw-r--r-- | localwebsite/htdocs/index.php | 1 | ||||
-rw-r--r-- | localwebsite/templates-web/index.twig | 1 |
4 files changed, 19 insertions, 0 deletions
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 %} <li class="list-group-item"><a href="/cams/{{ id }}/">{{ name }}</a> (<a href="/cams/{{ id }}/?high=1">HQ</a>)</li> {% endfor %} + <li class="list-group-item"><a href="/cams/stat/">Статистика</a></li> </ul> </div>
\ No newline at end of file |