Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a VPN client on a remote website

I have been researching this for day and I haven't been able to find the way to do this.

I am building a react app, running express at the backend, that needs to access some data in a remote database that lives inside a VPN. At the moment the app lives on my localhost so its enough for me to connect my machine using openvpn client and everything works a beauty. The problem will rise when the app will be live and I will need it to have access to the vpn by (I'm guessing) having a vpn client running on the site/domain.

Has anyone done this before?

I have tried to install the node-openvpn package that seems could do the job but unfortunately I can't manage to make it work as the connection doesn't seem to be configured properly.

This is the function I call to connect to the vpn that systematically fails at the line

--> openvpnmanager.authorize(auth);

const openvpnmanager = require('node-openvpn');

...

const connectToVpn = () => {
var opts = {
    host: 'wopr.remotedbserver.com', 
    port: 1337, //port openvpn management console
    timeout: 1500, //timeout for connection - optional,
    logpath: '/log.txt'
};
var auth = {
    user: 'userName',
    pass: 'passWord',
};

var openvpn = openvpnmanager.connect(opts);

openvpn.on('connected', function() {
    console.log('connecting..');
    openvpnmanager.authorize(auth); <-- Error: Unhandled "error" event. (Cannot connect)
});

openvpn.on('console-output', function(output) {
    console.log(output)
});

openvpn.on('state-change', function(state) { //emits console output of openvpn state as a array
    console.log(output)
});

};

Am I misusing this function? Is there a better way?

Any help will be extremely appreciated.

Thank You!

like image 833
Claudio Avatar asked Dec 17 '25 14:12

Claudio


1 Answers

The problem will rise when the app will be live and I will need it to have access to the vpn by (I'm guessing) having a OpenVPN client running on the site/domain.

Thats correct, you will need an openvpn client instance on the server where you will run the backend.

The above library (node-openvpn) is simply a library to interact with the local OpenVPN client instance. It cannot create a connection on its own. It depends on the OpenVPN binary (which should be running).

The solution you need is simply run the OpenVPN client on your server (apt-get openvpn). And let the daemon run. Check out the references below.

  1. node-openvpn issues that points out that a running instance of the client is needed
  2. OpenVPN CLI tutorial
like image 184
Mohamed Sohail Avatar answered Dec 20 '25 05:12

Mohamed Sohail



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!