mapid/fifo-webui/command.php

91 lines
1.6 KiB
PHP
Raw Normal View History

2023-10-15 18:41:15 +02:00
<?php
2023-11-09 12:43:54 +01:00
require_once("vendor/autoload.php");
2023-10-15 18:41:15 +02:00
2023-11-09 12:43:54 +01:00
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . "/..");
$dotenv->load();
2023-10-26 15:31:58 +02:00
2023-11-09 12:43:54 +01:00
//define("FIFO", "/tmp/mapid");
define("FIFO", $_ENV['FIFO']);
2023-10-26 15:31:58 +02:00
2023-11-09 12:43:54 +01:00
if (!file_exists(FIFO)) {
$ErrorDoc = <<<EOT
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<h3 style="color:red;">Error: FIFO file %FIFO% does not exist!</h3>
<p>
Is <tt>fifo_bridge.py</tt> running?
</p>
<p>
<a href="./">
<button>
Return
</button>
</a>
</p>
</body>
</html>
EOT;
$ErrorDoc = str_replace("%FIFO%", FIFO, $ErrorDoc);
die($ErrorDoc);
}
2023-10-26 15:31:58 +02:00
$f = fopen(FIFO, "w+");
2023-10-15 18:41:15 +02:00
2023-11-09 12:43:54 +01:00
if (count($_POST) == 0) {
/**
* Support httpie like this:
* http --print=HBhb POST mcp.local:8080/~malte70/mapid-fifo-webui/command.php cmd=cls
*/
2023-11-08 19:58:13 +01:00
$_POST = json_decode(file_get_contents('php://input'), true);
2023-11-09 12:43:54 +01:00
}
2023-11-08 19:58:13 +01:00
switch (@$_POST["cmd"]) {
2023-10-15 18:41:15 +02:00
case "getty":
fwrite($f, "GETTY");
break;
case "cls":
fwrite($f, "CLS");
break;
case "on":
fwrite($f, "ON");
break;
case "off":
fwrite($f, "OFF");
break;
case "lcdon":
fwrite($f, "LCDON");
break;
case "lcdoff":
fwrite($f, "LCDOFF");
break;
2023-10-15 18:41:15 +02:00
case "line":
fwrite($f, "LINE ");
fwrite($f, $_POST["line"]);
break;
case "echo":
fwrite($f, "ECHO ");
fwrite($f, $_POST["text"]);
break;
2023-11-08 19:58:13 +01:00
case "echo2":
fwrite($f, "CLS\n");
fwrite($f, "LINE 1\n");
fwrite($f, "ECHO ");
2023-11-09 12:43:54 +01:00
fwrite($f, substr($_POST["line1"], 0, 16));
2023-11-08 19:58:13 +01:00
fwrite($f, "\n");
fwrite($f, "LINE 2\n");
fwrite($f, "ECHO ");
2023-11-09 12:43:54 +01:00
fwrite($f, substr($_POST["line2"], 0, 16));
2023-11-08 19:58:13 +01:00
break;
2023-10-15 18:41:15 +02:00
}
fwrite($f, "\n");
fclose($f);
//header("Refresh: 5; url=./");
header("Location: ./");