-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudflare.py
79 lines (56 loc) · 2.18 KB
/
cloudflare.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
from requests import get, post, put, session
class Cloudflare:
baseURL = 'https://api.cloudflare.com/client/v4'
def __init__(self, auth):
self.auth = auth
headers ={
'Authorization': auth,
'Content-Type': 'application/json'
}
self.session = session()
self.session.headers = headers
def getZones(self, domainName):
response = self.session.get('https://api.cloudflare.com/client/v4/zones', params={'name':domainName})
return response
def getDNSRecords(self, zoneID):
response = self.session.get('https://api.cloudflare.com/client/v4/zones/' + zoneID + '/dns_records')
DNSRecords_Objects = []
DNSRecords = response.json()['result']
for record in DNSRecords:
DNSRecords_Objects.append( DNSRecord(record, self.session) )
return DNSRecords_Objects
class DNSRecord:
def __init__(self, data, session):
self.id = data['id']
self.zoneID = data['zone_id']
self.zoneName = data['zone_name']
self.name = data['name']
self.type = data['type']
self.content = data['content']
self.proxiable = data['proxiable']
self.proxied = data['proxied']
self.data = {
'type': self.type,
'name': self.name,
'proxied': self.proxied,
'content': self.content
}
self.session = session
def change(self, newContent = None, newProxied = None, newName = None, newType = None):
if newContent:
self.data['content'] = newContent
if newProxied:
self.data['proxied'] = newProxied
if newName:
self.data['name'] = newName
if newType:
self.data['type'] = newType
response = self.session.put(f'https://api.cloudflare.com/client/v4/zones/{self.zoneID}/dns_records/{self.id}', json=self.data)
return response
def __str__(self):
info = ''
info += 'Name: ' + self.name
info += '\nType: ' + self.type
info += '\nContent: ' + self.content
info += '\nProxied: ' + str(self.proxied)
return info