summaryrefslogtreecommitdiff
path: root/src/leap/eip/openvpnconnection.py
diff options
context:
space:
mode:
authorkali <kali@leap.se>2012-08-22 01:30:37 +0900
committerkali <kali@leap.se>2012-08-22 01:30:37 +0900
commit560232609ef229d46932f8ffcd66b8e114e8b3e6 (patch)
treecc39b180c09711eeba6bb858cdea05f4f0fbda0c /src/leap/eip/openvpnconnection.py
parentaf77050ce07ad884a39459a12bf22b74f6a858ab (diff)
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.
Diffstat (limited to 'src/leap/eip/openvpnconnection.py')
-rw-r--r--src/leap/eip/openvpnconnection.py48
1 files changed, 18 insertions, 30 deletions
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):