diff --git a/src/lib/Server.js b/src/lib/Server.js index c0d95cc..4c7e362 100644 --- a/src/lib/Server.js +++ b/src/lib/Server.js @@ -15,7 +15,6 @@ const { PASSWORD, } = require('../config'); -WireGuard.getClients().then(console.log); module.exports = class Server { constructor() { diff --git a/src/lib/Util.js b/src/lib/Util.js index b75ee48..e12fd74 100644 --- a/src/lib/Util.js +++ b/src/lib/Util.js @@ -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); + }); + }); + } + }; diff --git a/src/lib/WireGuard.js b/src/lib/WireGuard.js index 62c71a5..2d14233 100644 --- a/src/lib/WireGuard.js +++ b/src/lib/WireGuard.js @@ -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; }