a lot of debug
This commit is contained in:
38
webserver/class/db.class.php
Normal file
38
webserver/class/db.class.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
//logger(DEBUG, _("Including db.php"));
|
||||
|
||||
class db extends mysqli
|
||||
{
|
||||
public $mysqlServer = "127.0.0.1"; // Your production server
|
||||
public $username = "moha";
|
||||
public $passwd = "MysqlMoha";
|
||||
public $database = "moha";
|
||||
public $result;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
global $testMode;
|
||||
$flagError = false;
|
||||
if ($testMode)
|
||||
{
|
||||
$this->mysqlServer = "192.168.1.253"; // Your test server
|
||||
}
|
||||
while ($this->connect($this->mysqlServer, $this->username, $this->passwd, $this->database) === false)
|
||||
{
|
||||
//logger(ERROR,_("Connection to sql server error :") . $this->connect_error, __FILE__ . ":" . __LINE__);
|
||||
sleep(5);
|
||||
$flagError = true;
|
||||
}
|
||||
if ($flagError === true)
|
||||
{
|
||||
//logger(ERROR, _("Connection to sql server ready"), __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
$result = new mysqli_result($this);
|
||||
}
|
||||
|
||||
function protect($string)
|
||||
{
|
||||
return $this->real_escape_string($string);
|
||||
}
|
||||
}
|
||||
?>
|
5
webserver/config.php
Normal file
5
webserver/config.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
$varPath = "/usr/share/moha/";
|
||||
$mohaPath = "/home/daniel/moha";
|
||||
$configPath = "/etc/moha/";
|
||||
?>
|
@ -2,14 +2,19 @@
|
||||
|
||||
/****************************************************************/
|
||||
/* */
|
||||
/*need device ieeeAddress, property, startDate and finalDate */
|
||||
/*need device ieeeAddress, property, startDate and endDate */
|
||||
/* */
|
||||
/****************************************************************/
|
||||
|
||||
function displayStats($socket, $argList)
|
||||
require_once "config.php";
|
||||
require_once "utils.php";
|
||||
require_once "header.php";
|
||||
|
||||
|
||||
function displayStats($ieeeAddress, $fn, $property, $startDate, $endDate)
|
||||
{
|
||||
global $indexFriendlyNames, $mohaDB;
|
||||
logger(INFO, "Function displayStats", __FILE__ . ":" . __LINE__);
|
||||
//logger(INFO, "Function displayStats", __FILE__ . ":" . __LINE__);
|
||||
|
||||
// Validation of the dates
|
||||
if (validateDate($argList["startDate"]) && validateDate($argList["finalDate"]))
|
||||
@ -23,10 +28,10 @@ function displayStats($socket, $argList)
|
||||
}else
|
||||
{
|
||||
$query = "SELECT date, value FROM logs WHERE device='" . $indexFriendlyNames[$argList["fn"]]->ieeeAddress . "' AND property='" . $argList["property"] . "' AND '" . $argList["startDate"] . "'>= date AND '" . $argList["finalDate"] . "' <= date ORDER BY date";
|
||||
logger(DEBUG, _("query : ") . $query, __FILE__ . ":" . __LINE__);
|
||||
//logger(DEBUG, _("query : ") . $query, __FILE__ . ":" . __LINE__);
|
||||
if(!($mohaDB->result = $mohaDB->query($query)))
|
||||
{
|
||||
logger(ERROR, _("mysql query error: ") . $mohaDB->error, __FILE__ . ":" . __LINE__);
|
||||
//logger(ERROR, _("mysql query error: ") . $mohaDB->error, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
$datas = $mohaDB->result->fetch_all(MYSQLI_ASSOC);
|
||||
htmlSend($socket, diagramDisplay($datas));
|
||||
@ -144,4 +149,9 @@ function diagramDisplay($datas)
|
||||
//Desallouer la mémoire utiliser par l'image
|
||||
imagedestroy($courbe);
|
||||
}
|
||||
|
||||
$tmp = explode("|", $_GET["device"]);
|
||||
|
||||
displayStats($tmp[0], $tmp[1], $tmp[2]);
|
||||
|
||||
?>
|
||||
|
@ -1,10 +1,92 @@
|
||||
<?php
|
||||
require_once "header.php";
|
||||
require_once "config.php";
|
||||
require_once "db_config.php";
|
||||
require_once "utils.php";
|
||||
require_once $mohaPath . "/constants.php";
|
||||
require_once $mohaPath . "/class/db.php";
|
||||
require_once $configPath . "properties2log.php";
|
||||
|
||||
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"));
|
||||
|
||||
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";
|
||||
?>
|
||||
|
16
webserver/utils.php
Normal file
16
webserver/utils.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
function jsonDecode($json)
|
||||
{
|
||||
$jsonArray = array();
|
||||
$json = trim($json, " {[]}");
|
||||
$tmp = explode(",", $json);
|
||||
foreach($tmp as $value)
|
||||
{
|
||||
$tmp2 = explode (":" , $value);
|
||||
$jsonArray[trim($tmp2[0], '"')] = trim($tmp2[1], '"');
|
||||
}
|
||||
return $jsonArray;
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user