/
capepy.py
265 lines (243 loc) · 8.22 KB
/
capepy.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
import json
import requests
class Cape():
def __init__(self, username, password):
self.Login(username, password)
def Login(self, username, password):
self.username = username
self.password = password
params = {
"realm": "Username-Password-Authentication",
"audience": "https://cape.auth0.com/userinfo",
"client_id": "nSHMAgKcZCIoBjYXQtk5LvLdsz1B0Nk5",
"scope": "openid email company roles firebase_data",
"grant_type": "http://auth0.com/oauth/grant-type/password-realm",
"username": self.username,
"password": self.password
}
headers = {
"content-type": "application/json",
"Auth0-Client": "eyJuYW1lIjoiYXV0aDAuanMiLCJ2ZXJzaW9uIjoiOS42LjEifQ==",
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 11_1_2 like Mac OS X) AppleWebKit/604.3.5 (KHTML, like Gecko) Mobile/15B202 NETGEAR/v1 (iOS Vuezone)"
}
r = requests.post('https://cape.auth0.com/oauth/token', data=json.dumps(params), headers=headers)
body = r.json()
self.token = body['id_token']
return body
# Logout is returning 500 errors. Can't find correct headers
def Logout(self):
headers = {
"Authorization": self.token,
"Content-type": "application/json"
}
return requests.delete('https://api.capenetworks.com/user/logout', headers=headers)
def getUserProfile(self):
headers = {
"Authorization": self.token,
"Content-type": "application/json"
}
r = requests.get('https://api.capenetworks.com/user/profile', headers=headers)
data = r.json()
self.comp_id = data['company_uid']
return data
def getStartupData(self):
headers = {
"Authorization": self.token,
"Content-type": "application/json"
}
r = requests.get('https://api.capenetworks.com/dashboard/startup', headers=headers)
data = r.json()
return data
def getUsers(self):
headers = {
"Authorization": self.token,
"Content-type": "application/json"
}
r = requests.get('https://api.capenetworks.com/user', headers=headers)
data = r.json()
return data
def getSSID(self, ssid):
headers = {
"Authorization": self.token,
"Content-type": "application/json"
}
# Build nice uri
uri = 'https://api.capenetworks.com/ssid/' + ssid
r = requests.get(uri, headers=headers)
data = r.json()
return data
def getTimezones(self):
headers = {
"Authorization": self.token,
"Content-type": "application/json"
}
uri = 'https://api.capenetworks.com/timezone-list'
r = requests.get(uri, headers=headers)
data = r.json()
return data
def getSensorNeighbors(self):
headers = {
"Authorization": self.token,
"Content-type": "application/json"
}
uri = 'https://api.capenetworks.com/ssid/recent'
r = requests.get(uri, headers=headers)
data = r.json()
return data
def editUser(self, userID, role):
if role == 'viewer':
restricted = True
else:
restricted = False
headers = {
"Authorization": self.token,
"Content-type": "application/json"
}
params = {
"userId": "user-17a633826a03",
"role": role,
"restricted": restricted,
"groups": []
}
uri = 'https://api.capenetworks.com/user/role'
r = requests.post(uri, data=json.dumps(params), headers=headers)
data = r.json()
return data
def createUser(self, firstname, surname, email, role):
if role == 'viewer':
restricted = True
else:
restricted = False
headers = {
"Authorization": self.token,
"Content-type": "application/json"
}
params = {
"clientId": self.comp_id,
"email": email,
"firstname": firstname,
"surname": surname,
"role": role,
"restricted": restricted,
"groups": []
}
uri = 'https://api.capenetworks.com/user'
r = requests.post(uri, data=json.dumps(params), headers=headers)
data = r.json()
return data
def removeUser(self, userID):
headers = {
"Authorization": self.token,
"Content-type": "application/json"
}
uri = 'https://api.capenetworks.com/user' + userID
r = requests.delete(uri, headers=headers)
data = r.json()
return data
def removeSSID(self, ssid):
headers = {
"Authorization": self.token,
"Content-type": "application/json"
}
uri = 'https://api.capenetworks.com/ssid/' + ssid
r = requests.delete(uri, headers=headers)
data = r.json()
return data
def createSSID(self, ssid, security, passphrase, hidden=False, external=False, bandlock='auto'):
alias = ssid
headers = {
"Authorization": self.token,
"Content-type": "application/json"
}
params = {
"ssid": ssid,
"hidden": hidden,
"security": security,
"alias": alias,
"external_connectivity": external,
"band_locking": bandlock,
"phase2_auth": "",
"proxies": {},
"security_details": {"passphrase": passphrase}
}
uri = 'https://api.capenetworks.com/ssid'
r = requests.post(uri, data=json.dumps(params), headers=headers)
data = r.json()
return data
def getSSIDs(self):
headers = {
"Authorization": self.token,
"Content-type": "application/json"
}
uri = 'https://api.capenetworks.com/ssid'
r = requests.get(uri, headers=headers)
data = r.json()
return data
def getIssues(self):
headers = {
"Authorization": self.token,
"Content-type": "application/json"
}
uri = 'https://api.capenetworks.com/notifications/issues'
r = requests.get(uri, headers=headers)
data = r.json()
return data
def getSensors(self):
headers = {
"Authorization": self.token,
"Content-type": "application/json"
}
uri = 'https://api.capenetworks.com/sensor'
r = requests.get(uri, headers=headers)
data = r.json()
return data
def getMutes(self):
headers = {
"Authorization": self.token,
"Content-type": "application/json"
}
uri = 'https://api.capenetworks.com/notifications/mutes'
r = requests.get(uri, headers=headers)
data = r.json()
return data
def createGroup(self, name):
alias = name[:3]
headers = {
"Authorization": self.token,
"Content-type": "application/json"
}
params = {
"name": name,
"alias": alias
}
uri = 'https://api.capenetworks.com/group'
r = requests.post(uri, data=json.dumps(params), headers=headers)
data = r.json()
return data
def removeGroup(self, groupID):
headers = {
"Authorization": self.token,
"Content-type": "application/json"
}
uri = 'https://api.capenetworks.com/group' + groupID
r = requests.delete(uri, headers=headers)
data = r.json()
return data
def getGroups(self):
headers = {
"Authorization": self.token,
"Content-type": "application/json"
}
uri = 'https://api.capenetworks.com/group'
r = requests.get(uri, headers=headers)
data = r.json()
return data
def getLatest(self):
headers = {
"Authorization": self.token,
"Content-type": "application/json"
}
uri = 'https://api.capenetworks.com/dashboard/latest'
r = requests.get(uri, headers=headers)
data = r.json()
return data