Skip to content

Commit

Permalink
Fixed vpngate file parsing due to line separator type on linux | adde…
Browse files Browse the repository at this point in the history
…d openvpn options arg
  • Loading branch information
rodrigogs committed Feb 3, 2017
1 parent e1b53ae commit c9be804
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ You can even wait for easyvpn to resolve the countries and then choose between t
A proxy can be used to get data from vpngate.net:
> easyvpn -p http://myproxy:3128
To pass special arguments to openvpn:
> easyvpn -o "--dev-type tun --dev tun0"
## Contributing
1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
Expand Down
17 changes: 9 additions & 8 deletions bin/easyvpn
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

const program = require('commander');

function list(val) {
return val
.match(/[^\s"]+|"([^"]*)"/gi);
}

program
.version('1.1.3')
.option('-c, --country', 'Country name')
.option('-c, --country <name>', 'Country name')
.option('-q, --query', 'Enable country query')
.option('-p, --proxy', 'Proxy url')
.option('-p, --proxy <url>', 'Proxy url')
.option('-o, --options <options>', 'Openvpn options', list)
.parse(process.argv);

const options = {};
if (program.country) options.country = program.country;
if (program.query) options.query = true;
if (program.proxy) options.proxy = program.proxy;

require('../index.js')(options);
require('../index.js')(program);
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ function save(vpns) {
});
}

function startOpenvpn() {
function startOpenvpn(options = []) {
logger.info('Starting openvpn...');
const openvpn = `"${which.sync('openvpn')}"`;
const proc = spawn(openvpn, ['--config', `"${filePath}"`], { shell: true });
console.log(['--config', `"${filePath}"`].concat(options));
const proc = spawn(openvpn, ['--config', `"${filePath}"`].concat(options), { shell: true });
proc.stdout.pipe(logger.stream);
proc.stderr.on('data', data => logger.error(data.toString()));
proc.on('close', code => logger.info(`child process exited with code ${code}`));
Expand Down Expand Up @@ -86,7 +87,7 @@ function execute(options) {
})
.then(vpns => filter(vpns, options.country))
.then(save)
.then(startOpenvpn)
.then(() => startOpenvpn(options.options))
.catch(logger.error);
}

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "easyvpn",
"version": "1.1.3",
"version": "1.2.0",
"description": "Easy way to get a VPN connection.",
"main": "index.js",
"repository": "https://github.com/rodrigogs/easyvpn.git",
Expand All @@ -16,7 +16,6 @@
"tunnel"
],
"scripts": {
"start": "node index.js",
"eslint": "eslint . --ext .js"
},
"dependencies": {
Expand Down
5 changes: 2 additions & 3 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const request = require('request');
const csv = require('csvtojson');
const through2 = require('through2');
const Promise = require('bluebird');
const os = require('os');
const VPN = require('./vpn');

const VPNGATE_API_URL = 'http://www.vpngate.net/api/iphone/';
Expand All @@ -18,15 +17,15 @@ Error message: ${err.message}`;
function filter(chunk, enc, cb) {
const createBuffer = data => new Buffer(data, DEFAULT_ENCODE);
const lines = chunk.toString()
.split(os.EOL)
.split('\r\n')
.filter(line => (line !== '*vpn_servers' && line !== '*'))
.map((line) => {
if (line.startsWith('#HostName')) {
return line.replace('#HostName', 'HostName');
}
return line;
})
.join(os.EOL);
.join('\r\n');

this.push(createBuffer(lines));
cb();
Expand Down

0 comments on commit c9be804

Please sign in to comment.