|
@ -123,16 +123,6 @@ const servertest = apptest.listen(0, () => { |
|
|
RES.data = err |
|
|
RES.data = err |
|
|
return RES |
|
|
return RES |
|
|
}else{ |
|
|
}else{ |
|
|
fs.mkdir(`./hybrid/connect/${res.bootstrapstackid}/scripts/1`, { recursive: true }, (err) => { |
|
|
|
|
|
if (err){ |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
fs.mkdir(`./hybrid/connect/${res.bootstrapstackid}/scripts/5`, { recursive: true }, (err) => { |
|
|
|
|
|
if (err){ |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
var endpointfpath = `${res.serverip}:${res.endpoint}` |
|
|
var endpointfpath = `${res.serverip}:${res.endpoint}` |
|
|
var peerconfig =` |
|
|
var peerconfig =` |
|
@ -258,7 +248,7 @@ export NODE_PATH=$(npm root --quiet -g) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const myExec = ` |
|
|
const myExec = ` |
|
|
docker exec -it swarmlabwg-${res.bootstrapstackid} /bin/bash -c "ip link set ${DEV_NAME} down; ip link del ${DEV_NAME}" |
|
|
docker exec swarmlabwg-${res.bootstrapstackid} /bin/bash -c "ip link set ${DEV_NAME} down; ip link del ${DEV_NAME}" |
|
|
sleep 1 |
|
|
sleep 1 |
|
|
docker stop swarmlabwg-${res.bootstrapstackid}; docker container rm swarmlabwg-${res.bootstrapstackid} |
|
|
docker stop swarmlabwg-${res.bootstrapstackid}; docker container rm swarmlabwg-${res.bootstrapstackid} |
|
|
sleep 1 |
|
|
sleep 1 |
|
@ -304,7 +294,7 @@ node /usr/local/bin/venus-stats.js --insert=yes --port=${mongoserver.mongo_port} |
|
|
fs.chmodSync(`./hybrid/connect/${res.bootstrapstackid}/scripts/1/logs`, 0o755); |
|
|
fs.chmodSync(`./hybrid/connect/${res.bootstrapstackid}/scripts/1/logs`, 0o755); |
|
|
|
|
|
|
|
|
const myExec1 = ` |
|
|
const myExec1 = ` |
|
|
docker exec -it swarmlabwg-${res.bootstrapstackid} /bin/bash -c "ip link set ${DEV_NAME} down; ip link del ${DEV_NAME}" |
|
|
docker exec swarmlabwg-${res.bootstrapstackid} /bin/bash -c "ip link set ${DEV_NAME} down; ip link del ${DEV_NAME}" |
|
|
sleep 1 |
|
|
sleep 1 |
|
|
docker stop swarmlabwg-${res.bootstrapstackid}; docker container rm swarmlabwg-${res.bootstrapstackid} |
|
|
docker stop swarmlabwg-${res.bootstrapstackid}; docker container rm swarmlabwg-${res.bootstrapstackid} |
|
|
sleep 1 |
|
|
sleep 1 |
|
@ -340,8 +330,10 @@ console.log(RES.dev_name) |
|
|
// *****************************************
|
|
|
// *****************************************
|
|
|
// *** save wg config file wg0.conf
|
|
|
// *** save wg config file wg0.conf
|
|
|
// *****************************************
|
|
|
// *****************************************
|
|
|
|
|
|
//fs.mkdirSync(`./hybrid/connect/${res.bootstrapstackid}`, { recursive: true });
|
|
|
|
|
|
fs.mkdirSync(`./hybrid/connect/${RES.bootstrapstackid}/scripts/1`, { recursive: true }); |
|
|
|
|
|
//fs.mkdirSync(`./hybrid/connect/${res.bootstrapstackid}/scripts/5`, { recursive: true });
|
|
|
(async() => { |
|
|
(async() => { |
|
|
fs.mkdirSync(`./hybrid/connect/${res.bootstrapstackid}`, { recursive: true }); |
|
|
|
|
|
RES.serverconf = await wg_save_clientconf(RES) |
|
|
RES.serverconf = await wg_save_clientconf(RES) |
|
|
RES.serverrun = await wg_save_ifup_linux(RES) |
|
|
RES.serverrun = await wg_save_ifup_linux(RES) |
|
|
RES.serverconnect = await wg_save_connect_linux(RES) |
|
|
RES.serverconnect = await wg_save_connect_linux(RES) |
|
@ -518,8 +510,223 @@ app.get('/getserviceshybridstatus', (req, res, next) => { |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
function myserverStatus(){ |
|
|
app.get('/getwginterfaces', (req, res, next) => { |
|
|
|
|
|
|
|
|
|
|
|
var mypath = process.cwd() |
|
|
|
|
|
var mongoserver = JSON.parse(fs.readFileSync('./hybrid/venus-stats/config.json', 'utf8')) |
|
|
|
|
|
var showexec = `docker exec swlabadminvenus /bin/bash -c "/usr/local/bin/check-wg-connection.sh"` |
|
|
|
|
|
var RES = new Object(); |
|
|
|
|
|
const page = req.query["page"] |
|
|
|
|
|
const per_page = req.query["per_page"] |
|
|
|
|
|
var sort = req.query["sort"] |
|
|
|
|
|
var filter = req.query["filter"] |
|
|
|
|
|
var type = req.query["type"] |
|
|
|
|
|
var sort = req.query["sort"] |
|
|
|
|
|
var sorttmp1 = sort.split('|'); |
|
|
|
|
|
var sortname = sorttmp1[0]; |
|
|
|
|
|
var sortorder = sorttmp1[1]; |
|
|
|
|
|
log = spawn(showexec, { |
|
|
|
|
|
shell: true, |
|
|
|
|
|
cwd: mypath, |
|
|
|
|
|
detached: false, |
|
|
|
|
|
stdio: 'pipe' |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
log.stderr.on('data', function (data) { |
|
|
|
|
|
console.log('error '+JSON.stringify(n)); |
|
|
|
|
|
RES.code = req.query["action"] |
|
|
|
|
|
RES.token = req.query["token"] |
|
|
|
|
|
RES.error = true |
|
|
|
|
|
RES.error_msg = "no" |
|
|
|
|
|
RES.data = data.toString(); |
|
|
|
|
|
res.json(RES.data) |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
log.stdout.on('data', function (data) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.data = data.toString() |
|
|
|
|
|
n.data = n.data.replace(/(\r\n|\n|\r|\t)/g,""); |
|
|
|
|
|
var interfaces = JSON.parse(n.data); |
|
|
|
|
|
var total = interfaces.length; |
|
|
|
|
|
var perpage = per_page |
|
|
|
|
|
var lastpage = total/perpage; |
|
|
|
|
|
|
|
|
|
|
|
if(lastpage <= 1) { |
|
|
|
|
|
lastpage=1 |
|
|
|
|
|
}else{ |
|
|
|
|
|
lastpage++ |
|
|
|
|
|
} |
|
|
|
|
|
lastpage = Math.trunc(lastpage); |
|
|
|
|
|
|
|
|
|
|
|
var next=(page+1); |
|
|
|
|
|
if(next >= lastpage){ |
|
|
|
|
|
next=lastpage; |
|
|
|
|
|
} |
|
|
|
|
|
var prev=(page-1); |
|
|
|
|
|
if(prev == 0){ |
|
|
|
|
|
prev=1; |
|
|
|
|
|
} |
|
|
|
|
|
var from=((page-1)*perpage)+1; |
|
|
|
|
|
var to=(perpage*page) |
|
|
|
|
|
|
|
|
|
|
|
var mywgint = new Object(); |
|
|
|
|
|
var links = ` |
|
|
|
|
|
{ |
|
|
|
|
|
"pagination": { |
|
|
|
|
|
"total": ${total}, |
|
|
|
|
|
"per_page": ${perpage}, |
|
|
|
|
|
"current_page": ${page}, |
|
|
|
|
|
"last_page": ${lastpage}, |
|
|
|
|
|
"next_page_url": "?page=${next}", |
|
|
|
|
|
"prev_page_url": "?page=${prev}", |
|
|
|
|
|
"from": ${from}, |
|
|
|
|
|
"to": ${to}, |
|
|
|
|
|
"frommongo": ${from}, |
|
|
|
|
|
"tomongo": ${to} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
` |
|
|
|
|
|
mywgint.links = JSON.parse(links); |
|
|
|
|
|
from-- |
|
|
|
|
|
mywgint.data = interfaces.slice(from,to); |
|
|
|
|
|
|
|
|
|
|
|
RES.code = req.query["action"] |
|
|
|
|
|
RES.token = req.query["token"] |
|
|
|
|
|
RES.error = false |
|
|
|
|
|
RES.error_msg = "ok" |
|
|
|
|
|
RES.data = mywgint; |
|
|
|
|
|
res.json(RES.data) |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
app.get('/getwginterfacesstats', (req, res, next) => { |
|
|
|
|
|
var mypath = process.cwd() |
|
|
var mongoserver = JSON.parse(fs.readFileSync('./hybrid/venus-stats/config.json', 'utf8')) |
|
|
var mongoserver = JSON.parse(fs.readFileSync('./hybrid/venus-stats/config.json', 'utf8')) |
|
|
|
|
|
const bootstrapstackid = req.query["stackid"] |
|
|
|
|
|
const respublickey = req.query["publickey"] |
|
|
|
|
|
try { |
|
|
|
|
|
var mongourl = `mongodb://${mongoserver.mongo_user}:${mongoserver.mongo_pass}@${mongoserver.mongo_ip}:${mongoserver.mongo_port}`; |
|
|
|
|
|
const OPTS = { |
|
|
|
|
|
useNewUrlParser: true, |
|
|
|
|
|
useUnifiedTopology: true |
|
|
|
|
|
}; |
|
|
|
|
|
MongoClient.connect(mongourl, OPTS, function(err, db) { |
|
|
|
|
|
if(err){ |
|
|
|
|
|
console.log(err); |
|
|
|
|
|
} else { |
|
|
|
|
|
var dbo = db.db(mongoserver.mongo_db); |
|
|
|
|
|
var limit = 10 |
|
|
|
|
|
dbo.collection(mongoserver.mongo_coll).find({"stackid":bootstrapstackid},{sort:{_id:-1}}).limit(limit).toArray(function(err, result) { |
|
|
|
|
|
if(err){ |
|
|
|
|
|
console.log(err); |
|
|
|
|
|
} else { |
|
|
|
|
|
try { |
|
|
|
|
|
if(result[0].log[0].peers[respublickey].transferTx){ |
|
|
|
|
|
var datalenth = result.length |
|
|
|
|
|
var labels = [] |
|
|
|
|
|
var datain = [] |
|
|
|
|
|
var dataout = [] |
|
|
|
|
|
for (var i=0 ; i < datalenth ; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
labels.push(result[i].date) |
|
|
|
|
|
datain.push(result[i].log[0].peers[respublickey].transferTx) |
|
|
|
|
|
dataout.push(result[i].log[0].peers[respublickey].transferRx) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
var chartdata = { |
|
|
|
|
|
labels: labels, |
|
|
|
|
|
datasets: [ |
|
|
|
|
|
{ |
|
|
|
|
|
label: "In", |
|
|
|
|
|
backgroundColor: "#f87979", |
|
|
|
|
|
data: datain, |
|
|
|
|
|
borderColor: '#249EBF', |
|
|
|
|
|
pointBackgroundColor: 'white', |
|
|
|
|
|
borderWidth: 1, |
|
|
|
|
|
fill: false, |
|
|
|
|
|
lineTension: 0, |
|
|
|
|
|
steppedLine: true, |
|
|
|
|
|
pointBorderColor: '#249EBF' |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
label: "Out", |
|
|
|
|
|
backgroundColor: "#A5CC82", |
|
|
|
|
|
data: dataout, |
|
|
|
|
|
borderColor: '#A5CC82', |
|
|
|
|
|
pointBackgroundColor: 'white', |
|
|
|
|
|
fill: false, |
|
|
|
|
|
borderWidth: 1, |
|
|
|
|
|
steppedLine: true, |
|
|
|
|
|
pointBorderColor: '#A5CC82' |
|
|
|
|
|
} |
|
|
|
|
|
], |
|
|
|
|
|
} |
|
|
|
|
|
//console.log(JSON.stringify(chartdata));
|
|
|
|
|
|
//console.log(JSON.stringify('-------- '+JSON.stringify(result[0].log[0].peers[respublickey].transferTx)));
|
|
|
|
|
|
db.close(); |
|
|
|
|
|
res.json(chartdata) |
|
|
|
|
|
} catch (err) { |
|
|
|
|
|
console.error(err); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} catch (err) { |
|
|
|
|
|
console.error(err); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
async function mywgStatus(){ |
|
|
|
|
|
//var mongoserver = JSON.parse(fs.readFileSync('./hybrid/venus-stats/config.json', 'utf8'))
|
|
|
|
|
|
var mypath = process.cwd() |
|
|
|
|
|
|
|
|
|
|
|
var showexec = `docker exec swlabadminvenus /bin/bash -c "/usr/local/bin/check-wg-connection.sh"` |
|
|
|
|
|
log = spawn(showexec, { |
|
|
|
|
|
shell: true, |
|
|
|
|
|
cwd: mypath, |
|
|
|
|
|
detached: false, |
|
|
|
|
|
stdio: 'pipe' |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
log.stdout.on('data', function (data) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.data = data.toString() |
|
|
|
|
|
n.data = n.data.replace(/(\r\n|\n|\r|\t)/g,""); |
|
|
|
|
|
var interfaces = JSON.parse(n.data); |
|
|
|
|
|
var datalenth = interfaces.length |
|
|
|
|
|
for (var i=0 ; i < datalenth ; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
var nn = {} |
|
|
|
|
|
nn.connection = interfaces[i].connection; |
|
|
|
|
|
nn.AllowedIPs = interfaces[i].ip; |
|
|
|
|
|
nn.publickey = interfaces[i].publickey; |
|
|
|
|
|
nn.bootstrapstackid = interfaces[i].stackid; |
|
|
|
|
|
} |
|
|
|
|
|
console.log(interfaces) |
|
|
|
|
|
return interfaces |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
log.stderr.on('data', function (data) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.data = data.toString() |
|
|
|
|
|
console.log('error '+JSON.stringify(n)); |
|
|
|
|
|
return n |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
log.on('close', function (code) { |
|
|
|
|
|
console.log('close '+JSON.stringify(code)); |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.data = code |
|
|
|
|
|
return interfaces |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function mywgRemoveClosedConnection(){ |
|
|
|
|
|
//var mongoserver = JSON.parse(fs.readFileSync('./hybrid/venus-stats/config.json', 'utf8'))
|
|
|
var mypath = process.cwd() |
|
|
var mypath = process.cwd() |
|
|
|
|
|
|
|
|
var showexec = `docker exec swlabadminvenus /bin/bash -c "/usr/local/bin/check-wg-connection.sh"` |
|
|
var showexec = `docker exec swlabadminvenus /bin/bash -c "/usr/local/bin/check-wg-connection.sh"` |
|
@ -534,8 +741,8 @@ function myserverStatus(){ |
|
|
var n = {} |
|
|
var n = {} |
|
|
n.data = data.toString() |
|
|
n.data = data.toString() |
|
|
n.data = n.data.replace(/(\r\n|\n|\r|\t)/g,""); |
|
|
n.data = n.data.replace(/(\r\n|\n|\r|\t)/g,""); |
|
|
console.log(n); |
|
|
//console.log(n);
|
|
|
console.log(n.data); |
|
|
//console.log(n.data);
|
|
|
var interfaces = JSON.parse(n.data); |
|
|
var interfaces = JSON.parse(n.data); |
|
|
var datalenth = interfaces.length |
|
|
var datalenth = interfaces.length |
|
|
for (var i=0 ; i < datalenth ; i++) |
|
|
for (var i=0 ; i < datalenth ; i++) |
|
@ -552,7 +759,8 @@ function myserverStatus(){ |
|
|
nn.bootstrapstackid = interfaces[i].stackid; |
|
|
nn.bootstrapstackid = interfaces[i].stackid; |
|
|
console.log('no connection '+JSON.stringify(nn)); |
|
|
console.log('no connection '+JSON.stringify(nn)); |
|
|
var wgdown = `/bin/bash /config/${nn.bootstrapstackid}/ifdown_linux` |
|
|
var wgdown = `/bin/bash /config/${nn.bootstrapstackid}/ifdown_linux` |
|
|
var showexec1 = `docker exec swlabadminvenus /bin/bash -c "${wgdown}"` |
|
|
var showexecrm1 = `/bin/sh ./hybrid/connect/${bootstrapstackid}/swarmlabwgdown` |
|
|
|
|
|
var showexec1 = `docker exec swlabadminvenus /bin/bash -c "${wgdown}"; ${showexecrm1}` |
|
|
log1 = spawn(showexec1, { |
|
|
log1 = spawn(showexec1, { |
|
|
shell: true, |
|
|
shell: true, |
|
|
cwd: mypath, |
|
|
cwd: mypath, |
|
@ -653,10 +861,10 @@ function myserverStatus(){ |
|
|
} |
|
|
} |
|
|
*/ |
|
|
*/ |
|
|
} |
|
|
} |
|
|
myserverStatus(); |
|
|
mywgRemoveClosedConnection(); |
|
|
|
|
|
|
|
|
setInterval(function(){ |
|
|
setInterval(function(){ |
|
|
myserverStatus() |
|
|
mywgRemoveClosedConnection() |
|
|
}, 30000) |
|
|
}, 30000) |
|
|
|
|
|
|
|
|
io.on('connection', function(socket) { |
|
|
io.on('connection', function(socket) { |
|
|