Initial vommit
This commit is contained in:
commit
8ff5e1a1fc
4 changed files with 85 additions and 0 deletions
8
README.md
Normal file
8
README.md
Normal file
|
@ -0,0 +1,8 @@
|
|||
ledcat webinterface
|
||||
===================
|
||||
|
||||
1. Stick your executables in `programs`.
|
||||
2. Point ledcat to `$FIFO`.
|
||||
3. Fire up PHP.
|
||||
4. ????
|
||||
5. PROFIT
|
65
index.php
Normal file
65
index.php
Normal file
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
$TMPDIR = "/tmp/ledcat-www";
|
||||
$PIDFILE = "$TMPDIR/program.pid";
|
||||
$FIFO = "$TMPDIR/fifo";
|
||||
$PROGDIR = "./programs";
|
||||
|
||||
|
||||
// Report all errors. Errors should never be ignored, it means that our
|
||||
// application is broken and we need to fix it.
|
||||
error_reporting(-1);
|
||||
|
||||
// Transform PHP's super weird error system to comprehensible exceptions.
|
||||
set_error_handler(function($errno, $errstr, $errfile, $errline) {
|
||||
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
|
||||
// Don't execute PHP internal error handler.
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
// Make our tmpdir.
|
||||
try {
|
||||
mkdir($TMPDIR, $mode=0777, $recursive=true);
|
||||
} catch (Exception $ex) { }
|
||||
// Build an index of the programs we can use.
|
||||
$programs = array_values(array_filter(scandir("./programs"), function($d) {
|
||||
return $d[0] != ".";
|
||||
}));
|
||||
|
||||
if (!file_exists($FIFO)) {
|
||||
posix_mkfifo($FIFO, 0777);
|
||||
}
|
||||
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$program = $_POST["program"] ?? $programs[0];
|
||||
|
||||
// Ok, let's add a bit of security and make sure that the program is known
|
||||
// in our program index.
|
||||
if (!in_array($program, $programs)) {
|
||||
die("no hax, pl0x");
|
||||
}
|
||||
|
||||
try {
|
||||
$pid = file_get_contents($PIDFILE);
|
||||
posix_kill($pid, SIGKILL);
|
||||
// Let ledcat timeout so it clears its input buffers.
|
||||
sleep(1);
|
||||
} catch (Exception $ex) { }
|
||||
|
||||
$pid = shell_exec("$PROGDIR/$program > $FIFO & echo $!");
|
||||
file_put_contents($PIDFILE, $pid);
|
||||
|
||||
echo "Started $program";
|
||||
}
|
||||
?>
|
||||
|
||||
<form method="post">
|
||||
<?php
|
||||
foreach ($programs as $program) {
|
||||
echo "<input type=\"radio\" name=\"program\" value=\"$program\">$program<br>\n";
|
||||
}
|
||||
?>
|
||||
<input type="submit" value="Ok" />
|
||||
</form>
|
6
programs/blue.py
Executable file
6
programs/blue.py
Executable file
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
|
||||
while True:
|
||||
sys.stdout.buffer.write(b"\x00\x00\xff")
|
6
programs/red.py
Executable file
6
programs/red.py
Executable file
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
|
||||
while True:
|
||||
sys.stdout.buffer.write(b"\xff\x00\x00")
|
Reference in a new issue