]> git.proxmox.com Git - mirror_acme.sh.git/blob - dnsapi/dns_netcup.sh
Merge branch 'dev' into master
[mirror_acme.sh.git] / dnsapi / dns_netcup.sh
1 #!/usr/bin/env sh
2 #developed by linux-insideDE
3
4 NC_Apikey="${NC_Apikey:-$(_readaccountconf_mutable NC_Apikey)}"
5 NC_Apipw="${NC_Apipw:-$(_readaccountconf_mutable NC_Apipw)}"
6 NC_CID="${NC_CID:-$(_readaccountconf_mutable NC_CID)}"
7 end="https://ccp.netcup.net/run/webservice/servers/endpoint.php?JSON"
8 client=""
9
10 dns_netcup_add() {
11 _debug NC_Apikey "$NC_Apikey"
12 login
13 if [ "$NC_Apikey" = "" ] || [ "$NC_Apipw" = "" ] || [ "$NC_CID" = "" ]; then
14 _err "No Credentials given"
15 return 1
16 fi
17 _saveaccountconf_mutable NC_Apikey "$NC_Apikey"
18 _saveaccountconf_mutable NC_Apipw "$NC_Apipw"
19 _saveaccountconf_mutable NC_CID "$NC_CID"
20 fulldomain=$1
21 txtvalue=$2
22 domain=""
23 exit=$(echo "$fulldomain" | tr -dc '.' | wc -c)
24 exit=$(_math "$exit" + 1)
25 i=$exit
26
27 while
28 [ "$exit" -gt 0 ]
29 do
30 tmp=$(echo "$fulldomain" | cut -d'.' -f"$exit")
31 if [ "$(_math "$i" - "$exit")" -eq 0 ]; then
32 domain="$tmp"
33 else
34 domain="$tmp.$domain"
35 fi
36 if [ "$(_math "$i" - "$exit")" -ge 1 ]; then
37 msg=$(_post "{\"action\": \"updateDnsRecords\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\",\"clientrequestid\": \"$client\" , \"domainname\": \"$domain\", \"dnsrecordset\": { \"dnsrecords\": [ {\"id\": \"\", \"hostname\": \"$fulldomain.\", \"type\": \"TXT\", \"priority\": \"\", \"destination\": \"$txtvalue\", \"deleterecord\": \"false\", \"state\": \"yes\"} ]}}}" "$end" "" "POST")
38 _debug "$msg"
39 if [ "$(_getfield "$msg" "5" | sed 's/"statuscode"://g')" != 5028 ]; then
40 if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then
41 _err "$msg"
42 return 1
43 else
44 break
45 fi
46 fi
47 fi
48 exit=$(_math "$exit" - 1)
49 done
50 logout
51 }
52
53 dns_netcup_rm() {
54 login
55 fulldomain=$1
56 txtvalue=$2
57
58 domain=""
59 exit=$(echo "$fulldomain" | tr -dc '.' | wc -c)
60 exit=$(_math "$exit" + 1)
61 i=$exit
62 rec=""
63
64 while
65 [ "$exit" -gt 0 ]
66 do
67 tmp=$(echo "$fulldomain" | cut -d'.' -f"$exit")
68 if [ "$(_math "$i" - "$exit")" -eq 0 ]; then
69 domain="$tmp"
70 else
71 domain="$tmp.$domain"
72 fi
73 if [ "$(_math "$i" - "$exit")" -ge 1 ]; then
74 msg=$(_post "{\"action\": \"infoDnsRecords\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\", \"domainname\": \"$domain\"}}" "$end" "" "POST")
75 rec=$(echo "$msg" | sed 's/\[//g' | sed 's/\]//g' | sed 's/{\"serverrequestid\".*\"dnsrecords\"://g' | sed 's/},{/};{/g' | sed 's/{//g' | sed 's/}//g')
76 _debug "$msg"
77 if [ "$(_getfield "$msg" "5" | sed 's/"statuscode"://g')" != 5028 ]; then
78 if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then
79 _err "$msg"
80 return 1
81 else
82 break
83 fi
84 fi
85 fi
86 exit=$(_math "$exit" - 1)
87 done
88
89 ida=0000
90 idv=0001
91 ids=0000000000
92 i=1
93 while
94 [ "$i" -ne 0 ]
95 do
96 specrec=$(_getfield "$rec" "$i" ";")
97 idv="$ida"
98 ida=$(_getfield "$specrec" "1" "," | sed 's/\"id\":\"//g' | sed 's/\"//g')
99 txtv=$(_getfield "$specrec" "5" "," | sed 's/\"destination\":\"//g' | sed 's/\"//g')
100 i=$(_math "$i" + 1)
101 if [ "$txtvalue" = "$txtv" ]; then
102 i=0
103 ids="$ida"
104 fi
105 if [ "$ida" = "$idv" ]; then
106 i=0
107 fi
108 done
109 msg=$(_post "{\"action\": \"updateDnsRecords\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\",\"clientrequestid\": \"$client\" , \"domainname\": \"$domain\", \"dnsrecordset\": { \"dnsrecords\": [ {\"id\": \"$ids\", \"hostname\": \"$fulldomain.\", \"type\": \"TXT\", \"priority\": \"\", \"destination\": \"$txtvalue\", \"deleterecord\": \"TRUE\", \"state\": \"yes\"} ]}}}" "$end" "" "POST")
110 _debug "$msg"
111 if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then
112 _err "$msg"
113 return 1
114 fi
115 logout
116 }
117
118 login() {
119 tmp=$(_post "{\"action\": \"login\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apipassword\": \"$NC_Apipw\", \"customernumber\": \"$NC_CID\"}}" "$end" "" "POST")
120 sid=$(echo "$tmp" | tr '{}' '\n' | grep apisessionid | cut -d '"' -f 4)
121 _debug "$tmp"
122 if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then
123 _err "$msg"
124 return 1
125 fi
126 }
127 logout() {
128 tmp=$(_post "{\"action\": \"logout\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\"}}" "$end" "" "POST")
129 _debug "$tmp"
130 if [ "$(_getfield "$msg" "4" | sed s/\"status\":\"//g | sed s/\"//g)" != "success" ]; then
131 _err "$msg"
132 return 1
133 fi
134 }