]> PHS Git Server - phs-api.git/commitdiff
Adding available clients to VPN.
authorcharleswrayjr <charleswrayjr@gmail.com>
Tue, 9 Sep 2025 14:12:33 +0000 (09:12 -0500)
committercharleswrayjr <charleswrayjr@gmail.com>
Tue, 9 Sep 2025 14:12:33 +0000 (09:12 -0500)
src/controllers/vpn.controller.js

index 31e64e7f4e5cc0dbd57e537803bee53a1c8edd9f..fe10bd6c21a309838f92dede49c6d7ffa5c1ab99 100644 (file)
@@ -149,6 +149,7 @@ module.exports = {
       const commands = [
         `ls /etc/openvpn/ccd/* 2>/dev/null || true`,
         `ls /etc/openvpn/easy-rsa/pki/issued/*.crt 2>/dev/null || true`,
+        'ls /home/node/clients/* 2>/dev/null || true'
       ];
       conn.exec( commands.join( ' && ' ), ( err, stream ) => {
           if (err) {
@@ -166,9 +167,10 @@ module.exports = {
           }
           console.log(output);
           const clients = [];
-          const ccdFiles = output.split('\n').filter(line => !line.endsWith('.crt')).filter( l => !l.startsWith('.') && l !== '' && !l.endsWith('server'));
+          const ccdFiles = output.split('\n').filter(line => !line.endsWith('.crt') && !line.endsWith('.ovpn')).filter( l => !l.startsWith('.') && l !== '' && !l.endsWith('server'));
           const crtFiles = output.split('\n').filter(line => line.endsWith('.crt')).filter( l => !l.startsWith('.') && l !== ''  && !l.endsWith('server.crt'));
-
+          const ovpnFiles = output.split('\n').filter(line => line.endsWith('.ovpn')).filter( l => !l.startsWith('.') && l !== '');
+          console.log(ovpnFiles);
           console.log(ccdFiles);
           console.log(crtFiles);
 
@@ -183,10 +185,14 @@ module.exports = {
               logger.warn( `staticIpMatch: ${ staticIpMatch }`);
               const hasCrt = crtFiles.some( crt => crt.includes( `${ clientName }.crt` ) );
               logger.warn(`hasCrt: ${ hasCrt }`);
+              const hasOvpn = ovpnFiles.some( ovpn => ovpn.includes( `${ clientName }.ovpn` ) );
+              const ovpnPath = `/home/node/clients/${ clientName }.ovpn`;
               clients.push( {
                 clientName,
                 staticIp:staticIpMatch ? staticIpMatch[1] : null,
                 hasCertificate:hasCrt,
+                hasOvpn:hasOvpn,
+                ovpnPath
               } );
             } catch (error) {
               logger.warn( `Failed to read ${ ccdFile }: ${ error.message }` );