-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommandCenter.py
152 lines (125 loc) · 4.23 KB
/
CommandCenter.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
#!/usr/bin/python
from flask import Flask, render_template, request, jsonify, redirect, session, flash, make_response
import os
import json
import requests
app = Flask(__name__)
app.secret_key = "bulkingseason"
AUTH_API_URL = 'http://atlas.whiteteam.ritsec:9000'
def validate_session(token):
"""
Sends token to auth server to validate, should recieve
associated team number if it is valid
:param token: the session token to validate
:return team_id: the id of the team the token is attached to
"""
post_data = dict()
post_data['token'] = token
resp = requests.post("{}/validate-session".format(AUTH_API_URL, data=post_data))
if resp.status_code != 200:
raise Exception("Bad status code")
if 'success' not in resp.json():
raise Exception(resp.json()['error'])
team_id = resp['success']
return team_id
@app.route('/')
def home():
if session.get('token'):
token = session.get('token')
team_id = session.get('team_id')
try:
validate_session(token)
except:
redirect('/login')
return render_template('index.html', team_id=team_id)
else:
return render_template('login.html')
@app.route('/login', methods=['POST'])
def login():
password = request.form['password']
username = request.form['username']
data = {'username': username, 'password': password}
r = requests.post("{}/login".format(AUTH_API_URL), data=data)
if r.status_code != 200:
# error
pass
elif 'error' in r.json():
# error
pass
else:
token = r.json()['token']
team_id = r.json()['team_id']
session['token'] = token
session['team_id'] = team_id
response = make_response(redirect('/'))
response.set_cookie('token', token)
return response
#print(r.json())
return home()
@app.route('/logout', methods=['GET'])
def logout():
data = {'token': session['token']}
requests.post("{}/expire-session".format(AUTH_API_URL), data=data)
session.clear()
return redirect('/')
@app.route('/hq_coms', methods=['POST'])
def hq_coms():
host1 = request.form['server1']
host2 = request.form['server2']
host3 = request.form['server3']
host4 = request.form['server4']
host5 = request.form['server5']
host6 = request.form['server6']
host7 = request.form['server7']
host8 = request.form['server8']
host9 = request.form['server9']
host10 = request.form['server10']
return jsonify({
'reachable1': [host1, ping(host1)],
'reachable2': [host2, ping(host2)],
'reachable3': [host3, ping(host3)],
'reachable4': [host4, ping(host4)],
'reachable5': [host5, ping(host5)],
'reachable6': [host6, ping(host6)],
'reachable7': [host7, ping(host7)],
'reachable8': [host8, ping(host8)],
'reachable9': [host9, ping(host9)],
'reachable10': [host10, ping(host10)]
})
"""
Ansible
"""
@app.route('/ansible_playbook1', methods=['POST'])
def ansible_playbook1():
command = "ansible-playbook /var/www/ISTS16-ansible/predeploy.yml -t jenkins -i /var/www/ISTS16-ansible/hosts"
os.system(command)
return redirect('/')
@app.route('/ansible_playbook2', methods=['POST'])
def ansible_playbook2():
command = "ansible-playbook /var/www/ISTS16-ansible/predeploy.yml -t ecommerce -i /var/www/ISTS16-ansible/hosts"
os.system(command)
return redirect('/')
@app.route('/ansible_playbook3', methods=['POST'])
def ansible_playbook3():
command = "ansible-playbook /var/www/ISTS16-ansible/predeploy.yml -t mail -i /var/www/ISTS16-ansible/hosts"
os.system(command)
return redirect('/')
@app.route('/ansible_playbook4', methods=['POST'])
def ansible_playbook4():
command = "ansible-playbook /var/www/ISTS16-ansible/predeploy.yml -t jenkinswin -i /var/www/ISTS16-ansible/hosts"
os.system(command)
return redirect('/')
"""
Helpers
"""
def ping(host):
if host.lower() == "luna":
host = "localhost"
response = os.system("ping -c 1 -W 1 " + host)
if response == 0:
return 'UP'
else:
return 'DOWN'
if __name__ == '__main__':
app.secret_key = os.urandom(12)
app.run(host='0.0.0.0', port=80, debug=True)