]> PHS Git Server - phs-api.git/commitdiff
Testing vpn paths.
authorcharleswrayjr <charleswrayjr@gmail.com>
Mon, 8 Sep 2025 04:07:41 +0000 (23:07 -0500)
committercharleswrayjr <charleswrayjr@gmail.com>
Mon, 8 Sep 2025 04:07:41 +0000 (23:07 -0500)
src/controllers/vpn.controller.js

index 7ec5747347b87bb64f01b2508e0f82967c203015..f1e9c9ed29d9457b9b62ef2c32d39b5bd8267f97 100644 (file)
@@ -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