-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
33 lines (29 loc) · 1.1 KB
/
app.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
from flask import Flask
from flask import request, render_template
import subprocess, os
app = Flask(__name__)
@app.route('/', methods=['POST', 'GET'])
def index():
ip = request.remote_addr
if request.method == 'POST':
code = request.form.get('code')
if "os" in code or "subprocess" in code:
return render_template("index.html", success="Código contém bibliotecas não permitidas!")
f = open(str(ip), 'w+')
f.write(str(code))
return render_template("index.html", success="Código enviado com sucesso!")
else:
return render_template("index.html")
@app.route('/run', methods=['POST', 'GET'])
def run():
if request.method == 'POST':
try:
output = subprocess.check_output(["python /home/unclear/Projetos/pyweb-flask/" + str(request.remote_addr)], shell=True, stderr=subprocess.STDOUT)
output = output.decode("utf-8")
except subprocess.CalledProcessError as e:
return render_template("index.html", output=e.output.decode("utf-8"))
return render_template("index.html", output=output)
else:
return render_template("index.html")
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')