From 3a24100c1ce4894eb2eec9ae57bc4a8afe598f35 Mon Sep 17 00:00:00 2001 From: charleswrayjr Date: Sun, 7 Sep 2025 23:07:41 -0500 Subject: [PATCH] Testing vpn paths. --- src/controllers/vpn.controller.js | 32 +++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/controllers/vpn.controller.js b/src/controllers/vpn.controller.js index 7ec5747..f1e9c9e 100644 --- a/src/controllers/vpn.controller.js +++ b/src/controllers/vpn.controller.js @@ -73,7 +73,35 @@ module.exports = { res.status( 500 ).json( { error:`SSH connection failed: ${ err.message }` } ); } ).connect( sshConfig ); }, getClients:async ( req, res, next ) => { - const conn = new Client(); + const statusContent = await fs.readFile('/var/log/openvpn/status.log', 'utf8'); + const clients = []; + let inClientList = false; + + console.log(statusContent); + + statusContent.split('\n').forEach(line => { + console.log(line); + if (line.startsWith('Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since')) { + inClientList = true; + return; + } + if (line.startsWith('ROUTING TABLE') || line === '') { + inClientList = false; + return; + } + if (inClientList) { + const [common_name, real_address, bytes_received, bytes_sent, connected_since] = line.split(','); + console.log(common_name, real_address, bytes_received, bytes_sent, connected_since); + clients.push({ + common_name, + virtual_address: real_address.split(':')[0], + bytes_received, + bytes_sent, + connected_since, + }); + } + }); + /*const conn = new Client(); conn.on( 'ready', () => { const command = `cat /var/log/openvpn/openvpn-status.log`; conn.exec( command, ( err, stream ) => { @@ -99,6 +127,6 @@ module.exports = { } ); } ).on( 'error', ( err ) => { res.status( 500 ).json( { error:`SSH connection failed: ${ err.message }` } ); - } ).connect( sshConfig ); + } ).connect( sshConfig );*/ } }; \ No newline at end of file -- 2.43.0