lws: add ipcam_server stats

This commit is contained in:
Evgeny Zinoviev 2023-01-19 19:58:57 +03:00
parent a58f4ef588
commit ec1e287bf1
4 changed files with 19 additions and 0 deletions

View File

@ -86,5 +86,7 @@ return [
'grafana_sensors_url' => '',
'grafana_inverter_url' => '',
'ipcam_server_api_addr' => '',
'dhcp_hostname_overrides' => [],
];

View File

@ -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);
}

View File

@ -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

View File

@ -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>