|
|
@ -533,7 +533,7 @@ app.get('/getwginterfaces', (req, res, next) => { |
|
|
|
}); |
|
|
|
|
|
|
|
log.stderr.on('data', function (data) { |
|
|
|
console.log('error '+JSON.stringify(n)); |
|
|
|
//console.log('error '+JSON.stringify(n));
|
|
|
|
RES.code = req.query["action"] |
|
|
|
RES.token = req.query["token"] |
|
|
|
RES.error = true |
|
|
@ -745,19 +745,24 @@ function mywgRemoveClosedConnection(){ |
|
|
|
//console.log(n.data);
|
|
|
|
var interfaces = JSON.parse(n.data); |
|
|
|
var datalenth = interfaces.length |
|
|
|
// interfaces found with connection=yes or no
|
|
|
|
for (var i=0 ; i < datalenth ; i++) |
|
|
|
{ |
|
|
|
//console.log(i)
|
|
|
|
//console.log(interfaces)
|
|
|
|
|
|
|
|
var intconnection = interfaces[i].connection; |
|
|
|
var resprivatekey = interfaces[i].ip; |
|
|
|
var respublickey = interfaces[i].publickey; |
|
|
|
var bootstrapstackid = interfaces[i].stackid; |
|
|
|
if(intconnection == 'no'){ |
|
|
|
|
|
|
|
var nn = {} |
|
|
|
nn.connection = interfaces[i].connection; |
|
|
|
nn.AllowedIPs = interfaces[i].ip; |
|
|
|
nn.publickey = interfaces[i].publickey; |
|
|
|
nn.bootstrapstackid = interfaces[i].stackid; |
|
|
|
console.log('no connection '+JSON.stringify(nn)); |
|
|
|
if(intconnection == 'no'){ |
|
|
|
//console.log('no connection '+JSON.stringify(nn));
|
|
|
|
var wgdown = `/bin/bash /config/${nn.bootstrapstackid}/ifdown_linux` |
|
|
|
var showexecrm1 = `/bin/sh ./hybrid/connect/${bootstrapstackid}/swarmlabwgdown` |
|
|
|
var showexec1 = `docker exec swlabadminvenus /bin/bash -c "${wgdown}"; ${showexecrm1}` |
|
|
@ -768,12 +773,74 @@ function mywgRemoveClosedConnection(){ |
|
|
|
stdio: 'pipe' |
|
|
|
}); |
|
|
|
log1.on('close', function (code) { |
|
|
|
console.log('close1 '+JSON.stringify(code)); |
|
|
|
//console.log('close1 '+JSON.stringify(code));
|
|
|
|
var n = {} |
|
|
|
n.data = code |
|
|
|
io.emit('message_close', n); |
|
|
|
}); |
|
|
|
} |
|
|
|
}else if(intconnection == 'yes'){ |
|
|
|
//connection is ok
|
|
|
|
// check if container is ok
|
|
|
|
|
|
|
|
var showexeccheck = `docker ps --format '{"Names":"{{ .Names }}", "Status":"{{.Status}}"}' | jq . -s ` |
|
|
|
exec(showexeccheck, (err, stdout, stderr) => { |
|
|
|
if (err) { |
|
|
|
console.error(`exec error: ${err}`); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (stdout) { |
|
|
|
var string = stdout.toString() |
|
|
|
var datajson = JSON.parse(string); |
|
|
|
|
|
|
|
var search = `swarmlabwg-${bootstrapstackid}` |
|
|
|
var extenderror = new RegExp(search); |
|
|
|
var found = 'no'; |
|
|
|
for(var ia = 0; ia < datajson.length; ia++) { |
|
|
|
var servicename = datajson[ia].Names |
|
|
|
//console.log(JSON.stringify(search+' '+servicename))
|
|
|
|
if(extenderror.test(servicename)){ |
|
|
|
found = 'yes'; |
|
|
|
} |
|
|
|
} |
|
|
|
// container is down
|
|
|
|
// exec interface to down
|
|
|
|
if( found == 'no'){ |
|
|
|
//console.log(interfaces)
|
|
|
|
//console.log('no connection '+JSON.stringify(nn));
|
|
|
|
var wgdown = `/bin/bash /config/${nn.bootstrapstackid}/ifdown_linux` |
|
|
|
var showexecrm1 = `/bin/sh ./hybrid/connect/${bootstrapstackid}/swarmlabwgdown` |
|
|
|
|
|
|
|
//console.log('fount '+found + ' ' + search )
|
|
|
|
var showexec1 = `docker exec swlabadminvenus /bin/bash -c "${wgdown}"; ${showexecrm1}` |
|
|
|
log1 = spawn(showexec1, { |
|
|
|
shell: true, |
|
|
|
cwd: mypath, |
|
|
|
detached: false, |
|
|
|
stdio: 'pipe' |
|
|
|
}); |
|
|
|
log1.on('close', function (code) { |
|
|
|
//console.log('close1 '+JSON.stringify(code));
|
|
|
|
var n = {} |
|
|
|
n.data = code |
|
|
|
io.emit('message_close', n); |
|
|
|
}); |
|
|
|
}else{ |
|
|
|
console.log('fount '+found + ' ' + search ) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|