From: charleswrayjr Date: Tue, 9 Sep 2025 04:15:15 +0000 (-0500) Subject: Cleaning up the revoke client function and starting on the create client function... X-Git-Url: https://git.phasecustomsoft.com/static/gitweb.js?a=commitdiff_plain;h=a1e07788f020d713102a3d2e4570304db5aa51ad;p=phs-api.git Cleaning up the revoke client function and starting on the create client function in the vpn controller. --- 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 }` );