-
-
Save Recovery-95/a85988608579e6d972426283b17d536c 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment