6 #INWX_Password="password"
10 # - oathtool (When using 2 Factor Authentication)
12 INWX_Api
="https://api.domrobot.com/xmlrpc/"
14 ######## Public functions #####################
16 #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
21 INWX_User
="${INWX_User:-$(_readaccountconf_mutable INWX_User)}"
22 INWX_Password
="${INWX_Password:-$(_readaccountconf_mutable INWX_Password)}"
23 INWX_Shared_Secret
="${INWX_Shared_Secret:-$(_readaccountconf_mutable INWX_Shared_Secret)}"
24 if [ -z "$INWX_User" ] ||
[ -z "$INWX_Password" ]; then
27 _err
"You don't specify inwx user and password yet."
28 _err
"Please create you key and try again."
32 #save the api key and email to the account conf file.
33 _saveaccountconf_mutable INWX_User
"$INWX_User"
34 _saveaccountconf_mutable INWX_Password
"$INWX_Password"
35 _saveaccountconf_mutable INWX_Shared_Secret
"$INWX_Shared_Secret"
37 if ! _inwx_login
; then
41 _debug
"First detect the root zone"
42 if ! _get_root
"$fulldomain"; then
46 _debug _sub_domain
"$_sub_domain"
47 _debug _domain
"$_domain"
50 _inwx_add_record
"$_domain" "$_sub_domain" "$txtvalue"
60 INWX_User
="${INWX_User:-$(_readaccountconf_mutable INWX_User)}"
61 INWX_Password
="${INWX_Password:-$(_readaccountconf_mutable INWX_Password)}"
62 INWX_Shared_Secret
="${INWX_Shared_Secret:-$(_readaccountconf_mutable INWX_Shared_Secret)}"
63 if [ -z "$INWX_User" ] ||
[ -z "$INWX_Password" ]; then
66 _err
"You don't specify inwx user and password yet."
67 _err
"Please create you key and try again."
71 if ! _inwx_login
; then
75 _debug
"First detect the root zone"
76 if ! _get_root
"$fulldomain"; then
80 _debug _sub_domain
"$_sub_domain"
81 _debug _domain
"$_domain"
83 _debug
"Getting txt records"
85 xml_content
=$
(printf '<?xml version="1.0" encoding="UTF-8"?>
87 <methodName>nameserver.info</methodName>
114 </methodCall>' "$_domain" "$_sub_domain")
115 response
="$(_post "$xml_content" "$INWX_Api" "" "POST
")"
117 if ! _contains
"$response" "Command completed successfully"; then
118 _err
"Error could not get txt records"
122 if ! printf "%s" "$response" |
grep "count" >/dev
/null
; then
123 _info
"Do not need to delete record"
125 _record_id
=$
(printf '%s' "$response" | _egrep_o
'.*(<member><name>record){1}(.*)([0-9]+){1}' | _egrep_o
'<name>id<\/name><value><int>[0-9]+' | _egrep_o
'[0-9]+')
126 _info
"Deleting record"
127 _inwx_delete_record
"$_record_id"
132 #################### Private functions below ##################################
134 _inwx_check_cookie
() {
135 INWX_Cookie
="${INWX_Cookie:-$(_readaccountconf_mutable INWX_Cookie)}"
136 if [ -z "$INWX_Cookie" ]; then
137 _debug
"No cached cookie found"
143 xml_content
=$
(printf '<?xml version="1.0" encoding="UTF-8"?>
145 <methodName>account.info</methodName>
148 response
="$(_post "$xml_content" "$INWX_Api" "" "POST
")"
150 if _contains
"$response" "<member><name>code</name><value><int>1000</int></value></member>"; then
151 _debug
"Cached cookie still valid"
155 _debug
"Cached cookie no longer valid"
159 _saveaccountconf_mutable INWX_Cookie
"$INWX_Cookie"
165 if _inwx_check_cookie
; then
166 _debug
"Already logged in"
170 xml_content
=$
(printf '<?xml version="1.0" encoding="UTF-8"?>
172 <methodName>account.login</methodName>
193 </methodCall>' "$INWX_User" "$INWX_Password")
195 response
="$(_post "$xml_content" "$INWX_Api" "" "POST
")"
197 INWX_Cookie
=$
(printf "Cookie: %s" "$(grep "domrobot
=" "$HTTP_HEADER" | grep "^Set-Cookie
:" | _tail_n 1 | _egrep_o 'domrobot=[^;]*;' | tr -d ';')")
201 _saveaccountconf_mutable INWX_Cookie
"$INWX_Cookie"
203 if ! _contains
"$response" "<member><name>code</name><value><int>1000</int></value></member>"; then
204 _err
"INWX API: Authentication error (username/password correct?)"
208 #https://github.com/inwx/php-client/blob/master/INWX/Domrobot.php#L71
209 if _contains
"$response" "<member><name>tfa</name><value><string>GOOGLE-AUTH</string></value></member>"; then
210 if [ -z "$INWX_Shared_Secret" ]; then
211 _err
"INWX API: Mobile TAN detected."
212 _err
"Please define a shared secret."
216 if ! _exists oathtool
; then
217 _err
"Please install oathtool to use 2 Factor Authentication."
222 tan
="$(oathtool --base32 --totp "${INWX_Shared_Secret}" 2>/dev/null)"
224 xml_content
=$
(printf '<?xml version="1.0" encoding="UTF-8"?>
226 <methodName>account.unlock</methodName>
241 </methodCall>' "$tan")
243 response
="$(_post "$xml_content" "$INWX_Api" "" "POST
")"
245 if ! _contains
"$response" "<member><name>code</name><value><int>1000</int></value></member>"; then
246 _err
"INWX API: Mobile TAN not correct."
261 xml_content
='<?xml version="1.0" encoding="UTF-8"?>
263 <methodName>nameserver.list</methodName>
269 <name>pagelimit</name>
280 response
="$(_post "$xml_content" "$INWX_Api" "" "POST
")"
282 h
=$
(printf "%s" "$domain" | cut
-d .
-f $i-100)
289 if _contains
"$response" "$h"; then
290 _sub_domain
=$
(printf "%s" "$domain" | cut
-d .
-f 1-$p)
301 _inwx_delete_record
() {
303 xml_content
=$
(printf '<?xml version="1.0" encoding="UTF-8"?>
305 <methodName>nameserver.deleteRecord</methodName>
320 </methodCall>' "$record_id")
322 response
="$(_post "$xml_content" "$INWX_Api" "" "POST
")"
324 if ! printf "%s" "$response" |
grep "Command completed successfully" >/dev
/null
; then
332 _inwx_update_record
() {
335 xml_content
=$
(printf '<?xml version="1.0" encoding="UTF-8"?>
337 <methodName>nameserver.updateRecord</methodName>
358 </methodCall>' "$txtval" "$record_id")
360 response
="$(_post "$xml_content" "$INWX_Api" "" "POST
")"
362 if ! printf "%s" "$response" |
grep "Command completed successfully" >/dev
/null
; then
376 xml_content
=$
(printf '<?xml version="1.0" encoding="UTF-8"?>
378 <methodName>nameserver.createRecord</methodName>
411 </methodCall>' "$domain" "$txtval" "$sub_domain")
413 response
="$(_post "$xml_content" "$INWX_Api" "" "POST
")"
415 if ! printf "%s" "$response" |
grep "Command completed successfully" >/dev
/null
; then