luigiplr / node-openvpn

Communicate with a openvpn instance via telnet.
131 stars 26 forks source link

How to use it with .ovpn file? #4

Closed SashaDesigN closed 8 years ago

SashaDesigN commented 8 years ago

I want to start use OpenVPN connection in it. To do that I found 2 modules on npm (openvpn-client and openvpn-bin) - but any of them has no good docs and examples, but I try as I can to use them and it was unsuccessful.

I have Ipvanish account (login/password) with 540 .opvn files, which I can use. I try this:

var openvpnmanager = require('node-openvpn');
 var openvpnBin = require('openvpn-bin');
 var path = require('path');

 var filePath = path.normalize('../geo/ipvanish/ipvanish-AU-Sydney-syd-a16.ovpn');

    var opts = {
        host: 'syd-a16.ipvanish.com', // normally '127.0.0.1', will default to if undefined
        port: 443, //port openvpn management console
        timeout: 60000, //timeout for connection - optional, will default to 1500ms if undefined
        config: filePath
    };
    var auth = {
        user: 'email@gmail.com',
        pass: 'password'
    };

    var openvpn = openvpnmanager.connect(opts)

    openvpn.on('connected', function() { 
        // will be emited on successful interfacing with openvpn instance
        console.log('connected')
        openvpnmanager.authorize(auth).then(function(res){

        });
    });
luigiplr commented 8 years ago

try this:

var openvpnmanager = require('node-openvpn')
var openvpnBin = require('openvpn-bin')
var path = require('path')

var openvpnInstance = new openvpnBin('path/to/openvpn.exe', {
  host: '127.0.0.1',
  port: 1337,
  config: path.normalize('../geo/ipvanish/ipvanish-AU-Sydney-syd-a16.ovpn')
})

openvpnInstance.initialize().then(function() {
  var managerInstance = openvpnmanager.connect({ host: '127.0.0.1', port: 1337 })

  managerInstance.on('connected', function() {
    managerInstance.authorize({
      user: 'vpnUserName',
      pass: 'vpnPassword'
    })
  })

  managerInstance.on('console-output', function(output) {
    console.log(output)
  })
})
SashaDesigN commented 8 years ago

Yes but I can't understand what is there path/to/openvpn.exe? I am on Linux now)

luigiplr commented 8 years ago

@SashaDesigN try just setting as openvpn or alternatively find the absolute path of the openvpn executable on your system.

SashaDesigN commented 8 years ago

var openvpnInstance = new openvpnBin('openvpn', { TypeError: openvpnBin is not a function

luigiplr commented 8 years ago

Opes my bad (been a while since i wrote these modules :smile: ). Can you give the following a try?

var openvpnmanager = require('node-openvpn')
var openvpnBin = require('openvpn-bin')
var path = require('path')

openvpnBin.initialize('openvpn', {
  host: '127.0.0.1',
  port: 1337,
  config: path.normalize('../geo/ipvanish/ipvanish-AU-Sydney-syd-a16.ovpn')
}).then(function() {
  var managerInstance = openvpnmanager.connect({ host: '127.0.0.1', port: 1337 })

  managerInstance.on('connected', function() {
    managerInstance.authorize({
      user: 'vpnUserName',
      pass: 'vpnPassword'
    })
  })

  managerInstance.on('console-output', function(output) {
    console.log(output)
  })
})
luigiplr commented 8 years ago

Can this be closed?

SashaDesigN commented 8 years ago

Oh yes - thanks its works

SashaDesigN commented 8 years ago

Actually it didn't work) but I use child_process and openvpn)