-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvaro.py
340 lines (315 loc) · 8.71 KB
/
varo.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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
import requests
import os
import dotenv
dotenv.load_dotenv()
zone = ""
TLSA = ""
REG_KEY = os.getenv('REG_KEY')
city_domain = os.getenv('CITY_DOMAIN')
if city_domain == "localhost":
city_domain = "exampledomainnathan1"
alt_domains = os.getenv('ALT_DOMAINS')
if alt_domains == None:
alt_domains = []
else:
alt_domains = alt_domains.split(",")
server_ip = os.getenv('CITY_IP')
def update_auth(auth,domain):
verify_ALIAS(domain)
record = get_auth_id(domain)
if record == "":
data = {
"action": "addRecord",
"zone": zone,
"type": "TXT",
"name": domain,
"content": auth,
}
else:
data = {
"action": "updateRecord",
"zone": zone,
"record": record,
"column": "content",
"value": auth
}
if auth == "" and record == "":
return
if auth == "" and record != "":
data = {
"action": "deleteRecord",
"zone": zone,
"record": record
}
# Update TXT record
url = "https://reg.woodburn.au/api"
headers = {
'Authorization': 'Bearer '+REG_KEY,
'Content-Type': 'application/json'
}
r = requests.put(url, headers=headers, json=data)
copy_to_alts(domain)
return r.text
def get_auth_id(domain):
if zone == "":
get_zone()
data = {
"action": "getRecords",
"zone": zone,
"name": domain + "." + city_domain,
"type": "TXT",
"content": ""
}
url = "https://reg.woodburn.au/api"
headers = {
'Authorization': 'Bearer '+REG_KEY,
'Content-Type': 'application/json'
}
r = requests.post(url, headers=headers, json=data)
r = r.json()
if 'data' not in r:
return ""
for record in r['data']:
if 'profile avatar=' not in record['content']:
return record['uuid']
return ""
def get_auth(domain):
if zone == "":
get_zone()
data = {
"action": "getRecords",
"zone": zone,
"name": domain + "." + city_domain,
"type": "TXT",
"content": ""
}
url = "https://reg.woodburn.au/api"
headers = {
'Authorization': 'Bearer '+REG_KEY,
'Content-Type': 'application/json'
}
r = requests.post(url, headers=headers, json=data)
r = r.json()
if 'data' not in r:
return ""
for record in r['data']:
if 'profile avatar=' not in record['content']:
return record['content']
return ""
def get_zone():
global zone
global TLSA
url = "https://reg.woodburn.au/api"
headers = {
'Authorization': 'Bearer '+REG_KEY,
'Content-Type': 'application/json'
}
data = {
"action": "getZones"
}
r = requests.post(url, headers=headers, json=data)
r = r.json()
for domain in r['data']:
if domain['name'] == city_domain:
zone = domain['id']
data = {
"action": "getRecords",
"zone": zone,
"name": "*."+city_domain,
"type": "TLSA",
"content": ""
}
r = requests.post(url, headers=headers, json=data)
r = r.json()
for record in r['data']:
TLSA = record['content']
return zone
def update_avatar(avatar,domain):
verify_ALIAS(domain)
if zone == "":
get_zone()
data = {
"action": "getRecords",
"zone": zone,
"name": domain + "." + city_domain,
"type": "TXT",
"content": ""
}
url = "https://reg.woodburn.au/api"
headers = {
'Authorization': 'Bearer '+REG_KEY,
'Content-Type': 'application/json'
}
r = requests.post(url, headers=headers, json=data)
r = r.json()
record_id = ""
if 'data' in r:
for record in r['data']:
if record['name'] == domain + "." + city_domain:
if 'profile avatar=' in record['content']:
if record['content'].split("profile avatar=")[1] == avatar:
print("Avatar already set", flush=True)
return "Avatar already set"
record_id = record['uuid']
if record_id == "":
data = {
"action": "addRecord",
"zone": zone,
"type": "TXT",
"name": domain,
"content": "profile avatar=" + avatar,
}
else:
data = {
"action": "updateRecord",
"zone": zone,
"record": record_id,
"column": "content",
"value": "profile avatar=" + avatar
}
if avatar == "" and record_id == "":
return
if avatar == "" and record_id != "":
data = {
"action": "deleteRecord",
"zone": zone,
"record": record_id
}
r = requests.post(url, headers=headers, json=data)
copy_to_alts(domain)
return r.text
def verify_ALIAS(domain):
if zone == "":
get_zone()
data = {
"action": "getRecords",
"zone": zone,
"name": domain+"."+city_domain,
"type": "A",
"content": ""
}
url = "https://reg.woodburn.au/api"
headers = {
'Authorization': 'Bearer '+REG_KEY,
'Content-Type': 'application/json'
}
r = requests.post(url, headers=headers, json=data)
r = r.json()
if 'data' in r:
return
data = {
"action": "addRecord",
"zone": zone,
"type": "A",
"name": domain,
"content": server_ip,
}
r = requests.post(url, headers=headers, json=data)
data = {
"action": "addRecord",
"zone": zone,
"type": "TLSA",
"name": "_443._tcp."+domain+"."+city_domain,
"content": TLSA,
}
r = requests.post(url, headers=headers, json=data)
copy_to_alts(domain)
return r.text
def copy_to_alts(domain):
# Get DNS from domain and copy to each alt
data = {
"action": "getRecords",
"zone": zone,
"name": domain+"."+city_domain,
"type": "",
"content": ""
}
url = "https://reg.woodburn.au/api"
headers = {
'Authorization': 'Bearer '+REG_KEY,
'Content-Type': 'application/json'
}
r = requests.post(url, headers=headers, json=data)
r = r.json()
if 'data' not in r:
return
records = r['data']
for alt_domain in alt_domains:
# Get the zone for the alt
alt_zone = ""
data = {
"action": "getZones"
}
r = requests.post(url, headers=headers, json=data)
r = r.json()
for tmpzone in r['data']:
if tmpzone['name'] == alt_domain:
alt_zone = tmpzone['id']
print(alt_zone)
if alt_zone == "":
continue
# Delete all records from domain.alt
data = {
"action": "getRecords",
"zone": alt_zone,
"name": domain+"."+alt_domain,
"type": "",
"content": ""
}
r = requests.post(url, headers=headers, json=data)
r = r.json()
if 'data' in r:
for record in r['data']:
data = {
"action": "deleteRecord",
"zone": alt_zone,
"record": record['uuid']
}
r = requests.post(url, headers=headers, json=data)
print(r.text)
# Add each record to each alt
for record in records:
data = {
"action": "addRecord",
"zone": alt_zone,
"type": record['type'],
"name": domain+"."+alt_domain,
"content": record['content'],
}
print(data)
r = requests.post(url, headers=headers, json=data)
print(r.text)
# Add TLSA record if it doesn't exist
data = {
"action": "getRecords",
"zone": alt_zone,
"name": "_443._tcp."+domain+"."+alt_domain,
"type": "TLSA",
"content": ""
}
r = requests.post(url, headers=headers, json=data)
r = r.json()
if 'data' not in r:
# Get alt TLSA from _443._tcp.alt_domain
data = {
"action": "getRecords",
"zone": alt_zone,
"name": "_443._tcp."+alt_domain,
"type": "TLSA",
"content": ""
}
r = requests.post(url, headers=headers, json=data)
r = r.json()
if 'data' not in r:
continue
for record in r['data']:
ALT_TLSA = record['content']
data = {
"action": "addRecord",
"zone": alt_zone,
"type": "TLSA",
"name": "_443._tcp."+domain+"."+alt_domain,
"content": ALT_TLSA,
}
r = requests.post(url, headers=headers, json=data)
print(r.text)