You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.3 KiB
89 lines
2.3 KiB
|
|
var fs = require('fs');
|
|
var https = require('https');
|
|
|
|
var express = require('express');
|
|
var app = express();
|
|
|
|
var options = {
|
|
key: fs.readFileSync('./llo/swarmlab.key'),
|
|
cert: fs.readFileSync('./llo/swarmlab.crt')
|
|
};
|
|
var serverPort = 3000;
|
|
|
|
var server = https.createServer(options, app);
|
|
var io = require('socket.io')(server);
|
|
|
|
const { spawn } = require('child_process')
|
|
|
|
io.on('connection', function(socket) {
|
|
console.log('new connection');
|
|
socket.on('start', () => {
|
|
//const childstart = spawn('/bin/sh ./swarmlab-sec/hybrid//start.sh');
|
|
const start = spawn('/bin/sh ./start.sh', {
|
|
stdio: 'pipe',
|
|
shell: true,
|
|
cwd: './swarmlab-sec/hybrid'
|
|
});
|
|
start.stdout.on('data', function (data) {
|
|
var n = {}
|
|
n.data = data.toString()
|
|
io.emit('message_out', n);
|
|
});
|
|
|
|
start.stderr.on('data', function (data) {
|
|
var n = {}
|
|
n.data = data.toString()
|
|
io.emit('message_err', n);
|
|
});
|
|
|
|
start.on('close', function (code) {
|
|
var n = {}
|
|
n.data = code.toString()
|
|
io.emit('message_close', n);
|
|
});
|
|
|
|
/*
|
|
// Async Iteration available since Node 10
|
|
childstart.on('data', (data) => {
|
|
var n = {}
|
|
n.data = data.toString()
|
|
io.emit('message', n);
|
|
console.log('stdout from the child: ' + data);
|
|
|
|
});
|
|
*/
|
|
console.log('hi from server');
|
|
});
|
|
|
|
socket.on('stop', () => {
|
|
const stop = spawn('/bin/sh ./stop.sh', {
|
|
stdio: 'pipe',
|
|
shell: true,
|
|
cwd: './swarmlab-sec/hybrid'
|
|
});
|
|
stop.stdout.on('data', function (data) {
|
|
var n = {}
|
|
n.data = data.toString()
|
|
io.emit('message_out', n);
|
|
});
|
|
|
|
stop.stderr.on('data', function (data) {
|
|
var n = {}
|
|
n.data = data.toString()
|
|
io.emit('message_err', n);
|
|
});
|
|
|
|
stop.on('close', function (code) {
|
|
var n = {}
|
|
n.data = code.toString()
|
|
io.emit('message_close', n);
|
|
});
|
|
stop.kill('SIGHUP');
|
|
});
|
|
|
|
});
|
|
|
|
server.listen(serverPort, function() {
|
|
console.log('server up and running at %s port', serverPort);
|
|
});
|
|
|