summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkali <kali@leap.se>2012-09-05 10:23:24 +0900
committerkali <kali@leap.se>2012-09-05 10:23:24 +0900
commitc190b7f66cc1977d0e058bfa2d8fc1a850326320 (patch)
tree2f19a173c5e312c09d4bbe379749d534b7f23199
parent535e584ba978a7a234a52df14f89197fbc3cea14 (diff)
missing_pkexec error converted to "auto" error.
idea is that we define user messages in the exceptions, and queue them during (conductor) checks. user facing dialogs get constucted from exception attrs. if critical, log as such and exit.
-rw-r--r--src/leap/app.py2
-rw-r--r--src/leap/baseapp/dialogs.py17
-rw-r--r--src/leap/baseapp/eip.py59
-rw-r--r--src/leap/eip/eipconnection.py38
-rw-r--r--src/leap/eip/exceptions.py64
-rw-r--r--src/leap/eip/openvpnconnection.py16
6 files changed, 116 insertions, 80 deletions
diff --git a/src/leap/app.py b/src/leap/app.py
index 1ab806ca..5849848c 100644
--- a/src/leap/app.py
+++ b/src/leap/app.py
@@ -35,7 +35,7 @@ def main():
logfile = getattr(opts, 'log_file', False)
if logfile:
- logger.debug('setting logfile ', logfile)
+ logger.debug('setting logfile to %s ', logfile)
fileh = logging.FileHandler(logfile)
fileh.setLevel(logging.DEBUG)
fileh.setFormatter(formatter)
diff --git a/src/leap/baseapp/dialogs.py b/src/leap/baseapp/dialogs.py
index 4b1b5b62..d37a234c 100644
--- a/src/leap/baseapp/dialogs.py
+++ b/src/leap/baseapp/dialogs.py
@@ -4,7 +4,6 @@ from PyQt4.QtGui import (QDialog, QFrame, QPushButton, QLabel, QMessageBox)
class ErrorDialog(QDialog):
def __init__(self, parent=None):
super(ErrorDialog, self).__init__(parent)
-
frameStyle = QFrame.Sunken | QFrame.Panel
self.warningLabel = QLabel()
self.warningLabel.setFrameStyle(frameStyle)
@@ -15,19 +14,17 @@ class ErrorDialog(QDialog):
"QMessageBox.warning()", msg,
QMessageBox.NoButton, self)
msgBox.addButton("&Ok", QMessageBox.AcceptRole)
- msgBox.addButton("&Cancel", QMessageBox.RejectRole)
if msgBox.exec_() == QMessageBox.AcceptRole:
- self.warningLabel.setText("Save Again")
- else:
- self.warningLabel.setText("Continue")
+ pass
+ # do whatever we want to do after
+ # closing the dialog. we can pass that
+ # in the constructor
def criticalMessage(self, msg, label):
msgBox = QMessageBox(QMessageBox.Critical,
"QMessageBox.critical()", msg,
QMessageBox.NoButton, self)
msgBox.addButton("&Ok", QMessageBox.AcceptRole)
- msgBox.addButton("&Cancel", QMessageBox.RejectRole)
- if msgBox.exec_() == QMessageBox.AcceptRole:
- self.warningLabel.setText("Save Again")
- else:
- self.warningLabel.setText("Continue")
+ msgBox.exec_()
+ import sys
+ sys.exit()
diff --git a/src/leap/baseapp/eip.py b/src/leap/baseapp/eip.py
index 856cb197..dd88b7f5 100644
--- a/src/leap/baseapp/eip.py
+++ b/src/leap/baseapp/eip.py
@@ -12,6 +12,7 @@ logger = logging.getLogger(name=__name__)
class EIPConductorApp(object):
+ # XXX EIPConductorMixin ?
"""
initializes an instance of EIPConnection,
gathers errors, and passes status-change signals
@@ -51,8 +52,38 @@ class EIPConductorApp(object):
lambda: self.start_or_stopVPN())
def error_check(self):
-
- # XXX refactor (by #504)
+ logger.debug('error check')
+
+ #####################################
+ # XXX refactor in progress (by #504)
+ errq = self.conductor.error_queue
+ while errq.qsize() != 0:
+ logger.debug('%s errors left in conductor queue', errq.qsize())
+ error = errq.get()
+ logger.error('%s: %s', error.__class__.__name__, error.message)
+
+ if issubclass(error.__class__, eip_exceptions.EIPClientError):
+ if error.critical:
+ logger.critical(error.message)
+ logger.error('quitting')
+
+ # XXX
+ # check headless = False before
+ # launching dialog.
+ # (for Qt tests)
+
+ dialog = ErrorDialog()
+ if getattr(error, 'usermessage', None):
+ message = error.usermessage
+ else:
+ message = error.message
+ dialog.criticalMessage(message, 'error')
+ else:
+ logger.exception(error.message)
+ else:
+ import traceback
+ traceback.print_exc()
+ raise error
if self.conductor.missing_definition is True:
dialog = ErrorDialog()
@@ -78,12 +109,14 @@ class EIPConductorApp(object):
# os.kill of subprocess fails if we have
# some of this errors.
- if self.conductor.bad_provider is True:
- dialog = ErrorDialog()
- dialog.criticalMessage(
- 'Bad provider entry. Check that remote_ip entry '
- 'has an IP under section [provider] in eip.cfg',
- 'error')
+ # deprecated.
+ # get something alike.
+ #if self.conductor.bad_provider is True:
+ #dialog = ErrorDialog()
+ #dialog.criticalMessage(
+ #'Bad provider entry. Check that remote_ip entry '
+ #'has an IP under section [provider] in eip.cfg',
+ #'error')
if self.conductor.bad_keyfile_perms is True:
dialog = ErrorDialog()
@@ -91,16 +124,6 @@ class EIPConductorApp(object):
'The vpn keys file has bad permissions',
'error')
- if self.conductor.missing_auth_agent is True:
- dialog = ErrorDialog()
- dialog.warningMessage(
- 'We could not find any authentication '
- 'agent in your system.<br/>'
- 'Make sure you have '
- '<b>polkit-gnome-authentication-agent-1</b> '
- 'running and try again.',
- 'error')
-
if self.conductor.missing_pkexec is True:
dialog = ErrorDialog()
dialog.warningMessage(
diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py
index 3a6f4d49..e090f9a7 100644
--- a/src/leap/eip/eipconnection.py
+++ b/src/leap/eip/eipconnection.py
@@ -3,6 +3,7 @@ EIP Connection Class
"""
from __future__ import (absolute_import,)
import logging
+import Queue
from leap.eip.checks import EIPConfigChecker
from leap.eip import exceptions as eip_exceptions
@@ -23,8 +24,8 @@ class EIPConnection(OpenVPNConnection):
self.settingsfile = kwargs.get('settingsfile', None)
self.logfile = kwargs.get('logfile', None)
- # not used atm. but should.
- self.error_queue = []
+ # XXX USE THIS
+ self.error_queue = Queue.Queue()
status_signals = kwargs.pop('status_signals', None)
self.status = EIPConnectionStatus(callbacks=status_signals)
@@ -36,7 +37,12 @@ class EIPConnection(OpenVPNConnection):
"""
run all eip checks previous to attempting a connection
"""
- self.config_checker.run_all(skip_download=skip_download)
+ logger.debug('running conductor checks')
+ try:
+ self.config_checker.run_all(skip_download=skip_download)
+ self.run_openvpn_checks()
+ except Exception as exc:
+ self.error_queue.put(exc)
def connect(self):
"""
@@ -44,7 +50,6 @@ class EIPConnection(OpenVPNConnection):
"""
self.forget_errors()
self._try_connection()
- # XXX should capture errors?
def disconnect(self):
"""
@@ -65,11 +70,11 @@ class EIPConnection(OpenVPNConnection):
"""
return self.status.current
- def desired_connection_state(self):
- """
- returns the desired_connection state
- """
- return self.desired_con_state
+ #def desired_connection_state(self):
+ #"""
+ #returns the desired_connection state
+ #"""
+ #return self.desired_con_state
def poll_connection_state(self):
"""
@@ -107,26 +112,27 @@ class EIPConnection(OpenVPNConnection):
private method for disconnecting
"""
if self.subp is not None:
+ logger.debug('disconnecting...')
self.subp.terminate()
self.subp = None
- # XXX signal state changes! :)
- def _is_alive(self):
- """
- don't know yet
- """
- pass
+ #def _is_alive(self):
+ #"""
+ #don't know yet
+ #"""
+ #pass
def _connect(self):
"""
entry point for connection cascade methods.
"""
- #conn_result = ConState.DISCONNECTED
try:
conn_result = self._try_connection()
except eip_exceptions.UnrecoverableError as except_msg:
logger.error("FATAL: %s" % unicode(except_msg))
conn_result = self.status.UNRECOVERABLE
+
+ # XXX enqueue exceptions themselves instead?
except Exception as except_msg:
self.error_queue.append(except_msg)
logger.error("Failed Connection: %s" %
diff --git a/src/leap/eip/exceptions.py b/src/leap/eip/exceptions.py
index 19a0e707..a30cd2a6 100644
--- a/src/leap/eip/exceptions.py
+++ b/src/leap/eip/exceptions.py
@@ -1,68 +1,72 @@
-class EIPNoCommandError(Exception):
- pass
-
-
-class ConnectionError(Exception):
- """
- generic connection error
- """
- pass
-
-
class EIPClientError(Exception):
"""
base EIPClient exception
"""
- def __str__(self):
- if len(self.args) >= 1:
- return repr(self.args[0])
- else:
- return ConnectionError
+ # Should inherit from LeapException
+ # and move basic attrs there
+ critical = False
+
+ #def __str__(self):
+ #if len(self.args) >= 1:
+ #return repr(self.args[0])
+ #else:
+ #return ConnectionError
-class UnrecoverableError(EIPClientError):
+class CriticalError(EIPClientError):
"""
we cannot do anything about it, sorry
"""
- # XXX we should catch this and raise
- # to qtland, so we emit signal
- # to translate whatever kind of error
- # to user-friendly msg in dialog.
- pass
+ critical = True
-class MissingSocketError(Exception):
+class EIPNoPolkitAuthAgentAvailable(CriticalError):
+ message = "No polkit authentication agent could be found"
+ usermessage = ("We could not find any authentication "
+ "agent in your system.<br/>"
+ "Make sure you have "
+ "<b>polkit-gnome-authentication-agent-1</b> "
+ "running and try again.")
+
+# Errors needing some work
+
+
+class EIPNoPkexecAvailable(Exception):
pass
-class ConnectionRefusedError(Exception):
+class EIPInitNoProviderError(Exception):
pass
-class EIPNoPkexecAvailable(Exception):
+class EIPInitBadProviderError(Exception):
pass
-class EIPNoPolkitAuthAgentAvailable(Exception):
+class EIPInitNoKeyFileError(Exception):
pass
-class EIPInitNoProviderError(Exception):
+class EIPInitBadKeyFilePermError(Exception):
pass
-class EIPInitBadProviderError(Exception):
+class EIPNoCommandError(Exception):
pass
+# Errors that probably we don't need anymore
-class EIPInitNoKeyFileError(Exception):
+
+class MissingSocketError(Exception):
pass
-class EIPInitBadKeyFilePermError(Exception):
+class ConnectionRefusedError(Exception):
pass
+
+
class EIPMissingDefaultProvider(Exception):
pass
diff --git a/src/leap/eip/openvpnconnection.py b/src/leap/eip/openvpnconnection.py
index 48252e10..4a6a495a 100644
--- a/src/leap/eip/openvpnconnection.py
+++ b/src/leap/eip/openvpnconnection.py
@@ -22,7 +22,6 @@ class OpenVPNConnection(Connection):
All related to invocation
of the openvpn binary
"""
- # Connection Methods
def __init__(self, config_file=None,
watcher_cb=None,
@@ -45,7 +44,6 @@ to be triggered for each one of them.
"""
logger.debug('init openvpn connection')
self.debug = debug
- #print('conductor:%s' % debug)
self.config_file = config_file
self.watcher_cb = watcher_cb
@@ -58,15 +56,18 @@ to be triggered for each one of them.
self.port = None
self.proto = None
+ ##################################
# XXX move all error messages
# into a more encapsulated object.
self.missing_pkexec = False
self.missing_auth_agent = False
+
self.bad_keyfile_perms = False
self.missing_vpn_keyfile = False
self.missing_provider = False
self.missing_definition = False
self.bad_provider = False
+ #################################
#XXX workaround for signaling
#the ui that we don't know how to
@@ -78,9 +79,6 @@ to be triggered for each one of them.
# XXX get autostart from config
self.autostart = True
- #self._get_or_create_config()
- self._set_ovpn_command()
- self._check_vpn_keys()
#
# management init methods
@@ -96,6 +94,11 @@ to be triggered for each one of them.
self.port = port
self.password = password
+ def run_openvpn_checks(self):
+ logger.debug('running openvpn checks')
+ self._set_ovpn_command()
+ self._check_vpn_keys()
+
def _set_ovpn_command(self):
# XXX check also for command-line --command flag
try:
@@ -103,10 +106,13 @@ to be triggered for each one of them.
debug=self.debug)
except eip_exceptions.EIPNoPolkitAuthAgentAvailable:
command = args = None
+ # XXX deprecate
self.missing_auth_agent = True
+ raise
except eip_exceptions.EIPNoPkexecAvailable:
command = args = None
self.missing_pkexec = True
+ raise
# XXX if not command, signal error.
self.command = command