summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2017-08-11 03:21:35 +0200
committerKali Kaneko <kali@leap.se>2017-08-11 14:21:58 -0400
commit4a7e29b6eae34f34016c9b409bd887c74b949ca4 (patch)
treea343c5de481f888c45c527401e13672ade0ab041
parentd64f3c22c132c5de0d759d1e76ff7ced054bfcaa (diff)
[feature] add vpn list command
-rw-r--r--src/leap/bitmask/cli/command.py22
-rw-r--r--src/leap/bitmask/cli/vpn.py5
-rw-r--r--src/leap/bitmask/core/dispatcher.py15
-rw-r--r--src/leap/bitmask/vpn/service.py25
4 files changed, 52 insertions, 15 deletions
diff --git a/src/leap/bitmask/cli/command.py b/src/leap/bitmask/cli/command.py
index cc3514b0..1daadc5e 100644
--- a/src/leap/bitmask/cli/command.py
+++ b/src/leap/bitmask/cli/command.py
@@ -39,10 +39,9 @@ def _print_result(result):
def default_dict_printer(result):
- if not result:
- return
- for key, value in result.items():
- if value is not str:
+
+ def pprint(value):
+ if not isinstance(value, str):
value = str(value)
if value in ('OFF', 'OFFLINE', 'ABORTED', 'False'):
color = Fore.RED
@@ -50,6 +49,21 @@ def default_dict_printer(result):
color = Fore.GREEN
print(Fore.RESET + key.ljust(10) + color + value + Fore.RESET)
+ if not result:
+ return
+
+ for key, value in result.items():
+ if isinstance(value, list):
+ if isinstance(value[0], list):
+ value = map(lambda l: ' '.join(l), value)
+ for item in value:
+ pprint('\t' + item)
+ else:
+ value = ' '.join(value)
+ pprint(value)
+ else:
+ pprint(value)
+
def print_status(status, depth=0):
diff --git a/src/leap/bitmask/cli/vpn.py b/src/leap/bitmask/cli/vpn.py
index 219cac17..44556ac2 100644
--- a/src/leap/bitmask/cli/vpn.py
+++ b/src/leap/bitmask/cli/vpn.py
@@ -37,6 +37,7 @@ SUBCOMMANDS:
stop Stop VPN
status Display status about the VPN
check Check whether VPN service is properly configured
+ list List the configured gateways
get_cert Get VPN Certificate from provider
install Install helpers (needs root)
uninstall Uninstall helpers (needs root)
@@ -94,6 +95,10 @@ SUBCOMMANDS:
return self._send(command.default_dict_printer)
+ def list(self, raw_args):
+ self.data += ['list']
+ return self._send(command.default_dict_printer)
+
def get_cert(self, raw_args):
parser = argparse.ArgumentParser(
description='Bitmask VPN cert fetcher',
diff --git a/src/leap/bitmask/core/dispatcher.py b/src/leap/bitmask/core/dispatcher.py
index 3d6f6704..7a2d48a2 100644
--- a/src/leap/bitmask/core/dispatcher.py
+++ b/src/leap/bitmask/core/dispatcher.py
@@ -108,8 +108,7 @@ class UserCmd(SubCommand):
label = 'bonafide.user'
- @register_method("{'srp_token': unicode, 'uuid': unicode "
- "'lcl_token': unicode}")
+ @register_method("{'srp_token': unicode, 'uuid': unicode}")
def do_AUTHENTICATE(self, bonafide, *parts):
try:
user, password = parts[2], parts[3]
@@ -122,15 +121,8 @@ class UserCmd(SubCommand):
if parts[4] == 'True':
autoconf = True
- # FIXME We still SHOULD pass a local token
- # even if the SRP authentication times out!!!
- def add_local_token(result):
- result['lcl_token'] = bonafide.local_tokens.get(user)
- return result
-
d = defer.maybeDeferred(
bonafide.do_authenticate, user, password, autoconf)
- d.addCallback(add_local_token)
return d
@register_method("{'signup': 'ok', 'user': str}")
@@ -240,6 +232,11 @@ class VPNCmd(SubCommand):
d = vpn.do_uninstall()
return d
+ @register_method('dict')
+ def do_LIST(self, vpn, *parts):
+ d = vpn.do_list()
+ return d
+
class MailCmd(SubCommand):
diff --git a/src/leap/bitmask/vpn/service.py b/src/leap/bitmask/vpn/service.py
index 8bcee2e8..b0dcba86 100644
--- a/src/leap/bitmask/vpn/service.py
+++ b/src/leap/bitmask/vpn/service.py
@@ -190,14 +190,35 @@ class VPNService(HookableService):
return {'uninstall': 'ok'}
@defer.inlineCallbacks
+ def do_list(self):
+ bonafide = self.parent.getServiceNamed("bonafide")
+ _providers = yield bonafide.do_provider_list()
+ providers = [p['domain'] for p in _providers]
+ provider_dict = {}
+ for provider in providers:
+ try:
+ config = yield bonafide.do_provider_read(provider, 'eip')
+ except ValueError:
+ continue
+ locations = config.locations
+ info = tuple([
+ ('[%s]' % locations[loc]['country_code'],
+ locations[loc]['name'],
+ '(UTC%s)' % locations[loc]['timezone'])
+ for loc in locations])
+ provider_dict[provider] = info
+ defer.returnValue(provider_dict)
+
+
+ @defer.inlineCallbacks
def _setup(self, provider):
"""Set up TunnelManager for a specified provider.
:param provider: the provider to use, e.g. 'demo.bitmask.net'
:type provider: str"""
- bonafide = self.parent.getServiceNamed("bonafide")
- config = yield bonafide.do_provider_read(provider, "eip")
+ bonafide = self.parent.getServiceNamed('bonafide')
+ config = yield bonafide.do_provider_read(provider, 'eip')
sorted_gateways = GatewaySelector(
config.gateways, config.locations).select_gateways()