6 # export HOSTINGDE_ENDPOINT='https://secure.hosting.de'
7 # export HOSTINGDE_APIKEY='xxxxx'
9 ######## Public functions #####################
14 _debug
"Calling: _hostingde_addRecord() '${fulldomain}' '${txtvalue}'"
15 _hostingde_apiKey
&& _hostingde_getZoneConfig
&& _hostingde_addRecord
22 _debug
"Calling: _hostingde_removeRecord() '${fulldomain}' '${txtvalue}'"
23 _hostingde_apiKey
&& _hostingde_getZoneConfig
&& _hostingde_removeRecord
27 #################### own Private functions below ##################################
30 HOSTINGDE_APIKEY
="${HOSTINGDE_APIKEY:-$(_readaccountconf_mutable HOSTINGDE_APIKEY)}"
31 HOSTINGDE_ENDPOINT
="${HOSTINGDE_ENDPOINT:-$(_readaccountconf_mutable HOSTINGDE_ENDPOINT)}"
32 if [ -z "$HOSTINGDE_APIKEY" ] ||
[ -z "$HOSTINGDE_ENDPOINT" ]; then
35 _err
"You haven't specified hosting.de API key or endpoint yet."
36 _err
"Please create your key and try again."
40 _saveaccountconf_mutable HOSTINGDE_APIKEY
"$HOSTINGDE_APIKEY"
41 _saveaccountconf_mutable HOSTINGDE_ENDPOINT
"$HOSTINGDE_ENDPOINT"
49 if [ "${notfind}" ]; then
50 _egrep_o
\""${find}\":.*" |
grep -v "${notfind}" | cut
-d ':' -f 2 | cut
-d ',' -f 1 |
tr -d ' '
52 _egrep_o
\""${find}\":.*" | cut
-d ':' -f 2 | cut
-d ',' -f 1 |
tr -d ' '
56 _hostingde_parse_no_strip_whitespace
() {
61 if [ "${notfind}" ]; then
62 _egrep_o
\""${find}\":.*" |
grep -v "${notfind}" | cut
-d ':' -f 2 | cut
-d ',' -f 1
64 _egrep_o
\""${find}\":.*" | cut
-d ':' -f 2 | cut
-d ',' -f 1
68 _hostingde_getZoneConfig
() {
69 _info
"Getting ZoneConfig"
70 curZone
="${fulldomain#*.}"
72 while _contains
"${curZone}" "\\."; do
73 curData
="{\"filter\":{\"field\":\"zoneName\",\"value\":\"${curZone}\"},\"limit\":1,\"authToken\":\"${HOSTINGDE_APIKEY}\"}"
74 curResult
="$(_post "${curData}" "${HOSTINGDE_ENDPOINT}/api
/dns
/v
1/json
/zoneConfigsFind
")"
75 _debug
"Calling zoneConfigsFind: '${curData}' '${HOSTINGDE_ENDPOINT}/api/dns/v1/json/zoneConfigsFind'"
76 _debug
"Result of zoneConfigsFind: '$curResult'"
77 if _contains
"${curResult}" '"status": "error"'; then
78 if _contains
"${curResult}" '"code": 10109'; then
79 _err
"The API-Key is invalid or could not be found"
81 _err
"UNKNOWN API ERROR"
86 if _contains
"${curResult}" '"totalEntries": 1'; then
87 _info
"Retrieved zone data."
88 _debug
"Zone data: '${curResult}'"
89 zoneConfigId
=$
(echo "${curResult}" | _hostingde_parse
"id")
90 zoneConfigName
=$
(echo "${curResult}" | _hostingde_parse
"name")
91 zoneConfigType
=$
(echo "${curResult}" | _hostingde_parse
"type" "FindZoneConfigsResult")
92 zoneConfigExpire
=$
(echo "${curResult}" | _hostingde_parse
"expire")
93 zoneConfigNegativeTtl
=$
(echo "${curResult}" | _hostingde_parse
"negativeTtl")
94 zoneConfigRefresh
=$
(echo "${curResult}" | _hostingde_parse
"refresh")
95 zoneConfigRetry
=$
(echo "${curResult}" | _hostingde_parse
"retry")
96 zoneConfigTtl
=$
(echo "${curResult}" | _hostingde_parse
"ttl")
97 zoneConfigDnsServerGroupId
=$
(echo "${curResult}" | _hostingde_parse
"dnsServerGroupId")
98 zoneConfigEmailAddress
=$
(echo "${curResult}" | _hostingde_parse
"emailAddress")
99 zoneConfigDnsSecMode
=$
(echo "${curResult}" | _hostingde_parse
"dnsSecMode")
100 zoneConfigTemplateValues
=$
(echo "${curResult}" | _hostingde_parse_no_strip_whitespace
"templateValues")
102 if [ "$zoneConfigTemplateValues" != "null" ]; then
103 _debug
"Zone is tied to a template."
104 zoneConfigTemplateValuesTemplateId
=$
(echo "${curResult}" | _hostingde_parse
"templateId")
105 zoneConfigTemplateValuesTemplateName
=$
(echo "${curResult}" | _hostingde_parse_no_strip_whitespace
"templateName")
106 zoneConfigTemplateValuesTemplateReplacementsIPv4
=$
(echo "${curResult}" | _hostingde_parse
"ipv4Replacement")
107 zoneConfigTemplateValuesTemplateReplacementsIPv6
=$
(echo "${curResult}" | _hostingde_parse
"ipv6Replacement")
108 zoneConfigTemplateValuesTemplateReplacementsMailIPv4
=$
(echo "${curResult}" | _hostingde_parse
"mailIpv4Replacement")
109 zoneConfigTemplateValuesTemplateReplacementsMailIPv6
=$
(echo "${curResult}" | _hostingde_parse
"mailIpv6Replacement")
110 zoneConfigTemplateValuesTemplateTieToTemplate
=$
(echo "${curResult}" | _hostingde_parse
"tieToTemplate")
112 zoneConfigTemplateValues
="{\"templateId\":${zoneConfigTemplateValuesTemplateId},\"templateName\":${zoneConfigTemplateValuesTemplateName},\"templateReplacements\":{\"ipv4Replacement\":${zoneConfigTemplateValuesTemplateReplacementsIPv4},\"ipv6Replacement\":${zoneConfigTemplateValuesTemplateReplacementsIPv6},\"mailIpv4Replacement\":${zoneConfigTemplateValuesTemplateReplacementsMailIPv4},\"mailIpv6Replacement\":${zoneConfigTemplateValuesTemplateReplacementsMailIPv6}},\"tieToTemplate\":${zoneConfigTemplateValuesTemplateTieToTemplate}}"
113 _debug
"Template values: '{$zoneConfigTemplateValues}'"
116 if [ "${zoneConfigType}" != "\"NATIVE\"" ]; then
117 _err
"Zone is not native"
121 _debug
"zoneConfigId '${zoneConfigId}'"
125 curZone
="${curZone#*.}"
127 if [ $returnCode -ne 0 ]; then
128 _info
"ZoneEnd reached, Zone ${curZone} not found in hosting.de API"
133 _hostingde_getZoneStatus
() {
134 _debug
"Checking Zone status"
135 curData
="{\"filter\":{\"field\":\"zoneConfigId\",\"value\":${zoneConfigId}},\"limit\":1,\"authToken\":\"${HOSTINGDE_APIKEY}\"}"
136 curResult
="$(_post "${curData}" "${HOSTINGDE_ENDPOINT}/api
/dns
/v
1/json
/zonesFind
")"
137 _debug
"Calling zonesFind '${curData}' '${HOSTINGDE_ENDPOINT}/api/dns/v1/json/zonesFind'"
138 _debug
"Result of zonesFind '$curResult'"
139 zoneStatus
=$
(echo "${curResult}" | _hostingde_parse
"status" "success")
140 _debug
"zoneStatus '${zoneStatus}'"
144 _hostingde_addRecord
() {
145 _info
"Adding record to zone"
146 _hostingde_getZoneStatus
147 _debug
"Result of zoneStatus: '${zoneStatus}'"
148 while [ "${zoneStatus}" != "\"active\"" ]; do
150 _hostingde_getZoneStatus
151 _debug
"Result of zoneStatus: '${zoneStatus}'"
153 curData
="{\"authToken\":\"${HOSTINGDE_APIKEY}\",\"zoneConfig\":{\"id\":${zoneConfigId},\"name\":${zoneConfigName},\"type\":${zoneConfigType},\"dnsServerGroupId\":${zoneConfigDnsServerGroupId},\"dnsSecMode\":${zoneConfigDnsSecMode},\"emailAddress\":${zoneConfigEmailAddress},\"soaValues\":{\"expire\":${zoneConfigExpire},\"negativeTtl\":${zoneConfigNegativeTtl},\"refresh\":${zoneConfigRefresh},\"retry\":${zoneConfigRetry},\"ttl\":${zoneConfigTtl}},\"templateValues\":${zoneConfigTemplateValues}},\"recordsToAdd\":[{\"name\":\"${fulldomain}\",\"type\":\"TXT\",\"content\":\"\\\"${txtvalue}\\\"\",\"ttl\":3600}]}"
154 curResult
="$(_post "${curData}" "${HOSTINGDE_ENDPOINT}/api
/dns
/v
1/json
/zoneUpdate
")"
155 _debug
"Calling zoneUpdate: '${curData}' '${HOSTINGDE_ENDPOINT}/api/dns/v1/json/zoneUpdate'"
156 _debug
"Result of zoneUpdate: '$curResult'"
157 if _contains
"${curResult}" '"status": "error"'; then
158 if _contains
"${curResult}" '"code": 10109'; then
159 _err
"The API-Key is invalid or could not be found"
161 _err
"UNKNOWN API ERROR"
168 _hostingde_removeRecord
() {
169 _info
"Removing record from zone"
170 _hostingde_getZoneStatus
171 _debug
"Result of zoneStatus: '$zoneStatus'"
172 while [ "$zoneStatus" != "\"active\"" ]; do
174 _hostingde_getZoneStatus
175 _debug
"Result of zoneStatus: '$zoneStatus'"
177 curData
="{\"authToken\":\"${HOSTINGDE_APIKEY}\",\"zoneConfig\":{\"id\":${zoneConfigId},\"name\":${zoneConfigName},\"type\":${zoneConfigType},\"dnsServerGroupId\":${zoneConfigDnsServerGroupId},\"dnsSecMode\":${zoneConfigDnsSecMode},\"emailAddress\":${zoneConfigEmailAddress},\"soaValues\":{\"expire\":${zoneConfigExpire},\"negativeTtl\":${zoneConfigNegativeTtl},\"refresh\":${zoneConfigRefresh},\"retry\":${zoneConfigRetry},\"ttl\":${zoneConfigTtl}},\"templateValues\":${zoneConfigTemplateValues}},\"recordsToDelete\":[{\"name\":\"${fulldomain}\",\"type\":\"TXT\",\"content\":\"\\\"${txtvalue}\\\"\"}]}"
178 curResult
="$(_post "${curData}" "${HOSTINGDE_ENDPOINT}/api
/dns
/v
1/json
/zoneUpdate
")"
179 _debug
"Calling zoneUpdate: '${curData}' '${HOSTINGDE_ENDPOINT}/api/dns/v1/json/zoneUpdate'"
180 _debug
"Result of zoneUpdate: '$curResult'"
181 if _contains
"${curResult}" '"status": "error"'; then
182 if _contains
"${curResult}" '"code": 10109'; then
183 _err
"The API-Key is invalid or could not be found"
185 _err
"UNKNOWN API ERROR"