1
0
moha/webserver/index.php

93 lines
2.5 KiB
PHP
Raw Normal View History

<?php
require_once "header.php";
require_once "config.php";
2022-04-23 02:00:52 +02:00
require_once "utils.php";
require_once $mohaPath . "/constants.php";
require_once $mohaPath . "/class/db.php";
require_once $configPath . "properties2log.php";
2022-04-23 02:00:52 +02:00
function logger($level, $log, $pos = "")
{
global $logFh, $logLevel, $notificationLevel, $logLevels;
$logString = $logLevels[$level] . " " ;
if ($pos !== false)
{
$logString .= $pos;
}
$logString .= " - " . $log;
if ($level & $logLevel)
{
fwrite($logFh, date("c") . ' ' . $logString . EOL);
print ("MOHA-" . $logString . EOL);
}
}
function htmlGetFriendlyNames($ieeeAddress = '') : array
{
$url = "HTTP://localhost:1025/friendlyname";
$ch = curl_init($url);
if ($ieeeAddress !== '')
{
$url .= "&ieeeAddress=" . $ieeeAddress;
}
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$fn = curl_exec($ch);
curl_close($ch);
$start = strpos($fn, "{");
$end = strpos($fn, "}");
$length = $end - $start + 1;
$fn = substr($fn, $start, $length);
return jsonDecode($fn);
}
$indexIeeeAddress = htmlGetFriendlyNames();
//print_r($indexIeeeAddress);
print (_("This is the Statistics of Moha"));
2022-04-23 02:00:52 +02:00
if (empty($indexIeeeAddress))
{
$response = _("ERROR getting list of Friendly names: json error =>") . json_last_error_msg() .EOLH;
}else
{
$query = "SELECT DISTINCT device, property FROM logs";
$result = $mohaDB->query($query);
$devices = mysqli_fetch_all($result, MYSQLI_ASSOC);
$devicesList = array();
// print_r($devices);
print '<form method="GET" action="display_stats.php">';
//print '<input type="hidden" name="fn" value="">';
print '<label for="devicesSelectList">' . _("Choose a device:") . '</label>
<select name="device" id="devicesSelectList">' ;
foreach ($devices as $value)
{
if ( array_key_exists($value["device"], $indexIeeeAddress))
{
$devicesList[$value["device"]]["fn"] = $indexIeeeAddress[$value["device"]];
$devicesList[$value["device"]][] = $value["property"];
}
}
//$devicesList = array_intersect_key($indexIeeeAddress, $tmp);
//print_r($devicesList);
foreach($devicesList as $ieeeAddress => $array)
{
print '<optgroup label="' . $array["fn"] . '">';
foreach($array as $key => $property)
{
if ($key != "fn")
{
print '<option value="' . $ieeeAddress . '|' . $array["fn"] . '|' . $property . '">' . $property . '</option>' . EOL;
}
}
print '</optgroup>' . EOL;
}
print "</select>";
print '<input type="submit" value="Afficher les statistiques">';
print "</form>" . EOL;
}
require_once "footer.php";
?>