forked from easyctf/easyctf-2017-problems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
30 lines (27 loc) · 893 Bytes
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from flask import Flask, request
from qrt import generate
from base64 import b64encode
from binascii import b2a_base64
from cStringIO import StringIO
from traceback import format_exc
app = Flask(__name__)
@app.route("/", methods=["GET", "POST"])
def index():
try:
html = "<title>hex qr</title><form method=post>enter a string: <input type=text name=text value='%s' autocomplete=off autofocus /></form>"
if request.method == "POST":
if not request.form.get("text"):
html %= ""
html += "<p>empty</p>"
else:
html %= request.form["text"]
im = generate(request.form["text"])
buf = StringIO()
im.save(buf, format="JPEG")
html += "<img src='data:image/jpeg;base64,%s'>" % b2a_base64(buf.getvalue())
else:
html %= ""
return html
except:
return "<!--\nthere's a problem, here's the details:\n%s\n-->" % format_exc()
app.run(host="0.0.0.0", port=5000)