From 85389fcae58e76a0cef0d402f8a1da99a1cf7788 Mon Sep 17 00:00:00 2001 From: Felix Date: Wed, 27 Nov 2019 01:22:43 +0000 Subject: [PATCH] send command from the web --- src/routes/index.js | 20 +++++++++++++++- src/views/index.ejs | 4 ++-- src/views/starter.ejs | 55 ++++++++++++++++++++++++++++++++++--------- styles/starter.css | 7 +++++- 4 files changed, 71 insertions(+), 15 deletions(-) diff --git a/src/routes/index.js b/src/routes/index.js index d4f9b59..f65c4ef 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -225,7 +225,25 @@ router.get('/stopcontroller', (req, res) => { res.send(stdout); }); }); - +router.get('/sendcommand', (req, res) => { + var sys = require('sys') + var exec = require('child_process').exec; + var child; + request = JSON.parse(req.query.cmd); //recibiendo el comando + child = exec("cd /home/pi/scripts && echo \""+request+"\" > fifo", function(error, stdout, stderr) { + console.log("command received \n" + request+"\n"); + res.send(stdout); + }); +}); +router.get('/cancel', (req, res) => { + var sys = require('sys') + var exec = require('child_process').exec; + var child; + child = exec("sudo kill -2 $(ps aux | grep GRE| grep sudo|awk {'print $2'})", function(error, stdout, stderr) { + console.log("cancelled"); + res.send(stdout); + }); +}); router.get('/startvsorc', (req, res) => { var sys = require('sys') var exec = require('child_process').exec; diff --git a/src/views/index.ejs b/src/views/index.ejs index 4eeb92f..9999db8 100644 --- a/src/views/index.ejs +++ b/src/views/index.ejs @@ -58,7 +58,7 @@ } } xhr.send(); - }, 2000) + }, 1000) @@ -182,7 +182,7 @@ //clearInterval(intervalController); } - setInterval(showtemp,3000); + setInterval(showtemp,10000); diff --git a/src/views/starter.ejs b/src/views/starter.ejs index 01aca3a..50c1ec6 100644 --- a/src/views/starter.ejs +++ b/src/views/starter.ejs @@ -48,7 +48,13 @@ - +
+ +
+ + +
+
@@ -56,21 +62,20 @@
-
- -
+