- changed webserver to apiserver
- added webserver - a lot of debugging - install shell script
This commit is contained in:
@ -1,413 +0,0 @@
|
||||
<?php
|
||||
require_once "events.php";
|
||||
|
||||
function webDashboard($socket, $n="Général")
|
||||
{
|
||||
global $dashboards, $indexDevices;
|
||||
require_once "webserver/javascript.php";
|
||||
logger(DEBUG, _("webDashboard function"));
|
||||
$response = insertJavascript();
|
||||
|
||||
if(array_key_exists($n, $dashboards))
|
||||
{
|
||||
foreach ($dashboards[$n] as $array)
|
||||
{
|
||||
if (array_key_exists($array[0], $indexDevices))
|
||||
{
|
||||
$device = $indexDevices[$array[0]];
|
||||
$property = $array[1];
|
||||
if (array_key_exists($array[1], $device->properties))
|
||||
{
|
||||
$propertyObject = $device->properties[$property];
|
||||
$value = $propertyObject["value"];
|
||||
logger(DEBUG, $device->friendlyName . " => " . bool2string(_($value)));
|
||||
$response .= $device->friendlyName . aliases($device->friendlyName, $property) . ' => ';
|
||||
if (array_key_exists("access", $propertyObject))
|
||||
{
|
||||
logger(DEBUG, _("Access = ") . $propertyObject["access"], __FILE__ . ":" . __LINE__);
|
||||
if(($propertyObject["access"] & 2))
|
||||
{
|
||||
logger(DEBUG, _("Write Access OK ") . ($propertyObject["access"] & 2), __FILE__ . ":" . __LINE__);
|
||||
$response .= " " . displayChoice($device, $property, $value);
|
||||
}
|
||||
if(($propertyObject["access"] & 4))
|
||||
{
|
||||
logger(DEBUG, _("can get value") . ($propertyObject["access"] & 4), __FILE__ . ":" . __LINE__);
|
||||
$response .= '<input type="button" id="' . $device->topic ."/" . $device->friendlyName . "/" . $propertyObject["name"] . '" value="' . _("Update") . "\" onmouseup=\"getPropertyValue('" . $device->topic . "','" . $device->friendlyName . "','" . $propertyObject["name"] . "')\">";
|
||||
}
|
||||
$response .= EOLH;
|
||||
}else
|
||||
{
|
||||
$response .= bool2string(_($value));
|
||||
if(array_key_exists("unit", $propertyObject))
|
||||
{
|
||||
$response .= $propertyObject["unit"];
|
||||
logger(DEBUG, _("unit = ") . $unit, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
$response .= EOLH;
|
||||
}
|
||||
|
||||
}else
|
||||
{
|
||||
logger(ERROR, _("Property does not exists"), __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
}else
|
||||
{
|
||||
logger(ERROR, _("Device does not exists"), __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
}
|
||||
}else
|
||||
{
|
||||
logger(ERROR, _("Dashboard does not exists"), __FILE__ . ":" . __LINE__);
|
||||
$response = _("dashboard not found");
|
||||
}
|
||||
htmlSend($socket, $response, '<meta http-equiv="refresh" content="10">');
|
||||
}
|
||||
|
||||
function displayChoice($device, $propertyName, $value)
|
||||
{
|
||||
logger(INFO, _("function displayChoice"), __FILE__ . ":" . __LINE__);
|
||||
$propertyObject = $device->properties[$propertyName];
|
||||
$unit = '';
|
||||
|
||||
if(array_key_exists("unit", $propertyObject))
|
||||
{
|
||||
$unit = $propertyObject["unit"];
|
||||
logger(DEBUG, _("unit = ") . $unit, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
if (!array_key_exists("type", $propertyObject)) return "";
|
||||
switch ($propertyObject["type"])
|
||||
{
|
||||
case "binary":
|
||||
logger(DEBUG, _("type is binary"), __FILE__ . ":" . __LINE__);
|
||||
$formHTML = bool2string($value);
|
||||
$choice["on"] = $propertyObject["value_on"];
|
||||
$choice["off"] = $propertyObject["value_off"];
|
||||
if (array_key_exists("toggle", $propertyObject))
|
||||
{
|
||||
$choice["toggle"] = $propertyObject["toggle"];
|
||||
}
|
||||
$formHTML .= mkHTML($device, $propertyName, $choice);
|
||||
break;
|
||||
case "numeric":
|
||||
logger(DEBUG, _("type is numeric") . "#" . $value . "#", __FILE__ . ":" . __LINE__);
|
||||
$step = '';
|
||||
if (array_key_exists("value_step", $propertyObject))
|
||||
{
|
||||
$step = ' step="' . $propertyObject["value_step"] . '"';
|
||||
}
|
||||
//$formHTML .= $device->friendlyName . aliases($device->friendlyName, $property) . ' => ';
|
||||
$formHTML = '<input type="number" id="' . $device->topic . "/"
|
||||
. $device->friendlyName . "/"
|
||||
. $propertyObject["name"] ."/value" . '"'
|
||||
. ' min="' . $propertyObject["value_min"] . '"'
|
||||
. ' max="' . $propertyObject["value_max"] . '"'
|
||||
. $step
|
||||
. ' value="' . $value . '">' . $unit . EOL;
|
||||
$formHTML .= '<input type="range" id="' . $device->topic . "/" . $device->friendlyName . "/" . $propertyObject["name"] . '"';
|
||||
$formHTML .= ' name="' . $propertyObject["name"] . '"';
|
||||
$formHTML .= ' min="' . $propertyObject["value_min"] . '"';
|
||||
$formHTML .= ' max="' . $propertyObject["value_max"] . '"';
|
||||
$formHTML .= ' value="' . $propertyObject["value"] . '"';
|
||||
$formHTML .= $step;
|
||||
$formHTML .= " oninput=\"setPropertyValue('" . $device->topic . "', '" . $device->friendlyName . "', this.value, '" . $propertyObject["name"] . "')\">";
|
||||
break;
|
||||
case "enum":
|
||||
logger(DEBUG, _("type is enum"), __FILE__ . ":" . __LINE__);
|
||||
$formHTML = bool2string($value);
|
||||
$choice = $propertyObject["values"];
|
||||
$formHTML .= mkHTML($device, $propertyName, $choice);
|
||||
break;
|
||||
default:
|
||||
logger(DEBUG, "type of property not recognized:" . $propertyObject["type"] , __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
return $formHTML;
|
||||
}
|
||||
|
||||
function mkHTML($device, $propertyName, $choice)
|
||||
{
|
||||
$html = "";
|
||||
logger(DEBUG, "function mkHTML", __FILE__ . ":" . __LINE__);
|
||||
foreach ($choice as $key => $value)
|
||||
{
|
||||
$html .= '<input type="button" id="' . $device->topic ."/" . $device->friendlyName . "/" . $propertyName . "/" . $key . '" value="' . $value . "\" onmouseup=\"setPropertyValue('" . $device->topic . "', '" . $device->friendlyName . "', '" . $value . "', '" . $propertyName . "')\">";
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
function webBrowse($socket, $argList, $page="/browse")
|
||||
{
|
||||
global $topics, $devices, $listenPort,$indexDevices;
|
||||
logger(DEBUG, _("Generic response to choose device and property"), __FILE__ . ":" . __LINE__);
|
||||
//$response = "<html><header></header><body>" . _("unknown command") . "</body></html>";
|
||||
$response = "";
|
||||
$flag = false;
|
||||
$tab = "";
|
||||
|
||||
if (array_key_exists("topic", $argList))
|
||||
{
|
||||
if (array_key_exists($argList["topic"], $topics))
|
||||
{
|
||||
logger(DEBUG, _("Topic exists: ") . $argList["topic"] , __FILE__ . ":" . __LINE__);
|
||||
$topicRef = '<a href="/browse&topic=' . htmlentities($argList["topic"]);
|
||||
if (array_key_exists("fn", $argList))
|
||||
{
|
||||
logger(DEBUG, _("FriendlyName exists: ") . $argList["fn"] , __FILE__ . ":" . __LINE__);
|
||||
$fn = "";
|
||||
$fnArray = explode("/", $argList["fn"]);
|
||||
$device = $devices[$argList["topic"]];
|
||||
|
||||
//var_dump($fnArray);
|
||||
foreach($fnArray as $value)
|
||||
{
|
||||
if ($flag) $fn .= "/";
|
||||
$fn .= $value;
|
||||
if (!array_key_exists($value, $device))
|
||||
{
|
||||
htmlSend($socket, sprintf(_('"%s" does not exists'), $value));
|
||||
return false;
|
||||
}
|
||||
$device = $device[$value];
|
||||
$flag = true;
|
||||
}
|
||||
//var_dump($device);
|
||||
if (array_key_exists("device", $device)) // TODO
|
||||
{
|
||||
$device = $device["device"];
|
||||
$fn .= "device/" . $fn;
|
||||
}
|
||||
|
||||
if (is_a($device, "device"))
|
||||
{
|
||||
require_once "webserver/javascript.php";
|
||||
$response .= insertJavascript();
|
||||
foreach($device->properties as $key => $value)
|
||||
{
|
||||
$response = displayProperty($device, $key, $value, $response);
|
||||
}
|
||||
/*foreach($device->properties as $key => $value)
|
||||
{
|
||||
$response = value($key, $value, $response);
|
||||
}*/
|
||||
}else
|
||||
{
|
||||
foreach($device as $key => $value)
|
||||
{
|
||||
$response .= $topicRef . htmlentities("&fn=" . $fn . "/" . $key) . '">' . $key . "</a><br>\n";
|
||||
}
|
||||
}
|
||||
//logger(DEBUG, _("response: ") . EOL . $response , __FILE__ . ":" . __LINE__);
|
||||
//htmlSend($socket, $response);
|
||||
}else
|
||||
{
|
||||
logger(DEBUG, _("no FriendlyName given"), __FILE__ . ":" . __LINE__);
|
||||
if (empty($devices[$argList["topic"]]))
|
||||
{
|
||||
$response .= _("No devices yet found");
|
||||
}else
|
||||
{
|
||||
foreach($devices[$argList["topic"]] as $key => $value)
|
||||
{
|
||||
//print "key = " . print_r($key, true) . " value = " . print_r($value, true) . EOL;
|
||||
logger(DEBUG, _("devices de topic: ") . $key , __FILE__ . ":" . __LINE__);
|
||||
$response .= $topicRef . htmlentities("&fn=" . $key) . '">' . $key . "</a><br>\n";
|
||||
logger(DEBUG, _("response: ") . $response , __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else
|
||||
{
|
||||
$response = webListTopics();
|
||||
}
|
||||
}else
|
||||
{
|
||||
$response = webListTopics();
|
||||
}
|
||||
htmlSend($socket, $response);
|
||||
}
|
||||
|
||||
function displayProperty($device, $key, $value, $response)
|
||||
{
|
||||
$tab="";
|
||||
$response .= $key . " ";
|
||||
if (array_key_exists("access", $value))
|
||||
{
|
||||
if(($value["access"] & 2))
|
||||
{
|
||||
logger(DEBUG, _("Write Access OK: ") . ($value["access"] & 2) . "value:" . $value["value"], __FILE__ . ":" . __LINE__);
|
||||
$response .= displayChoice($device, $key, $value["value"]);
|
||||
}
|
||||
if(($value["access"] & 4))
|
||||
{
|
||||
logger(DEBUG, _("can get value") . ($value["access"] & 4), __FILE__ . ":" . __LINE__);
|
||||
$response .= ' <input type="button" id="' . $device->topic ."/" . $device->friendlyName . "/" . $key . '" value="' . _("Update") . "\" onmouseup=\"getPropertyValue('" . $device->topic . "', '" . $device->friendlyName . "', '" . $key . "')\">";
|
||||
}
|
||||
}
|
||||
$response .= "<br>\n" . $tab . "[<br>\n";
|
||||
//echo memory_get_usage();
|
||||
//$response = value($key, $value, $response);
|
||||
iterateProperty($device, $key, $value, $response, $tab);
|
||||
$response .= $tab . "]<br>\n";
|
||||
return $response;
|
||||
}
|
||||
|
||||
function iterateProperty($device, $property, $value, &$response, $tab="")
|
||||
{
|
||||
$tab .= " ";
|
||||
if (is_array($value) or is_object($value))
|
||||
{
|
||||
logger(DEBUG, _("is array"), __FILE__ . ":" . __LINE__ );
|
||||
foreach($value as $key => $value2)
|
||||
{
|
||||
logger(DEBUG, $key, __FILE__ . ":" . __LINE__ );
|
||||
$response .= $tab . $key;
|
||||
if (is_array($value2) or is_object($value2))
|
||||
{
|
||||
$response .= "<br>\n";
|
||||
}else
|
||||
{
|
||||
$response .= " = ";
|
||||
}
|
||||
iterateProperty($device, $key, $value2, $response, $tab);
|
||||
}
|
||||
}else
|
||||
{
|
||||
$response .= bool2string($value) . "<br>\n";//. displayChoice($device, $property); //value($property, $value, "");
|
||||
}
|
||||
}
|
||||
|
||||
function webListTopics()
|
||||
{
|
||||
global $topics;
|
||||
logger(DEBUG, _("webListTopics function"));
|
||||
$response = "";
|
||||
foreach ($topics as $name => $topic)
|
||||
{
|
||||
$response .= '<a href="/browse&topic=' . $name . '">' . $name ."</a><br>\n";
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
function webGet($argList)
|
||||
{
|
||||
if(!array_key_exists("topic", $argList) or !array_key_exists("fn", $argList) or !array_key_exists("property", $argList))
|
||||
{
|
||||
$response = "GET: " . _("no parameters passed, need topic, fn and property");
|
||||
}else
|
||||
{
|
||||
if (($device = getDevice($argList["topic"], $argList["fn"])) === false)
|
||||
{
|
||||
$response = sprintf(_('"%s" or "%s" does not exists'), $argList["topic"], $argList["fn"]);
|
||||
}else
|
||||
{
|
||||
logger(DEBUG, _("Getting "), __FILE__ . ":" . __LINE__ );
|
||||
$property = $argList["property"];
|
||||
$response = "Sending GET command for: " . $argList["topic"] . $argList["fn"];
|
||||
$payload = array($argList["property"] => "");
|
||||
publish($argList["topic"] . "/" . $argList["fn"], $payload, "get");
|
||||
}
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
function webSet($argList)
|
||||
{
|
||||
global $indexFriendlyName;
|
||||
if(!array_key_exists("topic", $argList) or !array_key_exists("fn", $argList) or !array_key_exists("property", $argList) or !array_key_exists("value", $argList))
|
||||
{
|
||||
if (!array_key_exists($argList["topic"], $topics) )
|
||||
{
|
||||
$response = "SET: " . _("bad parameter passed: topic does not exists") . "<br>\n";
|
||||
}
|
||||
if (!array_key_exists(!array_key_exists($argList["fn"], $indexFriendlyName)))
|
||||
{
|
||||
$response = "SET: " . _("bad parameter passed: fn does not exists") . "<br>\n";
|
||||
}
|
||||
$response .= "SET: " . _("not all parameters passed, need topic, fn, property and value");
|
||||
}else
|
||||
{
|
||||
$response = "setting property " . $argList["property"] . " of " . $argList["fn"] . " to value: " . $argList["value"];
|
||||
$payload = array($argList["property"] => $argList["value"]);
|
||||
publish($argList["topic"] . "/" . $argList["fn"], $payload);
|
||||
//removeEvent($indexFriendlyName($argList["fn"]), $argList["property"], "OFF");
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
function webPrint($argList, $command)
|
||||
{
|
||||
global $GLOBALS, $topics;
|
||||
if (array_key_exists($argList["object"], $GLOBALS))
|
||||
{
|
||||
$var = $GLOBALS[$argList["object"]];
|
||||
|
||||
if (isset($argList["topic"]))
|
||||
{
|
||||
$topic = $argList["topic"];
|
||||
}
|
||||
if (isset($argList["address"]))
|
||||
{
|
||||
$var = $var[$argList["address"]];
|
||||
}elseif (isset($argList["fn"]))
|
||||
{
|
||||
if(!empty($topic))
|
||||
{
|
||||
$var = getDevice($topic, $argList["fn"]);
|
||||
}else
|
||||
{
|
||||
$str = _("topic is not defining: add &topic=\nThese topics are availables: ");
|
||||
foreach($topics as $key => $value)
|
||||
{
|
||||
$str .= $key . EOL;
|
||||
}
|
||||
logger(ERROR, $str, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
}
|
||||
$error = error_get_last();
|
||||
if($error !== null)
|
||||
{
|
||||
$response = $error["message"] . " file: " . $error["file"] . " line: " . $error["line"];
|
||||
}
|
||||
if ($command === "print")
|
||||
{
|
||||
$response = "<pre>" . nl2br(print_r($var, true)) . "<pre>";
|
||||
}elseif($command === "dump")
|
||||
{
|
||||
$response = "Dump" . EOL;
|
||||
$response .= "<pre>" . nl2br(var_export($var, true)) . "<pre>";
|
||||
}
|
||||
}else
|
||||
{
|
||||
$response = _("Object do not exists");
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
function webNotify($argList)
|
||||
{
|
||||
if (!array_key_exists("topic", $argList) or !array_key_exists("fn", $argList) or !array_key_exists("property", $argList) or !array_key_exists("condition", $argList) or !array_key_exists("value", $argList))
|
||||
{
|
||||
$response = _("Error: With 'notify' command, you need 5 parameters: topic, fn, property, condition, value");
|
||||
}else
|
||||
{
|
||||
$response = _("notify command have been set");
|
||||
$monitored[] = new watch($argList["topic"], $argList["fn"], $argList["property"], $argList["condition"], $argList["value"]);
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
/*
|
||||
function webDisplayByType($argList)
|
||||
{
|
||||
global $indexTypes, $config;
|
||||
require_once $config . "porpertiesbytype.php";
|
||||
require_once "webserver/javascript.php";
|
||||
|
||||
$response .= insertJavascript();
|
||||
foreach($indexTypes[$argList["type"]] as $device)
|
||||
{
|
||||
foreach($)
|
||||
displayProperty($device, $device->, $value, $response)
|
||||
}
|
||||
}
|
||||
*/
|
||||
?>
|
@ -8,21 +8,32 @@
|
||||
|
||||
function displayStats($socket, $argList)
|
||||
{
|
||||
global $indexFriendlyNames;
|
||||
global $indexFriendlyNames, $mohaDB;
|
||||
logger(INFO, "Function displayStats", __FILE__ . ":" . __LINE__);
|
||||
|
||||
// Validation of the dates
|
||||
if (validateDate($argList["startDate"]) && validateDate($argList["finalDate"]))
|
||||
{
|
||||
$query = "SELECT date, value FROM logs WHERE device='" . indexFriendlyNames[$argList->device] . "' AND property='" . $$argList["property"] . "' AND '" . $argList["startDate"] . ">= date AND '" . $argList["finalDate"] . "' <= date";
|
||||
if(!$this->result = $this->query($query))
|
||||
if (!array_key_exists($argList["fn"], $indexFriendlyNames))
|
||||
{
|
||||
logger(ERROR, _("mysql query errror: ") . $this->error, __FILE__ . ":" . __LINE__);
|
||||
htmlSend($socket, $argList["fn"] . _(" not found: Verify the syntax"));
|
||||
}elseif(!array_key_exists($argList["property"], $indexFriendlyNames[$argList["fn"]]->properties))
|
||||
{
|
||||
htmlSend($socket, $argList["property"] . _(" not found : Verify the syntax"));
|
||||
}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__);
|
||||
if(!($mohaDB->result = $mohaDB->query($query)))
|
||||
{
|
||||
logger(ERROR, _("mysql query error: ") . $mohaDB->error, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
$datas = $mohaDB->result->fetch_all(MYSQLI_ASSOC);
|
||||
htmlSend($socket, diagramDisplay($datas));
|
||||
}
|
||||
$datas = $this->result->fetch_all(MYSQLI_ASSOC);
|
||||
diagramDisplay($datas);
|
||||
}else
|
||||
{
|
||||
htmlSend($socket, _("Dates are not of the form: YYYY-MM-DD"));
|
||||
htmlSend($socket, _("Dates are not of the form: YYYY-MM-DD 00:00:00"));
|
||||
}
|
||||
|
||||
}
|
||||
@ -39,8 +50,11 @@ function diagramDisplay($datas)
|
||||
global $months;
|
||||
|
||||
$ndata = count($datas);
|
||||
$min = min($datas);
|
||||
$max = max($datas);
|
||||
$i = $ndata;
|
||||
$tmp = min($datas);
|
||||
$min = $tmp["value"];
|
||||
$tmp = max($datas);
|
||||
$max = $tmp["value"];
|
||||
//Type mime de l'image
|
||||
//Chemin vers le police à utiliser
|
||||
$font_file = '/usr/share/fonts/TTF/dejavu/DejaVuSans.ttf';
|
||||
@ -64,6 +78,7 @@ function diagramDisplay($datas)
|
||||
//Tracer l'axe des ordonnées
|
||||
imageline($courbe, 50, $hauteur - $absis, 50, 20, $noir);
|
||||
//Decaler 10px vers le haut le si le minimum est différent de 0
|
||||
$a = 0;
|
||||
if($min != 0)
|
||||
{
|
||||
$absis += 10;
|
||||
@ -94,14 +109,17 @@ function diagramDisplay($datas)
|
||||
$j = -1;
|
||||
$pasX = 90;
|
||||
//Parcourir le tableau pour le traçage de la diagramme
|
||||
foreach ($datas as $mois => $quantite)
|
||||
foreach ($datas as $row)
|
||||
{
|
||||
$date = $row["date"];
|
||||
$quantite = $row["value"];
|
||||
//calculer la hateur du point par rapport à sa valeur
|
||||
$y = ($hauteur) - (($quantite - $min) * ($echelleY / $py)) - $absis;
|
||||
//dessiner le point
|
||||
imagefilledellipse($courbe, $pasX, $y, 6, 6, $rouge);
|
||||
//Afficher le mois en français avec une inclinaison de 315°
|
||||
imagefttext($courbe, 10, 315, $pasX, $hauteur - $absis + 20, $noir, $font_file, $months[$mois-1]);
|
||||
printf("pasx = %d hauteur = %d absis = %d noir= %d", $pasX, $hauteur, $absis, $noir);
|
||||
imagefttext($courbe, 10, 315, $pasX, $hauteur - $absis + 20, $noir, $font_file, $date);
|
||||
//Tacer une ligne veticale de l'axe de l'abscisse vers le point
|
||||
imageline($courbe, $pasX, $hauteur - $absis + $a, $pasX, $y, $noir);
|
||||
if($j!==-1)
|
||||
@ -118,8 +136,12 @@ function diagramDisplay($datas)
|
||||
$pasX +=$echelleX;
|
||||
}
|
||||
//Envoyer le flux de l'image
|
||||
imagepng($courbe);
|
||||
//Desallouer le memoire utiliser par l'image
|
||||
|
||||
//header('Content-Type: image/png');
|
||||
$file = tempnam("php://temp", "moha-");
|
||||
imagepng($courbe,$file);
|
||||
return '<img src="/' . basename($file) . '">';
|
||||
//Desallouer la mémoire utiliser par l'image
|
||||
imagedestroy($courbe);
|
||||
}
|
||||
?>
|
||||
|
2
webserver/footer.php
Normal file
2
webserver/footer.php
Normal file
@ -0,0 +1,2 @@
|
||||
</body>
|
||||
</html>
|
7
webserver/header.php
Normal file
7
webserver/header.php
Normal file
@ -0,0 +1,7 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Moha</title>
|
||||
</head>
|
||||
<body>
|
10
webserver/index.php
Normal file
10
webserver/index.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
require_once "header.php";
|
||||
require_once "config.php";
|
||||
require_once "db_config.php";
|
||||
|
||||
print (_("This is the Statistics of Moha"));
|
||||
|
||||
|
||||
require_once "footer.php";
|
||||
?>
|
@ -1,30 +0,0 @@
|
||||
<?php
|
||||
function insertJavascript()
|
||||
{
|
||||
global $listenPort;
|
||||
return '<script language="javascript">
|
||||
<!--
|
||||
function setPropertyValue(topic, fn, value, property)
|
||||
{
|
||||
document.getElementById(topic+"/"+fn+"/"+property+"/value").value = value;
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "http://192.168.1.253:' . $listenPort . '/set&fn="+fn+"&property="+property+"&topic="+topic+"&value="+value);
|
||||
xhr.onload = function () {};
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
function getPropertyValue(topic, fn, property)
|
||||
{
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "http://192.168.1.253:' . $listenPort . '/get&fn="+fn+"&property="+property+"&topic="+topic );
|
||||
xhr.onload = function () {};
|
||||
xhr.send();
|
||||
setTimeout(function()
|
||||
{
|
||||
location.reload();
|
||||
}, 1000);
|
||||
}
|
||||
// -->
|
||||
</script>';
|
||||
}
|
||||
?>
|
@ -1,145 +0,0 @@
|
||||
<?php
|
||||
|
||||
// server init: No Timeout
|
||||
set_time_limit(0);
|
||||
ob_implicit_flush();
|
||||
|
||||
|
||||
$error_message = null;
|
||||
$error_code = null;
|
||||
$listenHost = "0.0.0.0";
|
||||
$listenPort = 1025;
|
||||
$Dashboards = array();
|
||||
for ($m=1; $m<=12; $m++)
|
||||
{
|
||||
$months[$m] = date('F', mktime(0,0,0,$m, 1));
|
||||
}
|
||||
|
||||
require_once $configDir . "/aliases.php";
|
||||
require_once $configDir . "/dashboard_conf.php";
|
||||
require_once "class/main.php";
|
||||
require_once "webserver/cmd_functions.php";
|
||||
//require_once "webserver/display_stats.php";
|
||||
|
||||
|
||||
// opening listening server
|
||||
$socket = stream_socket_server("tcp://" . $listenHost . ":" . $listenPort, $error_code, $error_message) or logger(ERROR, _("Could not create socket"), __FILE__ . ":" . __LINE__);
|
||||
stream_set_blocking($socket, false);
|
||||
$read = array( $socket );
|
||||
|
||||
function htmlSend($socket, $text, $meta="")
|
||||
{
|
||||
$httpHeader = "HTTP/1.1 200 OK" . EOLR .
|
||||
"Date: " . date("r") . EOLR .
|
||||
"Connection: close" . EOLR .
|
||||
"Content-Type: text/html; charset=UTF-8" . EOLR . EOLR;
|
||||
$response = $httpHeader
|
||||
. '<!doctype html>' . EOL
|
||||
. '<html lang="fr">' . EOL
|
||||
. '<head>' . EOL
|
||||
. $meta . EOL
|
||||
. '<meta charset="utf-8">' . EOL
|
||||
. '<title>Moha</title>' . EOL
|
||||
. '</head><body>' . EOL
|
||||
. $text . "</body></html>";
|
||||
stream_socket_sendto($socket, $response);
|
||||
}
|
||||
|
||||
function askWebServer($read)
|
||||
{
|
||||
global $topics, $indexDevices, $devices;
|
||||
$array = array();
|
||||
$argList =array();
|
||||
//logger(DEBUG, _("askWebserver function starting"), __FILE__ . ":" . __LINE__);
|
||||
if ( stream_select( $read, $array, $array, 0 ))
|
||||
{
|
||||
logger(DEBUG, _("socket ready to read"), __FILE__ . ":" . __LINE__);
|
||||
$spawn = stream_socket_accept($read[0]);
|
||||
if ($spawn !== false)
|
||||
{
|
||||
logger(DEBUG, _("socket accepted"), __FILE__ . ":" . __LINE__);
|
||||
$input = fgets($spawn, 4096);
|
||||
logger(DEBUG, $input, __FILE__ . ":" . __LINE__);
|
||||
$input = substr($input,5);
|
||||
$page = $input;
|
||||
$input = explode(" ", $input); // suppress text
|
||||
if (!empty($input[0]))
|
||||
{
|
||||
$argTmp = explode("&", urldecode($input[0]));
|
||||
foreach($argTmp as $tmp)
|
||||
{
|
||||
logger(DEBUG, $tmp, __FILE__ . ":" . __LINE__);
|
||||
if(strpos($tmp, "=") === false)
|
||||
{
|
||||
logger(DEBUG, _("no ="), __FILE__ . ":" . __LINE__);
|
||||
$argList["cmd"] = trim($tmp);
|
||||
}else
|
||||
{
|
||||
$key = trim(strchr($tmp, "=", true));
|
||||
$argList[$key] = trim(substr(strchr($tmp, "="), 1));
|
||||
if (count($argTmp) == 1) $argList["cmd"] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
logger(DEBUG, print_r($argList, true), __FILE__ . ":" . __LINE__);
|
||||
if(array_key_exists("cmd", $argList))
|
||||
{
|
||||
$command = strtolower($argList["cmd"]);
|
||||
logger(DEBUG, _("command is ") . $command, __FILE__ . ":" . __LINE__);
|
||||
switch($command)
|
||||
{
|
||||
case "dashboard":
|
||||
webDashboard($spawn, $argList["dashboard"]);
|
||||
break;
|
||||
case "browse":
|
||||
logger(DEBUG, _("Browsing"), __FILE__ . ":" . __LINE__);
|
||||
webBrowse($spawn, $argList);
|
||||
//return true;
|
||||
break;
|
||||
case "get":
|
||||
logger(DEBUG, _("GET reached"), __FILE__ . ":" . __LINE__);
|
||||
htmlSend($spawn, webGet($argList));
|
||||
break;
|
||||
case "set":
|
||||
logger(DEBUG, _("SET reached"), __FILE__ . ":" . __LINE__);
|
||||
htmlSend($spawn, webSet($argList));
|
||||
break;
|
||||
case "dump":
|
||||
case "print":
|
||||
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
|
||||
htmlSend($spawn, webPrint($argList, $command));
|
||||
break;
|
||||
case "notify":
|
||||
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
|
||||
htmlSend($spawn, webNotify($argList));
|
||||
logger(DEBUG, print_r($monitored, true), __FILE__ . ":" . __LINE__);
|
||||
break;
|
||||
case "type":
|
||||
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
|
||||
//htmlSend($spawn, webDisplayByType($argList));
|
||||
case "stat":
|
||||
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
|
||||
htmlSend($spawn, displayStats($argList));
|
||||
default:
|
||||
if (is_numeric(array_key_first($argList)))
|
||||
{
|
||||
webDashboard($spawn, $argList[0]);
|
||||
}
|
||||
}
|
||||
if (array_key_exists("page", $argList))
|
||||
{
|
||||
htmlSend($spawn, '<meta http-equiv="refresh" content="1; URL=' . $argList["page"] . '" />');
|
||||
return;
|
||||
}
|
||||
}else
|
||||
{
|
||||
webDashboard($spawn);
|
||||
}
|
||||
}else
|
||||
{
|
||||
webDashboard($spawn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user