summaryrefslogtreecommitdiff
path: root/src/leap/platform_init
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap/platform_init')
-rw-r--r--src/leap/platform_init/initializers.py119
1 files changed, 113 insertions, 6 deletions
diff --git a/src/leap/platform_init/initializers.py b/src/leap/platform_init/initializers.py
index 2e8cbe95..9dd31a18 100644
--- a/src/leap/platform_init/initializers.py
+++ b/src/leap/platform_init/initializers.py
@@ -22,10 +22,15 @@ Platform dependant initializing code
import logging
import os
import platform
+import stat
import subprocess
+import tempfile
from PySide import QtGui
+from leap.config.leapsettings import LeapSettings
+from leap.services.eip import vpnlaunchers
+
logger = logging.getLogger(__name__)
# NOTE we could use a deferToThread here, but should
@@ -74,6 +79,28 @@ def _windows_has_tap_device():
pass
return False
+def _get_missing_updown_dialog():
+ """
+ Creates a dialog for notifying of missing updown scripts.
+ Returns that dialog.
+
+ :rtype: QtGui.QMessageBox instance
+ """
+ msg = QtGui.QMessageBox()
+ msg.setWindowTitle(msg.tr("Missing up/down scripts"))
+ msg.setText(msg.tr(
+ "LEAPClient needs to install up/down scripts "
+ "for Encrypted Internet to work properly. "
+ "Would you like to proceed?"))
+ msg.setInformativeText(msg.tr(
+ "It looks like either you have not installed "
+ "LEAP Client in a permanent location or you have an "
+ "incomplete installation. This will ask for "
+ "administrative privileges."))
+ msg.setStandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
+ msg.addButton("No, don't ask again", QtGui.QMessageBox.RejectRole)
+ msg.setDefaultButton(QtGui.QMessageBox.Yes)
+ return msg
def WindowsInitializer():
"""
@@ -128,15 +155,73 @@ def _darwin_has_tun_kext():
return has_tun_and_startup
+def _darwin_install_missing_scripts(badexec, notfound):
+ """
+ Tries to install the missing up/down scripts.
+
+ :param badexec: error for notifying execution error during command.
+ :type badexec: str
+ :param notfound: error for notifying missing path.
+ :type notfound: str
+ """
+ # We expect to execute this from some way of bundle, since
+ # the up/down scripts should be put in place by the installer.
+ installer_path = os.path.join(
+ os.getcwd(),
+ "..",
+ "Resources",
+ "openvpn")
+ launcher = vpnlaunchers.DarwinVPNLauncher
+ if os.path.isdir(installer_path):
+ tempscript = tempfile.mktemp()
+ try:
+ cmd = launcher.OSASCRIPT_BIN
+ scriptlines = launcher.cmd_for_missing_scripts(installer_path)
+ with open(tempscript, 'w') as f:
+ f.write(scriptlines)
+ st = os.stat(tempscript)
+ os.chmod(tempscript, st.st_mode | stat.S_IEXEC | stat.S_IXUSR |
+ stat.S_IXGRP | stat.S_IXOTH)
+
+ osascript = launcher.OSX_ASADMIN % ("/bin/sh %s" % (tempscript,),)
+ cmdline = ["%s -e '%s'" % (cmd, osascript)]
+ ret = subprocess.call(
+ cmdline, stdout=subprocess.PIPE,
+ shell=True)
+ assert(ret)
+ except Exception as exc:
+ logger.error(badexec)
+ logger.error("Error was: %r" % (exc,))
+ f.close()
+ finally:
+ # XXX remove file
+ pass
+ else:
+ logger.error(notfound)
+ logger.debug('path searched: %s' % (installer_path,))
+
+
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
"""
- NOTFOUND_MSG = ("Tried to install tuntaposx kext, but the installer "
- "is not found inside this bundle.")
- BADEXEC_MSG = ("Tried to install tuntaposx kext, but the installer "
- "failed to be launched.")
+ # XXX split this function into several
+
+ NOTFOUND_MSG = ("Tried to install %s, but %s "
+ "not found inside this bundle.")
+ BADEXEC_MSG = ("Tried to install %s, but %s "
+ "failed to %s.")
+
+ TUNTAP_NOTFOUND_MSG = NOTFOUND_MSG % (
+ "tuntaposx kext", "the installer")
+ TUNTAP_BADEXEC_MSG = BADEXEC_MSG % (
+ "tuntaposx kext", "the installer", "be launched")
+
+ UPDOWN_NOTFOUND_MSG = NOTFOUND_MSG % (
+ "updown scripts", "those were")
+ UPDOWN_BADEXEC_MSG = BADEXEC_MSG % (
+ "updown scripts", "they", "be copied")
# TODO DRY this with other cases, and
# factor out to _should_install() function.
@@ -170,6 +255,28 @@ def DarwinInitializer():
cmd, stdout=subprocess.PIPE,
shell=True)
except:
- logger.error(BADEXEC_MSG)
+ logger.error(TUNTAP_BADEXEC_MSG)
else:
- logger.error(NOTFOUND_MSG)
+ logger.error(TUNTAP_NOTFOUND_MSG)
+
+ config = LeapSettings()
+ alert_missing = config.get_alert_missing_scripts()
+ missing_scripts = vpnlaunchers.DarwinVPNLauncher.missing_updown_scripts
+ if alert_missing and missing_scripts():
+ msg = _get_missing_updown_dialog()
+ ret = msg.exec_()
+
+ if ret == QtGui.QMessageBox.Yes:
+ _darwin_install_missing_scripts(
+ UPDOWN_BADEXEC_MSG,
+ UPDOWN_NOTFOUND_MSG)
+
+ elif ret == QtGui.QMessageBox.No:
+ logger.debug("Not installing missing scripts, "
+ "user decided to ignore our warning.")
+
+ elif ret == QtGui.QMessageBox.Rejected:
+ logger.debug(
+ "Setting alert_missing_scripts to False, we will not "
+ "ask again")
+ config.set_alert_missing_scripts(False)