-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdns-backup.py
More file actions
executable file
·70 lines (50 loc) · 1.72 KB
/
Copy pathdns-backup.py
File metadata and controls
executable file
·70 lines (50 loc) · 1.72 KB
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
#!/usr/bin/python3
import pandas as ps
import json
import sys
import sys
import requests as req
import datetime
api1 = './api-key-local'
api2 = './api-key-external'
ip1 = '10.1.0.2:5380'
ip2 = '209.145.62.205:82'
file1 = './10.1.0.2-key'
file2 = './209.145.62.205-key'
def new_keys():
server1 = [api1, ip1, file1]
server2 = [api2, ip2, file2]
hit_list = [server1, server2]
for serverkey in hit_list:
api_file = serverkey[0]
ip_addr = str(serverkey[1])
formatted_api = str(serverkey[2])
with open(api_file) as j:
api_data = json.load(j)
with open(formatted_api, "w") as write_file:
json.dump(api_data, write_file, indent=2)
def backups():
now = datetime.datetime.now()
timestamp = now.strftime("%d-%m-%Y")
server1 = [ip1, file1]
server2 = [ip2, file2]
hit_list = [server1, server2]
for server in hit_list:
ip_addr = str(server[0])
api_key = str(server[1])
with open(api_key) as j:
api_data = json.load(j)
dns_token = str(api_data['token'])
dns_username = str(api_data['username'])
url = f"http://{ip_addr}/api/settings/backup?token={dns_token}&blockLists=true&logs=true&scopes=true&stats=true&zones=true&allowedZones=true&blockedZones=true&dnsSettings=true&logSettings=true&authConfig=true"
file = req.get(url, allow_redirects=True)
download_name = f"/opt/backups/dns/data/{timestamp}-{ip_addr}.zip"
print(open(download_name, 'wb').write(file.content))
# print(dns_username)
arguments = int(len(sys.argv))
if arguments == 2:
function = str(sys.argv[1])
if function == "backups":
backups()
else:
a=1