File size: 1,028 Bytes
dcfa366
7f07db8
f9f8d44
dcfa366
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f9f8d44
 
 
dcfa366
 
 
5f32ca7
dcfa366
 
5f32ca7
5ba3309
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
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.method)
    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)