This commit is contained in:
Emile Nijssen 2021-05-22 22:45:47 +02:00
parent d8f45476da
commit 650128cacb
3 changed files with 22 additions and 9 deletions

View File

@ -15,7 +15,6 @@ const {
PASSWORD,
} = require('../config');
WireGuard.getClients().then(console.log);
module.exports = class Server {
constructor() {

View File

@ -1,5 +1,9 @@
'use strict';
const { rejects } = require('assert');
const childProcess = require('child_process');
const { resolve } = require('path');
module.exports = class Util {
static requireSession(req, res, next) {
@ -43,4 +47,17 @@ module.exports = class Util {
};
}
static async exec(cmd) {
if (process.platform !== 'linux') {
return '';
}
return new Promise((resolve, reject) => {
childProcess.exec(cmd, (err, stdout) => {
if (err) return reject(err);
return resolve(stdout);
});
});
}
};

View File

@ -90,9 +90,9 @@ AllowedIPs = ${client.allowedIPs}`;
}));
// Loop WireGuard status
// const clientsDump = await Util.exec('wg show wg0 dump');
const clientsDump = `iOQJS7OUUGPYATsX6nqlL+sOODoiWiN5IOE8Msfw/0o= BkdntwYazhYZzEEHhcYayq6TGw9/YUDQ251s+5bTgC0= 51820 off
i8xWKqicnDkNL14I4B+I1zlB8od/booA1joIosWn7X4= MzplKtOQ44/IaAKri2VKqCoIlg4XiVH7TCp5bcYRTQU= 172.17.0.1:60475 10.8.0.2/32 1621679257 7920 7440 off`;
const clientsDump = await Util.exec('wg show wg0 dump');
// const clientsDump = `iOQJS7OUUGPYATsX6nqlL+sOODoiWiN5IOE8Msfw/0o= BkdntwYazhYZzEEHhcYayq6TGw9/YUDQ251s+5bTgC0= 51820 off
// i8xWKqicnDkNL14I4B+I1zlB8od/booA1joIosWn7X4= MzplKtOQ44/IaAKri2VKqCoIlg4XiVH7TCp5bcYRTQU= 172.17.0.1:60475 10.8.0.2/32 1621679257 7920 7440 off`;
clientsDump
.trim()
.split('\n')
@ -100,9 +100,9 @@ i8xWKqicnDkNL14I4B+I1zlB8od/booA1joIosWn7X4= MzplKtOQ44/IaAKri2VKqCoIlg4XiVH7TCp
.forEach(line => {
const [
publicKey,
preSharedKey,
preSharedKey, // eslint-disable-line no-unused-vars
endpoint,
allowedIps,
allowedIps, // eslint-disable-line no-unused-vars
latestHandshakeAt,
transferRx,
transferTx,
@ -110,7 +110,6 @@ i8xWKqicnDkNL14I4B+I1zlB8od/booA1joIosWn7X4= MzplKtOQ44/IaAKri2VKqCoIlg4XiVH7TCp
] = line.split('\t');
const client = clients.find(client => client.publicKey === publicKey);
console.log({ publicKey, client });
if (!client) return;
client.endpoint = endpoint === '(none)'
@ -124,8 +123,6 @@ i8xWKqicnDkNL14I4B+I1zlB8od/booA1joIosWn7X4= MzplKtOQ44/IaAKri2VKqCoIlg4XiVH7TCp
client.persistentKeepalive = persistentKeepalive;
});
console.log('clients', clients);
return clients;
}