diff options
Diffstat (limited to 'src/leap')
-rw-r--r-- | src/leap/baseapp/mainwindow.py | 43 | ||||
-rw-r--r-- | src/leap/eip/checks.py | 12 | ||||
-rw-r--r-- | src/leap/eip/eipconnection.py | 24 | ||||
-rw-r--r-- | src/leap/eip/openvpnconnection.py | 3 |
4 files changed, 39 insertions, 43 deletions
diff --git a/src/leap/baseapp/mainwindow.py b/src/leap/baseapp/mainwindow.py index 086e905a..d7f4ecac 100644 --- a/src/leap/baseapp/mainwindow.py +++ b/src/leap/baseapp/mainwindow.py @@ -11,18 +11,11 @@ from PyQt4.QtGui import (QMainWindow, QWidget, QVBoxLayout, QMessageBox, QTextBrowser, qApp) from PyQt4.QtCore import (pyqtSlot, pyqtSignal, QTimer) -from leap.base.config import Configuration - from leap.baseapp.dialogs import ErrorDialog - from leap.eip import exceptions as eip_exceptions from leap.eip.eipconnection import EIPConnection - from leap.gui import mainwindow_rc -#TODO: Get rid of this and do something clever -DEFAULT_PROVIDER_URL = "http://localhost/definition.json" - class LeapWindow(QMainWindow): #XXX tbd: refactor into model / view / controller @@ -35,9 +28,7 @@ class LeapWindow(QMainWindow): super(LeapWindow, self).__init__() self.debugmode = getattr(opts, 'debug', False) - self.configuration = Configuration() - - self.vpn_service_started = False + self.eip_service_started = False self.createWindowHeader() self.createIconGroupBox() @@ -69,7 +60,9 @@ class LeapWindow(QMainWindow): widget.setLayout(mainLayout) self.trayIcon.show() - config_file = getattr(opts, 'config_file', None) + self.setWindowTitle("LEAP Client") + self.resize(400, 300) + self.set_statusbarMessage('ready') # # conductor is in charge of all @@ -84,15 +77,19 @@ class LeapWindow(QMainWindow): status_signals=(self.statusChange.emit, ), debug=self.debugmode) + # XXX remove skip download when sample service is ready + self.conductor.run_checks(skip_download=True) + + ####### error checking ################ # # bunch of self checks. # XXX move somewhere else alltogether. # - if self.configuration.error is True: + if self.conductor.missing_definition is True: dialog = ErrorDialog() dialog.criticalMessage( - 'There is a problem with the default ' - 'definition.json file', + 'The default ' + 'definition.json file cannot be found', 'error') if self.conductor.missing_provider is True: @@ -144,10 +141,7 @@ class LeapWindow(QMainWindow): '(<i>DOES NOTHING YET</i>)', 'error') - self.setWindowTitle("LEAP Client") - self.resize(400, 300) - - self.set_statusbarMessage('ready') + ############ end error checking ################### if self.conductor.autostart: self.start_or_stopVPN() @@ -387,9 +381,10 @@ technolust</i>") """ stub for running child process with vpn """ - if self.vpn_service_started is False: + if self.eip_service_started is False: try: self.conductor.connect() + # XXX move this to error queue except eip_exceptions.EIPNoCommandError: dialog = ErrorDialog() dialog.warningMessage( @@ -398,7 +393,7 @@ technolust</i>") 'error') if self.debugmode: self.startStopButton.setText('&Disconnect') - self.vpn_service_started = True + self.eip_service_started = True # XXX what is optimum polling interval? # too little is overkill, too much @@ -406,13 +401,11 @@ technolust</i>") self.timer.start(250.0) return - if self.vpn_service_started is True: + if self.eip_service_started is True: self.conductor.disconnect() - # FIXME this should trigger also - # statuschange event. why isn't working?? if self.debugmode: self.startStopButton.setText('&Connect') - self.vpn_service_started = False + self.eip_service_started = False self.timer.stop() return @@ -430,7 +423,7 @@ technolust</i>") # XXX it's too expensive to poll # continously. move to signal events instead. - if not self.vpn_service_started: + if not self.eip_service_started: return # XXX remove all access to manager layer diff --git a/src/leap/eip/checks.py b/src/leap/eip/checks.py index 7ef80cae..794e69e1 100644 --- a/src/leap/eip/checks.py +++ b/src/leap/eip/checks.py @@ -2,7 +2,9 @@ import json import logging import os +logging.basicConfig() logger = logging.getLogger(name=__name__) +logger.setLevel(logging.DEBUG) import requests @@ -31,7 +33,7 @@ class EIPChecker(object): self.config = None self.fetcher = fetcher - def run_all(self, checker=None): + def run_all(self, checker=None, skip_download=False): """ runs all checks in a row. will raise if some error encountered. @@ -50,8 +52,8 @@ class EIPChecker(object): checker.check_default_eipconfig() checker.check_is_there_default_provider() - checker.fetch_definition() - checker.fetch_eip_config() + checker.fetch_definition(skip_download=skip_download) + checker.fetch_eip_config(skip_download=skip_download) checker.check_complete_eip_config() #checker.ping_gateway() @@ -70,6 +72,7 @@ class EIPChecker(object): # dump it right now, we can get an in-memory # config object and dump it to disk in a # later moment + logger.debug('checking default eip config') if not self._is_there_default_eipconfig(): self._dump_default_eipconfig() @@ -84,6 +87,7 @@ class EIPChecker(object): # else: self.get_eipconfig # XXX parse EIPConfig. # XXX get default_provider. + logger.debug('checking default provider') eipcfg = self._get_default_eipconfig_path() with open(eipcfg, 'r') as fp: config = json.load(fp) @@ -103,8 +107,10 @@ class EIPChecker(object): # TODO: # - Implement diff # - overwrite if different. + logger.debug('fetching definition') if skip_download: + logger.debug('(fetching def skipped)') return True if config is None: config = self.config diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index 2dfc1503..aea560c9 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -8,7 +8,7 @@ logging.basicConfig() logger = logging.getLogger(name=__name__) logger.setLevel(logging.DEBUG) -from leap.base.connection import ConnectionError +from leap.eip.checks import EIPChecker from leap.eip import exceptions as eip_exceptions from leap.eip.openvpnconnection import OpenVPNConnection @@ -22,17 +22,23 @@ class EIPConnection(OpenVPNConnection): Status updates (connected, bandwidth, etc) are signaled to the GUI. """ - def __init__(self, *args, **kwargs): + def __init__(self, checker=EIPChecker, *args, **kwargs): self.settingsfile = kwargs.get('settingsfile', None) self.logfile = kwargs.get('logfile', None) self.error_queue = [] - #self.desired_con_state = None # not in use status_signals = kwargs.pop('status_signals', None) self.status = EIPConnectionStatus(callbacks=status_signals) + self.checker = checker() super(EIPConnection, self).__init__(*args, **kwargs) + def run_checks(self, skip_download=False): + """ + run all eip checks previous to attempting a connection + """ + self.checker.run_all(skip_download=skip_download) + def connect(self): """ entry point for connection process @@ -128,10 +134,6 @@ class EIPConnection(OpenVPNConnection): unicode(except_msg)) return conn_result -"""generic watcher object that keeps track of connection status""" -# This should be deprecated in favor of daemon mode + management -# interface. But we can leave it here for debug purposes. - class EIPConnectionStatus(object): """ @@ -272,11 +274,3 @@ class EIPConnectionStatus(object): for cb in self.callbacks: if callable(cb): cb(self) - - -# XXX move to exceptions -class EIPClientError(ConnectionError): - """ - base EIPClient Exception - """ - pass diff --git a/src/leap/eip/openvpnconnection.py b/src/leap/eip/openvpnconnection.py index 3972b617..5f67d27a 100644 --- a/src/leap/eip/openvpnconnection.py +++ b/src/leap/eip/openvpnconnection.py @@ -59,11 +59,14 @@ 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 |