]> PHS Git Server - phs-api.git/commitdiff
Cleaning up the revoke client function and starting on the create client function...
authorcharleswrayjr <charleswrayjr@gmail.com>
Tue, 9 Sep 2025 04:15:15 +0000 (23:15 -0500)
committercharleswrayjr <charleswrayjr@gmail.com>
Tue, 9 Sep 2025 04:15:15 +0000 (23:15 -0500)
src/controllers/vpn.controller.js

index 945c13f0910a5a648d8004e220c27b9caef1c435..2b6b0f0681d035b0ed444277c2829018e95761c2 100644 (file)
@@ -1,4 +1,5 @@
 const { Client } = require( 'ssh2' );
+const fs = require( 'fs' );
 
 /**
  *
@@ -59,8 +60,8 @@ module.exports = {
       const commands = [
         `cd /etc/openvpn/easy-rsa`,
         `sudo ./easyrsa --batch build-client-full ${clientName} nopass`,
-        `cp ../client-template.txt /etc/openvpn/clients/${ clientName }.ovpn`,
         staticIp ? `echo "ifconfig-push ${staticIp} 255.255.255.0" | tee -a /etc/openvpn/ccd/${clientName}` : 'true',
+        `touch /etc/openvpn/clients/${ clientName }.ovpn`,
         `echo "<ca>" | tee /etc/openvpn/clients/${clientName}.ovpn`,
         `sudo cat pki/ca.crt | tee -a /etc/openvpn/clients/${clientName}.ovpn`,
         `echo "</ca>\n<cert>" | tee -a /etc/openvpn/clients/${clientName}.ovpn`,
@@ -85,10 +86,11 @@ module.exports = {
         stream.stderr.on( 'data', ( data ) => (output += data) );
         stream.on( 'close', ( code ) => {
           conn.end();
+          const final = fs.readFileSync( `/home/node/clients/${ clientName }.ovpn` );
           if (code === 0) {
             res.json( {
               message:`Client ${ clientName } created${ staticIp ? ` with IP ${ staticIp }` : '' }`,
-              ovpn:output
+              ovpn:final
             } );
           } else {
             const error = new createError( 500, `Command failed: ${ output }` );