Skip to content

Instantly share code, notes, and snippets.

@greatghoul
Created February 18, 2014 08:15
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save greatghoul/9066705 to your computer and use it in GitHub Desktop.
Save greatghoul/9066705 to your computer and use it in GitHub Desktop.
# coding: utf-8
# http://forums.fedoraforum.org/showthread.php?t=272322
import os
import uuid
import fnmatch
import subprocess
CURRENT_DIR = os.path.dirname(__file__)
CFG_DIR = '/etc/NetworkManager/system-connections'
VPN_SERVERS = [
{ 'id': 'yunti.pptp.a', 'gateway': 'a.example.com' },
{ 'id': 'yunti.pptp.b', 'gateway': 'b.example.com' },
{ 'id': 'yunti.pptp.c', 'gateway': 'c.example.com' },
]
def add_connection(tpl, conn_info):
filename = os.path.join(CFG_DIR, conn_info['id'])
print ' Creating file:', filename
out = open(filename, 'w')
out.write(tpl % conn_info)
out.close()
os.chmod(filename, 0600)
def cleanup():
print 'Cleaning up yunti connection files...'
for cfg_file in os.listdir(CFG_DIR):
if fnmatch.fnmatch(cfg_file, 'yunti.*'):
filename = os.path.join(CFG_DIR, cfg_file)
print ' Removing file:', filename
os.remove(filename)
def create_all():
tpl = open(os.path.join(CURRENT_DIR, 'tpl.cfg'), 'r').read()
print 'Creating yunti connection files under', CFG_DIR
for conn_info in VPN_SERVERS:
conn_info.update(uuid=str(uuid.uuid1()))
add_connection(tpl, conn_info)
if __name__ == '__main__':
cleanup()
create_all()
[connection]
id=%(id)s
uuid=%(uuid)s
type=vpn
permissions=user:greatghoul:;
autoconnect=false
[vpn]
service-type=org.freedesktop.NetworkManager.pptp
gateway=%(gateway)s
require-mppe=yes
user=greatghoul
refuse-chap=yes
refuse-eap=yes
password-flags=1
refuse-pap=yes
[ipv4]
method=auto
dns=8.8.8.8;8.8.4.4;
ignore-auto-dns=true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment