From 14f433c16de60753d122d5946df68e8e82285ca3 Mon Sep 17 00:00:00 2001 From: antialias Date: Mon, 19 Nov 2012 16:16:01 -0800 Subject: implemented abstracted layer with matching and passed callback. tests as well. --- src/leap/base/checks.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/leap/base/checks.py') diff --git a/src/leap/base/checks.py b/src/leap/base/checks.py index 4d4a5d8b..587012fb 100644 --- a/src/leap/base/checks.py +++ b/src/leap/base/checks.py @@ -12,6 +12,9 @@ from leap.base import exceptions logger = logging.getLogger(name=__name__) +#EVENTS OF NOTE +EVENT_CONNECT_REFUSED = "[ECONNREFUSED]: Connection refused (code=111)" + class LeapNetworkChecker(object): """ @@ -34,6 +37,8 @@ class LeapNetworkChecker(object): if self.provider_gateway: checker.ping_gateway(self.provider_gateway) + checker.parse_log_and_react([], ()) + def check_internet_connection(self): try: # XXX remove this hardcoded random ip @@ -136,3 +141,19 @@ class LeapNetworkChecker(object): return True except socket.gaierror: raise exceptions.CannotResolveDomainError + + def parse_log_and_react(self, log, error_matrix=None): + """ + compares the recent openvpn status log to + strings passed in and executes the callbacks passed in. + @param log: openvpn log + @type log: list of strings + @param error_matrix: tuples of strings and tuples of callbacks + @type error_matrix: tuples strings and call backs + """ + for line in log: + for each in error_matrix: + error, callbacks = each + if error in line: + for cb in callbacks: + cb() -- cgit v1.2.3 From 8139b39dedc3dc99d310d082f6edb10d2303a1ce Mon Sep 17 00:00:00 2001 From: antialias Date: Wed, 21 Nov 2012 11:06:19 -0800 Subject: added if callable sanity check. --- src/leap/base/checks.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/leap/base/checks.py') diff --git a/src/leap/base/checks.py b/src/leap/base/checks.py index 587012fb..e5767018 100644 --- a/src/leap/base/checks.py +++ b/src/leap/base/checks.py @@ -152,8 +152,10 @@ class LeapNetworkChecker(object): @type error_matrix: tuples strings and call backs """ for line in log: + # we could compile a regex here to save some cycles up -- kali for each in error_matrix: error, callbacks = each if error in line: for cb in callbacks: - cb() + if callable(cb): + cb() -- cgit v1.2.3