Last active
January 16, 2019 02:09
-
-
Save xand79/3998800ee1df9e2244d96750e829b8ff to your computer and use it in GitHub Desktop.
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/bash | |
# Autochange both @ and www records at freenom.com with dynamical IP. | |
# Extended from https://gist.github.com/tkidd77 | |
# Added: | |
# - admin e-mail notifications; | |
# - old IP memory for not to touch freenom each time if new IP is the same (stored in /etc/current-ip). | |
# October 2016 > working well | |
# Just put your values below, then make crontab task for this script | |
info_mail="mail-for-notifications@mailbox" | |
freenom_email="your-freenom-registration@mailbox" | |
freenom_passwd="password" | |
freenom_domain_name="your-domain.com" | |
freenom_domain_id="0000000000" | |
current_ip="$(curl -s "ident.me")" | |
if [ "${current_ip}" == "" ]; then | |
current_ip="$(curl -s "https://api.ipify.org/")" | |
fi | |
if [ "${current_ip}" == "" ]; then | |
echo "Empty new IP" | mail -s "Your server - IP" "${info_mail}" | |
exit 0 | |
fi | |
old_ip="$(cat "/etc/current-ip")" | |
if [ "${current_ip}" == "${old_ip}" ]; then | |
exit 0 | |
fi | |
echo $current_ip > /etc/current-ip | |
cookie_file=$(mktemp) | |
loginResult=$(curl --compressed -k -L -c "${cookie_file}" \ | |
-F "username=${freenom_email}" -F "password=${freenom_passwd}" \ | |
"https://my.freenom.com/dologin.php" 2>&1) | |
if [ "$(echo -e "${loginResult}" | grep "/clientarea.php?incorrect=true")" != "" ]; then | |
echo "Freenom login fail" | mail -s "Your server - IP" "${info_mail}" | |
exit 0 | |
fi | |
updateResult=$(curl --compressed -k -L -b "${cookie_file}" \ | |
-F "dnsaction=modify" -F "records[0][line]=" -F "records[0][type]=A" -F "records[0][name]=" -F "records[0][ttl]=14440" -F "records[0][value]=${current_ip}" \ | |
-F "dnsaction=modify" -F "records[1][line]=" -F "records[1][type]=A" -F "records[1][name]=www" -F "records[1][ttl]=14440" -F "records[1][value]=${current_ip}" \ | |
"https://my.freenom.com/clientarea.php?managedns=${freenom_domain_name}&domainid=${freenom_domain_id}" 2>&1) | |
if [ "$(echo -e "$updateResult" | grep "<li class=\"dnssuccess\">")" == "" ]; then | |
echo "Freenom update fail" | mail -s "Your server - IP" "${info_mail}" | |
exit 0 | |
fi | |
curl --compressed -k -b "${cookie_file}" "https://my.freenom.com/logout.php" > /dev/null 2>&1 | |
rm -f ${cookie_file} | |
echo "Freenom IP update OK" | mail -s "Your server - new IP OK" "${info_mail}" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment