t-eye v1.0.5
T-Eye Server
T-Eye (Terminal Eye) Server allows you to execute predefined commands (shell scripts) at remote server via websocket. Output is streamed to client and you can display real time terminal output in the browser.
Client can execute only predefined commands. You can define multiple commands and multiple arguments for each command.
Install
npm install -g t-eyeUsage
Start t-eye server:
t-eye --config path/to/config/file.json [--debug] [--port 1234]Command line arguments:
--configpath to config file where commands are defined.--debugor-drun terminal-eye in debug mode. Navigating browser here will show page where you can manually send commands and see output.--port=1234or-p 1234specify port. Default is 1234.
Debug mode
If you pass --debug switch, then you can navigate your browser to t-eye's address:port and you'll get minimal UI for testing your configuration file.
Configuration file
Example config.json
{
"list_dir": {
"script": "/root/list.sh",
"args": [
{
"name": "my_arg",
"type": "string",
"required": true,
"regex": "^(.+)/([^/]+)$"
}
]
}
}In this example:
list_diris command name (alias).scriptis path to script to be executed.argsis array of arguments expected for this command. Argument must havename.- For each argument, you can specify
type,requiredandregex(not mandatory). - Argument
typeis one of the types returned bytypeOf()
Example request from client:
{
"command": "list_dir",
"args": {
"my_arg": "/tmp/"
}
}Command will execute /root/list.sh /tmp/
Client side
In short: you need to open websocket conection, send command (JSON string) and listen for output.
Example HTML:
<!doctype html>
<html>
<body>
<textarea id="message" style="width: 100%; height: 200px;">{
"command": "",
"args": {
}
}
</textarea>
<br />
<button type="button" onclick="sendMessage()">Send</button>
<br />
<div id="console" style="background: black; color: lime; font-family: Courier New, Courier, monospace; height: 500px; overflow: auto;"></div>
<script>
var ws = new WebSocket('ws://localhost:1234', 'echo-protocol');
function sendMessage() {
var message = document.getElementById('message').value;
ws.send(message);
}
ws.addEventListener("message", function(e) {
var msg = JSON.parse(e.data);
var consoleDiv = document.getElementById('console');
var color = "inherit";
if(msg.status == "error") color = "red";
consoleDiv.innerHTML += '<br /><span style="color: ' + color + ';">' + msg.msg + '</span>';
consoleDiv.scrollTop = consoleDiv.scrollHeight;
});
</script>
</body>
</html>Full config file format
In the root of the config object you can add special key named terminal_eye with additional settings:
{
"terminal_eye": {
"port": 1234,
"ssl": false,
"ssl_key": "/path/to/privkey.pem",
"ssl_cert": "/path/to/fullchain.pem",
"default_force_uid": 0,
"default_force_gid": 0
},
...
}portinteger, default1234. Override default port. Note: port given via command line--portswitch have precedence over this one.sslbool, defaultfalse. If t-eye is exposed directly to host port (not behind reverse proxy e.g. nginx) then you still can run it via SSL.ssl_keyifssl: truethis is full path to file containing private key issued by SSL CA (for example:/etc/letsencrypt/live/example.com/privkey.pem).ssl_certifssl: truethis is full path to file containing SSL certificate (for example:/etc/letsencrypt/live/example.com/fullchain.pem).default_force_uidtry running commands as specified user id.default_force_gidtry running commands as specified group id.
That's it. Enjoy! :)