forked from eshaan7/Flask-Shell2HTTP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_script.py
More file actions
42 lines (34 loc) · 942 Bytes
/
run_script.py
File metadata and controls
42 lines (34 loc) · 942 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
36
37
38
39
40
41
42
# system imports
import requests
# web imports
from flask import Flask
from flask_executor import Executor
from flask_shell2http import Shell2HTTP
# Flask application instance
app = Flask(__name__)
# application factory
executor = Executor(app)
shell2http = Shell2HTTP(app, executor, base_url_prefix="/scripts/")
shell2http.register_command(endpoint="hacktheplanet", command_name="./fuxsocy.py")
# Example route. Go to "/" to execute.
@app.route("/")
def test():
"""
The final executed command becomes:
```bash
$ ./fuxsocy.py
```
"""
url = "http://localhost:4000/scripts/hacktheplanet"
# request without any data
resp = requests.post(url)
resp_data = resp.json()
print(resp_data)
key = resp_data["key"]
if key:
report = requests.get(f"{url}?key={key}")
return report.json()
return resp_data
# Application Runner
if __name__ == "__main__":
app.run(port=4000)