diff options
author | Ruben Pollan <meskio@sindominio.net> | 2017-08-02 00:05:25 +0200 |
---|---|---|
committer | Ruben Pollan <meskio@sindominio.net> | 2017-08-02 00:05:25 +0200 |
commit | c49293b7f3eff7a478fc388768366e7b025f7da0 (patch) | |
tree | 00e205a21f9541f5bd4debd57136eee9ecfdfcc8 /service/src/pixelated/resources | |
parent | ccb4f03fe5854793742bed68ee5a83c343899ee1 (diff) |
[feat] Display mixnet status on outgoing emails
Diffstat (limited to 'service/src/pixelated/resources')
-rw-r--r-- | service/src/pixelated/resources/mixnet_resource.py | 61 | ||||
-rw-r--r-- | service/src/pixelated/resources/root_resource.py | 2 |
2 files changed, 63 insertions, 0 deletions
diff --git a/service/src/pixelated/resources/mixnet_resource.py b/service/src/pixelated/resources/mixnet_resource.py new file mode 100644 index 00000000..aa895c91 --- /dev/null +++ b/service/src/pixelated/resources/mixnet_resource.py @@ -0,0 +1,61 @@ +# +# Copyright (c) 2017 LEAP +# +# Pixelated is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pixelated is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Pixelated. If not, see <http://www.gnu.org/licenses/>. + +import json + +from email.utils import parseaddr +from pixelated.resources import respond_json_deferred, BaseResource +from twisted.web import server +from twisted.logger import Logger +from txzmq import ZmqEndpoint, ZmqEndpointType +from txzmq import ZmqFactory, ZmqREQConnection + +from leap.bitmask.core import ENDPOINT + + +class MixnetResource(BaseResource): + # XXX: this is hacky, we should use bitmask.js properly in the web-ui + # But, if we and up doing zmq interface, we can do + # something more generic for all the API. + + isLeaf = True + log = Logger() + + def render_GET(self, request): + zf = ZmqFactory() + e = ZmqEndpoint(ZmqEndpointType.connect, ENDPOINT) + _conn = ZmqREQConnection(zf, e) + + _mail = self.mail_service(request) + userid = _mail.account_email + _, address = parseaddr(request.args.get('search')[0]) + + def callback(resp_json): + response = json.loads(resp_json[0]) + if response['error'] is not None: + respond_json_deferred(response['error'], request, status_code=404) + else: + respond_json_deferred(response['result'], request, status_code=200) + + def err(fail): + respond_json_deferred(str(fail), request, status_code=404) + + data = ["mail", "mixnet_status", userid, address] + d = _conn.sendMsg(*data) + d.addCallback(callback) + d.addErrback(err) + + return server.NOT_DONE_YET diff --git a/service/src/pixelated/resources/root_resource.py b/service/src/pixelated/resources/root_resource.py index b014a590..6398c000 100644 --- a/service/src/pixelated/resources/root_resource.py +++ b/service/src/pixelated/resources/root_resource.py @@ -35,6 +35,7 @@ from pixelated.resources.mail_resource import MailResource from pixelated.resources.mails_resource import MailsResource from pixelated.resources.tags_resource import TagsResource from pixelated.resources.keys_resource import KeysResource +from pixelated.resources.mixnet_resource import MixnetResource from twisted.web.resource import NoResource from twisted.web.static import File @@ -96,6 +97,7 @@ class RootResource(BaseResource): self._child_resources.add('backup-account', BackupAccountResource(self._services_factory, authenticator, provider)) self._child_resources.add('sandbox', SandboxResource(self._protected_static_folder)) self._child_resources.add('keys', KeysResource(self._services_factory)) + self._child_resources.add('mixnet', MixnetResource(self._services_factory)) self._child_resources.add(AttachmentsResource.BASE_URL, AttachmentsResource(self._services_factory)) self._child_resources.add('contacts', ContactsResource(self._services_factory)) self._child_resources.add('features', FeaturesResource(provider)) |