From a1e07788f020d713102a3d2e4570304db5aa51ad Mon Sep 17 00:00:00 2001 From: charleswrayjr Date: Mon, 8 Sep 2025 23:15:15 -0500 Subject: [PATCH] Cleaning up the revoke client function and starting on the create client function in the vpn controller. --- src/controllers/vpn.controller.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/controllers/vpn.controller.js b/src/controllers/vpn.controller.js index 945c13f..2b6b0f0 100644 --- a/src/controllers/vpn.controller.js +++ b/src/controllers/vpn.controller.js @@ -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 "" | tee /etc/openvpn/clients/${clientName}.ovpn`, `sudo cat pki/ca.crt | tee -a /etc/openvpn/clients/${clientName}.ovpn`, `echo "\n" | 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 }` ); -- 2.43.0