-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
56 lines (41 loc) · 1.41 KB
/
main.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from flask import Flask, request, make_response, redirect
from werkzeug.security import safe_join
from pathlib import Path
import subprocess, html
app = Flask("reflectionwebserver")
@app.route("/")
def index():
return redirect("/upload")
@app.route("/upload", methods=["GET", "POST"])
def upload():
if request.method == "POST":
if len(request.files) != 1:
resp = make_response()
resp.status_code = 400
resp.set_data("Wrong number of files.\n")
return resp
fileitem = request.files["file"]
fname = fileitem.filename.replace(".jar", "")
folder = safe_join(
"./tmp",
fname,
)
file = safe_join(folder, "tmp.jar")
if file == None:
return "Unsafe file name detected"
Path(file).parents[0].mkdir(parents=True, exist_ok=True)
fileitem.save(file)
process = subprocess.Popen(["java", "Main", file], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out = process.communicate()
return html.escape(f"stdout: {out[0]}, stderr: {out[1]}")
else:
return """
<!doctype html>
<title>Upload new File</title>
<h1>Upload new File</h1>
<form method=post enctype=multipart/form-data>
<input type=file name=file>
<input type=submit value=Upload>
</form>"""
if __name__ == "__main__":
app.run("0.0.0.0")