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