diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2014-12-27 23:06:51 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2014-12-27 23:06:51 +1300 |
commit | 8a8437470e224ee53acbd9a353c7d01a83168cd4 (patch) | |
tree | 171a7b465155959bdd0b1d210f03cfcf6067a656 /libmproxy/onboarding | |
parent | 1f454b577f7db434d79388eb101006b065f62a2b (diff) | |
download | mitmproxy-8a8437470e224ee53acbd9a353c7d01a83168cd4.tar.gz mitmproxy-8a8437470e224ee53acbd9a353c7d01a83168cd4.tar.bz2 mitmproxy-8a8437470e224ee53acbd9a353c7d01a83168cd4.zip |
Move onboarding app to Tornado
Two reasons for this. First, this removes flask and its dependencies, which are
quite sizeable. Second, pyinstaller now barfs on simplejson, which is a Flask
dependency. I just don't have time to fix this upstream, so doing what we
should be doing anyway is a no-brainer.
Diffstat (limited to 'libmproxy/onboarding')
-rw-r--r-- | libmproxy/onboarding/app.py | 83 | ||||
-rw-r--r-- | libmproxy/onboarding/templates/frame.html | 4 | ||||
-rw-r--r-- | libmproxy/onboarding/templates/index.html | 2 | ||||
-rw-r--r-- | libmproxy/onboarding/templates/layout.html | 2 |
4 files changed, 71 insertions, 20 deletions
diff --git a/libmproxy/onboarding/app.py b/libmproxy/onboarding/app.py index 4023fae2..f0aecc15 100644 --- a/libmproxy/onboarding/app.py +++ b/libmproxy/onboarding/app.py @@ -1,29 +1,80 @@ from __future__ import absolute_import -import flask import os +import tornado.web +import tornado.wsgi +import tornado.template + +from .. import utils from ..proxy import config -mapp = flask.Flask(__name__) -mapp.debug = True + +loader = tornado.template.Loader(utils.pkg_data.path("onboarding/templates")) + + +class Adapter(tornado.wsgi.WSGIAdapter): + # Tornado doesn't make the WSGI environment available to pages, so this + # hideous monkey patch is the easiest way to get to the mitmproxy.master + # variable. + def __init__(self, application): + self._application = application + + def application(self, request): + request.master = self.environ["mitmproxy.master"] + return self._application(request) + + def __call__(self, environ, start_response): + self.environ = environ + return tornado.wsgi.WSGIAdapter.__call__( + self, + environ, + start_response + ) -def master(): - return flask.request.environ["mitmproxy.master"] +class Index(tornado.web.RequestHandler): + def get(self): + t = loader.load("index.html") + self.write(t.generate()) -@mapp.route("/") -def index(): - return flask.render_template("index.html", section="home") +class PEM(tornado.web.RequestHandler): + def get(self): + p = os.path.join( + self.request.master.server.config.cadir, + config.CONF_BASENAME + "-ca-cert.pem" + ) + self.set_header( + "Content-Type", "application/x-x509-ca-cert" + ) + self.write(open(p, "rb").read()) -@mapp.route("/cert/pem") -def certs_pem(): - p = os.path.join(master().server.config.cadir, config.CONF_BASENAME + "-ca-cert.pem") - return flask.Response(open(p, "rb").read(), mimetype='application/x-x509-ca-cert') +class P12(tornado.web.RequestHandler): + def get(self): + p = os.path.join( + self.request.master.server.config.cadir, + config.CONF_BASENAME + "-ca-cert.p12" + ) + self.set_header( + "Content-Type", "application/x-pkcs12" + ) + self.write(open(p, "rb").read()) -@mapp.route("/cert/p12") -def certs_p12(): - p = os.path.join(master().server.config.cadir, config.CONF_BASENAME + "-ca-cert.p12") - return flask.Response(open(p, "rb").read(), mimetype='application/x-pkcs12') +application = tornado.web.Application( + [ + (r"/", Index), + (r"/cert/pem", PEM), + (r"/cert/p12", P12), + ( + r"/static/(.*)", + tornado.web.StaticFileHandler, + { + "path": utils.pkg_data.path("onboarding/static") + } + ), + ], + #debug=True +) +mapp = Adapter(application) diff --git a/libmproxy/onboarding/templates/frame.html b/libmproxy/onboarding/templates/frame.html index b5c5c67c..f00e1a66 100644 --- a/libmproxy/onboarding/templates/frame.html +++ b/libmproxy/onboarding/templates/frame.html @@ -3,7 +3,7 @@ <div class="row"> <div class="span12"> {% block body %} - {% endblock %} + {% end %} </div> </div> -{% endblock %} +{% end %} diff --git a/libmproxy/onboarding/templates/index.html b/libmproxy/onboarding/templates/index.html index 65fda5d2..1bcff1b8 100644 --- a/libmproxy/onboarding/templates/index.html +++ b/libmproxy/onboarding/templates/index.html @@ -32,4 +32,4 @@ between mitmproxy installations. </div> -{% endblock %} +{% end %} diff --git a/libmproxy/onboarding/templates/layout.html b/libmproxy/onboarding/templates/layout.html index 622858be..8726a788 100644 --- a/libmproxy/onboarding/templates/layout.html +++ b/libmproxy/onboarding/templates/layout.html @@ -25,7 +25,7 @@ <div class="container"> {% block content %} - {% endblock %} + {% end %} </div> </body> |