2

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!

stone
  • 8,422
  • 5
  • 54
  • 66
Claudio
  • 92
  • 2
  • 11
  • Hi @Claudio, I am facing a similar requirement. How did you go about this please? Did you install the OpenVPN client on your server and then manage it using the node-openvpn package? – Luke Galea Jun 15 '22 at 08:33

1 Answers1

2

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
Mohamed Sohail
  • 1,659
  • 12
  • 23
  • That is a great explanation thank you Mohammed. Would this work even for multiple simultaneous vpn client configurations? In case I wanted each user to be able to enter his/her creedentials through a form to login to his/her own vpn? In other words: can multiple instances of openvpn run on the same server with different configurations/ pointing to different endpoints? – Claudio Aug 12 '18 at 11:51
  • Multiple client configurations through a single server can get messy as you will have to create multiple TAP adapters for every unique VPN connection. There are GUI programs to help achieve this like TunXTen. But I wouldn't recommend it. http://www.tunxten.com/faq#q_4 – Mohamed Sohail Aug 12 '18 at 12:17
  • Hi @MohamedSohail, should I install this [OpenVPN Client for Linux](https://openvpn.net/cloud-docs/openvpn-3-client-for-linux/) and then use the node-openvpn package to connect? – Luke Galea Jun 15 '22 at 08:34