1
0

- debug\n- webserver fonctionnel

This commit is contained in:
2022-03-04 22:30:16 +01:00
parent a29aa9b653
commit 9d10e51a24
17 changed files with 273 additions and 128 deletions

View File

@@ -11,22 +11,23 @@ $listenHost = "0.0.0.0";
$listenPort = 1025;
$Dashboards = array();
require_once $configDir . "/aliases.php";
require_once $configDir . "/dashboard_conf.php";
require_once "class/main.php";
require "webserver/cmd_functions.php";
require_once "webserver/cmd_functions.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)
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 charset="utf-8">' . EOL . '<title>Moha</title>' . EOL . '</head><body>' . $text . "</body></html>";
$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);
}
@@ -47,6 +48,7 @@ function askWebServer($read)
$input = fgets($spawn, 4096);
logger(DEBUG, $input, __FILE__ . ":" . __LINE__);
$input = substr($input,5);
$page = $input;
$input = explode(" ", $input); // suppress text
if (!empty($input[0]))
{
@@ -64,6 +66,7 @@ function askWebServer($read)
}
}
logger(DEBUG, print_r($argList, true), __FILE__ . ":" . __LINE__);
if(array_key_exists("cmd", $argList))
{
$command = strtolower($argList["cmd"]);
@@ -71,11 +74,11 @@ function askWebServer($read)
switch($command)
{
case "dashboard":
webDashboard($spawn, $argList["dashboard"]);
webDashboard($spawn, $argList["dashboard"], $argList["page"]);
break;
case "browse":
logger(DEBUG, _("Browsing"), __FILE__ . ":" . __LINE__);
webBrowse($spawn, $argList);
webBrowse($spawn, $argList, $argList["page"]);
//return true;
break;
case "get":
@@ -97,7 +100,15 @@ function askWebServer($read)
logger(DEBUG, print_r($monitored, true), __FILE__ . ":" . __LINE__);
break;
default:
webBrowse($spawn, $argList);
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
{