modified device database and the code for managing it
This commit is contained in:
125
webserver.php
125
webserver.php
@@ -12,6 +12,7 @@ $listenPort = 1025;
|
||||
$Dashboards = array();
|
||||
|
||||
require_once $configDir . "/dashboard_conf.php";
|
||||
require_once "class/main.php";
|
||||
|
||||
// opening listening server
|
||||
$socket = stream_socket_server("tcp://" . $listenHost . ":" . $listenPort, $error_code, $error_message) or logger(ERROR, _("Could not create socket") . EOL);
|
||||
@@ -37,7 +38,7 @@ function webListTopics()
|
||||
$response = "";
|
||||
foreach ($topics as $name => $topic)
|
||||
{
|
||||
$response .= '<a href="/topic=' . $name . '">' . $name ."</a><br>";
|
||||
$response .= '<a href="/browse&topic=' . $name . '">' . $name ."</a><br>";
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
@@ -45,7 +46,6 @@ function webListTopics()
|
||||
function webBrowse($socket, $argList)
|
||||
{
|
||||
global $topics, $devices;
|
||||
$response = "";
|
||||
logger(DEBUG, _("Generic response to choose device and property"), __FILE__ . ":" . __LINE__);
|
||||
//$response = "<html><header></header><body>" . _("unknown command") . "</body></html>";
|
||||
$response = "";
|
||||
@@ -55,13 +55,14 @@ function webBrowse($socket, $argList)
|
||||
if (array_key_exists($argList["topic"], $topics))
|
||||
{
|
||||
logger(DEBUG, _("Topic exists") , __FILE__ . ":" . __LINE__);
|
||||
$topicRef = '<a href="topic=' . $argList["topic"];
|
||||
$topicRef = '<a href="browse&topic=' . $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 .= "/";
|
||||
@@ -74,21 +75,25 @@ function webBrowse($socket, $argList)
|
||||
$device = $device[$value];
|
||||
$flag = true;
|
||||
}
|
||||
if (array_key_exists("device", $device))
|
||||
var_dump($device);
|
||||
if (array_key_exists("device", $device)) // TODO
|
||||
{
|
||||
$device = $device["device"];
|
||||
$fn .= "device/" . $fn;
|
||||
}
|
||||
if (is_object($device))
|
||||
if (is_a($device, "device"))
|
||||
{
|
||||
foreach($device as $key => $value)
|
||||
{
|
||||
if ($key != "device" and is_array($value))
|
||||
if ($key != "devicarray_key_existse" and is_array($value))
|
||||
{
|
||||
print_r($value);
|
||||
//print_r($value);
|
||||
if (array_key_exists("value", $value))
|
||||
{
|
||||
$response .= $key . ' = ' . bool2string($value["value"]) . "<br>";
|
||||
}else
|
||||
{
|
||||
$response .= $key . ' = ' . bool2string($value) . "<br>";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -96,7 +101,7 @@ function webBrowse($socket, $argList)
|
||||
{
|
||||
foreach($device as $key => $value)
|
||||
{
|
||||
$response .= $topicRef . "&fn=" . $fn . "/" . $key . '">' . $key . "</a><br>";
|
||||
$response .= $topicRef . "&fn=" . $fn . "/" . $key . '">' . $key . "</a><br>";
|
||||
}
|
||||
}
|
||||
logger(DEBUG, _("response: ") . EOL . $response , __FILE__ . ":" . __LINE__);
|
||||
@@ -106,8 +111,9 @@ function webBrowse($socket, $argList)
|
||||
{
|
||||
foreach($devices[$argList["topic"]] as $key => $value)
|
||||
{
|
||||
print "key = " . print_r($key, true) . " value = " . print_r($value, true) . EOLR;
|
||||
logger(DEBUG, _("devices de topic: ") . $key , __FILE__ . ":" . __LINE__);
|
||||
$response .= $topicRef . "&fn=" . $key . '">' . $key . "</a><br>";
|
||||
$response .= $topicRef . "&fn=" . $key . '">' . $key . "</a><br>";
|
||||
logger(DEBUG, _("response: ") . $response , __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
}
|
||||
@@ -157,27 +163,26 @@ function askWebServer($read)
|
||||
logger(DEBUG, _("socket accepted"), __FILE__ . ":" . __LINE__);
|
||||
$input = fgets($spawn, 4096);
|
||||
logger(DEBUG, $input, __FILE__ . ":" . __LINE__);
|
||||
if (!empty($input))
|
||||
$input = substr($input,5);
|
||||
$input = explode(" ", $input); // suppress text
|
||||
if (!empty($input[0]))
|
||||
{
|
||||
$input = substr($input,5);
|
||||
$input = explode(" ", $input); // suppress text
|
||||
|
||||
$argTmp = explode("&", urldecode($input[0]));
|
||||
foreach($argTmp as $tmp)
|
||||
{
|
||||
logger(DEBUG, $tmp, __FILE__ . ":" . __LINE__);
|
||||
if(strpos($tmp, "=") === false)
|
||||
{
|
||||
logger(DEBUG, _("no ="));
|
||||
$argList[trim($tmp)] = "";
|
||||
logger(DEBUG, _("no ="), __FILE__ . ":" . __LINE__);
|
||||
$argList["cmd"] = trim($tmp);
|
||||
}else
|
||||
{
|
||||
$argList[trim(strchr($tmp, "=", true))] = trim(substr(strchr($tmp, "="), 1));
|
||||
}
|
||||
}
|
||||
logger(DEBUG, print_r($argList, true));
|
||||
logger(DEBUG, print_r($argList, true), __FILE__ . ":" . __LINE__);
|
||||
|
||||
if (array_key_exists("browse", $argList))
|
||||
/*if (array_key_exists("browse", $argList))
|
||||
{
|
||||
logger(DEBUG, _("Browsing"));
|
||||
webBrowse($spawn, $argList);
|
||||
@@ -186,13 +191,21 @@ function askWebServer($read)
|
||||
{
|
||||
webDashboard($spawn, $argList["dashboard"]);
|
||||
return true;
|
||||
}
|
||||
}*/
|
||||
if(array_key_exists("cmd", $argList))
|
||||
{
|
||||
$command = strtolower($argList["cmd"]);
|
||||
logger(DEBUG, _("command is ") . $command);
|
||||
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__);
|
||||
if(!array_key_exists("topic", $argList) or !array_key_exists("fn", $argList) or !array_key_exists("property", $argList))
|
||||
@@ -228,42 +241,50 @@ function askWebServer($read)
|
||||
case "dump":
|
||||
case "print":
|
||||
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
|
||||
$var = $GLOBALS[$argList["object"]];
|
||||
if (isset($argList["topic"]))
|
||||
if (array_key_exists($argList["object"], $GLOBALS))
|
||||
{
|
||||
$topic = $argList["topic"];
|
||||
}
|
||||
if (isset($argList["address"]))
|
||||
{
|
||||
$var = $var[$argList["address"]];
|
||||
}elseif (isset($argList["fn"]))
|
||||
{
|
||||
if(!empty($topic))
|
||||
$var = $GLOBALS[$argList["object"]];
|
||||
|
||||
if (isset($argList["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__);
|
||||
$topic = $argList["topic"];
|
||||
}
|
||||
}
|
||||
$error = error_get_last();
|
||||
if($error !== null)
|
||||
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 = $error["message"] . " file: " . $error["file"] . " line: " . $error["line"];
|
||||
}
|
||||
if ($command === "print")
|
||||
{
|
||||
$response = print_r($var, true);
|
||||
}elseif($command === "dump")
|
||||
{
|
||||
$response = "Dump" . EOL;
|
||||
$response .= var_export($var, true);
|
||||
$response = _("Object do not exists");
|
||||
}
|
||||
|
||||
htmlSend($spawn, $response);
|
||||
break;
|
||||
case "notify":
|
||||
@@ -278,14 +299,14 @@ function askWebServer($read)
|
||||
$monitored[] = new watch($argList["topic"], $argList["fn"], $argList["property"], $argList["condition"], $argList["value"]);
|
||||
htmlSend($spawn, $response);
|
||||
}
|
||||
logger(DEBUG, print_r($monitored, true));
|
||||
logger(DEBUG, print_r($monitored, true), __FILE__ . ":" . __LINE__);
|
||||
break;
|
||||
default:
|
||||
webBrowse($spawn, $argList);
|
||||
}
|
||||
}else
|
||||
{
|
||||
webBrowse($spawn,$argList);
|
||||
webDashboard($spawn);
|
||||
}
|
||||
}else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user