summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/leap/base/checks.py23
-rw-r--r--src/leap/base/network.py6
-rw-r--r--src/leap/eip/eipconnection.py19
-rw-r--r--src/leap/eip/openvpnconnection.py63
4 files changed, 73 insertions, 38 deletions
diff --git a/src/leap/base/checks.py b/src/leap/base/checks.py
index 84f9dd46..7285e74f 100644
--- a/src/leap/base/checks.py
+++ b/src/leap/base/checks.py
@@ -16,13 +16,9 @@ class LeapNetworkChecker(object):
"""
all network related checks
"""
- # #718
- # XXX get provider gateway as a parameter
- # for constructor.
- # def __init__(self, *args, **kwargs):
- # ...
- # provider_gw = kwargs.pop('provider_gw', None)
- # self.provider_gateway = provider_gw
+ def __init__(self, *args, **kwargs):
+ provider_gw = kwargs.pop('provider_gw', None)
+ self.provider_gateway = provider_gw
def run_all(self, checker=None):
if not checker:
@@ -34,15 +30,8 @@ class LeapNetworkChecker(object):
checker.check_internet_connection()
checker.is_internet_up()
- # XXX We are pinging the default gateway for our connection right?
- # kali: 2012-10-05 20:59 -- I think we should get
- # also the default gateway and ping it instead.
- checker.ping_gateway()
-
- # something like: ?
- # see __init__ above
- # if self.provider_gateway:
- # checker.ping_gateway(self.provider_gateway)
+ if self.provider_gateway:
+ checker.ping_gateway(self.provider_gateway)
def check_internet_connection(self):
try:
@@ -65,7 +54,7 @@ class LeapNetworkChecker(object):
def is_internet_up(self):
iface, gateway = self.get_default_interface_gateway()
- self.ping_gateway(self)
+ self.ping_gateway(self.provider_gateway)
def check_tunnel_default_interface(self):
"""
diff --git a/src/leap/base/network.py b/src/leap/base/network.py
index e90139c4..3891b00a 100644
--- a/src/leap/base/network.py
+++ b/src/leap/base/network.py
@@ -3,6 +3,7 @@ from __future__ import (print_function)
import logging
import threading
+from leap.eip.config import get_eip_gateway
from leap.base.checks import LeapNetworkChecker
from leap.base.constants import ROUTE_CHECK_INTERVAL
from leap.base.exceptions import TunnelNotDefaultRouteError
@@ -29,7 +30,8 @@ class NetworkCheckerThread(object):
# XXX get provider_gateway and pass it to checker
# see in eip.config for function
# #718
- self.checker = LeapNetworkChecker()
+ self.checker = LeapNetworkChecker(
+ provider_gw = get_eip_gateway())
def start(self):
self.process_handle = self._launch_recurrent_network_checks(
@@ -55,6 +57,8 @@ class NetworkCheckerThread(object):
break
except TunnelNotDefaultRouteError:
# XXX ??? why do we sleep here???
+ # aa: If the openvpn isn't up and running yet,
+ # let's give it a moment to breath.
sleep(1)
fail_observer_dict = dict(((
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):
#"""
diff --git a/src/leap/eip/openvpnconnection.py b/src/leap/eip/openvpnconnection.py
index 14839f6b..d93bc40f 100644
--- a/src/leap/eip/openvpnconnection.py
+++ b/src/leap/eip/openvpnconnection.py
@@ -168,24 +168,58 @@ to be triggered for each one of them.
for process in psutil.get_process_list():
if process.name == "openvpn":
logger.debug('an openvpn instance is already running.')
- raise eip_exceptions.OpenVPNAlreadyRunning
+ logger.debug('attempting to stop openvpn instance.')
+ if not self._stop():
+ raise eip_exceptions.OpenVPNAlreadyRunning
logger.debug('no openvpn instance found.')
def cleanup(self):
"""
- terminates child subprocess
+ terminates openvpn child subprocess
"""
- # XXX we should send a quit process using management
- # interface.
if self.subp:
- try:
- self.subp.terminate()
- except OSError:
- logger.error('cannot terminate subprocess!'
+ self._stop()
+ RETCODE = self.subp.wait()
+ if RETCODE:
+ logger.error('cannot terminate subprocess! '
'(maybe openvpn still running?)')
- #
+ def _stop(self):
+ """
+ stop openvpn process
+ """
+ logger.debug("disconnecting...")
+ self._send_command("signal SIGTERM\n")
+
+ if self.subp:
+ return True
+
+ #shutting openvpn failured
+ #try patching in old openvpn host and trying again
+ process = self._get_openvpn_process()
+ if process:
+ self.host = \
+ process.cmdline[process.cmdline.index("--management") + 1]
+ self._send_command("signal SIGTERM\n")
+
+ #make sure the process was terminated
+ process = self._get_openvpn_process()
+ if not process:
+ logger.debug("Exisiting OpenVPN Process Terminated")
+ return True
+ else:
+ logger.error("Unable to terminate exisiting OpenVPN Process.")
+ return False
+
+ return True
+
+ def _get_openvpn_process(self):
+ for process in psutil.get_process_list():
+ if process.name == "openvpn":
+ return process
+ return None
+
# management methods
#
# XXX REVIEW-ME
@@ -221,9 +255,16 @@ to be triggered for each one of them.
"""
Read as much as available. Position seek pointer to end of stream
"""
- b = self.tn.read_eager()
- while b:
+ try:
b = self.tn.read_eager()
+ except EOFError:
+ logger.debug("Could not read from socket. Assuming it died.")
+ return
+ while b:
+ try:
+ b = self.tn.read_eager()
+ except EOFError:
+ logger.debug("Could not read from socket. Assuming it died.")
def connected(self):
"""