-
Notifications
You must be signed in to change notification settings - Fork 2
/
proxy.py
39 lines (29 loc) · 1.02 KB
/
proxy.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
31
32
33
34
35
36
37
38
39
import flask
import subprocess
proxy = flask.Flask(__name__)
@proxy.route("/init", methods=[ "POST" ])
def init():
return flask.jsonify(ok=True)
@proxy.route("/run", methods=[ "POST" ])
def run():
msg = flask.request.get_json(force=True, silent=True)
if not msg or not isinstance(msg, dict):
r = flask.jsonify({ "error": "Invalid payload." })
r.status_code = 400
return r
else:
input_string = msg.get("value", {}).get("input", {})
with open("/root/dos/INPUT.STR", "w") as fp:
fp.write("\"%s\"\n" % input_string)
subprocess.call([
"dosbox", "./PRINT.EXE", "-c", "C:\\QBASIC.EXE /run C:\\MORSE.BAS > C:\\LOG.TXT", "-exit"
], cwd="/root/dos")
output = "???"
try:
with open("/root/dos/LOG.TXT", "r") as fp:
output = fp.read().strip()
except e:
pass
return flask.jsonify(input=input_string, output=output)
if __name__ == "__main__":
proxy.run(host='0.0.0.0', port=8080)