summaryrefslogtreecommitdiff
path: root/src/leap
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap')
-rw-r--r--src/leap/base/connection.py37
-rw-r--r--src/leap/baseapp/mainwindow.py3
-rw-r--r--src/leap/eip/eipconnection.py9
-rw-r--r--src/leap/eip/openvpnconnection.py48
4 files changed, 40 insertions, 57 deletions
diff --git a/src/leap/base/connection.py b/src/leap/base/connection.py
index cd0ae565..8cd78433 100644
--- a/src/leap/base/connection.py
+++ b/src/leap/base/connection.py
@@ -3,17 +3,8 @@ Base Connection Classs
"""
from __future__ import (division, unicode_literals, print_function)
-#XXX move these imports to util.coroutines!!!
-
-#import threading
-#from functools import partial
import logging
-#from leap.utils.coroutines import spawn_and_watch_process
-#from leap.baseapp.config import get_config, get_vpn_stdout_mockup
-#from leap.eip.vpnwatcher import EIPConnectionStatus, status_watcher
-from leap.eip.vpnmanager import ConnectionRefusedError
-
from leap.base.configuration import Configuration
from leap.base.authentication import Authentication
@@ -58,21 +49,21 @@ class Connection(Configuration, Authentication):
"""
return self.desired_connection_state
- def poll_connection_state(self):
- """
- """
- try:
- state = self.get_connection_state()
- except ConnectionRefusedError:
+ #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)
+ #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):
"""
diff --git a/src/leap/baseapp/mainwindow.py b/src/leap/baseapp/mainwindow.py
index c5bdd8e9..bc844437 100644
--- a/src/leap/baseapp/mainwindow.py
+++ b/src/leap/baseapp/mainwindow.py
@@ -13,9 +13,6 @@ from PyQt4.QtCore import (pyqtSlot, pyqtSignal, QTimer)
from leap.baseapp.dialogs import ErrorDialog
-#from leap.eip.conductor import (EIPConductor,
- #EIPNoCommandError)
-#from leap.eip.config import (EIPInitBadKeyFilePermError)
from leap.eip import exceptions as eip_exceptions
from leap.eip.eipconnection import EIPConnection
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):
diff --git a/src/leap/eip/openvpnconnection.py b/src/leap/eip/openvpnconnection.py
index 81e6b1ba..a230d229 100644
--- a/src/leap/eip/openvpnconnection.py
+++ b/src/leap/eip/openvpnconnection.py
@@ -9,6 +9,7 @@ from functools import partial
logging.basicConfig()
logger = logging.getLogger(name=__name__)
+logger.setLevel(logging.DEBUG)
from leap.base.connection import Connection
from leap.util.coroutines import spawn_and_watch_process
@@ -86,7 +87,7 @@ to be triggered for each one of them.
port = int(port)
self.port = port
self.password = password
- self.tn = None
+ #self.tn = None
def _set_autostart(self):
config = self.config
@@ -235,16 +236,11 @@ to be triggered for each one of them.
print('forgetting errors')
self.with_errors = False
- def connect(self):
+ def connect_to_management(self):
"""Connect to openvpn management interface"""
- try:
+ #logger.debug('connecting socket')
+ if hasattr(self, 'tn'):
self.close()
- except:
- #XXX don't like this general
- #catch here.
- raise
- if self.connected():
- return True
self.tn = UDSTelnet(self.host, self.port)
# XXX make password optional
@@ -273,47 +269,39 @@ to be triggered for each one of them.
Returns True if connected
rtype: bool
"""
- try:
- assert self.tn
- return True
- except:
- #XXX get rid of
- #this pokemon exception!!!
- return False
+ return hasattr(self, 'tn')
def close(self, announce=True):
"""
Close connection to openvpn management interface
"""
+ logger.debug('closing socket')
if announce:
self.tn.write("quit\n")
self.tn.read_all()
self.tn.get_socket().close()
del self.tn
- def _send_command(self, cmd, tries=0):
+ def _send_command(self, cmd):
"""
Send a command to openvpn and return response as list
"""
- if tries > 3:
- return []
- if self.tn is None:
- return []
+ #logger.debug('connected? %s' % self.connected())
if not self.connected():
try:
- self.connect()
+ #logger.debug('try to connect')
+ self.connect_to_management()
except eip_exceptions.MissingSocketError:
#XXX capture more helpful error
- #messages
- #pass
return self.make_error()
+ except:
+ raise
try:
- self.tn.write(cmd + "\n")
+ if hasattr(self, 'tn'):
+ self.tn.write(cmd + "\n")
except socket.error:
logger.error('socket error')
- print('socket error!')
self.close(announce=False)
- self._send_command(cmd, tries=tries + 1)
return []
buf = self.tn.read_until(b"END", 2)
self._seek_to_eof()
@@ -371,14 +359,14 @@ to be triggered for each one of them.
else:
return state[-1]
- def status(self):
+ def vpn_status(self):
"""
OpenVPN command: status
"""
status = self._send_command("status")
return status
- def status2(self):
+ def vpn_status2(self):
"""
OpenVPN command: last 2 statuses
"""
@@ -389,7 +377,7 @@ to be triggered for each one of them.
#
def get_status_io(self):
- status = self.status()
+ status = self.vpn_status()
if isinstance(status, str):
lines = status.split('\n')
if isinstance(status, list):