diff --git a/fifo-webui/command.php b/fifo-webui/command.php index 4dad2ee..0dd7741 100644 --- a/fifo-webui/command.php +++ b/fifo-webui/command.php @@ -1,16 +1,48 @@ load(); +//define("FIFO", "/tmp/mapid"); +define("FIFO", $_ENV['FIFO']); -if (!file_exists(FIFO)) - die("\n\n

Error: FIFO file “" . FIFO . "” does not exist!

Is fifo_bridge.py running?

"); +if (!file_exists(FIFO)) { + $ErrorDoc = << + + + + + +

Error: FIFO file “%FIFO%” does not exist!

+

+ Is fifo_bridge.py running? +

+

+ + + +

+ + +EOT; + $ErrorDoc = str_replace("%FIFO%", FIFO, $ErrorDoc); + die($ErrorDoc); +} $f = fopen(FIFO, "w+"); -if (count($_POST) == 0) +if (count($_POST) == 0) { + /** + * Support httpie like this: + * http --print=HBhb POST mcp.local:8080/~malte70/mapid-fifo-webui/command.php cmd=cls + */ $_POST = json_decode(file_get_contents('php://input'), true); +} switch (@$_POST["cmd"]) { case "getty": @@ -43,11 +75,11 @@ switch (@$_POST["cmd"]) { fwrite($f, "CLS\n"); fwrite($f, "LINE 1\n"); fwrite($f, "ECHO "); - fwrite($f, $_POST["line1"]); + fwrite($f, substr($_POST["line1"], 0, 16)); fwrite($f, "\n"); fwrite($f, "LINE 2\n"); fwrite($f, "ECHO "); - fwrite($f, $_POST["line2"]); + fwrite($f, substr($_POST["line2"], 0, 16)); break; } diff --git a/fifo-webui/composer.json b/fifo-webui/composer.json new file mode 100644 index 0000000..cfccd7d --- /dev/null +++ b/fifo-webui/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "vlucas/phpdotenv": "^5.5" + } +}