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_getZoneConfig
() {
57 _info
"Getting ZoneConfig"
58 curZone
="${fulldomain#*.}"
60 while _contains
"${curZone}" "\\."; do
61 curData
="{\"filter\":{\"field\":\"zoneName\",\"value\":\"${curZone}\"},\"limit\":1,\"authToken\":\"${HOSTINGDE_APIKEY}\"}"
62 curResult
="$(_post "${curData}" "${HOSTINGDE_ENDPOINT}/api
/dns
/v
1/json
/zoneConfigsFind
")"
63 _debug
"Calling zoneConfigsFind: '${curData}' '${HOSTINGDE_ENDPOINT}/api/dns/v1/json/zoneConfigsFind'"
64 _debug
"Result of zoneConfigsFind: '$curResult'"
65 if _contains
"${curResult}" '"status": "error"'; then
66 if _contains
"${curResult}" '"code": 10109'; then
67 _err
"The API-Key is invalid or could not be found"
69 _err
"UNKNOWN API ERROR"
74 if _contains
"${curResult}" '"totalEntries": 1'; then
75 _info
"Retrieved zone data."
76 _debug
"Zone data: '${curResult}'"
77 zoneConfigId
=$
(echo "${curResult}" | _hostingde_parse
"id")
78 zoneConfigName
=$
(echo "${curResult}" | _hostingde_parse
"name")
79 zoneConfigType
=$
(echo "${curResult}" | _hostingde_parse
"type" "FindZoneConfigsResult")
80 zoneConfigExpire
=$
(echo "${curResult}" | _hostingde_parse
"expire")
81 zoneConfigNegativeTtl
=$
(echo "${curResult}" | _hostingde_parse
"negativeTtl")
82 zoneConfigRefresh
=$
(echo "${curResult}" | _hostingde_parse
"refresh")
83 zoneConfigRetry
=$
(echo "${curResult}" | _hostingde_parse
"retry")
84 zoneConfigTtl
=$
(echo "${curResult}" | _hostingde_parse
"ttl")
85 zoneConfigDnsServerGroupId
=$
(echo "${curResult}" | _hostingde_parse
"dnsServerGroupId")
86 zoneConfigEmailAddress
=$
(echo "${curResult}" | _hostingde_parse
"emailAddress")
87 zoneConfigDnsSecMode
=$
(echo "${curResult}" | _hostingde_parse
"dnsSecMode")
88 zoneConfigTemplateValues
=$
(echo "${curResult}" | _hostingde_parse
"templateValues")
90 if [ "$zoneConfigTemplateValues" != "null" ]; then
91 _debug
"Zone is tied to a template."
92 zoneConfigTemplateValuesTemplateId
=$
(echo "${curResult}" | _hostingde_parse
"templateId")
93 zoneConfigTemplateValuesTemplateName
=$
(echo "${curResult}" | _hostingde_parse
"templateName")
94 zoneConfigTemplateValuesTemplateReplacementsIPv4
=$
(echo "${curResult}" | _hostingde_parse
"ipv4Replacement")
95 zoneConfigTemplateValuesTemplateReplacementsIPv6
=$
(echo "${curResult}" | _hostingde_parse
"ipv6Replacement")
96 zoneConfigTemplateValuesTemplateReplacementsMailIPv4
=$
(echo "${curResult}" | _hostingde_parse
"mailIpv4Replacement")
97 zoneConfigTemplateValuesTemplateReplacementsMailIPv6
=$
(echo "${curResult}" | _hostingde_parse
"mailIpv6Replacement")
98 zoneConfigTemplateValuesTemplateTieToTemplate
=$
(echo "${curResult}" | _hostingde_parse
"tieToTemplate")
100 zoneConfigTemplateValues
="{\"templateId\":${zoneConfigTemplateValuesTemplateId},\"templateName\":${zoneConfigTemplateValuesTemplateName},\"templateReplacements\":{\"ipv4Replacement\":${zoneConfigTemplateValuesTemplateReplacementsIPv4},\"ipv6Replacement\":${zoneConfigTemplateValuesTemplateReplacementsIPv6},\"mailIpv4Replacement\":${zoneConfigTemplateValuesTemplateReplacementsMailIPv4},\"mailIpv6Replacement\":${zoneConfigTemplateValuesTemplateReplacementsMailIPv6}},\"tieToTemplate\":${zoneConfigTemplateValuesTemplateTieToTemplate}}"
101 _debug
"Template values: '{$zoneConfigTemplateValues}'"
104 if [ "${zoneConfigType}" != "\"NATIVE\"" ]; then
105 _err
"Zone is not native"
109 _debug
"zoneConfigId '${zoneConfigId}'"
113 curZone
="${curZone#*.}"
115 if [ $returnCode -ne 0 ]; then
116 _info
"ZoneEnd reached, Zone ${curZone} not found in hosting.de API"
121 _hostingde_getZoneStatus
() {
122 _debug
"Checking Zone status"
123 curData
="{\"filter\":{\"field\":\"zoneConfigId\",\"value\":${zoneConfigId}},\"limit\":1,\"authToken\":\"${HOSTINGDE_APIKEY}\"}"
124 curResult
="$(_post "${curData}" "${HOSTINGDE_ENDPOINT}/api
/dns
/v
1/json
/zonesFind
")"
125 _debug
"Calling zonesFind '${curData}' '${HOSTINGDE_ENDPOINT}/api/dns/v1/json/zonesFind'"
126 _debug
"Result of zonesFind '$curResult'"
127 zoneStatus
=$
(echo "${curResult}" | _hostingde_parse
"status" "success")
128 _debug
"zoneStatus '${zoneStatus}'"
132 _hostingde_addRecord
() {
133 _info
"Adding record to zone"
134 _hostingde_getZoneStatus
135 _debug
"Result of zoneStatus: '${zoneStatus}'"
136 while [ "${zoneStatus}" != "\"active\"" ]; do
138 _hostingde_getZoneStatus
139 _debug
"Result of zoneStatus: '${zoneStatus}'"
141 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}]}"
142 curResult
="$(_post "${curData}" "${HOSTINGDE_ENDPOINT}/api
/dns
/v
1/json
/zoneUpdate
")"
143 _debug
"Calling zoneUpdate: '${curData}' '${HOSTINGDE_ENDPOINT}/api/dns/v1/json/zoneUpdate'"
144 _debug
"Result of zoneUpdate: '$curResult'"
145 if _contains
"${curResult}" '"status": "error"'; then
146 if _contains
"${curResult}" '"code": 10109'; then
147 _err
"The API-Key is invalid or could not be found"
149 _err
"UNKNOWN API ERROR"
156 _hostingde_removeRecord
() {
157 _info
"Removing record from zone"
158 _hostingde_getZoneStatus
159 _debug
"Result of zoneStatus: '$zoneStatus'"
160 while [ "$zoneStatus" != "\"active\"" ]; do
162 _hostingde_getZoneStatus
163 _debug
"Result of zoneStatus: '$zoneStatus'"
165 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}\\\"\"}]}"
166 curResult
="$(_post "${curData}" "${HOSTINGDE_ENDPOINT}/api
/dns
/v
1/json
/zoneUpdate
")"
167 _debug
"Calling zoneUpdate: '${curData}' '${HOSTINGDE_ENDPOINT}/api/dns/v1/json/zoneUpdate'"
168 _debug
"Result of zoneUpdate: '$curResult'"
169 if _contains
"${curResult}" '"status": "error"'; then
170 if _contains
"${curResult}" '"code": 10109'; then
171 _err
"The API-Key is invalid or could not be found"
173 _err
"UNKNOWN API ERROR"