From d0540e808749ff9f9e90ec5e055168f5f408e51b Mon Sep 17 00:00:00 2001 From: antialias Date: Mon, 1 Oct 2012 16:58:39 -0400 Subject: Now throws a CriticalError when an pre-exisiting openvpn istance is found. --- src/leap/eip/exceptions.py | 7 +++++++ src/leap/eip/openvpnconnection.py | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'src/leap/eip') diff --git a/src/leap/eip/exceptions.py b/src/leap/eip/exceptions.py index f048621f..bb375cf0 100644 --- a/src/leap/eip/exceptions.py +++ b/src/leap/eip/exceptions.py @@ -93,6 +93,13 @@ class LeapBadConfigFetchedError(Warning): message = "provider sent a malformed json file" usermessage = "an error occurred during configuratio of leap services" + +class OpenVPNAlreadyRunning(EIPClientError): + message = "Another OpenVPN Process is already running." + usermessage = ("Another OpenVPN Process has been detect it." + "Please close it before starting LEAP") + + # # errors still needing some love # diff --git a/src/leap/eip/openvpnconnection.py b/src/leap/eip/openvpnconnection.py index f4d1c449..a835ead9 100644 --- a/src/leap/eip/openvpnconnection.py +++ b/src/leap/eip/openvpnconnection.py @@ -3,6 +3,7 @@ OpenVPN Connection """ from __future__ import (print_function) import logging +import psutil import socket import time from functools import partial @@ -87,6 +88,7 @@ to be triggered for each one of them. def run_openvpn_checks(self): logger.debug('running openvpn checks') + self._check_if_running_instance() self._set_ovpn_command() self._check_vpn_keys() @@ -156,9 +158,20 @@ to be triggered for each one of them. raise eip_exceptions.EIPNoCommandError if self.subp is not None: logger.debug('cowardly refusing to launch subprocess again') - return + self._launch_openvpn() + def _check_if_running_instance(self): + """ + check if openvpn is already running + """ + 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('no openvpn instance found.') + def cleanup(self): """ terminates child subprocess -- cgit v1.2.3 From cdc80a4b84bc68dd179376e8c4cbd7db478ffd32 Mon Sep 17 00:00:00 2001 From: kali Date: Fri, 5 Oct 2012 19:57:42 +0900 Subject: typo --- src/leap/eip/exceptions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/leap/eip') diff --git a/src/leap/eip/exceptions.py b/src/leap/eip/exceptions.py index bb375cf0..a6216caa 100644 --- a/src/leap/eip/exceptions.py +++ b/src/leap/eip/exceptions.py @@ -96,8 +96,8 @@ class LeapBadConfigFetchedError(Warning): class OpenVPNAlreadyRunning(EIPClientError): message = "Another OpenVPN Process is already running." - usermessage = ("Another OpenVPN Process has been detect it." - "Please close it before starting LEAP") + usermessage = ("Another OpenVPN Process has been detected." + "Please close it before starting leap-client") # -- cgit v1.2.3