-
Notifications
You must be signed in to change notification settings - Fork 0
/
flask_server.py
executable file
·158 lines (140 loc) · 5.39 KB
/
flask_server.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!flask/bin/python
import os, subprocess
from flask import Flask, jsonify, request
from flask_cors import CORS, cross_origin
import requests, json
from ping_all import ping_all_main, ping_all_with_list
from logging_checks import logging_checks_main, logging_checks_with_list
from space_checks import space_checks_main, space_checks_with_list
from start_logging import start_logging_main, start_logging_with_list
from stop_logging import stop_logging_main, stop_logging_with_list
from clear_memory import clear_memory_main, clear_memory_with_list
from start_active_bots import start_active_bots_with_list
from start_passive_bots import start_passive_bots_with_list
from submission_server import request_job, upload_job
from reset_duckiebot import reset_duckiebot_with_list
from create_log import generate_log_file
app = Flask(__name__)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
@app.route('/lights_off', methods=['GET'])
@cross_origin()
def lights_off():
return jsonify({'success': True})
@app.route('/lights_on', methods=['GET'])
@cross_origin()
def lights_on():
return jsonify({'success': True})
@app.route('/ping', methods=['GET','POST'])
@cross_origin()
def ping_hosts():
if request.method == 'GET':
host, ping = ping_all_main()
return jsonify({'hostname': host, 'ping': ping})
else:
data=request.get_json()["list"]
host, ping = ping_all_with_list(data)
return jsonify({'hostname': host, 'ping': ping})
@app.route('/logging_checks', methods=['GET','POST'])
@cross_origin()
def logging_checker():
if request.method == 'GET':
host, check = logging_checks_main()
return jsonify({'hostname': host, 'logging_check': check})
else:
data=request.get_json()["list"]
host, check = logging_checks_with_list(data)
return jsonify({'hostname': host, 'logging_check': check})
@app.route('/storage_space_checks', methods=['GET','POST'])
@cross_origin()
def space_checker():
if request.method == 'GET':
host, check = space_checks_main()
return jsonify({'hostname': host, 'space_check': check})
else:
data=request.get_json()["list"]
host, check = space_checks_with_list(data)
return jsonify({'hostname': host, 'space_check': check})
@app.route('/start_logging', methods=['GET','POST'])
@cross_origin()
def logging_starter():
if request.method == 'GET':
host, check = start_logging_main()
return jsonify({'hostname': host, 'logging_start': check})
else:
data=request.get_json()["list"]
host, check = start_logging_with_list(data)
return jsonify({'hostname': host, 'logging_start': check})
@app.route('/stop_logging', methods=['GET','POST'])
@cross_origin()
def logging_stopper():
if request.method == 'GET':
host, check = stop_logging_main()
return jsonify({'hostname': host, 'logging_stop': check})
else:
data=request.get_json()["list"]
host, check = stop_logging_with_list(data)
return jsonify({'hostname': host, 'logging_stop': check})
@app.route('/clear_memory', methods=['GET','POST'])
@cross_origin()
def memory_clearer():
if request.method == 'GET':
host, check = clear_memory_main()
return jsonify({'hostname': host, 'clear_memory': check})
else:
data=request.get_json()["list"]
host, check = clear_memory_with_list(data)
return jsonify({'hostname': host, 'clear_memory': check})
@app.route('/start_active_bots', methods=['POST'])
@cross_origin()
def start_active():
bot_list=request.get_json()["list"]
container=request.get_json()["container"]
duration=int(request.get_json()["duration"])
host, check = start_active_bots_with_list(bot_list, container, duration)
return jsonify({'hostname': host, 'container': check})
@app.route('/start_passive_bots', methods=['POST'])
@cross_origin()
def start_passive():
bot_list=request.get_json()["list"]
demo=request.get_json()["demo"]
host, check = start_passive_bots_with_list(bot_list, demo)
return jsonify({'hostname': host, 'container': check})
@app.route('/toggle_switch', methods=['GET'])
@cross_origin()
def toggle_switch():
url = 'http://172.31.168.15/report'
response = requests.request('GET', url)
response = response.json()
return jsonify(response)
@app.route('/request_submission', methods=['POST'])
@cross_origin()
def submission_request():
token = request.get_json()["token"]
endpoint = request.get_json()["endpoint"]
url = request.get_json()["url"]
response = request_job(token, endpoint, url)
return jsonify(response)
@app.route('/upload_data', methods=['POST'])
@cross_origin()
def data_upload():
token = request.get_json()["token"]
endpoint = request.get_json()["endpoint"]
url = request.get_json()["url"]
response = upload_job(token, endpoint, url)
return jsonify(response)
@app.route('/reset_duckiebot', methods=['POST'])
@cross_origin()
def duckiebot_reset():
bot_list=request.get_json()["list"]
host, outcome = reset_duckiebot_with_list(bot_list)
return jsonify({'hostname': host, 'outcome': outcome})
@app.route('/create_log', methods=['POST'])
@cross_origin()
def log_creator():
content=request.get_json()["content"]
filename=request.get_json()["filename"]
outcome = generate_log_file(content,filename)
return jsonify({'outcome': outcome})
if __name__ == '__main__':
app.run(host= '0.0.0.0', port=5050)