Skip to content

Instantly share code, notes, and snippets.

@thesabbir
Last active August 29, 2015 14:03
Show Gist options
  • Save thesabbir/ced11cc905738ea36cd2 to your computer and use it in GitHub Desktop.
Save thesabbir/ced11cc905738ea36cd2 to your computer and use it in GitHub Desktop.
Openvpn config to network manager config converter. Download and make this script executable and run (you need to have node.js installed).
#!/usr/bin/env node
var args = process.argv.slice(2);
if (args[0] == '-h' || args[0] == undefined) {
console.log('\nUsage : ovpn2nm.js [file]');
console.log('Example : ovpn2nm.js client.ovpn');
console.log('\nVersion 0.0.1');
return 0;
};
var fs= require('fs');
var file = args[0];
console.log("Reading config file : "+file);
fs.readFile(file, 'utf-8', function (err, data) {
if (err) {
console.log(err);
return 0;
};
console.log("Extracting config file...");
var cert = data.match(/<cert>([\s\S]*)<\/cert>/gm)[0].replace(/<cert>|<\/cert>/gm, "");
var ca = data.match(/<ca>([\s\S]*)<\/ca>/gm)[0].replace(/<ca>|<\/ca>/gm, "");
var key = data.match(/<key>([\s\S]*)<\/key>/gm)[0].replace(/<key>|<\/key>/gm, "");
var ta = data.match(/<tls-auth>([\s\S]*)<\/tls-auth>/gm)[0].replace(/<tls-auth>|<\/tls-auth>/gm, "");
var ovpn = data.replace(/<cert>([\s\S]*)<\/cert>|<ca>([\s\S]*)<\/ca>|<key>([\s\S]*)<\/key>|<tls-auth>([\s\S]*)<\/tls-auth>/gm, "");
ovpn = ovpn.replace(/key-direction\s1/, "ca ca.crt\ncert client.crt\nkey client.key\ntls-auth\nta.key 1");
console.log('Extraction complete... \nMaking new directory...');
fs.mkdir('openvpn', 0755,function(err) {
console.log('Creating files..');
fs.writeFile('openvpn/client.crt', cert);
fs.writeFile('openvpn/ca.crt', ca);
fs.writeFile('openvpn/client.key', key);
fs.writeFile('openvpn/ta.key', ta);
fs.writeFile('openvpn/client.ovpn', ovpn);
console.log('Completed..!')
});
});
@thesabbir
Copy link
Author

This script will extract configurations files in /path-to-script/openvpn folder.
If you have network-manager-openvpn-gnome installed.
Go to network manger > Vpn connection > configure vpn > import
and select client.ovpn from new openvpn folder.

Enter your username and password and youre ready to go !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment