Last active
July 22, 2023 11:31
-
-
Save mueslo/9258f8b75fe942d36eea4a6d67019f81 to your computer and use it in GitHub Desktop.
Dynamic A-Record DNS Updater for united-domains.de (OpenWRT/LEDE)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# requires: wget, ca-certificates, grep | |
#rm /tmp/cookies.txt | |
cookiefile="/tmp/cookies.txt" | |
#domain should contain "domain_id-record_id" | |
domain_id=$(echo $domain | tr "-" "\n" | sed -n "1p") | |
record_id=$(echo $domain | tr "-" "\n" | sed -n "2p") | |
#csrf tokens for login + language xmlhttprequest required to login (nice try blocking my API access, UD) | |
loginpage=$(/usr/bin/wget --save-cookies $cookiefile --keep-session-cookies --delete-after -qO- "https://www.united-domains.de/login/") | |
csrf=$(echo "$loginpage" | /bin/grep -oP -m 2 "(?<=<input type=\"hidden\" name=\"csrf\" value=\")[^\"]*(?=\"( /)?>)" | tail -1) | |
csrfmeta=$(echo "$loginpage" | /bin/grep -oP -m 1 "(?<=<meta name=\"csrf\" content=\")[^\"]*(?=\"( /)?>)") | |
csrfscript=$(echo "$loginpage" | /bin/grep -oP -m 1 "(?<=\"CSRF_TOKEN\":\")[^\"]*(?=\")") | |
/usr/bin/wget --load-cookies $cookiefile --save-cookies $cookiefile --keep-session-cookies --delete-after --post-data "language=en-US" --header="HTTP-X-CSRF-TOKEN: $csrfmeta" --header="X-Csrf-Token: $csrfscript" --header="X-Requested-With: XMLHttpRequest" -qO- "https://www.united-domains.de/set-user-language" | |
ipv4=$1 | |
#login | |
echo 'login' | |
loginresp=$(/usr/bin/wget --load-cookies $cookiefile --save-cookies $cookiefile --keep-session-cookies --post-data "csrf=$csrf&email=$username&pwd=$password&selector=login&loginBtn=Login" -qO- "https://www.united-domains.de/login/") | |
#get current dns record json object & modify ip | |
record=$(/usr/bin/wget --load-cookies $cookiefile --save-cookies $cookiefile --keep-session-cookies -qO- "https://www.united-domains.de/pfapi/dns/domain/$domain_id/records" | jsonfilter -e "$[\"data\"][\"A\"][@.id=$record_id]" | sed "s/ //g" | sed "s/\"address\":\"[0-9.]\+\"/\"address\":\"$ipv4\"/g") | |
payload="{\"record\":$record,\"domain_lock_state\":{\"domain_locked\":false,\"email_locked\":false}}" | |
url="https://www.united-domains.de/pfapi/dns/domain/$domain_id/records" | |
#send changes | |
output=$(/usr/bin/wget --load-cookies $cookiefile --method=PUT --header=Content-Type:application/json --header="Http-X-Csrf-Token: $csrf" --body-data=$payload -qO- $url 2>&1) | |
echo "UD answered: $output" | |
write_log 7 "UD answered:\n$output" | |
echo $output | /usr/grep "$ipv4" >/dev/null 2>&1 | |
success=$? | |
#write_log 7 "Retval: $success" | |
echo "Retval: $success" | |
return $success |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@rapkin61 I went to cloudflare. No need to transfer your Domain. Just add it to the Dashboard and set the NS records. If you want to keep mail functionality, set it accordingly in the UD settings and set the MX records as shown in the instructions.
Never had any trouble with it after going that route. And much stuff has integration for Cloudflare like certbot.