- def __init__(self, netname=None, pidfile=None):
- if platform.system() == 'Windows':
- sam = _winreg.KEY_READ
- if platform.machine().endswith('64'):
- sam = sam | _winreg.KEY_WOW64_64KEY
- try:
- reg = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
- try:
- key = _winreg.OpenKey(reg, "SOFTWARE\\tinc", 0, sam)
- except WindowsError:
- key = _winreg.OpenKey(reg, "SOFTWARE\\Wow6432Node\\tinc", 0, sam)
- VPN.confdir = _winreg.QueryValue(key, None)
- except WindowsError:
- pass
-
- if netname:
- self.netname = netname
- self.confbase = os.path.join(VPN.confdir, netname)
- else:
- self.confbase = VPN.confdir
-
- self.tincconf = os.path.join(self.confbase, 'tinc.conf')
-
- if pidfile is not None:
- self.pidfile = pidfile
- else:
- if platform.system() == 'Windows':
- self.pidfile = os.path.join(self.confbase, 'pid')
- else:
- if netname:
- self.pidfile = os.path.join(VPN.piddir, 'tinc.' + netname + '.pid')
- else:
- self.pidfile = os.path.join(VPN.piddir, 'tinc.pid')
-
-
-# GUI starts here
-
-argv0 = sys.argv[0]
-del sys.argv[0]
-netname = None
-pidfile = None
-
-
-def usage(exitcode=0):
- print('Usage: ' + argv0 + ' [options]')
- print('\nValid options are:')
- print(' -n, --net=NETNAME Connect to net NETNAME.')
- print(' --pidfile=FILENAME Read control cookie from FILENAME.')
- print(' --help Display this help and exit.')
- print('\nReport bugs to tinc@tinc-vpn.org.')
- sys.exit(exitcode)
-
-
-while sys.argv:
- if sys.argv[0] in ('-n', '--net'):
- del sys.argv[0]
- netname = sys.argv[0]
- elif sys.argv[0] in '--pidfile':
- del sys.argv[0]
- pidfile = sys.argv[0]
- elif sys.argv[0] in '--help':
- usage(0)
- else:
- print(argv0 + ': unrecognized option \'' + sys.argv[0] + '\'')
- usage(1)
-
- del sys.argv[0]
-
-if netname is None:
- netname = os.getenv('NETNAME')
-elif netname == '.':
- netname = None
-
-vpn = VPN(netname, pidfile)
-vpn.connect()
-