Skip to content

Instantly share code, notes, and snippets.

@glego
Last active May 22, 2023 00:54
Show Gist options
  • Save glego/4d9edd4ce6cfa425735be3edcb9e6254 to your computer and use it in GitHub Desktop.
Save glego/4d9edd4ce6cfa425735be3edcb9e6254 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Description:
# Update the DNS A Record with your public IP address for the one.com host.
#
# Recommendation:
# - Create a separate user that can only access the DNS records.
# - Create a cron tab to run this script every 30 minutes:
# crontab -e
# */30 * * * * ~/Scripts/update-dns-one.com.sh >/dev/null 2&>1
# - To get the Sub Domain Id you will have to manually update the domain and record the network traffic using your browser
#
# Require:
# sudo apt-get install wget gawk curl ca-certificates
myusername="Username"
mypassword="Password"
mysubdomain="subDomain"
mysubdomainid="111111"
# Get my public ip address
myip=$(curl -s http://whatismyip.akamai.com/)
echo "My current ip address is $myip"
# Compare updated IP with Current IP
updateip=$(cat ~/one.com.d/myip.updated)
if [ "$myip" = "$updateip" ]
then
echo "No need to update: Current IP '$myip' equals updated IP '$updateip', exiting..."
exit 0
fi
# Make working path
cd ~/ \
&& rm -fr ~/one.com.d \
&& mkdir -p ~/one.com.d \
&& cd ~/one.com.d || exit
# Open the one.com login website
wget --user-agent=Mozilla \
--delete-after \
https://login.one.com/cp/
# Login with user and password
postdata="loginDomain=true"
postdata+="&displayUsername=$myusername&username=$myusername"
postdata+="&targetDomain="
postdata+="&password1=$mypassword"
postdata+="&loginTarget="
echo "$postdata"
wget --user-agent=Mozilla \
--content-disposition \
--save-cookies cookies.one.com.txt \
--keep-session-cookies \
--delete-after \
--post-data "$postdata" \
https://www.one.com/admin/login.do
# Open the dns overview page
wget --user-agent=Mozilla \
--content-disposition \
--load-cookies cookies.one.com.txt \
--delete-after \
https://www.one.com/admin/dns-overview.do
# Get CSRF_G_TOKEN from the cookies
mycsrft=$(< cookies.one.com.txt grep "CSRF_G_TOKEN" | awk '{print $7}')
echo "My current crft is $mycsrft"
# Update the IP address for domain entry
postdata="cmd=update&oldSubDomain=$mysubdomain&oldType=A&oldValue=8.8.8.8&oldTtl=3600&oldPriority=&subDomain=$mysubdomain&type=A"
postdata+="&value=$myip"
postdata+="&ttl=3600&priority=&id=$mysubdomainid"
postdata+="&csrft=$mycsrft"
echo "$postdata"
wget --user-agent=Mozilla \
--load-cookies cookies.one.com.txt \
--keep-session-cookies \
--save-cookies cookies.one.com.txt \
--output-document=response-$mysubdomain \
--post-data "$postdata" \
https://www.one.com/admin/dns-web-handler.do
response=$(< response-$mysubdomain \
grep -oEi '\{\s*"success"\s*:.*}' |
grep -oEi ':\w+' |
cut -c 2-)
if [ "$response" != "true" ]
then
echo "Error: Could not update subdomain '$mysubdomain', exiting..."
exit 2
fi
# Saving current ip
echo "$myip" > ~/one.com.d/myip.updated
@glego
Copy link
Author

glego commented Jan 24, 2020

Hi guys, one.com changed their website since I last created the script. I'm no longer using one.com DNS Services anymore and switched to cloudflare. They have many APIs to manage the DNS entries so it's easier to maintain.

I suggest you might do the same, their services are for free so there is no extra cost.

For the moment I'm not planning to update the script.

Cheers,
Glenn

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