This repository has been archived by the owner on Jul 31, 2019. It is now read-only.
/
flaws.py
270 lines (226 loc) · 7.66 KB
/
flaws.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# -*- coding: utf-8 -*-
from flask import Flask, render_template
import boto
app = Flask(__name__)
@app.route("/")
def index():
'''
http://localhost/
show main menu
'''
return render_template('index.html')
''' EC2 '''
@app.route("/ec2/region/")
@app.route("/ec2/region/<region>")
def ec2Region(region=None):
import boto.ec2
if region == None:
'''
http://localhost/ec2/region/
get all available regions ec2
'''
region_list = [{
'name': region.name,
'endpoint':region.endpoint
} for region in boto.ec2.regions()]
return render_template('ec2/RegionIndex.html',
region_list=region_list)
else:
''' http://localhost/ec2/region/<region> '''
con = boto.ec2.connect_to_region(region)
instance_list = []
for r in con.get_all_instances():
for i in r.instances:
instance_list.append({
'id':i.id,
'type':i.instance_type,
'pub_name': i.public_dns_name,
'pri_name': i.private_dns_name,
'vpc': i.vpc_id
})
return render_template('ec2/RegionView.html',
region=region, il=instance_list)
@app.route("/ec2/instance/")
@app.route("/ec2/instance/<instance_id>")
def ec2Instance(instance_id=None):
import boto.ec2
if instance_id == None:
pass
''' '''
''' Autoscaling '''
@app.route("/ec2/autoscale/")
@app.route("/ec2/autoscale/<region>")
def asRegion(region=None):
import boto.ec2.autoscale
if region == None:
'''
http://localhost/ec2/autoscale
get all available regions for autoscaling
'''
region_list = [{
'name': region.name,
'endopoint':region.endpoint
} for region in boto.ec2.autoscale.regions()]
return render_template('as/RegionIndex.html',
region_list=region_list)
else:
con = boto.ec2.autoscale.connect_to_region(region)
con.get_all_groups()
return render_template('as/RegionView.html')
''' RDS '''
@app.route("/rds/region/")
@app.route("/rds/region/<region>")
def rdsRegion(region=None):
import boto.rds
if region == None:
'''
http://localhost/rds/region/
get all available regions for rds
'''
region_list =[{
'name': region.name,
'endpoint':region.endpoint
} for region in boto.rds.regions()]
return render_template('rds/RegionIndex.html',
region_list=region_list)
else:
con = boto.rds.connect_to_region(region)
instance_list = [{
'id':r.id,
'type':r.instance_class,
'engine':r.engine,
'db':r.DBName
}for r in con.get_all_dbinstances()]
return render_template('rds/RegionView.html',
region=region, instance_list=instance_list)
''' VPC '''
@app.route("/vpc/")
@app.route("/vpc/region/<region>")
def VirtualPrivateCloud(region=None):
con = boto.connect_vpc()
vpc_list = [{
'id': vpc.id,
'cidr': vpc.cidr_block,
'state': vpc.state,
'dhcp': vpc.dhcp_options_id
} for vpc in con.get_all_vpcs()]
return
''' SNS '''
@app.route("/sns/region/")
@app.route("/sns/region/<region>")
def snsRegion(region=None):
import boto.sns
if region == None:
region_list =[{
'name': region.name,
'endpoint': region.endpoint
} for region in boto.sns.regions()]
return render_template('sns/RegionIndex.html',
region_list=region_list)
else:
con = boto.sns.connect_to_region(region)
tr = con.get_all_topics()
topics = tr['ListTopicsResponse']['ListTopicsResult']['Topics']
con.get_all_subscriptions()
return render_template('sns/RegionView.html',
sbl=sbl, tpl=tpl)
''' No Region Start '''
''' Route 53 '''
@app.route("/r53/")
@app.route("/r53/<zone_id>")
def Route53(zone_id=None):
con = boto.connect_route53()
if zone_id != None:
''' http://localhost/r53/<zone_id>
get all rrset specified zone id '''
rl = con.get_all_rrsets(zone_id)
rr = [{
'type': r.type,
'name': r.name,
'ttl': r.ttl,
'content': r.to_print()
} for r in rl]
return render_template('r53/ZoneView.html',
zone_id=zone_id, rr=rr)
else:
''' http://localhost/r53/
get all hosted zone '''
hl = con.get_all_hosted_zones()
hzl = [{
'id': hz['Id'].split("/")[-1],
'name': hz['Name'],
'count': hz['ResourceRecordSetCount']
} for hz in hl['ListHostedZonesResponse']['HostedZones']]
return render_template('r53/ZoneIndex.html',
hzl=hzl)
''' IAM '''
@app.route("/iam/group/")
@app.route("/iam/group/<group_name>")
def IamGroup(group_name=None):
con = boto.connect_iam()
if group_name == None:
''' http://localhost/iam/group '''
gr = con.get_all_groups()
gl = [{
'id': g.group_id,
'name': g.group_name,
'arn': g.arn,
'created': g.create_date
} for g in gr['list_groups_response']['list_groups_result']['groups']]
return render_template('iam/GroupIndex.html',
gl=gl)
elif group_name != None:
''' http://localhost/iam/group/<group_name> '''
gr = con.get_group(group_name)
group = gr['get_group_response']['get_group_result']['group']
gd = {'id':group.group_id,
'name':group.group_name,
'created':group.create_date,
'arn':group.arn}
ul = gr['get_group_response']['get_group_result']['users']
users = [{
'id':u.user_id,
'name':u.user_name,
'arn':u.arn,
'created':u.create_date
} for u in ul]
return render_template('iam/GroupView.html',
gd=gd, users=users)
@app.route('/iam/user/')
@app.route("/iam/user/<user_name>")
def IamUser(user_name=None):
con = boto.connect_iam()
if user_name == None:
''' http://localhost/iam/user
get all IAM user '''
ul = con.get_all_users()
users = ul['list_users_response']['list_users_result']['users']
user_list = [{
'id': user.user_id,
'name': user.user_name,
'arn': user.arn,
'created': user.create_date
} for user in users ]
return render_template('iam/UserIndex.html',
user_list=user_list)
elif user_name != None:
''' http://localhost/iam/user/<user_name> '''
''' get specified user detail '''
ud = con.get_user(user_name)
user = ud['get_user_response']['get_user_result']['user']
''' get all groups for specified user '''
ug = con.get_groups_for_user(user_name)
groups = ug['list_groups_for_user_response']['list_groups_for_user_result']['groups']
group_list = [{
'id': g.group_id,
'name': g.group_name,
'created': g.create_date
} for g in groups ]
''' get all policies for specified user '''
up = con.get_all_user_policies(user_name)
policies = up['list_user_policies_response']['list_user_policies_result']
return render_template('iam/UserView.html',
user=user,group_list=group_list,policies=policies)
''' No Region End '''
if __name__ == "__main__":
app.run(debug=True,host="0.0.0.0",port=8834)