Skip to content

Instantly share code, notes, and snippets.

@rooty
Created August 8, 2017 18:18
Show Gist options
  • Save rooty/de7ef6da2204f31b29d79c8c13f86ba3 to your computer and use it in GitHub Desktop.
Save rooty/de7ef6da2204f31b29d79c8c13f86ba3 to your computer and use it in GitHub Desktop.
VPNUnlimited: create VPN config for Network Manager using ovpn files
  • Download ovpn config files from VPNUnlimited (contact: support@keepsolid.com)
  • Extract zip file, remove email and UserID from file name. Filename should be location.ovpn. You can use rename tool like PyRenamer
  • Put all ovpn files to ovpn_conf
  • Put nm_vpn_gen.py and nm_conf.tpl to directory contain ovpn_conf directory
  • Run "python nm_vpn_gen.py".
[connection]
id=VPNUnlimited $name
uuid=$uuid
type=vpn
permissions=
secondaries=
[vpn]
connection-type=tls
remote=$server.vpnunlimitedapp.com
comp-lzo=yes
reneg-seconds=0
cert-pass-flags=0
cert=$path/certs/client_$server.crt
dev=tun
key=$path/certs/client_$server.key
ca=$path/certs/ca.crt
service-type=org.freedesktop.NetworkManager.openvpn
[vpn-secrets]
no-secret=true
[ipv4]
dns=8.8.8.8;8.8.4.4;
dns-search=
ignore-auto-dns=true
method=auto
[ipv6]
dns-search=
ip6-privacy=0
method=ignore
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" Generate NetworkManager VPN config from VPNUnlimited ovpn files
"""
import re
import os
import glob
from string import Template
from uuid import uuid4 as random_uuid
nm_vpn_template = open("nm_conf.tpl", 'r')
tpl_src = Template(nm_vpn_template.read())
vpn_conf_path = os.path.dirname(os.path.realpath(__file__))
for directory in ["ovpn_conf", "certs", "nm_conf"]:
if not os.path.exists(directory):
os.makedirs(directory)
for fovpn in glob.glob("ovpn_conf/*.ovpn"):
with open(fovpn, 'r') as finput:
fbasename = os.path.basename(finput.name).split('.')[0]
certs = re.search(r'<cert>\n(.*?)</cert>\n<key>\n(.*?)</key>',
finput.read(),
re.DOTALL)
client_crt, client_key = certs.groups()
fclient_crt = open("certs/client_%s.crt" % fbasename, 'w+')
fclient_crt.write("{}".format(client_crt))
fclient_crt.close()
fclient_key = open("certs/client_%s.key" % fbasename, 'w+')
fclient_key.write("{}".format(client_key))
fclient_key.close()
data = {'name': fbasename.upper(),
'uuid': random_uuid(),
'path': vpn_conf_path,
'server': fbasename}
fnmconf = open("nm_conf/VPNUnlimited%s" % data['name'], 'w+')
fnmconf.write(tpl_src.substitute(data))
fnmconf.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment