2020-11-22 10:22:54 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
|
|
|
# World4You - www.world4you.com
|
|
|
|
# Lorenz Stechauner, 2020 - https://www.github.com/NerLOR
|
|
|
|
|
|
|
|
WORLD4YOU_API="https://my.world4you.com/en"
|
2020-11-27 21:12:11 +00:00
|
|
|
PAKETNR=''
|
2020-11-28 07:50:47 +00:00
|
|
|
TLD=''
|
|
|
|
RECORD=''
|
2020-11-22 10:22:54 +00:00
|
|
|
|
|
|
|
################ Public functions ################
|
|
|
|
|
|
|
|
# Usage: dns_world4you_add <fqdn> <value>
|
|
|
|
dns_world4you_add() {
|
|
|
|
fqdn="$1"
|
|
|
|
value="$2"
|
2020-11-29 14:22:41 +00:00
|
|
|
_info "Using world4you to add record"
|
2020-11-22 10:22:54 +00:00
|
|
|
_debug fulldomain "$fqdn"
|
|
|
|
_debug txtvalue "$value"
|
|
|
|
|
|
|
|
_login
|
|
|
|
if [ "$?" != 0 ]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
export _H1="Cookie: W4YSESSID=$sessid"
|
2022-01-24 15:47:47 +00:00
|
|
|
form=$(_get "$WORLD4YOU_API/")
|
2020-11-28 07:50:47 +00:00
|
|
|
_get_paketnr "$fqdn" "$form"
|
2020-11-27 21:12:11 +00:00
|
|
|
paketnr="$PAKETNR"
|
2020-11-22 10:22:54 +00:00
|
|
|
if [ -z "$paketnr" ]; then
|
|
|
|
_err "Unable to parse paketnr"
|
|
|
|
return 3
|
|
|
|
fi
|
|
|
|
_debug paketnr "$paketnr"
|
|
|
|
|
|
|
|
export _H1="Cookie: W4YSESSID=$sessid"
|
|
|
|
form=$(_get "$WORLD4YOU_API/$paketnr/dns")
|
|
|
|
formiddp=$(echo "$form" | grep 'AddDnsRecordForm\[uniqueFormIdDP\]' | sed 's/^.*name="AddDnsRecordForm\[uniqueFormIdDP\]" value="\([^"]*\)".*$/\1/')
|
|
|
|
form_token=$(echo "$form" | grep 'AddDnsRecordForm\[_token\]' | sed 's/^.*name="AddDnsRecordForm\[_token\]" value="\([^"]*\)".*$/\1/')
|
|
|
|
if [ -z "$formiddp" ]; then
|
|
|
|
_err "Unable to parse form"
|
|
|
|
return 3
|
|
|
|
fi
|
|
|
|
|
2020-11-29 10:55:22 +00:00
|
|
|
_resethttp
|
2020-11-29 11:03:51 +00:00
|
|
|
export ACME_HTTP_NO_REDIRECTS=1
|
2021-10-06 12:01:18 +00:00
|
|
|
body="AddDnsRecordForm[name]=$RECORD&AddDnsRecordForm[dnsType][type]=TXT&AddDnsRecordForm[value]=$value&AddDnsRecordForm[uniqueFormIdDP]=$formiddp&AddDnsRecordForm[_token]=$form_token"
|
2020-11-22 10:22:54 +00:00
|
|
|
_info "Adding record..."
|
|
|
|
ret=$(_post "$body" "$WORLD4YOU_API/$paketnr/dns" '' POST 'application/x-www-form-urlencoded')
|
2020-11-29 10:55:22 +00:00
|
|
|
_resethttp
|
2020-11-22 10:22:54 +00:00
|
|
|
|
2022-07-10 16:55:36 +00:00
|
|
|
if _contains "$(_head_n 1 <"$HTTP_HEADER")" '302'; then
|
2020-11-30 19:01:43 +00:00
|
|
|
res=$(_get "$WORLD4YOU_API/$paketnr/dns")
|
|
|
|
if _contains "$res" "successfully"; then
|
2020-11-30 16:57:25 +00:00
|
|
|
return 0
|
|
|
|
else
|
2022-04-28 08:57:31 +00:00
|
|
|
msg=$(echo "$res" | grep -A 15 'data-type="danger"' | grep "<h3[^>]*>[^<]" | sed 's/<[^>]*>\|^\s*//g')
|
|
|
|
if [ "$msg" = '' ]; then
|
|
|
|
_err "Unable to add record: Unknown error"
|
2020-12-21 08:41:05 +00:00
|
|
|
echo "$ret" >'error-01.html'
|
|
|
|
echo "$res" >'error-02.html'
|
2020-12-21 08:39:09 +00:00
|
|
|
_err "View error-01.html and error-02.html for debugging"
|
2022-04-28 08:57:31 +00:00
|
|
|
else
|
|
|
|
_err "Unable to add record: my.world4you.com: $msg"
|
2020-12-21 08:39:09 +00:00
|
|
|
fi
|
2020-11-30 16:57:25 +00:00
|
|
|
return 1
|
|
|
|
fi
|
2020-11-22 10:22:54 +00:00
|
|
|
else
|
2022-07-10 17:25:31 +00:00
|
|
|
msg=$(echo "$ret" | grep '"form-error-message"' | sed 's/^.*<div class="form-error-message">\([^<]*\)<\/div>.*$/\1/')
|
|
|
|
_err "Unable to add record: my.world4you.com: $msg"
|
2020-11-29 14:03:54 +00:00
|
|
|
return 1
|
2020-11-22 10:22:54 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Usage: dns_world4you_rm <fqdn> <value>
|
|
|
|
dns_world4you_rm() {
|
|
|
|
fqdn="$1"
|
|
|
|
value="$2"
|
2020-11-29 14:22:41 +00:00
|
|
|
_info "Using world4you to remove record"
|
2020-11-22 10:22:54 +00:00
|
|
|
_debug fulldomain "$fqdn"
|
|
|
|
_debug txtvalue "$value"
|
|
|
|
|
|
|
|
_login
|
|
|
|
if [ "$?" != 0 ]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
export _H1="Cookie: W4YSESSID=$sessid"
|
2022-01-24 15:47:47 +00:00
|
|
|
form=$(_get "$WORLD4YOU_API/")
|
2020-11-28 07:50:47 +00:00
|
|
|
_get_paketnr "$fqdn" "$form"
|
2020-11-27 21:12:11 +00:00
|
|
|
paketnr="$PAKETNR"
|
2020-11-22 10:22:54 +00:00
|
|
|
if [ -z "$paketnr" ]; then
|
|
|
|
_err "Unable to parse paketnr"
|
|
|
|
return 3
|
|
|
|
fi
|
|
|
|
_debug paketnr "$paketnr"
|
|
|
|
|
|
|
|
form=$(_get "$WORLD4YOU_API/$paketnr/dns")
|
|
|
|
formiddp=$(echo "$form" | grep 'DeleteDnsRecordForm\[uniqueFormIdDP\]' | sed 's/^.*name="DeleteDnsRecordForm\[uniqueFormIdDP\]" value="\([^"]*\)".*$/\1/')
|
|
|
|
form_token=$(echo "$form" | grep 'DeleteDnsRecordForm\[_token\]' | sed 's/^.*name="DeleteDnsRecordForm\[_token\]" value="\([^"]*\)".*$/\1/')
|
|
|
|
if [ -z "$formiddp" ]; then
|
|
|
|
_err "Unable to parse form"
|
|
|
|
return 3
|
|
|
|
fi
|
|
|
|
|
|
|
|
recordid=$(printf "TXT:%s.:\"%s\"" "$fqdn" "$value" | _base64)
|
|
|
|
_debug recordid "$recordid"
|
|
|
|
|
2020-11-29 10:55:22 +00:00
|
|
|
_resethttp
|
2020-11-29 11:03:51 +00:00
|
|
|
export ACME_HTTP_NO_REDIRECTS=1
|
2021-10-06 12:01:18 +00:00
|
|
|
body="DeleteDnsRecordForm[recordId]=$recordid&DeleteDnsRecordForm[uniqueFormIdDP]=$formiddp&DeleteDnsRecordForm[_token]=$form_token"
|
2020-11-22 10:22:54 +00:00
|
|
|
_info "Removing record..."
|
2021-10-06 12:01:18 +00:00
|
|
|
ret=$(_post "$body" "$WORLD4YOU_API/$paketnr/dns/record/delete" '' POST 'application/x-www-form-urlencoded')
|
2020-11-29 10:55:22 +00:00
|
|
|
_resethttp
|
2020-11-22 10:22:54 +00:00
|
|
|
|
2022-07-10 16:55:36 +00:00
|
|
|
if _contains "$(_head_n 1 <"$HTTP_HEADER")" '302'; then
|
2020-11-30 19:01:43 +00:00
|
|
|
res=$(_get "$WORLD4YOU_API/$paketnr/dns")
|
|
|
|
if _contains "$res" "successfully"; then
|
2020-11-30 16:57:25 +00:00
|
|
|
return 0
|
|
|
|
else
|
2022-04-28 08:57:31 +00:00
|
|
|
msg=$(echo "$res" | grep -A 15 'data-type="danger"' | grep "<h3[^>]*>[^<]" | sed 's/<[^>]*>\|^\s*//g')
|
|
|
|
if [ "$msg" = '' ]; then
|
|
|
|
_err "Unable to remove record: Unknown error"
|
2020-12-21 08:41:05 +00:00
|
|
|
echo "$ret" >'error-01.html'
|
|
|
|
echo "$res" >'error-02.html'
|
2020-12-21 08:39:09 +00:00
|
|
|
_err "View error-01.html and error-02.html for debugging"
|
2022-04-28 08:57:31 +00:00
|
|
|
else
|
|
|
|
_err "Unable to remove record: my.world4you.com: $msg"
|
2020-12-21 08:39:09 +00:00
|
|
|
fi
|
2020-11-30 16:57:25 +00:00
|
|
|
return 1
|
|
|
|
fi
|
2020-11-22 10:22:54 +00:00
|
|
|
else
|
2022-07-10 17:25:31 +00:00
|
|
|
msg=$(echo "$ret" | grep "form-error-message" | sed 's/^.*<div class="form-error-message">\([^<]*\)<\/div>.*$/\1/')
|
|
|
|
_err "Unable to remove record: my.world4you.com: $msg"
|
2020-11-29 14:03:54 +00:00
|
|
|
return 1
|
2020-11-22 10:22:54 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
################ Private functions ################
|
|
|
|
|
|
|
|
# Usage: _login
|
|
|
|
_login() {
|
|
|
|
WORLD4YOU_USERNAME="${WORLD4YOU_USERNAME:-$(_readaccountconf_mutable WORLD4YOU_USERNAME)}"
|
|
|
|
WORLD4YOU_PASSWORD="${WORLD4YOU_PASSWORD:-$(_readaccountconf_mutable WORLD4YOU_PASSWORD)}"
|
|
|
|
|
|
|
|
if [ -z "$WORLD4YOU_USERNAME" ] || [ -z "$WORLD4YOU_PASSWORD" ]; then
|
|
|
|
WORLD4YOU_USERNAME=""
|
|
|
|
WORLD4YOU_PASSWORD=""
|
2020-11-29 10:51:16 +00:00
|
|
|
_err "You didn't specify world4you username and password yet."
|
2020-11-22 10:22:54 +00:00
|
|
|
_err "Usage: export WORLD4YOU_USERNAME=<name>"
|
|
|
|
_err "Usage: export WORLD4YOU_PASSWORD=<password>"
|
2020-11-29 14:03:54 +00:00
|
|
|
return 1
|
2020-11-22 10:22:54 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
_saveaccountconf_mutable WORLD4YOU_USERNAME "$WORLD4YOU_USERNAME"
|
|
|
|
_saveaccountconf_mutable WORLD4YOU_PASSWORD "$WORLD4YOU_PASSWORD"
|
|
|
|
|
2022-07-10 16:55:36 +00:00
|
|
|
_resethttp
|
|
|
|
export ACME_HTTP_NO_REDIRECTS=1
|
|
|
|
page=$(_get "$WORLD4YOU_API/login")
|
|
|
|
_resethttp
|
|
|
|
|
|
|
|
if _contains "$(_head_n 1 <"$HTTP_HEADER")" '302'; then
|
|
|
|
_info "Already logged in"
|
|
|
|
_parse_sessid
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2020-11-22 10:22:54 +00:00
|
|
|
_info "Logging in..."
|
|
|
|
|
|
|
|
username="$WORLD4YOU_USERNAME"
|
|
|
|
password="$WORLD4YOU_PASSWORD"
|
2022-07-10 16:55:36 +00:00
|
|
|
csrf_token=$(echo "$page" | grep '_csrf_token' | sed 's/^.*<input[^>]*value=\"\([^"]*\)\".*$/\1/')
|
2022-07-10 15:38:26 +00:00
|
|
|
_parse_sessid
|
2020-11-22 10:22:54 +00:00
|
|
|
|
|
|
|
export _H1="Cookie: W4YSESSID=$sessid"
|
|
|
|
export _H2="X-Requested-With: XMLHttpRequest"
|
|
|
|
body="_username=$username&_password=$password&_csrf_token=$csrf_token"
|
|
|
|
ret=$(_post "$body" "$WORLD4YOU_API/login" '' POST 'application/x-www-form-urlencoded')
|
|
|
|
unset _H2
|
2022-07-10 15:38:26 +00:00
|
|
|
|
2020-11-22 10:22:54 +00:00
|
|
|
_debug ret "$ret"
|
|
|
|
if _contains "$ret" "\"success\":true"; then
|
|
|
|
_info "Successfully logged in"
|
2022-07-10 15:38:26 +00:00
|
|
|
_parse_sessid
|
2020-11-22 10:22:54 +00:00
|
|
|
else
|
2022-07-10 17:25:31 +00:00
|
|
|
msg=$(echo "$ret" | sed 's/^.*"message":"\([^\"]*\)".*$/\1/')
|
|
|
|
_err "Unable to log in: my.world4you.com: $msg"
|
2020-11-22 10:22:54 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
2020-11-27 18:34:16 +00:00
|
|
|
|
2022-07-10 15:38:26 +00:00
|
|
|
# Usage: _get_paketnr <fqdn> <form>
|
2020-11-27 21:12:11 +00:00
|
|
|
_get_paketnr() {
|
2020-11-28 07:50:47 +00:00
|
|
|
fqdn="$1"
|
2020-11-27 21:12:11 +00:00
|
|
|
form="$2"
|
|
|
|
|
2022-01-24 15:47:47 +00:00
|
|
|
domains=$(echo "$form" | grep 'header-paket-domain' | sed 's/<[^>]*>//g' | sed 's/^.*>\([^>]*\)$/\1/')
|
2020-11-27 21:22:50 +00:00
|
|
|
domain=''
|
|
|
|
for domain in $domains; do
|
2020-12-21 08:39:09 +00:00
|
|
|
if _contains "$fqdn" "$domain\$"; then
|
2020-11-27 21:22:50 +00:00
|
|
|
break
|
2020-11-27 21:12:11 +00:00
|
|
|
fi
|
2020-11-28 07:50:47 +00:00
|
|
|
domain=''
|
2020-11-27 21:12:11 +00:00
|
|
|
done
|
2020-11-27 21:22:50 +00:00
|
|
|
if [ -z "$domain" ]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2020-11-28 07:50:47 +00:00
|
|
|
TLD="$domain"
|
2020-12-20 19:17:05 +00:00
|
|
|
_debug domain "$domain"
|
2020-11-28 07:50:47 +00:00
|
|
|
RECORD=$(echo "$fqdn" | cut -c"1-$((${#fqdn} - ${#TLD} - 1))")
|
2022-04-28 08:57:31 +00:00
|
|
|
PAKETNR=$(echo "$form" | grep "data-textfilter=\".* $domain " | _tail_n 1 | sed "s|.*$WORLD4YOU_API/\\([0-9]*\\)/.*|\\1|")
|
2020-11-27 21:22:50 +00:00
|
|
|
return 0
|
2020-11-27 21:12:11 +00:00
|
|
|
}
|
2022-07-10 15:38:26 +00:00
|
|
|
|
|
|
|
# Usage: _parse_sessid
|
|
|
|
_parse_sessid() {
|
|
|
|
sessid=$(grep 'W4YSESSID' <"$HTTP_HEADER" | _tail_n 1 | sed 's/^.*W4YSESSID=\([^;]*\);.*$/\1/')
|
|
|
|
}
|