]>
Commit | Line | Data |
---|---|---|
e9782c32 | 1 | #!/usr/bin/env sh |
e9782c32 | 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() { | |
c74d597c | 11 | _debug NC_Apikey "$NC_Apikey" |
840b3a34 | 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 | |
c7b90450 | 26 | |
840b3a34 | 27 | while |
4fffb3c8 | 28 | [ "$exit" -gt 0 ] |
29 | do | |
840b3a34 | 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 | |
e9782c32 | 51 | } |
52 | ||
53 | dns_netcup_rm() { | |
840b3a34 | 54 | login |
55 | fulldomain=$1 | |
56 | txtvalue=$2 | |
c7b90450 | 57 | |
840b3a34 | 58 | domain="" |
59 | exit=$(echo "$fulldomain" | tr -dc '.' | wc -c) | |
60 | exit=$(_math "$exit" + 1) | |
61 | i=$exit | |
62 | rec="" | |
c7b90450 | 63 | |
840b3a34 | 64 | while |
4fffb3c8 | 65 | [ "$exit" -gt 0 ] |
66 | do | |
840b3a34 | 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 | |
c7b90450 | 88 | |
840b3a34 | 89 | ida=0000 |
90 | idv=0001 | |
91 | ids=0000000000 | |
92 | i=1 | |
93 | while | |
4fffb3c8 | 94 | [ "$i" -ne 0 ] |
95 | do | |
840b3a34 | 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 | |
e9782c32 | 116 | } |
117 | ||
118 | login() { | |
840b3a34 | 119 | tmp=$(_post "{\"action\": \"login\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apipassword\": \"$NC_Apipw\", \"customernumber\": \"$NC_CID\"}}" "$end" "" "POST") |
09bce5e6 | 120 | sid=$(echo "$tmp" | tr '{}' '\n' | grep apisessionid | cut -d '"' -f 4) |
840b3a34 | 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 | |
e9782c32 | 126 | } |
127 | logout() { | |
840b3a34 | 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 | |
e9782c32 | 134 | } |