summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/vpn
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap/bitmask/vpn')
-rw-r--r--src/leap/bitmask/vpn/_control.py2
-rw-r--r--src/leap/bitmask/vpn/_status.py37
-rw-r--r--src/leap/bitmask/vpn/fw/firewall.py16
-rw-r--r--src/leap/bitmask/vpn/process.py4
-rw-r--r--src/leap/bitmask/vpn/service.py9
-rw-r--r--src/leap/bitmask/vpn/vpn.py17
6 files changed, 56 insertions, 29 deletions
diff --git a/src/leap/bitmask/vpn/_control.py b/src/leap/bitmask/vpn/_control.py
index 8dfe4c6..a490934 100644
--- a/src/leap/bitmask/vpn/_control.py
+++ b/src/leap/bitmask/vpn/_control.py
@@ -145,7 +145,7 @@ class VPNControl(object):
@property
def status(self):
if not self._vpnproc:
- return 'OFFLINE'
+ return {'status': 'off', 'error': None}
return self._vpnproc.status
@property
diff --git a/src/leap/bitmask/vpn/_status.py b/src/leap/bitmask/vpn/_status.py
index a0e3842..7c8ff6b 100644
--- a/src/leap/bitmask/vpn/_status.py
+++ b/src/leap/bitmask/vpn/_status.py
@@ -2,6 +2,8 @@ from itertools import chain, repeat
from twisted.logger import Logger
from ._human import bytes2human
+from leap.common.events import catalog, emit_async
+
logger = Logger()
@@ -24,7 +26,8 @@ class VPNStatus(object):
}
def __init__(self):
- self.status = 'OFFLINE'
+ self._status = 'off'
+ self.errcode = None
self._traffic_down = None
self._traffic_up = None
@@ -49,8 +52,14 @@ class VPNStatus(object):
self.set_status(status, errcode)
def set_status(self, status, errcode):
- self.status = status
+ if status in ("AUTH", "WAIT"):
+ status = "starting"
+ elif status == "CONNECTED":
+ status = "on"
+
+ self._status = status
self.errcode = errcode
+ emit_async(catalog.VPN_STATUS_CHANGED)
def set_traffic_status(self, status):
up, down = status
@@ -58,16 +67,30 @@ class VPNStatus(object):
self._traffic_down = down
def get_traffic_status(self):
- return {'down': bytes2human(self._traffic_down),
- 'up': bytes2human(self._traffic_up)}
+ down = None
+ up = None
+ if self._traffic_down:
+ down = bytes2human(self._traffic_down)
+ if self._traffic_up:
+ up = bytes2human(self._traffic_up)
+ return {'down': down, 'up': up}
+
+ @property
+ def status(self):
+ status = self.get_traffic_status()
+ status.update({
+ 'status': self._status,
+ 'error': self.errcode
+ })
+ return status
def _status_codes(self, event):
# TODO check good transitions
# TODO check valid states
_table = {
- "network_unreachable": ('OFFLINE', 'network unreachable'),
- "process_restart_tls": ('RESTARTING', 'restart tls'),
- "initialization_completed": ('ONLINE', None)
+ "network_unreachable": ('off', 'network unreachable'),
+ "process_restart_tls": ('starting', 'restart tls'),
+ "initialization_completed": ('on', None)
}
return _table.get(event.lower())
diff --git a/src/leap/bitmask/vpn/fw/firewall.py b/src/leap/bitmask/vpn/fw/firewall.py
index 5eace20..8b71a9f 100644
--- a/src/leap/bitmask/vpn/fw/firewall.py
+++ b/src/leap/bitmask/vpn/fw/firewall.py
@@ -23,6 +23,7 @@ import commands
import subprocess
from leap.bitmask.vpn.constants import IS_MAC
+from leap.common.events import catalog, emit_async
class FirewallManager(object):
@@ -44,7 +45,6 @@ class FirewallManager(object):
:param remotes: the gateway(s) that we will allow
:type remotes: list
"""
- self.status = 'OFF'
self._remotes = remotes
def start(self, restart=False):
@@ -66,12 +66,11 @@ class FirewallManager(object):
# FIXME -- use a processprotocol
exitCode = subprocess.call(cmd + gateways)
+ emit_async(catalog.VPN_STATUS_CHANGED)
if exitCode == 0:
- self.status = 'ON'
return True
else:
- self.status = 'OFF'
return False
# def tear_down_firewall(self):
@@ -85,11 +84,10 @@ class FirewallManager(object):
exitCode = subprocess.call(["pkexec", self.BITMASK_ROOT,
"firewall", "stop"])
+ emit_async(catalog.VPN_STATUS_CHANGED)
if exitCode == 0:
- self.status = 'OFF'
return True
else:
- self.status = 'ON'
return False
def is_up(self):
@@ -104,3 +102,11 @@ class FirewallManager(object):
output = commands.getstatusoutput(cmd)[0]
return output != 256
+
+ @property
+ def status(self):
+ status = 'off'
+ if self.is_up():
+ status = 'on'
+
+ return {'status': status, 'error': None}
diff --git a/src/leap/bitmask/vpn/process.py b/src/leap/bitmask/vpn/process.py
index cb67eff..6096a47 100644
--- a/src/leap/bitmask/vpn/process.py
+++ b/src/leap/bitmask/vpn/process.py
@@ -136,9 +136,9 @@ class VPNProcess(protocol.ProcessProtocol, _management.VPNManagement):
internet_error.ProcessDone, internet_error.ProcessTerminated)
if err == internet_error.ProcessDone:
- status, errmsg = 'OFFLINE', None
+ status, errmsg = 'off', None
elif err == internet_error.ProcessTerminated:
- status, errmsg = 'ABORTED', failure.value.exitCode
+ status, errmsg = 'failure', failure.value.exitCode
if errmsg:
logger.debug("processExited, status %d" % (errmsg,))
else:
diff --git a/src/leap/bitmask/vpn/service.py b/src/leap/bitmask/vpn/service.py
index b5d7e52..2c7c69c 100644
--- a/src/leap/bitmask/vpn/service.py
+++ b/src/leap/bitmask/vpn/service.py
@@ -80,11 +80,14 @@ class VPNService(HookableService):
return {'result': 'stopped'}
def do_status(self):
+ status = {
+ 'status': 'off',
+ 'error': None,
+ 'childrenStatus': {}
+ }
if self._vpn:
status = self._vpn.get_status()
- else:
- status = {'VPN': 'OFF'}
- status['domain'] = self._domain
+ status['domain'] = self._domain
return status
def do_check(self, domain):
diff --git a/src/leap/bitmask/vpn/vpn.py b/src/leap/bitmask/vpn/vpn.py
index e19f662..dc3062a 100644
--- a/src/leap/bitmask/vpn/vpn.py
+++ b/src/leap/bitmask/vpn/vpn.py
@@ -18,6 +18,7 @@
from colorama import Fore
+from leap.bitmask.util import merge_status
from leap.bitmask.vpn.manager import TunnelManager
from leap.bitmask.vpn.fw.firewall import FirewallManager
@@ -68,14 +69,8 @@ class VPNManager(object):
return True
def get_status(self):
- vpn_status = self._vpn.status
- # TODO use firewall.is_up instead
- fw_status = self._firewall.status
-
- result = {'VPN': vpn_status,
- 'firewall': fw_status}
- if vpn_status == 'CONNECTED':
- traffic = self._vpn.traffic_status
- result['↑↑↑'] = traffic['up']
- result['↓↓↓'] = traffic['down']
- return result
+ childrenStatus = {
+ "vpn": self._vpn.status,
+ "firewall": self._firewall.status
+ }
+ return merge_status(childrenStatus)