Crates.io | webgate |
lib.rs | webgate |
version | 0.1.3 |
source | src |
created_at | 2021-12-26 19:02:22.177311 |
updated_at | 2022-01-08 13:45:38.564348 |
description | Tool to create web interfaces to command-line tools |
homepage | |
repository | https://github.com/NathanRoyer/webgate/ |
max_upload_size | |
id | 503399 |
size | 23,925 |
This command line utility allows you to:
The command's output is piped via websockets to the client as the command runs. You can write to the command's input pipe via the same socket at any time.
Here is an example config file:
{
"address": "127.0.0.1:9001",
"files": {
"index": ["static/index.html", "text/html"],
"favicon.png": ["static/favicon.png", "image/png"]
},
"directories": {
"dl": ["./dyn-service", "audio/flac"]
},
"not_found": "static/not_found.html",
"server": "basmati",
"commands": {
"pwd": ["pwd"],
"ls": ["ls", "-lha"],
"sh": ["sh"]
}
}
This would expose two files over HTTP on 127.0.0.1:9001, the "dyn-service" directory, as well as three commands.
Notes:
server
key is what will be used as HTTP "Server" Response Header.files
will be loaded from storage to RAM when webgate is launched.files
.const CLIENT_READY = String.fromCharCode(0);
const CLIENT_KILL = String.fromCharCode(1);
const CLIENT_PUSH = String.fromCharCode(2);
const R_TYPES = {
0: "fail", // the server could not start the subprocess
1: "exit", // the subprocess exited
2: "sout", // the process wrote new bytes to its standard output
3: "serr" // the process wrote new bytes to its standard error output
};
// Run the `/sh` command
let c = new WebSocket("ws://localhost:9001/sh");
c.onmessage = (e) => {
let type = e.data.charCodeAt(0);
let data = e.data.substring(1);
if (type > 1) { // stdout has new bytes
console.log(data); // print them to the console
} else {
console.log("--- end of subprocess ---");
}
}
c.send(CLIENT_READY);
// when you want to write something to to subprocess's stdin:
c.send(CLIENT_PUSH + "echo $USER\n");
// when you want to kill the subprocess
c.send(CLIENT_KILL);