|
|
@ -1133,6 +1133,52 @@ setInterval(function(){ |
|
|
|
mywgRemoveClosedConnection() |
|
|
|
}, 45000) |
|
|
|
|
|
|
|
async function socket_get_container_ports(containerservice){ |
|
|
|
try { |
|
|
|
var mypath = process.cwd() |
|
|
|
var service = {} |
|
|
|
service.Name = containerservice |
|
|
|
service.Dir = mypath |
|
|
|
var showexec = `docker cp ${mypath}/files/findports.sh ${service.Name}:/tmp/findports.sh; docker exec ${service.Name} /bin/sh -c "/bin/sh /tmp/findports.sh"` |
|
|
|
console.log(showexec) |
|
|
|
log = spawn(showexec, { |
|
|
|
shell: true, |
|
|
|
cwd: service.Dir, |
|
|
|
detached: false, |
|
|
|
stdio: 'pipe' |
|
|
|
}); |
|
|
|
log.stdout.on('data', function (data) { |
|
|
|
var n = {} |
|
|
|
n.status = 'data' |
|
|
|
n.exec = 'info' |
|
|
|
try { |
|
|
|
n.data = data.toString() |
|
|
|
//n.data = JSON.parse(n.data)
|
|
|
|
} catch (err) { |
|
|
|
console.log(err.stack || String(err)); |
|
|
|
} |
|
|
|
console.log('data '+JSON.stringify(n.data)); |
|
|
|
io.emit('virtual_port_info_res', n); |
|
|
|
}); |
|
|
|
log.stderr.on('data', function (data) { |
|
|
|
var n = {} |
|
|
|
n.status = 'error' |
|
|
|
n.exec = 'info' |
|
|
|
n.data = data.toString() |
|
|
|
io.emit('virtual_port_info_reserror', n); |
|
|
|
console.log('error '+JSON.stringify(n.data)); |
|
|
|
}); |
|
|
|
log.on('close', function (code) { |
|
|
|
var n = {} |
|
|
|
n.status = 'close' |
|
|
|
n.exec = 'info' |
|
|
|
n.data = code |
|
|
|
io.emit('virtual_port_info_resclose', n); |
|
|
|
}); |
|
|
|
} catch (err) { |
|
|
|
console.log(err.stack || String(err)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
io.on('connection', function(socket) { |
|
|
@ -1390,15 +1436,30 @@ io.on('connection', function(socket) { |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
socket.on('virtual_port_getinfo', (value) => { |
|
|
|
var service = {} |
|
|
|
var mypath = process.cwd() |
|
|
|
console.log(JSON.stringify(value)); |
|
|
|
try { |
|
|
|
socket_get_container_ports(value.name) |
|
|
|
} catch (err) { |
|
|
|
console.log(err.stack || String(err)); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
socket.on('container_info', (value) => { |
|
|
|
var service = {} |
|
|
|
var mypath = process.cwd() |
|
|
|
console.log(JSON.stringify(value)); |
|
|
|
console.log('-----------------------------------'); |
|
|
|
try { |
|
|
|
service.Name = mpath.basename(value.s.Names) |
|
|
|
service.Dir = value.c.dir |
|
|
|
var showexec = `docker inspect --format '{{json .HostConfig.NetworkMode}}' ${service.Name}` |
|
|
|
//get ports async
|
|
|
|
//console.log(" exec PORT "+ service.Name);
|
|
|
|
// ip --brief address show
|
|
|
|
//var showexec = `docker inspect --format '{{json .Config}}' ${service.Name}`
|
|
|
|
log = spawn(showexec, { |
|
|
@ -1475,6 +1536,7 @@ io.on('connection', function(socket) { |
|
|
|
var grep2a = new RegExp(/^microservice-/); |
|
|
|
var grep2b = new RegExp(/^hybrid-/); |
|
|
|
if(grep2a.test(n.data) || grep2b.test(n.data)){ |
|
|
|
console.log('-----------------------------------'); |
|
|
|
var showexec2 = `docker exec ${service.Name} /bin/sh -c "ip -j --brief address show"` |
|
|
|
log2 = spawn(showexec2, { |
|
|
|
shell: true, |
|
|
@ -1490,6 +1552,18 @@ io.on('connection', function(socket) { |
|
|
|
console.log(n) |
|
|
|
io.emit('container_info_res', n); |
|
|
|
}); |
|
|
|
log2.stderr.on('data', function (data) { |
|
|
|
var n = {} |
|
|
|
n.status = 'error' |
|
|
|
n.exec = 'sharedefault' |
|
|
|
n.data = data.toString() |
|
|
|
n.command = `docker exec ${service.Name} /bin/sh -c "ip address show" <br> <br>
|
|
|
|
docker exec ${service.Name} /bin/sh -c "ip a | grep 'scope global' | grep -Po '(?<=inet )[\d.]+'" <br><br> |
|
|
|
docker exec ${service.Name} /bin/sh -c "/sbin/ifconfig eth0 | awk '/inet addr/{print substr($2,6)}'" |
|
|
|
` |
|
|
|
console.log(n.data) |
|
|
|
io.emit('container_info_reserror', n); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
//var showexec1 = `docker inspect --format '{{json .HostConfig.NetworkMode}}' ${service.Name}`
|
|
|
@ -1514,8 +1588,56 @@ io.on('connection', function(socket) { |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
socket.on('virtual_net_info', (value) => { |
|
|
|
var service = {} |
|
|
|
var mypath = process.cwd() |
|
|
|
console.log(JSON.stringify(value)); |
|
|
|
console.log('-----------------------------------'); |
|
|
|
try { |
|
|
|
service.Name = mpath.basename(value.s.Names) |
|
|
|
service.Dir = value.c.dir |
|
|
|
var showexec = `docker exec ${service.Name} /bin/sh -c "ip -j --brief address show"` |
|
|
|
log = spawn(showexec, { |
|
|
|
shell: true, |
|
|
|
cwd: service.Dir, |
|
|
|
detached: false, |
|
|
|
stdio: 'pipe' |
|
|
|
}); |
|
|
|
log.stdout.on('data', function (data) { |
|
|
|
var n = {} |
|
|
|
n.status = 'data' |
|
|
|
n.exec = 'info' |
|
|
|
n.data = data.toString() |
|
|
|
try { |
|
|
|
n.data = JSON.parse(n.data) |
|
|
|
} catch (err) { |
|
|
|
console.log(err.stack || String(err)); |
|
|
|
} |
|
|
|
console.log(JSON.stringify(n.data)); |
|
|
|
io.emit('virtual_net_info_res', n); |
|
|
|
}); |
|
|
|
log.stderr.on('data', function (data) { |
|
|
|
var n = {} |
|
|
|
n.status = 'error' |
|
|
|
n.exec = 'info' |
|
|
|
n.data = data.toString() |
|
|
|
io.emit('virtual_net_info_reserror', n); |
|
|
|
}); |
|
|
|
log.on('close', function (code) { |
|
|
|
var n = {} |
|
|
|
n.status = 'close' |
|
|
|
n.exec = 'info' |
|
|
|
n.data = code |
|
|
|
io.emit('virtual_net_info_resclose', n); |
|
|
|
}); |
|
|
|
} catch (err) { |
|
|
|
console.log(err.stack || String(err)); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
server.listen(serverPort, function() { |
|
|
|
console.log('server up and running at %s port', serverPort); |
|
|
|
}); |
|
|
|