-
Notifications
You must be signed in to change notification settings - Fork 0
/
funwithflags.py
38 lines (33 loc) · 1.03 KB
/
funwithflags.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
from flask import Flask
from flask import request
import subprocess
app = Flask(__name__)
task_list = []
cmd_output = {}
index_counter = 0
@app.route('/')
def hello_world():
return 'Hello, World! This is fun with flags'
@app.route('/cmd', methods = ['POST'])
def run_command_and_store_output_and_command():
global task_list
global cmd_output
global index_counter
index_counter += 1
task_list = task_list + [request.json['command']]
print(str(task_list) + '\n')
cmd = request.json['command'].split()
p = subprocess.Popen(cmd, stdout = subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
out,err = p.communicate()
cmd_output[index_counter] = out
print(str(cmd_output) + '\n')
return 'Task id:' + str(index_counter) + '\n'
@app.route('/tasklist', methods = ['GET'])
def list_tasks():
return str(task_list)
@app.route('/spectask/<id>', methods = ['GET'])
def specific_task(id):
print(id)
return str(cmd_output[int(id)])