|
@ -114,11 +114,7 @@ const { spawn, exec, execSync } = require('child_process') |
|
|
//const logerr = fs.openSync('./logs/out.log', 'a');
|
|
|
//const logerr = fs.openSync('./logs/out.log', 'a');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
const logerribuild = fs.openSync('./logs/build-out.log', 'a'); |
|
|
const logerribuild = fs.openSync('./logs/build-out.log', 'a'); |
|
|
} catch (error) { |
|
|
|
|
|
console.log('Error:', error); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1450,15 +1446,7 @@ app.get('/rungui', (req, res, next) => { |
|
|
//const builderr = fs.openSync(builderrdir, 'a');
|
|
|
//const builderr = fs.openSync(builderrdir, 'a');
|
|
|
try { |
|
|
try { |
|
|
const buildout = fs.openSync(buildoutdir, 'a'); |
|
|
const buildout = fs.openSync(buildoutdir, 'a'); |
|
|
} catch (error) { |
|
|
|
|
|
console.log('Error:', error); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
const builderr = fs.openSync(builderrdir, 'a'); |
|
|
const builderr = fs.openSync(builderrdir, 'a'); |
|
|
} catch (error) { |
|
|
|
|
|
console.log('Error:', error); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var buildimage = `echo "EXEC PID: $$"; ${showexec}` |
|
|
var buildimage = `echo "EXEC PID: $$"; ${showexec}` |
|
|
//var buildimage = `echo "EXEC PID: $$"; docker run -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix microservice-firefox /bin/sh -c "firefox"`
|
|
|
//var buildimage = `echo "EXEC PID: $$"; docker run -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix microservice-firefox /bin/sh -c "firefox"`
|
|
@ -1512,6 +1500,79 @@ try { |
|
|
}); |
|
|
}); |
|
|
console.log(run_buildimage.pid); |
|
|
console.log(run_buildimage.pid); |
|
|
run_buildimage.unref(); |
|
|
run_buildimage.unref(); |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
console.log('Error:', error); |
|
|
|
|
|
RES.error = true |
|
|
|
|
|
RES.error_msg = error |
|
|
|
|
|
RES.data = 'no' |
|
|
|
|
|
res.json(RES) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
app.get('/runbackup', (req, res, next) => { |
|
|
|
|
|
var RES = new Object(); |
|
|
|
|
|
var mypath = process.cwd() |
|
|
|
|
|
RES.instance = req.query["instance"] |
|
|
|
|
|
RES.error = false |
|
|
|
|
|
RES.error_msg = "ok" |
|
|
|
|
|
RES.error_msg0 = "" |
|
|
|
|
|
RES.data = "All_services_are_running"; |
|
|
|
|
|
var showexec = `./swarmlab_backup_service.sh ${RES.instance}` |
|
|
|
|
|
console.log('exec tar :', showexec); |
|
|
|
|
|
var runpath = `${mypath}` |
|
|
|
|
|
var runpathfile = `${mypath}/swarmlab_backup_service.sh` |
|
|
|
|
|
|
|
|
|
|
|
var buildoutdir = `${runpath}/logs/tar-backup-out.log` |
|
|
|
|
|
var builderrdir = `${runpath}/logs/tar-backup-out.log` |
|
|
|
|
|
try { |
|
|
|
|
|
const buildout = fs.openSync(buildoutdir, 'a'); |
|
|
|
|
|
const builderr = fs.openSync(builderrdir, 'a'); |
|
|
|
|
|
console.log('buildout :', buildout); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var buildimage = `echo "EXEC PID: $$"; ${showexec}` |
|
|
|
|
|
const run_buildimage = spawn(buildimage, { |
|
|
|
|
|
detached: true, |
|
|
|
|
|
shell: true, |
|
|
|
|
|
stdio: [ 'ignore', buildout, builderr ], |
|
|
|
|
|
cwd: runpath |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.pid = run_buildimage.pid |
|
|
|
|
|
io.emit('build_set_buildpid', n); |
|
|
|
|
|
|
|
|
|
|
|
n.data = 'start ...' |
|
|
|
|
|
io.emit('message_out', n); |
|
|
|
|
|
|
|
|
|
|
|
n.data = 'Your backup might take a long time, depending on the number of files to back up. ' |
|
|
|
|
|
io.emit('message_out', n); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
run_buildimage.on('exit', (data) => { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.data = 'exit!' |
|
|
|
|
|
io.emit('message_close', n); |
|
|
|
|
|
}); |
|
|
|
|
|
run_buildimage.on('close', (data) => { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.data = 'close!' |
|
|
|
|
|
io.emit('message_close', n); |
|
|
|
|
|
|
|
|
|
|
|
n.name = `${RES.instance}` |
|
|
|
|
|
n.dir = `${runpath}` |
|
|
|
|
|
io.emit('message_close_build', n); |
|
|
|
|
|
}); |
|
|
|
|
|
console.log(run_buildimage.pid); |
|
|
|
|
|
run_buildimage.unref(); |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
console.log('Error:', error); |
|
|
|
|
|
RES.error = true |
|
|
|
|
|
RES.error_msg = error |
|
|
|
|
|
RES.data = 'no' |
|
|
|
|
|
res.json(RES) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
@ -2056,11 +2117,7 @@ app.get('/create_config', (req, res, next) => { |
|
|
RES.value = req.query["value"] |
|
|
RES.value = req.query["value"] |
|
|
//console.log('value error '+JSON.stringify(RES.value))
|
|
|
//console.log('value error '+JSON.stringify(RES.value))
|
|
|
//var showexec = `cd ./hybrid; /bin/bash ./create-keys.sh`
|
|
|
//var showexec = `cd ./hybrid; /bin/bash ./create-keys.sh`
|
|
|
try { |
|
|
|
|
|
fs.writeFileSync('./hybrid/keys.json', JSON.stringify(RES.value)); |
|
|
fs.writeFileSync('./hybrid/keys.json', JSON.stringify(RES.value)); |
|
|
} catch (error) { |
|
|
|
|
|
console.log('Error:', error); |
|
|
|
|
|
} |
|
|
|
|
|
RES.value = JSON.parse(RES.value); |
|
|
RES.value = JSON.parse(RES.value); |
|
|
|
|
|
|
|
|
var INTERFACE_IP=RES.value.wg_ip |
|
|
var INTERFACE_IP=RES.value.wg_ip |
|
@ -2103,11 +2160,7 @@ var swarmlab_config_template = ` |
|
|
ip rule add table main suppress_prefixlength 0 |
|
|
ip rule add table main suppress_prefixlength 0 |
|
|
ip rule show | grep -w "suppress_prefixlength" |
|
|
ip rule show | grep -w "suppress_prefixlength" |
|
|
` |
|
|
` |
|
|
try { |
|
|
|
|
|
fs.writeFileSync('./hybrid/connect/swarmlab-connect.sh', swarmlab_config_template); |
|
|
fs.writeFileSync('./hybrid/connect/swarmlab-connect.sh', swarmlab_config_template); |
|
|
} catch (error) { |
|
|
|
|
|
console.log('Error:', error); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var allowed_ips=RES.value.allowed_ips |
|
|
var allowed_ips=RES.value.allowed_ips |
|
|
var swarmlab_public_wgkey=RES.value.swarmlab_public_wgkey |
|
|
var swarmlab_public_wgkey=RES.value.swarmlab_public_wgkey |
|
@ -2125,11 +2178,7 @@ var swarmlab_wg0_template = `[Interface] |
|
|
|
|
|
|
|
|
` |
|
|
` |
|
|
//fs.writeFileSync('./hybrid/connect/template-wg0.conf', swarmlab_wg0_template);
|
|
|
//fs.writeFileSync('./hybrid/connect/template-wg0.conf', swarmlab_wg0_template);
|
|
|
try { |
|
|
|
|
|
fs.writeFileSync('./hybrid/connect/wg0.conf', swarmlab_wg0_template); |
|
|
fs.writeFileSync('./hybrid/connect/wg0.conf', swarmlab_wg0_template); |
|
|
} catch (error) { |
|
|
|
|
|
console.log('Error:', error); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var swarmlab_swarm=RES.value.workerkey |
|
|
var swarmlab_swarm=RES.value.workerkey |
|
|
var swarmlab_swarm_ip=RES.value.swarm_ip |
|
|
var swarmlab_swarm_ip=RES.value.swarm_ip |
|
@ -2137,11 +2186,7 @@ var swarmlab_swarm_template = ` |
|
|
docker swarm join --token ${swarmlab_swarm} ${swarmlab_swarm_ip} |
|
|
docker swarm join --token ${swarmlab_swarm} ${swarmlab_swarm_ip} |
|
|
` |
|
|
` |
|
|
//fs.writeFileSync('./hybrid/connect/template-swarm.sh', swarmlab_swarm_template);
|
|
|
//fs.writeFileSync('./hybrid/connect/template-swarm.sh', swarmlab_swarm_template);
|
|
|
try { |
|
|
|
|
|
fs.writeFileSync('./hybrid/connect/reload-swarmlab.sh', swarmlab_swarm_template); |
|
|
fs.writeFileSync('./hybrid/connect/reload-swarmlab.sh', swarmlab_swarm_template); |
|
|
} catch (error) { |
|
|
|
|
|
console.log('Error:', error); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var swarmlab_swarm_join_template = ` |
|
|
var swarmlab_swarm_join_template = ` |
|
@ -2193,11 +2238,7 @@ fi |
|
|
/bin/bash ${mypath}/hybrid/connect/get-swarmlab-ca |
|
|
/bin/bash ${mypath}/hybrid/connect/get-swarmlab-ca |
|
|
/bin/bash ${mypath}/hybrid/connect/get-base-ca |
|
|
/bin/bash ${mypath}/hybrid/connect/get-base-ca |
|
|
` |
|
|
` |
|
|
try { |
|
|
|
|
|
fs.writeFileSync('./hybrid/connect/join.sh', swarmlab_swarm_join_template); |
|
|
fs.writeFileSync('./hybrid/connect/join.sh', swarmlab_swarm_join_template); |
|
|
} catch (error) { |
|
|
|
|
|
console.log('Error:', error); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var swarmlab_swarm_leave_template = ` |
|
|
var swarmlab_swarm_leave_template = ` |
|
|
function hybrid_ifup() { |
|
|
function hybrid_ifup() { |
|
@ -2224,11 +2265,7 @@ else |
|
|
fi |
|
|
fi |
|
|
` |
|
|
` |
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
fs.writeFileSync('./hybrid/connect/leave.sh', swarmlab_swarm_leave_template); |
|
|
fs.writeFileSync('./hybrid/connect/leave.sh', swarmlab_swarm_leave_template); |
|
|
} catch (error) { |
|
|
|
|
|
console.log('Error:', error); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
RES.error = false |
|
|
RES.error = false |
|
|
RES.error_msg = "ok" |
|
|
RES.error_msg = "ok" |
|
@ -2339,6 +2376,7 @@ io.on('connection', function(socket) { |
|
|
//console.log('start')
|
|
|
//console.log('start')
|
|
|
//console.log('value '+JSON.stringify(value))
|
|
|
//console.log('value '+JSON.stringify(value))
|
|
|
if(value.swarmlabname){ |
|
|
if(value.swarmlabname){ |
|
|
|
|
|
try { |
|
|
var service = value.swarmlabname |
|
|
var service = value.swarmlabname |
|
|
var services_path = './instance/'+service+'/'+service |
|
|
var services_path = './instance/'+service+'/'+service |
|
|
var ENV_service_file_path = services_path+'/.env' |
|
|
var ENV_service_file_path = services_path+'/.env' |
|
@ -2402,11 +2440,7 @@ TEST=${service} |
|
|
` |
|
|
` |
|
|
//console.log('value1 '+JSON.stringify(ENV_service_file_path))
|
|
|
//console.log('value1 '+JSON.stringify(ENV_service_file_path))
|
|
|
//console.log('value2 '+JSON.stringify(ENV_service_file))
|
|
|
//console.log('value2 '+JSON.stringify(ENV_service_file))
|
|
|
try { |
|
|
|
|
|
fs.writeFileSync(ENV_service_file_path, ENV_service_file ,{encoding:'utf8',flag:'w'}); |
|
|
fs.writeFileSync(ENV_service_file_path, ENV_service_file ,{encoding:'utf8',flag:'w'}); |
|
|
} catch (error) { |
|
|
|
|
|
console.log('Error:', error); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var service_up = '/bin/bash ../install/usr/share/swarmlab.io/sec/swarmlab-sec up size='+service_size |
|
|
var service_up = '/bin/bash ../install/usr/share/swarmlab.io/sec/swarmlab-sec up size='+service_size |
|
|
|
|
|
|
|
@ -2443,6 +2477,9 @@ try { |
|
|
io.emit('message_close', n); |
|
|
io.emit('message_close', n); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
console.log('Error:', error); |
|
|
|
|
|
} |
|
|
}else{ |
|
|
}else{ |
|
|
var n = {} |
|
|
var n = {} |
|
|
n.data = 'NoSwarmlabname' |
|
|
n.data = 'NoSwarmlabname' |
|
@ -2452,6 +2489,7 @@ try { |
|
|
|
|
|
|
|
|
socket.on('start_storage', (value) => { |
|
|
socket.on('start_storage', (value) => { |
|
|
if(value.swarmlabname){ |
|
|
if(value.swarmlabname){ |
|
|
|
|
|
try { |
|
|
var service = value.swarmlabname |
|
|
var service = value.swarmlabname |
|
|
var services_path = './instance/'+service |
|
|
var services_path = './instance/'+service |
|
|
var ENV_service_file_path = services_path+'/.env' |
|
|
var ENV_service_file_path = services_path+'/.env' |
|
@ -2465,11 +2503,7 @@ try { |
|
|
var ENV_service_file = ` |
|
|
var ENV_service_file = ` |
|
|
SWARMLAB_STORAGE_PASSWORD=${service_password} |
|
|
SWARMLAB_STORAGE_PASSWORD=${service_password} |
|
|
` |
|
|
` |
|
|
try { |
|
|
|
|
|
fs.writeFileSync(ENV_service_file_path, ENV_service_file ,{encoding:'utf8',flag:'a'}); |
|
|
fs.writeFileSync(ENV_service_file_path, ENV_service_file ,{encoding:'utf8',flag:'a'}); |
|
|
} catch (error) { |
|
|
|
|
|
console.log('Error:', error); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var service_up = '/bin/bash ./run.sh' |
|
|
var service_up = '/bin/bash ./run.sh' |
|
|
|
|
|
|
|
@ -2501,6 +2535,9 @@ try { |
|
|
n.data = code |
|
|
n.data = code |
|
|
io.emit('message_close_storage', n); |
|
|
io.emit('message_close_storage', n); |
|
|
}); |
|
|
}); |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
console.log('Error:', error); |
|
|
|
|
|
} |
|
|
}else{ |
|
|
}else{ |
|
|
var n = {} |
|
|
var n = {} |
|
|
n.data = 'NoSwarmlabname' |
|
|
n.data = 'NoSwarmlabname' |
|
@ -2510,6 +2547,7 @@ try { |
|
|
|
|
|
|
|
|
socket.on('start_poc', (value) => { |
|
|
socket.on('start_poc', (value) => { |
|
|
if(value.swarmlabname){ |
|
|
if(value.swarmlabname){ |
|
|
|
|
|
try { |
|
|
var service = value.swarmlabname |
|
|
var service = value.swarmlabname |
|
|
var services_path = './instance/'+service |
|
|
var services_path = './instance/'+service |
|
|
var ENV_service_file_path = services_path+'/.env' |
|
|
var ENV_service_file_path = services_path+'/.env' |
|
@ -2523,11 +2561,7 @@ try { |
|
|
var ENV_service_file = ` |
|
|
var ENV_service_file = ` |
|
|
SWARMLAB_STORAGE_PASSWORD=${service_password} |
|
|
SWARMLAB_STORAGE_PASSWORD=${service_password} |
|
|
` |
|
|
` |
|
|
try { |
|
|
|
|
|
fs.writeFileSync(ENV_service_file_path, ENV_service_file ,{encoding:'utf8',flag:'a'}); |
|
|
fs.writeFileSync(ENV_service_file_path, ENV_service_file ,{encoding:'utf8',flag:'a'}); |
|
|
} catch (error) { |
|
|
|
|
|
console.log('Error:', error); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var service_up = '/bin/bash ./run.sh' |
|
|
var service_up = '/bin/bash ./run.sh' |
|
|
|
|
|
|
|
@ -2559,6 +2593,9 @@ try { |
|
|
n.data = code |
|
|
n.data = code |
|
|
io.emit('message_close_poc', n); |
|
|
io.emit('message_close_poc', n); |
|
|
}); |
|
|
}); |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
console.log('Error:', error); |
|
|
|
|
|
} |
|
|
}else{ |
|
|
}else{ |
|
|
var n = {} |
|
|
var n = {} |
|
|
n.data = 'NoSwarmlabname' |
|
|
n.data = 'NoSwarmlabname' |
|
@ -2648,6 +2685,7 @@ try { |
|
|
|
|
|
|
|
|
socket.on('install', (value) => { |
|
|
socket.on('install', (value) => { |
|
|
if(value.swarmlabname){ |
|
|
if(value.swarmlabname){ |
|
|
|
|
|
try { |
|
|
//console.log('install')
|
|
|
//console.log('install')
|
|
|
var service = value.swarmlabname |
|
|
var service = value.swarmlabname |
|
|
var service_git = value.git |
|
|
var service_git = value.git |
|
@ -2727,6 +2765,9 @@ SSH_PORT= |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
console.log('Error:', error); |
|
|
|
|
|
} |
|
|
}else{ |
|
|
}else{ |
|
|
var n = {} |
|
|
var n = {} |
|
|
n.data = 'no services' |
|
|
n.data = 'no services' |
|
@ -2737,6 +2778,7 @@ SSH_PORT= |
|
|
|
|
|
|
|
|
socket.on('installstorage', (value) => { |
|
|
socket.on('installstorage', (value) => { |
|
|
if(value.swarmlabname){ |
|
|
if(value.swarmlabname){ |
|
|
|
|
|
try { |
|
|
//console.log('install')
|
|
|
//console.log('install')
|
|
|
var service = value.swarmlabname |
|
|
var service = value.swarmlabname |
|
|
var service_git = value.git |
|
|
var service_git = value.git |
|
@ -2817,6 +2859,9 @@ SSH_PORT= |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
console.log('Error:', error); |
|
|
|
|
|
} |
|
|
}else{ |
|
|
}else{ |
|
|
var n = {} |
|
|
var n = {} |
|
|
n.data = 'no services' |
|
|
n.data = 'no services' |
|
@ -2877,9 +2922,6 @@ SSH_PORT= |
|
|
try { |
|
|
try { |
|
|
const buildout = fs.openSync(buildoutdir, 'a'); |
|
|
const buildout = fs.openSync(buildoutdir, 'a'); |
|
|
const builderr = fs.openSync(builderrdir, 'a'); |
|
|
const builderr = fs.openSync(builderrdir, 'a'); |
|
|
} catch (error) { |
|
|
|
|
|
console.log('Error:', error); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var buildimage = `echo "EXEC PID: $$"; packer build -force -only=virtualbox-iso ${image_config}` |
|
|
var buildimage = `echo "EXEC PID: $$"; packer build -force -only=virtualbox-iso ${image_config}` |
|
|
const run_buildimage = spawn(buildimage, { |
|
|
const run_buildimage = spawn(buildimage, { |
|
@ -2947,6 +2989,9 @@ try { |
|
|
|
|
|
|
|
|
console.log(run_buildimage.pid); |
|
|
console.log(run_buildimage.pid); |
|
|
run_buildimage.unref(); |
|
|
run_buildimage.unref(); |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
console.log('Error:', error); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
@ -3140,11 +3185,7 @@ try { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
let datajson = JSON.stringify(services_json); |
|
|
let datajson = JSON.stringify(services_json); |
|
|
try { |
|
|
|
|
|
fs.writeFileSync(rawdatafile, datajson); |
|
|
fs.writeFileSync(rawdatafile, datajson); |
|
|
} catch (error) { |
|
|
|
|
|
console.log('Error:', error); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var services_path = ` ----------------
|
|
|
var services_path = ` ----------------
|
|
|
create a file |
|
|
create a file |
|
|