telnet-openvpn
Connect to OpenVPN management port through telnet.
Installation
$ npm install telnet-openvpn --save
Usage
ECMAScript 5
var TelnetVPN = ; var vpn = ; var options = host: '127.0.0.1' port: 1337 ors: '\r\n' sendTimeout: 2000; var auth = username: 'username' password: 'password'; vpn; vpn; vpn; vpn; vpn; vpn;
ECMAScript 6
; let vpn = ; let options = host: '127.0.0.1' port: 1337 ors: '\r\n' sendTimeout: 2000; let auth = username: 'username' password: 'password'; vpn; vpn; vpn; vpn; vpn; vpn;
API
vpn.connect(options) -> Promise
Connects to the management port specified in the .ovpn file.
More options can be found in the telnet-client docs.
options:
- host: Management IP address specified under "management" in .ovpn file (default: '127.0.0.1').
- port: Management port specified under "management" in .ovpn file (default: 1337).
- negotiationMandatory: Enable to disable telnet negotiations (default: true).
- ors: Output record separator. Used to execute commands from telnet console (default: '\r\n').
- sendTimeout: Waits for input return character (default: 3000).
vpn.authorize(options) -> Promise
After user connects, vpn.authorize(auth) must be called if .ovpn file specifies auth-user-pass.
options:
- username: Client username for VPN service.
- password: Client password for VPN service
vpn.exec(event) -> Promise
Specify telnet console commands through this function.
vpn.on(event, [callback])
EventEmitter options emitted as information is received from telnet console.
events:
- connect: Telnet console has successfully connected to management port.
- log: Telnet console log outputs.
- error: Telnet console error outputs.
- end: Telnet console has ended session to management port.
- data: Telnet console output data important to user (JSON Formatted).
- state: (array) Current state of telnet console.
- hold: Telnet console waiting for user commands.
- success: Telnet data successfully obtained.
- bytecount: Telnet byte count.
- bytecount_cli: Per-client byte counts.
- password: Password information sent through telnet console.
- pid: Process id of session.
vpn.disconnect() -> Promise
Ends telnet session and triggers the 'end' event emitter.
vpn.destroy() -> Promise
Removes all instances of telnet console socket connection. Used for 'error' event emitter.
vpn.end() -> Promise
Closes telnet session but does not kill all telnet instances like vpn.destroy(). It is possible the server may send some data.
Important .ovpn file information:
# OpenVPN management IP and port (localhost 1337). management 127.0.0.1 1337# OpenVPN wait for hold release from telnet console (vpn.exec('hold release')). management-hold# OpenVPN wait for authentication from telnet console (vpn.authorize(auth)). management-query-passwords# OpenVPN authenticate using username and password from telnet console. auth-user-pass
Start OpenVPN through command line (requires OpenVPN) :
$ openvpn myconfig.ovpn
For more OpenVPN management commands please follow OpenVPN's documentation