' . EOL
. '' . EOL
. '
' . EOL
. $meta . EOL
. '' . EOL
. 'Moha' . EOL
. '' . EOL
. $text . "";
stream_socket_sendto($socket, $response);
}
function apiServer($read)
{
global $topics, $indexDevices, $devices;
logger(DEBUG, "Function apiServer", __FILE__ . ":" . __LINE__);
$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":
apiDashboard($spawn, $argList["dashboard"]);
break;
case "browse":
logger(DEBUG, _("Browsing"), __FILE__ . ":" . __LINE__);
apiBrowse($spawn, $argList);
//return true;
break;
case "get":
logger(DEBUG, _("GET reached"), __FILE__ . ":" . __LINE__);
htmlSend($spawn, apiGet($argList));
break;
case "set":
logger(DEBUG, _("SET reached"), __FILE__ . ":" . __LINE__);
htmlSend($spawn, apiSet($argList));
break;
case "dump":
case "print":
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
htmlSend($spawn, apiPrint($argList, $command));
break;
case "notify":
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
htmlSend($spawn, apiNotify($argList));
logger(DEBUG, print_r($monitored, true), __FILE__ . ":" . __LINE__);
break;
case "type":
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
//htmlSend($spawn, apiDisplayByType($argList));
case "enable":
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
htmlSend($spawn, apiHookActive($argList, true));
break;
case "disable":
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
htmlSend($spawn, apiHookActive($argList, false));
break;
case "verbose":
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
htmlSend($spawn, apiVerbose($argList));
break;
case "friendlyname":
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
htmlSend($spawn, getFn($argList));
break;
case "property":
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
htmlSend($spawn, PropertiesDashboard($argList));
break;
case "deleteDevice":
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
htmlSend($spawn, deleteDevice($argList));
break;
case "test":
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
htmlSend($spawn, test($argList));
break;
default:
if (is_numeric(array_key_first($argList)))
{
apiDashboard($spawn, $argList[0]);
}else
{
logger(DEBUG, $command . _(" so default action"), __FILE__ . ":" . __LINE__);
if (file_exists("php://temp/". $command))
{
logger(DEBUG, $command . _(" is a file"), __FILE__ . ":" . __LINE__);
htmlSend($spawn, file_get_contents("php://temp/". $command), 'Content-Type: image/png');
}
}
}
if (array_key_exists("page", $argList))
{
htmlSend($spawn, '');
return;
}
}else
{
apiDashboard($spawn);
}
}else
{
apiDashboard($spawn);
}
}
}
}
?>