From 451189d369f6661a67a1692945e68b5128cb9a65 Mon Sep 17 00:00:00 2001 From: antialias Date: Thu, 16 Aug 2012 16:06:53 -0700 Subject: Cleaned up files and file names using the PEP 8 style guide. --- src/leap/eip/eipconnection.py | 270 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 270 insertions(+) create mode 100644 src/leap/eip/eipconnection.py (limited to 'src/leap/eip/eipconnection.py') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py new file mode 100644 index 00000000..f16f01f5 --- /dev/null +++ b/src/leap/eip/eipconnection.py @@ -0,0 +1,270 @@ +""" +EIP Connection Class +""" + +from leap.OpenVPNConnection import OpenVPNConnection, MissingSocketError, ConnectionRefusedError +from leap.Connection import ConnectionError + +class EIPConnection(OpenVPNConnection): + """ + Manages the execution of the OpenVPN process, auto starts, monitors the + network connection, handles configuration, fixes leaky hosts, handles + errors, etc. + Preferences will be stored via the Storage API. (TBD) + Status updates (connected, bandwidth, etc) are signaled to the GUI. + """ + + def __init__(self, *args, **kwargs): + self.settingsfile = kwargs.get('settingsfile', None) + self.logfile = kwargs.get('logfile', None) + self.error_queue = [] + self.desired_con_state = None # ??? + + status_signals = kwargs.pop('status_signals', None) + self.status = EIPConnectionStatus(callbacks=status_signals) + + super(EIPConnection, self).__init__(*args, **kwargs) + + def connect(self): + """ + entry point for connection process + """ + self.forget_errors() + self._try_connection() + # XXX should capture errors? + + def disconnect(self): + """ + disconnects client + """ + self._disconnect() + self.status.change_to(self.status.DISCONNECTED) + pass + + def shutdown(self): + """ + shutdown and quit + """ + self.desired_con_state = self.status.DISCONNECTED + + def connection_state(self): + """ + returns the current connection state + """ + return self.status.current + + def desired_connection_state(self): + """ + returns the desired_connection state + """ + return self.desired_con_state + + def poll_connection_state(self): + """ + """ + try: + state = self.get_connection_state() + except ConnectionRefusedError: + # connection refused. might be not ready yet. + return + if not state: + return + (ts, status_step, + ok, ip, remote) = state + self.status.set_vpn_state(status_step) + status_step = self.status.get_readable_status() + return (ts, status_step, ok, ip, remote) + + def get_icon_name(self): + """ + get icon name from status object + """ + return self.status.get_state_icon() + + # + # private methods + # + + def _disconnect(self): + """ + private method for disconnecting + """ + if self.subp is not None: + self.subp.terminate() + self.subp = None + # XXX signal state changes! :) + + 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 UnrecoverableError as except_msg: + logger.error("FATAL: %s" % unicode(except_msg)) + conn_result = self.status.UNRECOVERABLE + except Exception as except_msg: + self.error_queue.append(except_msg) + logger.error("Failed Connection: %s" % + 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): + """ + Keep track of client (gui) and openvpn + states. + + These are the OpenVPN states: + CONNECTING -- OpenVPN's initial state. + WAIT -- (Client only) Waiting for initial response + from server. + AUTH -- (Client only) Authenticating with server. + GET_CONFIG -- (Client only) Downloading configuration options + from server. + ASSIGN_IP -- Assigning IP address to virtual network + interface. + ADD_ROUTES -- Adding routes to system. + CONNECTED -- Initialization Sequence Completed. + RECONNECTING -- A restart has occurred. + EXITING -- A graceful exit is in progress. + + We add some extra states: + + DISCONNECTED -- GUI initial state. + UNRECOVERABLE -- An unrecoverable error has been raised + while invoking openvpn service. + """ + CONNECTING = 1 + WAIT = 2 + AUTH = 3 + GET_CONFIG = 4 + ASSIGN_IP = 5 + ADD_ROUTES = 6 + CONNECTED = 7 + RECONNECTING = 8 + EXITING = 9 + + # gui specific states: + UNRECOVERABLE = 11 + DISCONNECTED = 0 + + def __init__(self, callbacks=None): + """ + EIPConnectionStatus is initialized with a tuple + of signals to be triggered. + :param callbacks: a tuple of (callable) observers + :type callbacks: tuple + """ + # (callbacks to connect to signals in Qt-land) + self.current = self.DISCONNECTED + self.previous = None + self.callbacks = callbacks + + def get_readable_status(self): + # XXX DRY status / labels a little bit. + # think we'll want to i18n this. + human_status = { + 0: 'disconnected', + 1: 'connecting', + 2: 'waiting', + 3: 'authenticating', + 4: 'getting config', + 5: 'assigning ip', + 6: 'adding routes', + 7: 'connected', + 8: 'reconnecting', + 9: 'exiting', + 11: 'unrecoverable error', + } + return human_status[self.current] + + def get_state_icon(self): + """ + returns the high level icon + for each fine-grain openvpn state + """ + connecting = (self.CONNECTING, + self.WAIT, + self.AUTH, + self.GET_CONFIG, + self.ASSIGN_IP, + self.ADD_ROUTES) + connected = (self.CONNECTED,) + disconnected = (self.DISCONNECTED, + self.UNRECOVERABLE) + + # this can be made smarter, + # but it's like it'll change, + # so +readability. + + if self.current in connecting: + return "connecting" + if self.current in connected: + return "connected" + if self.current in disconnected: + return "disconnected" + + def set_vpn_state(self, status): + """ + accepts a state string from the management + interface, and sets the internal state. + :param status: openvpn STATE (uppercase). + :type status: str + """ + if hasattr(self, status): + self.change_to(getattr(self, status)) + + def set_current(self, to): + """ + setter for the 'current' property + :param to: destination state + :type to: int + """ + self.current = to + + def change_to(self, to): + """ + :param to: destination state + :type to: int + """ + if to == self.current: + return + changed = False + from_ = self.current + self.current = to + + # We can add transition restrictions + # here to ensure no transitions are + # allowed outside the fsm. + + self.set_current(to) + changed = True + + #trigger signals (as callbacks) + #print('current state: %s' % self.current) + if changed: + self.previous = from_ + if self.callbacks: + for cb in self.callbacks: + if callable(cb): + cb(self) + + + +class EIPClientError(ConnectionError): + """ + base EIPClient Exception + """ + pass -- cgit v1.2.3 From f5948577939dce4f85dd86f37c0823a0a852e074 Mon Sep 17 00:00:00 2001 From: kali Date: Tue, 21 Aug 2012 03:11:32 +0900 Subject: fix imports + style cleaning --- src/leap/eip/eipconnection.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/leap/eip/eipconnection.py') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index f16f01f5..a0fdd77d 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -1,9 +1,15 @@ """ EIP Connection Class """ +from __future__ import (absolute_import,) +import logging + +logger = logging.getLogger(name=__name__) + +from leap.eip.openvpnconnection import ( + OpenVPNConnection, ConnectionRefusedError) +from leap.base.connection import ConnectionError -from leap.OpenVPNConnection import OpenVPNConnection, MissingSocketError, ConnectionRefusedError -from leap.Connection import ConnectionError class EIPConnection(OpenVPNConnection): """ @@ -39,7 +45,6 @@ class EIPConnection(OpenVPNConnection): """ self._disconnect() self.status.change_to(self.status.DISCONNECTED) - pass def shutdown(self): """ @@ -262,7 +267,7 @@ class EIPConnectionStatus(object): cb(self) - +# XXX move to exceptions class EIPClientError(ConnectionError): """ base EIPClient Exception -- cgit v1.2.3 From 1abd35337a186e7ab1bab414c0a3809b8583b5a3 Mon Sep 17 00:00:00 2001 From: kali Date: Tue, 21 Aug 2012 03:30:44 +0900 Subject: moved exceptions to its own file --- src/leap/eip/eipconnection.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/leap/eip/eipconnection.py') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index a0fdd77d..7e6c4038 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -6,9 +6,10 @@ import logging logger = logging.getLogger(name=__name__) +from leap.base.connection import ConnectionError +from leap.eip import exceptions as eip_exceptions from leap.eip.openvpnconnection import ( OpenVPNConnection, ConnectionRefusedError) -from leap.base.connection import ConnectionError class EIPConnection(OpenVPNConnection): @@ -112,7 +113,7 @@ class EIPConnection(OpenVPNConnection): #conn_result = ConState.DISCONNECTED try: conn_result = self._try_connection() - except UnrecoverableError as except_msg: + except eip_exceptions.UnrecoverableError as except_msg: logger.error("FATAL: %s" % unicode(except_msg)) conn_result = self.status.UNRECOVERABLE except Exception as except_msg: -- cgit v1.2.3 From 738b4bf8c6b75a1d73b7fa3e1a5edb69adf9d8a0 Mon Sep 17 00:00:00 2001 From: kali Date: Tue, 21 Aug 2012 04:58:05 +0900 Subject: fix out-of-sync refactor. manually merge changes from the develop branch that were lost due to having branched a previous state when refactored former "conductor" class. also, moved more exceptions to its own file. --- src/leap/eip/eipconnection.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/leap/eip/eipconnection.py') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index 7e6c4038..139ee750 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -8,8 +8,7 @@ logger = logging.getLogger(name=__name__) from leap.base.connection import ConnectionError from leap.eip import exceptions as eip_exceptions -from leap.eip.openvpnconnection import ( - OpenVPNConnection, ConnectionRefusedError) +from leap.eip.openvpnconnection import OpenVPNConnection class EIPConnection(OpenVPNConnection): @@ -25,7 +24,7 @@ class EIPConnection(OpenVPNConnection): self.settingsfile = kwargs.get('settingsfile', None) self.logfile = kwargs.get('logfile', None) self.error_queue = [] - self.desired_con_state = None # ??? + #self.desired_con_state = None # not in use status_signals = kwargs.pop('status_signals', None) self.status = EIPConnectionStatus(callbacks=status_signals) @@ -70,7 +69,7 @@ class EIPConnection(OpenVPNConnection): """ try: state = self.get_connection_state() - except ConnectionRefusedError: + except eip_exceptions.ConnectionRefusedError: # connection refused. might be not ready yet. return if not state: -- cgit v1.2.3 From 560232609ef229d46932f8ffcd66b8e114e8b3e6 Mon Sep 17 00:00:00 2001 From: kali Date: Wed, 22 Aug 2012 01:30:37 +0900 Subject: yay! First WORKING GUI in refactor branch :) Obviously then, you should ignore the commit message in 489ed46140d6d. That commit WAS NOT working, believe me :) Fix an annoying bug by which we were overwriting the "connect" method that came from vpnmanager with basically an empty stub. --- src/leap/eip/eipconnection.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/leap/eip/eipconnection.py') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index 139ee750..2dfc1503 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -4,7 +4,9 @@ EIP Connection Class from __future__ import (absolute_import,) import logging +logging.basicConfig() logger = logging.getLogger(name=__name__) +logger.setLevel(logging.DEBUG) from leap.base.connection import ConnectionError from leap.eip import exceptions as eip_exceptions @@ -67,12 +69,17 @@ class EIPConnection(OpenVPNConnection): def poll_connection_state(self): """ """ + # XXX this separation does not + # make sense anymore after having + # merged Connection and Manager classes. try: state = self.get_connection_state() except eip_exceptions.ConnectionRefusedError: # connection refused. might be not ready yet. + logger.warning('connection refused') return if not state: + logger.debug('no state') return (ts, status_step, ok, ip, remote) = state @@ -172,9 +179,9 @@ class EIPConnectionStatus(object): :param callbacks: a tuple of (callable) observers :type callbacks: tuple """ - # (callbacks to connect to signals in Qt-land) self.current = self.DISCONNECTED self.previous = None + # (callbacks to connect to signals in Qt-land) self.callbacks = callbacks def get_readable_status(self): -- cgit v1.2.3 From 06883461f2daa616b2e3c842f53d9422703cd9c7 Mon Sep 17 00:00:00 2001 From: kali Date: Tue, 28 Aug 2012 23:08:39 +0900 Subject: eip_checks called from main app. removed "configuration" object. checks are called from conductor. --- src/leap/eip/eipconnection.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'src/leap/eip/eipconnection.py') 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 -- cgit v1.2.3 From 7a8f4db1a4743582c34a52ab448eece0e7689bc8 Mon Sep 17 00:00:00 2001 From: kali Date: Tue, 28 Aug 2012 23:36:39 +0900 Subject: test for eip_config_checker called from eip_connection run_checks method also: - changed name EIPChecker -> EipConfigChecker - Added class documentation --- src/leap/eip/eipconnection.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/leap/eip/eipconnection.py') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index aea560c9..386b71be 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.eip.checks import EIPChecker +from leap.eip.checks import EIPConfigChecker from leap.eip import exceptions as eip_exceptions from leap.eip.openvpnconnection import OpenVPNConnection @@ -18,18 +18,19 @@ class EIPConnection(OpenVPNConnection): Manages the execution of the OpenVPN process, auto starts, monitors the network connection, handles configuration, fixes leaky hosts, handles errors, etc. - Preferences will be stored via the Storage API. (TBD) Status updates (connected, bandwidth, etc) are signaled to the GUI. """ - def __init__(self, checker=EIPChecker, *args, **kwargs): + def __init__(self, config_checker=EIPConfigChecker, *args, **kwargs): self.settingsfile = kwargs.get('settingsfile', None) self.logfile = kwargs.get('logfile', None) + + # not used atm. but should. self.error_queue = [] status_signals = kwargs.pop('status_signals', None) self.status = EIPConnectionStatus(callbacks=status_signals) - self.checker = checker() + self.config_checker = config_checker() super(EIPConnection, self).__init__(*args, **kwargs) @@ -37,7 +38,7 @@ class EIPConnection(OpenVPNConnection): """ run all eip checks previous to attempting a connection """ - self.checker.run_all(skip_download=skip_download) + self.config_checker.run_all(skip_download=skip_download) def connect(self): """ -- cgit v1.2.3 From a2804c3de1470db98d8c6aa8a01e2de1aa1718a1 Mon Sep 17 00:00:00 2001 From: kali Date: Wed, 5 Sep 2012 07:42:10 +0900 Subject: app wide logging handler --- src/leap/eip/eipconnection.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/leap/eip/eipconnection.py') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index 386b71be..3a6f4d49 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -4,14 +4,12 @@ EIP Connection Class from __future__ import (absolute_import,) import logging -logging.basicConfig() -logger = logging.getLogger(name=__name__) -logger.setLevel(logging.DEBUG) - from leap.eip.checks import EIPConfigChecker from leap.eip import exceptions as eip_exceptions from leap.eip.openvpnconnection import OpenVPNConnection +logger = logging.getLogger(name=__name__) + class EIPConnection(OpenVPNConnection): """ -- cgit v1.2.3 From c190b7f66cc1977d0e058bfa2d8fc1a850326320 Mon Sep 17 00:00:00 2001 From: kali Date: Wed, 5 Sep 2012 10:23:24 +0900 Subject: 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. --- src/leap/eip/eipconnection.py | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'src/leap/eip/eipconnection.py') 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" % -- cgit v1.2.3 From 8148bc9c8c113c41fcb18b397669b1f13447c653 Mon Sep 17 00:00:00 2001 From: kali Date: Thu, 6 Sep 2012 02:27:04 +0900 Subject: more generic error handler in EipConductorAppMixin documentation of the Exception Hierarchy and attributes. also a bit of general cleanup around error handling in conductor. Hopefully to be polished an abstracted to leap.base with time. not all errors are converted (and the old with_errors/ignoring errors) are still there, but we should be using this style of handlers from now on. wrapping up with this pseudo-feature for now. as we work on individual features we can mimick the exceptions that are working. --- src/leap/eip/eipconnection.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/leap/eip/eipconnection.py') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index e090f9a7..5c54a986 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -24,7 +24,6 @@ class EIPConnection(OpenVPNConnection): self.settingsfile = kwargs.get('settingsfile', None) self.logfile = kwargs.get('logfile', None) - # XXX USE THIS self.error_queue = Queue.Queue() status_signals = kwargs.pop('status_signals', None) @@ -33,6 +32,9 @@ class EIPConnection(OpenVPNConnection): super(EIPConnection, self).__init__(*args, **kwargs) + def has_errors(self): + return True if self.error_queue.qsize != 0 else True + def run_checks(self, skip_download=False): """ run all eip checks previous to attempting a connection -- cgit v1.2.3 From 5756a05eb9b66e46df55544d224e2dce7c312452 Mon Sep 17 00:00:00 2001 From: kali Date: Thu, 6 Sep 2012 03:14:36 +0900 Subject: fix silly return mistake on has_errors method --- src/leap/eip/eipconnection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/leap/eip/eipconnection.py') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index 5c54a986..ff71dc76 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -33,7 +33,7 @@ class EIPConnection(OpenVPNConnection): super(EIPConnection, self).__init__(*args, **kwargs) def has_errors(self): - return True if self.error_queue.qsize != 0 else True + return True if self.error_queue.qsize() != 0 else False def run_checks(self, skip_download=False): """ -- cgit v1.2.3 From fc8a54a40645412e9c738723e54159bfda40cfde Mon Sep 17 00:00:00 2001 From: kali Date: Thu, 6 Sep 2012 04:18:27 +0900 Subject: openvpn management socket is a temp path on each run --- src/leap/eip/eipconnection.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/leap/eip/eipconnection.py') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index ff71dc76..3a879f01 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -6,6 +6,7 @@ import logging import Queue from leap.eip.checks import EIPConfigChecker +from leap.eip import config as eipconfig from leap.eip import exceptions as eip_exceptions from leap.eip.openvpnconnection import OpenVPNConnection @@ -30,6 +31,9 @@ class EIPConnection(OpenVPNConnection): self.status = EIPConnectionStatus(callbacks=status_signals) self.config_checker = config_checker() + host = eipconfig.get_socket_path() + kwargs['host'] = host + super(EIPConnection, self).__init__(*args, **kwargs) def has_errors(self): @@ -72,12 +76,6 @@ class EIPConnection(OpenVPNConnection): """ return self.status.current - #def desired_connection_state(self): - #""" - #returns the desired_connection state - #""" - #return self.desired_con_state - def poll_connection_state(self): """ """ -- cgit v1.2.3 From 0d35f2a82bf15504ace2135af3e0c66ae1c16874 Mon Sep 17 00:00:00 2001 From: kali Date: Tue, 18 Sep 2012 11:11:43 +0900 Subject: do_branding command added to setup --- src/leap/eip/eipconnection.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/leap/eip/eipconnection.py') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index 3a879f01..d1c84b2a 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -4,6 +4,7 @@ EIP Connection Class from __future__ import (absolute_import,) import logging import Queue +import sys from leap.eip.checks import EIPConfigChecker from leap.eip import config as eipconfig @@ -48,7 +49,8 @@ class EIPConnection(OpenVPNConnection): self.config_checker.run_all(skip_download=skip_download) self.run_openvpn_checks() except Exception as exc: - self.error_queue.put(exc) + exc_traceback = sys.exc_info()[2] + self.error_queue.put((exc, exc_traceback)) def connect(self): """ -- cgit v1.2.3 From 89735a5fd3c81e8aba3cb7b1d4836c1bf1e8c098 Mon Sep 17 00:00:00 2001 From: kali Date: Tue, 18 Sep 2012 22:55:45 +0900 Subject: cert verification and malformed json checks --- src/leap/eip/eipconnection.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/leap/eip/eipconnection.py') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index d1c84b2a..4e240f16 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -6,6 +6,7 @@ import logging import Queue import sys +from leap.eip.checks import ProviderCertChecker from leap.eip.checks import EIPConfigChecker from leap.eip import config as eipconfig from leap.eip import exceptions as eip_exceptions @@ -22,7 +23,10 @@ class EIPConnection(OpenVPNConnection): Status updates (connected, bandwidth, etc) are signaled to the GUI. """ - def __init__(self, config_checker=EIPConfigChecker, *args, **kwargs): + def __init__(self, + provider_cert_checker=ProviderCertChecker, + config_checker=EIPConfigChecker, + *args, **kwargs): self.settingsfile = kwargs.get('settingsfile', None) self.logfile = kwargs.get('logfile', None) @@ -30,6 +34,8 @@ class EIPConnection(OpenVPNConnection): status_signals = kwargs.pop('status_signals', None) self.status = EIPConnectionStatus(callbacks=status_signals) + + self.provider_cert_checker = provider_cert_checker() self.config_checker = config_checker() host = eipconfig.get_socket_path() @@ -45,12 +51,25 @@ class EIPConnection(OpenVPNConnection): run all eip checks previous to attempting a connection """ logger.debug('running conductor checks') + + def push_err(exc): + # keep the original traceback! + exc_traceback = sys.exc_info()[2] + self.error_queue.put((exc, exc_traceback)) + + try: + # network (1) + self.provider_cert_checker.run_all() + except Exception as exc: + push_err(exc) try: self.config_checker.run_all(skip_download=skip_download) + except Exception as exc: + push_err(exc) + try: self.run_openvpn_checks() except Exception as exc: - exc_traceback = sys.exc_info()[2] - self.error_queue.put((exc, exc_traceback)) + push_err(exc) def connect(self): """ @@ -84,6 +103,7 @@ class EIPConnection(OpenVPNConnection): # XXX this separation does not # make sense anymore after having # merged Connection and Manager classes. + # XXX GET RID OF THIS FUNCTION HERE! try: state = self.get_connection_state() except eip_exceptions.ConnectionRefusedError: -- cgit v1.2.3 From d1ebe98239fbc2baffa345558d396fa539e79202 Mon Sep 17 00:00:00 2001 From: kali Date: Fri, 21 Sep 2012 06:32:40 +0900 Subject: added --no-provider-checks and --no-ca-verify for ease of debugging Close #604 --- src/leap/eip/eipconnection.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/leap/eip/eipconnection.py') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index 4e240f16..f0a98d8c 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -46,7 +46,7 @@ class EIPConnection(OpenVPNConnection): def has_errors(self): return True if self.error_queue.qsize() != 0 else False - def run_checks(self, skip_download=False): + def run_checks(self, skip_download=False, skip_verify=False): """ run all eip checks previous to attempting a connection """ @@ -59,7 +59,7 @@ class EIPConnection(OpenVPNConnection): try: # network (1) - self.provider_cert_checker.run_all() + self.provider_cert_checker.run_all(skip_verify=skip_verify) except Exception as exc: push_err(exc) try: -- cgit v1.2.3 From 479710e977327774b9ba9e1839f75b4a38b51e5f Mon Sep 17 00:00:00 2001 From: kali Date: Mon, 8 Oct 2012 09:32:34 +0900 Subject: add leap-status to main window in non-debug mode not very DRY but just to have it ready for rc cut. --- src/leap/eip/eipconnection.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/leap/eip/eipconnection.py') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index f0a98d8c..a5b59892 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -35,6 +35,9 @@ class EIPConnection(OpenVPNConnection): status_signals = kwargs.pop('status_signals', None) self.status = EIPConnectionStatus(callbacks=status_signals) + checker_signals = kwargs.pop('checker_signals', None) + self.checker_signals = checker_signals + self.provider_cert_checker = provider_cert_checker() self.config_checker = config_checker() @@ -59,10 +62,14 @@ class EIPConnection(OpenVPNConnection): try: # network (1) + for signal in self.checker_signals: + signal('checking encryption keys') self.provider_cert_checker.run_all(skip_verify=skip_verify) except Exception as exc: push_err(exc) try: + for signal in self.checker_signals: + signal('checking provider config') self.config_checker.run_all(skip_download=skip_download) except Exception as exc: push_err(exc) @@ -125,6 +132,9 @@ class EIPConnection(OpenVPNConnection): """ return self.status.get_state_icon() + def get_leap_status(self): + return self.status.get_leap_status() + # # private methods # @@ -231,6 +241,22 @@ class EIPConnectionStatus(object): } return human_status[self.current] + def get_leap_status(self): + # XXX improve nomenclature + leap_status = { + 1: 'connecting to gateway', + 2: 'connecting to gateway', + 3: 'authenticating', + 4: 'establishing network encryption', + 5: 'establishing network encryption', + 6: 'establishing network encryption', + 7: 'connected', + 8: 'reconnecting', + 9: 'exiting', + 11: 'unrecoverable error', + } + return leap_status[self.current] + def get_state_icon(self): """ returns the high level icon -- cgit v1.2.3 From 83bff4cad1e4345eb534cef28ea464b0b5a5e2fd Mon Sep 17 00:00:00 2001 From: kali Date: Wed, 10 Oct 2012 04:23:34 +0900 Subject: fix failing test on test_eipconnection Closes #738 --- src/leap/eip/eipconnection.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/leap/eip/eipconnection.py') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index a5b59892..2750d641 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -54,6 +54,7 @@ class EIPConnection(OpenVPNConnection): run all eip checks previous to attempting a connection """ logger.debug('running conductor checks') + print 'conductor checks!' def push_err(exc): # keep the original traceback! @@ -62,14 +63,16 @@ class EIPConnection(OpenVPNConnection): try: # network (1) - for signal in self.checker_signals: - signal('checking encryption keys') + if self.checker_signals: + for signal in self.checker_signals: + signal('checking encryption keys') self.provider_cert_checker.run_all(skip_verify=skip_verify) except Exception as exc: push_err(exc) try: - for signal in self.checker_signals: - signal('checking provider config') + if self.checker_signals: + for signal in self.checker_signals: + signal('checking provider config') self.config_checker.run_all(skip_download=skip_download) except Exception as exc: push_err(exc) -- cgit v1.2.3 From cf7ddd017f20ca4a3020628999562e9b3b82bd0b Mon Sep 17 00:00:00 2001 From: kali Date: Wed, 10 Oct 2012 05:13:29 +0900 Subject: fix geometry saving for debug/regular mode. Closes #732 --- src/leap/eip/eipconnection.py | 1 - 1 file changed, 1 deletion(-) (limited to 'src/leap/eip/eipconnection.py') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index 2750d641..bdf70f9c 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -54,7 +54,6 @@ class EIPConnection(OpenVPNConnection): run all eip checks previous to attempting a connection """ logger.debug('running conductor checks') - print 'conductor checks!' def push_err(exc): # keep the original traceback! -- cgit v1.2.3 From b70a6664f0603297bf8b20809b5a64677900b405 Mon Sep 17 00:00:00 2001 From: kali Date: Thu, 11 Oct 2012 08:23:22 +0900 Subject: add signal to end of eip checks this fixes random error on leap initialization --- src/leap/eip/eipconnection.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/leap/eip/eipconnection.py') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index bdf70f9c..fea830f3 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -84,7 +84,7 @@ class EIPConnection(OpenVPNConnection): """ entry point for connection process """ - self.forget_errors() + #self.forget_errors() self._try_connection() def disconnect(self): @@ -120,7 +120,7 @@ class EIPConnection(OpenVPNConnection): logger.warning('connection refused') return if not state: - logger.debug('no state') + #logger.debug('no state') return (ts, status_step, ok, ip, remote) = state -- cgit v1.2.3 From 0875a3d498c30187a40a788d3bd1eefa9c5924e2 Mon Sep 17 00:00:00 2001 From: antialias Date: Fri, 12 Oct 2012 15:49:28 -0400 Subject: stopping openvpn via management interface. --- src/leap/eip/eipconnection.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src/leap/eip/eipconnection.py') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index fea830f3..f0e7861e 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -91,7 +91,8 @@ class EIPConnection(OpenVPNConnection): """ disconnects client """ - self._disconnect() + self.cleanup() + logger.debug("disconnect: clicked.") self.status.change_to(self.status.DISCONNECTED) def shutdown(self): @@ -141,14 +142,14 @@ class EIPConnection(OpenVPNConnection): # private methods # - def _disconnect(self): - """ - private method for disconnecting - """ - if self.subp is not None: - logger.debug('disconnecting...') - self.subp.terminate() - self.subp = None + #def _disconnect(self): + # """ + # private method for disconnecting + # """ + # if self.subp is not None: + # logger.debug('disconnecting...') + # self.subp.terminate() + # self.subp = None #def _is_alive(self): #""" -- cgit v1.2.3 From 0060d3c74adce19fab7215b3788c5197cc05a9ae Mon Sep 17 00:00:00 2001 From: kali Date: Wed, 24 Oct 2012 04:05:19 +0900 Subject: sign up branch ends by triggering eip connection still need to bind signals properly, and block on the validation process until we receive the "connected" signal. but the basic flow is working again, i.e, user should be able to remove the .config/leap folder and get all the needed info from the provider. --- src/leap/eip/eipconnection.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/leap/eip/eipconnection.py') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index f0e7861e..d4aeddf6 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -29,6 +29,7 @@ class EIPConnection(OpenVPNConnection): *args, **kwargs): self.settingsfile = kwargs.get('settingsfile', None) self.logfile = kwargs.get('logfile', None) + self.provider = kwargs.pop('provider', None) self.error_queue = Queue.Queue() @@ -38,8 +39,10 @@ class EIPConnection(OpenVPNConnection): checker_signals = kwargs.pop('checker_signals', None) self.checker_signals = checker_signals - self.provider_cert_checker = provider_cert_checker() - self.config_checker = config_checker() + # initialize checkers + self.provider_cert_checker = provider_cert_checker( + domain=self.provider) + self.config_checker = config_checker(domain=self.provider) host = eipconfig.get_socket_path() kwargs['host'] = host @@ -49,6 +52,14 @@ class EIPConnection(OpenVPNConnection): def has_errors(self): return True if self.error_queue.qsize() != 0 else False + def set_provider_domain(self, domain): + """ + sets the provider domain. + used from the first run wizard when we launch the run_checks + and connect process after having initialized the conductor. + """ + self.provider = domain + def run_checks(self, skip_download=False, skip_verify=False): """ run all eip checks previous to attempting a connection -- cgit v1.2.3 From 593e4ba1ddf185d14f27c96ffb970fde7a3271fa Mon Sep 17 00:00:00 2001 From: kali Date: Fri, 26 Oct 2012 02:04:34 +0900 Subject: fix systray context menu. Closes #761 --- src/leap/eip/eipconnection.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'src/leap/eip/eipconnection.py') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index d4aeddf6..acd40beb 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -106,11 +106,11 @@ class EIPConnection(OpenVPNConnection): logger.debug("disconnect: clicked.") self.status.change_to(self.status.DISCONNECTED) - def shutdown(self): - """ - shutdown and quit - """ - self.desired_con_state = self.status.DISCONNECTED + #def shutdown(self): + #""" + #shutdown and quit + #""" + #self.desired_con_state = self.status.DISCONNECTED def connection_state(self): """ @@ -121,10 +121,6 @@ class EIPConnection(OpenVPNConnection): def poll_connection_state(self): """ """ - # XXX this separation does not - # make sense anymore after having - # merged Connection and Manager classes. - # XXX GET RID OF THIS FUNCTION HERE! try: state = self.get_connection_state() except eip_exceptions.ConnectionRefusedError: @@ -132,7 +128,7 @@ class EIPConnection(OpenVPNConnection): logger.warning('connection refused') return if not state: - #logger.debug('no state') + logger.debug('no state') return (ts, status_step, ok, ip, remote) = state @@ -258,6 +254,7 @@ class EIPConnectionStatus(object): def get_leap_status(self): # XXX improve nomenclature leap_status = { + 0: 'disconnected', 1: 'connecting to gateway', 2: 'connecting to gateway', 3: 'authenticating', -- cgit v1.2.3 From d2dcf5a1060d60c451570349a6a06ad102d6924c Mon Sep 17 00:00:00 2001 From: kali Date: Tue, 13 Nov 2012 21:54:04 +0900 Subject: fix missing provider parameter in leapconfig objects chain --- src/leap/eip/eipconnection.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/leap/eip/eipconnection.py') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index acd40beb..7828c864 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -30,6 +30,8 @@ class EIPConnection(OpenVPNConnection): self.settingsfile = kwargs.get('settingsfile', None) self.logfile = kwargs.get('logfile', None) self.provider = kwargs.pop('provider', None) + self._providercertchecker = provider_cert_checker + self._configchecker = config_checker self.error_queue = Queue.Queue() @@ -39,10 +41,7 @@ class EIPConnection(OpenVPNConnection): checker_signals = kwargs.pop('checker_signals', None) self.checker_signals = checker_signals - # initialize checkers - self.provider_cert_checker = provider_cert_checker( - domain=self.provider) - self.config_checker = config_checker(domain=self.provider) + self.init_checkers() host = eipconfig.get_socket_path() kwargs['host'] = host @@ -52,13 +51,24 @@ class EIPConnection(OpenVPNConnection): def has_errors(self): return True if self.error_queue.qsize() != 0 else False + def init_checkers(self): + # initialize checkers + self.provider_cert_checker = self._providercertchecker( + domain=self.provider) + self.config_checker = self._configchecker(domain=self.provider) + def set_provider_domain(self, domain): """ sets the provider domain. used from the first run wizard when we launch the run_checks and connect process after having initialized the conductor. """ + # This looks convoluted, right. + # We have to reinstantiate checkers cause we're passing + # the domain param that we did not know at the beginning + # (only for the firstrunwizard case) self.provider = domain + self.init_checkers() def run_checks(self, skip_download=False, skip_verify=False): """ -- cgit v1.2.3 From 38cc1758240a3c64db387b0437dcf1517b52da15 Mon Sep 17 00:00:00 2001 From: kali Date: Mon, 10 Dec 2012 19:51:53 +0900 Subject: cleanup and rewrite eipconnection/openvpnconnection classes --- src/leap/eip/eipconnection.py | 238 +++++++++++++++++++++++++----------------- 1 file changed, 144 insertions(+), 94 deletions(-) (limited to 'src/leap/eip/eipconnection.py') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index 7828c864..8751f643 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -5,6 +5,7 @@ from __future__ import (absolute_import,) import logging import Queue import sys +import time from leap.eip.checks import ProviderCertChecker from leap.eip.checks import EIPConfigChecker @@ -15,20 +16,143 @@ from leap.eip.openvpnconnection import OpenVPNConnection logger = logging.getLogger(name=__name__) -class EIPConnection(OpenVPNConnection): +class StatusMixIn(object): + + # a bunch of methods related with querying the connection + # state/status and displaying useful info. + # Needs to get clear on what is what, and + # separate functions. + # Should separate EIPConnectionStatus (self.status) + # from the OpenVPN state/status command and parsing. + + def connection_state(self): + """ + returns the current connection state + """ + return self.status.current + + def get_icon_name(self): + """ + get icon name from status object + """ + return self.status.get_state_icon() + + def get_leap_status(self): + return self.status.get_leap_status() + + def poll_connection_state(self): + """ + """ + try: + state = self.get_connection_state() + except eip_exceptions.ConnectionRefusedError: + # connection refused. might be not ready yet. + logger.warning('connection refused') + return + if not state: + logger.debug('no state') + return + (ts, status_step, + ok, ip, remote) = state + self.status.set_vpn_state(status_step) + status_step = self.status.get_readable_status() + return (ts, status_step, ok, ip, remote) + + def make_error(self): + """ + capture error and wrap it in an + understandable format + """ + # mostly a hack to display errors in the debug UI + # w/o breaking the polling. + #XXX get helpful error codes + self.with_errors = True + now = int(time.time()) + return '%s,LAUNCHER ERROR,ERROR,-,-' % now + + def state(self): + """ + Sends OpenVPN command: state + """ + state = self._send_command("state") + if not state: + return None + if isinstance(state, str): + return state + if isinstance(state, list): + if len(state) == 1: + return state[0] + else: + return state[-1] + + def vpn_status(self): + """ + OpenVPN command: status + """ + status = self._send_command("status") + return status + + def vpn_status2(self): + """ + OpenVPN command: last 2 statuses + """ + return self._send_command("status 2") + + # + # parse info as the UI expects + # + + def get_status_io(self): + status = self.vpn_status() + if isinstance(status, str): + lines = status.split('\n') + if isinstance(status, list): + lines = status + try: + (header, when, tun_read, tun_write, + tcp_read, tcp_write, auth_read) = tuple(lines) + except ValueError: + return None + + # XXX this will break with different locales I assume... + when_ts = time.strptime(when.split(',')[1], "%a %b %d %H:%M:%S %Y") + sep = ',' + # XXX clean up this! + tun_read = tun_read.split(sep)[1] + tun_write = tun_write.split(sep)[1] + tcp_read = tcp_read.split(sep)[1] + tcp_write = tcp_write.split(sep)[1] + auth_read = auth_read.split(sep)[1] + + # XXX this could be a named tuple. prettier. + return when_ts, (tun_read, tun_write, tcp_read, tcp_write, auth_read) + + def get_connection_state(self): + state = self.state() + if state is not None: + ts, status_step, ok, ip, remote = state.split(',') + ts = time.gmtime(float(ts)) + # XXX this could be a named tuple. prettier. + return ts, status_step, ok, ip, remote + + +class EIPConnection(OpenVPNConnection, StatusMixIn): """ + Aka conductor. Manages the execution of the OpenVPN process, auto starts, monitors the network connection, handles configuration, fixes leaky hosts, handles errors, etc. Status updates (connected, bandwidth, etc) are signaled to the GUI. """ + # XXX change name to EIPConductor ?? + def __init__(self, provider_cert_checker=ProviderCertChecker, config_checker=EIPConfigChecker, *args, **kwargs): - self.settingsfile = kwargs.get('settingsfile', None) - self.logfile = kwargs.get('logfile', None) + #self.settingsfile = kwargs.get('settingsfile', None) + #self.logfile = kwargs.get('logfile', None) self.provider = kwargs.pop('provider', None) self._providercertchecker = provider_cert_checker self._configchecker = config_checker @@ -48,11 +172,27 @@ class EIPConnection(OpenVPNConnection): super(EIPConnection, self).__init__(*args, **kwargs) + def connect(self): + """ + entry point for connection process + """ + # in OpenVPNConnection + self.try_openvpn_connection() + + def disconnect(self, shutdown=False): + """ + disconnects client + """ + self.terminate_openvpn_connection(shutdown=shutdown) + self.status.change_to(self.status.DISCONNECTED) + def has_errors(self): return True if self.error_queue.qsize() != 0 else False def init_checkers(self): - # initialize checkers + """ + initialize checkers + """ self.provider_cert_checker = self._providercertchecker( domain=self.provider) self.config_checker = self._configchecker(domain=self.provider) @@ -101,96 +241,6 @@ class EIPConnection(OpenVPNConnection): except Exception as exc: push_err(exc) - def connect(self): - """ - entry point for connection process - """ - #self.forget_errors() - self._try_connection() - - def disconnect(self): - """ - disconnects client - """ - self.cleanup() - logger.debug("disconnect: clicked.") - self.status.change_to(self.status.DISCONNECTED) - - #def shutdown(self): - #""" - #shutdown and quit - #""" - #self.desired_con_state = self.status.DISCONNECTED - - def connection_state(self): - """ - returns the current connection state - """ - return self.status.current - - def poll_connection_state(self): - """ - """ - try: - state = self.get_connection_state() - except eip_exceptions.ConnectionRefusedError: - # connection refused. might be not ready yet. - logger.warning('connection refused') - return - if not state: - logger.debug('no state') - return - (ts, status_step, - ok, ip, remote) = state - self.status.set_vpn_state(status_step) - status_step = self.status.get_readable_status() - return (ts, status_step, ok, ip, remote) - - def get_icon_name(self): - """ - get icon name from status object - """ - return self.status.get_state_icon() - - def get_leap_status(self): - return self.status.get_leap_status() - - # - # private methods - # - - #def _disconnect(self): - # """ - # private method for disconnecting - # """ - # if self.subp is not None: - # logger.debug('disconnecting...') - # self.subp.terminate() - # self.subp = None - - #def _is_alive(self): - #""" - #don't know yet - #""" - #pass - - def _connect(self): - """ - entry point for connection cascade methods. - """ - 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" % - unicode(except_msg)) - return conn_result - class EIPConnectionStatus(object): """ -- cgit v1.2.3 From f104e834c96c9ec10a465bda46ef05e87ea32516 Mon Sep 17 00:00:00 2001 From: kali Date: Tue, 18 Dec 2012 03:45:23 +0900 Subject: Fix parsing of timestamps in a locate independent way Close #772 --- src/leap/eip/eipconnection.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/leap/eip/eipconnection.py') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index 8751f643..27734f80 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -7,6 +7,8 @@ import Queue import sys import time +from dateutil.parser import parse as dateparse + from leap.eip.checks import ProviderCertChecker from leap.eip.checks import EIPConfigChecker from leap.eip import config as eipconfig @@ -114,8 +116,7 @@ class StatusMixIn(object): except ValueError: return None - # XXX this will break with different locales I assume... - when_ts = time.strptime(when.split(',')[1], "%a %b %d %H:%M:%S %Y") + when_ts = dateparse(when.split(',')[1]).timetuple() sep = ',' # XXX clean up this! tun_read = tun_read.split(sep)[1] -- cgit v1.2.3 From e35eb606faef1ccd06201a0b38a462375426cedd Mon Sep 17 00:00:00 2001 From: kali Date: Mon, 7 Jan 2013 21:10:41 +0900 Subject: Working OSX installer workflow. Using platypus for installer. Working installer at 17.6MB compressed. --- src/leap/eip/eipconnection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/leap/eip/eipconnection.py') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index 27734f80..540e7558 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -52,7 +52,7 @@ class StatusMixIn(object): logger.warning('connection refused') return if not state: - logger.debug('no state') + #logger.debug('no state') return (ts, status_step, ok, ip, remote) = state -- cgit v1.2.3 From bf39c45eddc62733fdb72b4f46cdb81ec649cb30 Mon Sep 17 00:00:00 2001 From: kali Date: Wed, 16 Jan 2013 00:58:22 +0900 Subject: handle loss of tun iface trigger only one dialog and disconnect. additional cleanup of log handling. --- src/leap/eip/eipconnection.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/leap/eip/eipconnection.py') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index 540e7558..20b45e36 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -27,6 +27,8 @@ class StatusMixIn(object): # Should separate EIPConnectionStatus (self.status) # from the OpenVPN state/status command and parsing. + ERR_CONNREFUSED = False + def connection_state(self): """ returns the current connection state @@ -49,7 +51,9 @@ class StatusMixIn(object): state = self.get_connection_state() except eip_exceptions.ConnectionRefusedError: # connection refused. might be not ready yet. - logger.warning('connection refused') + if not self.ERR_CONNREFUSED: + logger.warning('connection refused') + self.ERR_CONNREFUSED = True return if not state: #logger.debug('no state') -- cgit v1.2.3 From 407b030bb7d27b797fb27254710a358c9c69f8be Mon Sep 17 00:00:00 2001 From: kali Date: Thu, 24 Jan 2013 01:57:28 +0900 Subject: catch missing messages on last page of wizard --- src/leap/eip/eipconnection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/leap/eip/eipconnection.py') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index 20b45e36..d012c567 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -177,7 +177,7 @@ class EIPConnection(OpenVPNConnection, StatusMixIn): super(EIPConnection, self).__init__(*args, **kwargs) - def connect(self): + def connect(self, **kwargs): """ entry point for connection process """ -- cgit v1.2.3