summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap/bitmask/core')
-rw-r--r--src/leap/bitmask/core/_web.py7
-rw-r--r--src/leap/bitmask/core/dispatcher.py59
-rw-r--r--src/leap/bitmask/core/service.py18
3 files changed, 69 insertions, 15 deletions
diff --git a/src/leap/bitmask/core/_web.py b/src/leap/bitmask/core/_web.py
index 3f39e43..c597d18 100644
--- a/src/leap/bitmask/core/_web.py
+++ b/src/leap/bitmask/core/_web.py
@@ -71,10 +71,17 @@ class HTTPDispatcherService(service.Service):
# TODO use endpoints instead
self.listener = reactor.listenTCP(self.port, site,
interface='127.0.0.1')
+ self.running = True
def stopService(self):
self.site.stopFactory()
self.listener.stopListening()
+ self.running = False
+
+ def do_status(self):
+ status = 'running' if self.running else 'disabled'
+ return {'web': status}
+
class Api(Resource):
diff --git a/src/leap/bitmask/core/dispatcher.py b/src/leap/bitmask/core/dispatcher.py
index 0ea4e47..368a5bb 100644
--- a/src/leap/bitmask/core/dispatcher.py
+++ b/src/leap/bitmask/core/dispatcher.py
@@ -39,9 +39,12 @@ class SubCommand(object):
__metaclass__ = APICommand
def dispatch(self, service, *parts, **kw):
- subcmd = parts[1]
+ try:
+ subcmd = parts[1]
+ _method = getattr(self, 'do_' + subcmd.upper(), None)
+ except IndexError:
+ _method = None
- _method = getattr(self, 'do_' + subcmd.upper(), None)
if not _method:
raise RuntimeError('No such subcommand')
return defer.maybeDeferred(_method, service, *parts, **kw)
@@ -155,6 +158,27 @@ class MailCmd(SubCommand):
return d
+class WebUICmd(SubCommand):
+
+ label = 'web'
+
+ @register_method('dict')
+ def do_ENABLE(self, service, *parts, **kw):
+ d = service.do_enable_service(self.label)
+ return d
+
+ @register_method('dict')
+ def do_DISABLE(self, service, *parts, **kw):
+ d = service.do_disable_service(self.label)
+ return d
+
+ @register_method('dict')
+ def do_STATUS(self, webui, *parts, **kw):
+ print 'webui', webui
+ d = webui.do_status()
+ return d
+
+
class KeysCmd(SubCommand):
label = 'keys'
@@ -267,6 +291,7 @@ class CommandDispatcher(object):
self.subcommand_mail = MailCmd()
self.subcommand_keys = KeysCmd()
self.subcommand_events = EventsCmd()
+ self.subcommand_webui = WebUICmd()
# XXX --------------------------------------------
# TODO move general services to another subclass
@@ -298,7 +323,7 @@ class CommandDispatcher(object):
def do_EIP(self, *parts):
eip = self._get_service(self.subcommand_eip.label)
if not eip:
- return _format_result('eip: disabled')
+ return _format_result({'eip': 'disabled'})
subcmd = parts[1]
dispatch = self._subcommand_eip.dispatch
@@ -322,16 +347,39 @@ class CommandDispatcher(object):
kw = {'bonafide': bonafide}
if not mail:
- return _format_result('mail: disabled')
+ return _format_result({'mail': 'disabled'})
if subcmd == 'disable':
d = dispatch(self.core)
- else:
+ elif subcmd != 'enable':
d = dispatch(mail, *parts, **kw)
d.addCallbacks(_format_result, _format_error)
return d
+
+ def do_WEBUI(self, *parts):
+ subcmd = parts[1]
+ dispatch = self.subcommand_webui.dispatch
+
+ if subcmd == 'enable':
+ d = dispatch(self.core, *parts)
+
+ webui_label = 'web'
+ webui = self._get_service(webui_label)
+ kw = {}
+
+ if not webui:
+ return _format_result({'webui': 'disabled'})
+ if subcmd == 'disable':
+ d = dispatch(self.core, *parts)
+ elif subcmd != 'enable':
+ d = dispatch(webui, *parts, **kw)
+
+ d.addCallbacks(_format_result, _format_error)
+ return d
+
+
def do_KEYS(self, *parts):
dispatch = self.subcommand_keys.dispatch
@@ -353,6 +401,7 @@ class CommandDispatcher(object):
d.addCallbacks(_format_result, _format_error)
return d
+
def dispatch(self, msg):
cmd = msg[0]
diff --git a/src/leap/bitmask/core/service.py b/src/leap/bitmask/core/service.py
index b473f58..c254564 100644
--- a/src/leap/bitmask/core/service.py
+++ b/src/leap/bitmask/core/service.py
@@ -81,7 +81,7 @@ class BitmaskBackend(configurable.ConfigurableService):
def init_bonafide(self):
bf = BonafideService(self.basedir)
- bf.setName("bonafide")
+ bf.setName('bonafide')
bf.setServiceParent(self)
# TODO ---- these hooks should be activated only if
# (1) we have enabled that service
@@ -119,9 +119,9 @@ class BitmaskBackend(configurable.ConfigurableService):
zs.setServiceParent(self)
def init_web(self):
- # FIXME try to import leap.bitmask_www and fail otherwise
- http = _web.HTTPDispatcherService(self)
- http.setServiceParent(self)
+ service = _web.HTTPDispatcherService
+ web = self._maybe_start_service(
+ 'web', service, self)
def init_websockets(self):
from leap.bitmask.core import websocket
@@ -169,15 +169,13 @@ class BitmaskBackend(configurable.ConfigurableService):
elif service == 'web':
self.init_web()
- self.init_http()
-
- return 'ok'
+ return {'enabled': 'ok'}
def do_disable_service(self, service):
assert service in self.service_names
# TODO -- should stop also?
self.set_config('services', service, 'False')
- return 'ok'
+ return {'disabled': 'ok'}
class BackendCommands(object):
@@ -191,7 +189,7 @@ class BackendCommands(object):
def do_status(self):
# we may want to make this tuple a class member
- services = ('soledad', 'keymanager', 'mail', 'eip')
+ services = ('soledad', 'keymanager', 'mail', 'eip', 'web')
status = {}
for name in services:
@@ -212,7 +210,7 @@ class BackendCommands(object):
def do_stats(self):
log.msg('BitmaskCore Service STATS')
mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
- return {'mem_usage': '%s KB' % (mem / 1024)}
+ return {'mem_usage': '%s MB' % (mem / 1024)}
def do_shutdown(self):
self.core.stopService()