This repository has been archived by the owner on Jun 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnetcupapi.py
97 lines (82 loc) · 2.35 KB
/
netcupapi.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
import requests
import json
_endpoint = 'https://ccp.netcup.net/run/webservice/servers/endpoint.php?JSON'
_apikey = None
_apisessionid = None
_customernumber = None
def login(apikey, apipassword, customernumber):
global _apikey
global _apisessionid
global _customernumber
data = {
'action': 'login',
'param': {
'apikey': apikey,
'apipassword': apipassword,
'customernumber': customernumber
}
}
result = _execute(data)
_apikey = apikey
_customernumber = customernumber
_apisessionid = result['responsedata']['apisessionid']
return result
def logout():
global _apikey
global _apisessionid
global _customernumber
data = {
'action': 'logout',
'param': {
'apikey': _apikey,
'apisessionid': _apisessionid,
'customernumber': _customernumber
}
}
result = _execute(data)
_apikey = None
_customernumber = None
_apisessionid = None
return result
def update_dns_record(domainname, recordid, hostname, recordtype, destination):
data = {
'action': 'updateDnsRecords',
'param': {
'apikey': _apikey,
'apisessionid': _apisessionid,
'customernumber': _customernumber,
'dnsrecordset': {
'dnsrecords': [
{
'id': recordid,
'hostname': hostname,
'type': recordtype,
'destination': destination
}
]
},
'domainname': domainname
}
}
result = _execute(data)
return result
def info_dns_record(domainname):
data = {
'action': 'infoDnsRecords',
'param': {
'apikey': _apikey,
'apisessionid': _apisessionid,
'customernumber': _customernumber,
'domainname': domainname
}
}
result = _execute(data)
return result
def _execute(data):
response = requests.post(_endpoint, json=data)
if response.status_code != 200:
raise Exception
result = json.loads(response.text)
if result['status'] != 'success':
raise Exception
return result