router.get("/topology", (req, res) => {
res.render("topology")
});
-
+let isVsorcUP = false;
+let isControllerUP = false;
router.get("/topologyMaker", (req, res) => {
res.render("topologyMaker")
});
});
});
+router.get('/rpiping', (req, res) => {
+ var sys = require('sys')
+ var exec = require('child_process').exec;
+ var child;
+ child = exec("cd /home/pi/scripts && ./rpiping.sh", function(error, stdout, stderr) {
+ console.log("rpiping");
+ res.send(stdout);
+ });
+});
+
router.get('/nodes', (req, res) => {
var sys = require('sys')
var exec = require('child_process').exec;
});
router.get('/getvsorcdata', (req, res) => {
+
var sys = require('sys')
var exec = require('child_process').exec;
var child;
- child = exec("cd /home/pi/scripts && cat aichivo 2>&1", function(error, stdout, stderr) {
+ var child2;
+ child2 = exec("ps aux | grep GRE| grep sudo | grep -v tail| awk {'print $2'}", function(error, stdout, stderr) {
+ console.log("view status vsorc");
+ if (stdout === ""){
+ isVsorcUP = false;
+ }else {
+ isVsorcUP = true;
+ }
+ });
+ child = exec("cd /home/pi/scripts && cat aichivo 2>/dev/null", function(error, stdout, stderr) {
console.log("getting vsorc data");
- res.send(stdout);
+ res.send(stdout+"^"+isVsorcUP);
});
+
});
router.get('/getcontrollerdata', (req, res) => {
var sys = require('sys')
var exec = require('child_process').exec;
var child;
- child = exec("cd /home/pi/scripts && cat controllerout 2>&1", function(error, stdout, stderr) {
+ child = exec("cd /home/pi/scripts && cat controllerout 2>/dev/null", function(error, stdout, stderr) {
console.log("getting controller data");
- res.send(stdout);
+ res.send(stdout+"^"+isControllerUP);
});
});
router.get('/listswitch', (req, res) => {
router.get('/startcontroller', (req, res) => {
+ isControllerUP = true;
var sys = require('sys')
var exec = require('child_process').exec;
var child;
});
router.get('/stopcontroller', (req, res) => {
+ isControllerUP = false;
var sys = require('sys')
var exec = require('child_process').exec;
var child;
});
});
router.get('/startvsorc', (req, res) => {
+
var sys = require('sys')
var exec = require('child_process').exec;
var child0;//needs a mkfifo named fifo to exist
var child1;
var child2;
var child3;
+ var child4;
var answer;
request = JSON.parse(req.query.topology)
console.log("Topology is : \n"+ request);
console.log(stdout + stderr);
answer+=stdout;
});
- child1 = exec("cd /home/pi/scripts && mkfifo fifo && touch aichivo", function(error, stdout, stderr) {
+ child1 = exec("cd /home/pi/scripts && mkfifo fifo && rm aichivo && touch aichivo", function(error, stdout, stderr) {
console.log(stdout + stderr);
answer+=stdout;
});
console.log(stdout + stderr);
answer+=stdout;
});
+
+
//child3 uses tail so it can read from fifo even after a EOF
child3 = exec("cd /home/pi/scripts && tail -n +1 -f fifo | sudo ./clusterGRE.py > aichivo 2>&1 &", function(error, stdout, stderr) {
console.log(stdout + stderr);
});
router.get('/stopvsorc', (req,res) =>{
+
var sys = require('sys')
var exec = require('child_process').exec;
var child1;
var child3;
var payload
console.log("erasing...");
- child1 = exec("cd /home/pi/scripts && exec 3>&- && rm fifo && rm aichivo", function(error, stdout, stderr) {
+ child1 = exec("cd /home/pi/scripts && exec 3>&- ", function(error, stdout, stderr) {
console.log(stdout);
payload+="rm done\n\n"+stdout;
});//esto cierra el fifo, lo cual cierra el programa
- //sudo kill $(ps aux | grep GRE| grep sudo|awk {'print $2'}) && cd /home/pi && ./multissh.sh sudo -E mn -c; sudo -E mn -c
- console.log("killing all...");
- child2 = exec("sudo kill $(ps aux | grep GRE| grep sudo|awk {'print $2'})", function(error, stdout, stderr) {
+ //antes, en ves de echo exit > fifo, estaba sudo kill $(ps aux | grep GRE| grep sudo|awk {'print $2'})
+ console.log("Exiting...");
+ child2 = exec("cd /home/pi/scripts && echo exit > fifo && rm fifo", function(error, stdout, stderr) {
console.log(stdout);
payload+="killed\n\n"+stdout;
});
- console.log("Multisshing and cleaning...");
- child3 = exec("cd /home/pi/scripts && ./multissh.sh sudo -E mn -c; sudo -E mn -c", function(error, stdout, stderr) {
- console.log(stdout);
- console.log("multisshed");
- payload+="Multisshed\n\n"+stdout;
-
- });
+ // console.log("Multisshing and cleaning...");
+ // child3 = exec("cd /home/pi/scripts && ./multissh.sh sudo -E mn -c; sudo -E mn -c", function(error, stdout, stderr) {
+ // console.log(stdout);
+ // console.log("multisshed");
+ // payload+="Multisshed\n\n"+stdout;
+ //
+ // });
res.send(payload);
});
module.exports = router;
</header>
<body>
-
<main>
<div class="side">
<div class="panel">
<textarea class="text" rows="20" cols="7" id="comandos" placeholder="Definicion de la red como: h1:s1"></textarea>
<div class="buttons">
- <button type="button" name="button" onclick="startvsorc()">Iniciar VSoRC</button>
- <button type="button" name="button" onclick="stopvsorc()">Detener VSoRC</button>
- <button type="button" name="button" onclick="startcontroller()">Iniciar controlador</button>
- <button type="button" name="button" onclick="stopcontroller()">Detener controlador</button>
+ <button id="btnstartvsorc" type="button" name="button" onclick="startvsorc()">Iniciar VSoRC</button>
+ <button id="btnstopvsorc" type="button" name="button" onclick="stopvsorc()">Detener VSoRC</button>
+ <button id="btnstartcontroller" type="button" name="button" onclick="startcontroller()">Iniciar controlador</button>
+ <button id="btnstopcontroller" type="button" name="button" onclick="stopcontroller()">Detener controlador</button>
</div>
</div>
<div class="panel">
<textarea class="text" style="font-size: 12px;" disabled rows="20" cols="7" id="controllerout" placeholder="Salida del controlador"></textarea>
</div>
+ <div class="panel">
+ <textarea class="text" style="font-size: 12px;" disabled rows="16" cols="7" id="raspberrys" placeholder="Raspberry Pi UP!"></textarea>
+ </div>
+
</div>
let comando = document.getElementById('vsorccommand'); //Donde va escrito el comando para la terminal
let vsorcout = document.getElementById('vsorcout'); //salida del vsorc
let controllerout = document.getElementById('controllerout'); //salida del controlador
+ let raspberry = document.getElementById('raspberrys'); //monitor de las rpi disponibles
let timeVsorc = 1000;
- let timeController = 2000;
- //Estos time son para especificar cada cuantos ms se pedira leer la data de los archivos aichivo y controllerout
+ let timeController = 1000;
+ let timeping = 5000;
+ //Estos time son para especificar cada cuantos ms se pedira leer la data de los archivos aichivo, controllerout y que raspberry estan activas
let intervalController = null;//Para tener el id del interval para obtener data del controller
let intervalVsorc = null; //Para tener el id del interval para obtener data del vsorc
intervalVsorc = setInterval(getvsorcdata, timeVsorc);
intervalController=setInterval(getcontrollerdata, timeController);
+ setInterval(rpiping,timeping);
+ function rpiping() {
+ let xhr = new XMLHttpRequest();
+ xhr.open('GET', '/rpiping', true);
+ xhr.onload = function() {
+ if (xhr.status == 200) { //can use this.status instead
+ //console.log(xhr.responseText);// para ver en la consola
+ raspberry.value=xhr.response;
+ console.log("getting controller data");
+ }
+ }
+ xhr.send();
+ }
function startcontroller() {
let xhr = new XMLHttpRequest();
xhr.open('GET', '/startcontroller', true);
xhr.onload = function() {
if (xhr.status == 200) { //can use this.status instead
//console.log(xhr.responseText);// para ver en la consola
- controllerout.value=xhr.response;
+ let controllerstat = xhr.response.split('^');
+ if(controllerstat[1] === "true"){
+ document.getElementById('btnstopcontroller').disabled = false;
+ document.getElementById('btnstartcontroller').disabled = true;
+ }else{
+ document.getElementById('btnstopcontroller').disabled = true;
+ document.getElementById('btnstartcontroller').disabled = false;
+ }
+ controllerout.value=controllerstat[0];
console.log("getting controller data");
}
}
xhr.onload = function() {
if (xhr.status == 200) { //can use this.status instead
//console.log(xhr.responseText);// para ver en la consola
- vsorcout.value=xhr.response;
+
+ //strip
+ //cambiar boton con vaina[1]
+ //vsorcout = vaina[0]
+ let vsorcstat = xhr.response.split('^');
+ if(vsorcstat[1] === "true"){
+ document.getElementById('btnstopvsorc').disabled = false;
+ document.getElementById('btnstartvsorc').disabled = true;
+ }else{
+ document.getElementById('btnstopvsorc').disabled = true;
+ document.getElementById('btnstartvsorc').disabled = false;
+ }
+
+ vsorcout.value=vsorcstat[0];
+
console.log("getting vsorc data");