From 399b80dbc2a48806fe54fa4d84d513dc83269c3d Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Tue, 2 Apr 2013 23:58:34 +0900 Subject: add osx initializer --- src/leap/platform_init/initializers.py | 55 ++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'src') diff --git a/src/leap/platform_init/initializers.py b/src/leap/platform_init/initializers.py index ac08e23f..6392a3c5 100644 --- a/src/leap/platform_init/initializers.py +++ b/src/leap/platform_init/initializers.py @@ -30,6 +30,10 @@ logger = logging.getLogger(__name__) def init_platform(): + """ + Returns the right initializer for the platform we are running in, or + None if no proper initializer is found + """ initializer = None try: initializer = globals()[platform.system() + "Initializer"] @@ -43,6 +47,10 @@ def init_platform(): def _windows_has_tap_device(): + """ + Loops over the windows registry trying to find if the tap0901 tap driver + has been installed on this machine. + """ import _winreg as reg adapter_key = 'SYSTEM\CurrentControlSet\Control\Class' \ @@ -65,6 +73,10 @@ def _windows_has_tap_device(): def WindowsInitializer(): + """ + Raises a dialog in case that the windows tap driver has not been found + in the registry, asking the user for permission to install the driver + """ if not _windows_has_tap_device(): msg = QtGui.QMessageBox() msg.setWindowTitle(msg.tr("TAP Driver")) @@ -94,3 +106,46 @@ def WindowsInitializer(): else: logger.error("Tried to install TAP driver, but the installer " "is not found or not executable") + + +def _darwin_has_tun_kext(): + """ + Returns True only if we found a directory under the system kext folder + containing a kext named tun.kext, AND we found a startup item named 'tun' + """ + # XXX we should be smarter here and use kextstats output. + has_kext = lambda: os.path.isdir("/System/Library/Extensions/tun.kext") + has_startup = lambda: os.path.isdir("/System/Library/StartupItems/tun") + return has_kext() and has_startup() + +def DarwinInitializer(): + """ + Raises a dialog in case that the osx tuntap driver has not been found + in the registry, asking the user for permission to install the driver + """ + if not _darwin_has_tun_kext(): + msg = QtGui.QMessageBox() + msg.setWindowTitle(msg.tr("TUN Driver")) + msg.setText(msg.tr("LEAPClient needs to install the necessary drivers " + "for Encrypted Internet to work. Would you like to " + "proceed?")) + msg.setInformativeText(msg.tr("Encrypted Internet uses VPN, which " + "needs a kernel extension for a TUN " + "device installed and none " + "has been found")) + msg.setStandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No) + msg.setDefaultButton(QtGui.QMessageBox.Yes) + ret = msg.exec_() + + if ret == QtGui.QMessageBox.Yes: + installer_path = os.path.join(os.getcwd(), + "..", + "Resources", + "tuntap-installer.app") + if os.path.isfile(installer_path) and \ + os.access(installer_path, os.X_OK): + cmd = ["open", installer_path] + ret = subprocess.call(cmd, stdout=subprocess.PIPE, shell=True) + else: + logger.error("Tried to install tuntaposx kext, but the installer " + "is not found inside this bundle, or it is not executable") -- cgit v1.2.3