BASE_URL="https://my.freenom.com"
CAREA_URL="$BASE_URL/clientarea.php"
LOGIN_URL="$BASE_URL/dologin.php"
LOGOUT_URL="$BASE_URL/logout.php"
MANAGED_URL="$CAREA_URL?managedns=$freenom_domain_name&domainid=$freenom_domain_id"
#GET_IP_URL="https://api.ipify.org/"
perl <<'__HERE__'
use Socket;
use strict;
use warnings;
our $current_ip = inet_ntoa(scalar gethostbyname(my $host || 'midominio.ISP.es' ));
print "current ip: $current_ip\n";
our $server_ip = inet_ntoa(scalar gethostbyname( $host || 'midominio.com' ));
print "server ip: $server_ip\n";
if ($current_ip eq $server_ip){
print "Las IP coinciden\n";
exit 0;
}else{
print "se actulizaran las DNS";
exit 1;}
bash echo "print mi ip $current_ip"
__HERE__
if [ $? = "0" ]; then
exit 0
fi
# get current ip address
current_ip="$(curl -s ifconfig.me/ip)"
#salidaip="$(perl -e inet_ntoa(scalar gethostbyname(my $host || 'midominio.ISP.es' ))"
#echo "$salidaip"
#server_ip="$(host -t a $freenom_domain_name | sed 's/.*has address //')"
#server_ip="$(dig +short reno.gq @ns01.freenom.com)"
#echo "server ip:" $server_ip
echo "current ip:" $current_ip
if [ -z "$current_ip" ]; then
echo "Could not get current IP address." 1>&2
exit 1
fi
cookie_file=$(mktemp)
#Para prueba
#echo "sale por aca"
#exit 0
cleanup() {
echo "Cleanup"
rm -f "$cookie_file"
}
trap cleanup INT EXIT TERM
echo "Login"
loginResult=$(curl --compressed -k -L -c "$cookie_file" \
-F "username=$freenom_email" -F "password=$freenom_passwd" \
-e "$CAREA_URL" \
"$LOGIN_URL" 2>&1)
if [ ! -s "$cookie_file" ]; then
echo "Login failed: empty cookie." 1>&2
exit 1
fi
if echo "$loginResult" | grep -q "/clientarea.php?incorrect=true"; then
echo "Login failed." 1>&2
exit 1
fi
echo "Update $current_ip to domain($freenom_domain_name)"
updateResult=$(curl --compressed -k -L -b "$cookie_file" \
-e "$MANAGED_URL" \
-F "dnsaction=modify" \
-F "records[0][line]=" \
-F "records[0][type]=A" \
-F "records[0][name]=$freenom_domain_name" \
-F "records[0][ttl]=7200" \
-F "records[0][value]=$current_ip" \
-F "records[1][line]=" \
-F "records[1][type]=A" \
-F "records[1][name]=www.$freenom_domain_name" \
-F "records[1][ttl]=7200" \
-F "records[1][value]=$current_ip" \
"$MANAGED_URL" 2>&1)
if ! echo "$updateResult" | grep -q "name=\"records\[0\]\[value\]\" value=\"$current_ip\""; then
echo "Update failed." 1>&2
exit 1
fi
echo "Logout"
curl --compressed -k -b "$cookie_file" "$LOGOUT_URL" > /dev/null 2>&1
exit 0