Skip to content

Instantly share code, notes, and snippets.

@mueslo
Last active July 22, 2023 11:31
Show Gist options
  • Save mueslo/9258f8b75fe942d36eea4a6d67019f81 to your computer and use it in GitHub Desktop.
Save mueslo/9258f8b75fe942d36eea4a6d67019f81 to your computer and use it in GitHub Desktop.
Dynamic A-Record DNS Updater for united-domains.de (OpenWRT/LEDE)
#!/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
@schmyd
Copy link

schmyd commented Aug 2, 2022

Hi @ManuGithubSteam,

it's not really clear to me why you're getting a 404. Script is still working for me. Were you able to resolve it?

@x4FF3
Copy link

x4FF3 commented Jul 21, 2023

Hi,

did they change the login again? cannot login with this script.

EDIT: using the curl command from here: https://gist.github.com/bjuretko/abee8435c8d6f6de39a61322ad44699a does work, but cannot update the ip

@schmyd
Copy link

schmyd commented Jul 21, 2023

still worked for me this morning

@rapkin61
Copy link

Hi @izphi78,
where did you go?
I'm severly thinking about moving my domain to another hoster, that offers an API.

I'm fed up with with that scripting stuff. The shell script here worked for a while, but United Domains seem to permanently change their website. For a while I worked around this with a python script, but even this fails more and more often, because of permanent changes in the html/css code of UD.
This is extremely annoying!
Can you recommend me a good hoster, that has an API?

@mueslo
Copy link
Author

mueslo commented Jul 22, 2023

@rapkin61 FWIW, inwx was recommended to me by a friend, specifically for API access

@izphi78
Copy link

izphi78 commented Jul 22, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment