Last active
May 22, 2023 00:54
-
-
Save glego/4d9edd4ce6cfa425735be3edcb9e6254 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/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 |
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
Hi,
--2020-01-20 13:11:45-- https://www.one.com/admin/dns-overview.do
Resolving www.one.com (www.one.com)... 2a02:2350:6::6514:e26d, 195.47.247.9, 195 .47.247.8
Connecting to www.one.com (www.one.com)|2a02:2350:6::6514:e26d|:443... connected .
HTTP request sent, awaiting response... 404 Not Found
2020-01-20 13:11:46 ERROR 404: Not Found.
Second one:
My current crft is
....
--2020-01-20 13:11:46-- https://www.one.com/admin/dns-web-handler.do
Resolving www.one.com (www.one.com)... 2a02:2350:6::6514:e26d, 195.47.247.9, 195 .47.247.8
Connecting to www.one.com (www.one.com)|2a02:2350:6::6514:e26d|:443... connected .
HTTP request sent, awaiting response... 404 Not Found
2020-01-20 13:11:46 ERROR 404: Not Found.