X-Git-Url: https://www.tinc-vpn.org/git/browse?a=blobdiff_plain;f=gui%2Ftinc-gui;h=64b738ebaee196076f3dea2a3633b7417fb176f1;hb=ab583f7e8c550822c63a1a6b73a7a329f622d9e0;hp=9c6485f8a929b7fcab75a334bb262c4c0c0cff46;hpb=f417271ea1447589ea05901f54fbb0377e7afaf9;p=tinc diff --git a/gui/tinc-gui b/gui/tinc-gui index 9c6485f8..64b738eb 100755 --- a/gui/tinc-gui +++ b/gui/tinc-gui @@ -27,7 +27,7 @@ import time 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 @@ -111,11 +111,28 @@ class VPN: 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."); + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect((info[2], int(info[4]))) + self.sf = s.makefile() s.close() hello = string.split(self.sf.readline()) @@ -216,9 +233,9 @@ class VPN: return int(resp[2]) def __init__(self, netname = None, pidfile = None): - if platform.system == 'Windows': + if platform.system() == 'Windows': try: - reg = _winreg.ConnectRegistry(None, HKEY_LOCAL_MACHINE) + reg = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE) key = _winreg.OpenKey(reg, "SOFTWARE\\tinc") VPN.confdir = _winreg.QueryValue(key, None) except WindowsError: @@ -235,7 +252,7 @@ class VPN: 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: