From 96e19464f98b868bd93b76ac842ec5b32a17cfb6 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sat, 26 May 2018 15:58:21 +0200 Subject: means to run remote commands and get output --- app/relay/index.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'app/relay/index.js') diff --git a/app/relay/index.js b/app/relay/index.js index d43f221..2f93644 100644 --- a/app/relay/index.js +++ b/app/relay/index.js @@ -9,10 +9,7 @@ let remote = io.connect(process.env.SOCKETIO_REMOTE) remote.on('cmd', (data) => { console.log('cmd data', data) - if (! data.cmd) { - console.log('malformed param...?') - return - } + if (! data.cmd) return console.log('malformed param...?') console.log('got', data.cmd) switch (data.cmd) { case 'set_param': @@ -43,6 +40,24 @@ remote.on('cmd', (data) => { } }) +remote.on('system', (data) => { + console.log('system:', data.cmd) + switch(data.cmd) { + case 'run_system_command': + runner.run_system_command(data.payload, (error, stdout, stderr) => { + remote.emit('system_res', { + type: 'command_output', + cmd: data.payload, + error, stdout, stderr + }) + }) + break + default: + remote.emit('system_res', { error: 'unknown system command' }) + break + } +}) + let rpc = new zerorpc.Client() rpc.connect('tcp://127.0.0.1:' + process.env.RPC_PORT) rpc.on('error', function(error) { -- cgit v1.2.3-70-g09d2