#!/usr/bin/python
# tinc-gui -- GUI for controlling a running tincd
-# Copyright (C) 2009-2012 Guus Sliepen <guus@tinc-vpn.org>
+# Copyright (C) 2009-2014 Guus Sliepen <guus@tinc-vpn.org>
+# 2014 Dennis Joachimsthaler <dennis@efjot.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
from wx.lib.mixins.listctrl import ColumnSorterMixin
from wx.lib.mixins.listctrl import ListCtrlAutoWidthMixin
-if platform.system == 'Windows':
+if platform.system() == 'Windows':
import _winreg
# Classes to interface with a running tinc daemon
piddir = '/var/run/'
def connect(self):
+ # read the pidfile
f = open(self.pidfile)
info = string.split(f.readline())
f.close()
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.connect((info[2], int(info[4])))
+
+ # check if there is a UNIX socket as well
+ if self.pidfile.endswith(".pid"):
+ unixfile = self.pidfile.replace(".pid", ".socket");
+ else:
+ unixfile = self.pidfile + ".socket";
+
+ if os.path.exists(unixfile):
+ # use it if it exists
+ print(unixfile + " exists!");
+ s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ s.connect(unixfile)
+ else:
+ # otherwise connect via TCP
+ print(unixfile + " does not exist.");
+ if ':' in info[2]:
+ af = socket.AF_INET6
+ else:
+ af = socket.AF_INET
+ s = socket.socket(af, socket.SOCK_STREAM)
+ s.connect((info[2], int(info[4])))
+
self.sf = s.makefile()
s.close()
hello = string.split(self.sf.readline())
return int(resp[2])
def __init__(self, netname = None, pidfile = None):
- if platform.system == 'Windows':
+ if platform.system() == 'Windows':
+ sam = _winreg.KEY_READ
+ if platform.machine().endswith('64'):
+ sam = sam | _winreg.KEY_WOW64_64KEY
try:
- reg = _winreg.ConnectRegistry(None, HKEY_LOCAL_MACHINE)
- key = _winreg.OpenKey(reg, "SOFTWARE\\tinc")
+ 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 pidfile != None:
self.pidfile = pidfile
else:
- if platform.system == 'Windows':
+ if platform.system() == 'Windows':
self.pidfile = os.path.join(self.confbase, 'pid')
else:
if netname: