|
from flask import Flask,request,render_template,send_file |
|
import os |
|
|
|
app=Flask(__name__) |
|
MESSAGED={'title':'Script Server', |
|
'messageL':['script in "script" parameter or field of json input to /run will be run']} |
|
|
|
@app.route("/file/<string:filename>") |
|
def return_pdf(filename): |
|
return send_file(filename) |
|
|
|
@app.route('/run',methods=['GET','POST']) |
|
def run_script(): |
|
script='' |
|
|
|
print(request) |
|
if request.method=='GET': |
|
script=request.args.get('script') |
|
print('I am in get') |
|
elif request.method=='POST': |
|
print('I am in post') |
|
data=request.get_json() |
|
if 'script' in data: script=data['script'] |
|
if script=='' or script is None: return 'INVALID' |
|
os.system(script+' > ./out.txt') |
|
with open('./out.txt','r') as f: output=f.read() |
|
return output |
|
|
|
@app.route('/',methods=['GET', 'POST']) |
|
def home(): |
|
return render_template('home.html',messageD=MESSAGED) |
|
|
|
if __name__=='__main__': |
|
app.run(host="0.0.0.0", port=7860) |
|
|
|
|
|
|