#config_get domain $service_id domain
#
#
+#config_get use_https $service_id use_https
+#config_get cacert $service_id cacert
+#
#config_get ip_source $service_id ip_source
#config_get ip_interface $service_id ip_interface
#config_get ip_network $service_id ip_network
check_interval=600
fi
+if [ -z "$retry_interval" ]
+then
+ retry_interval=60
+fi
+
if [ -z "$check_unit" ]
then
check_unit="seconds"
force_unit="hours"
fi
+if [ -z "$use_https" ]
+then
+ use_https=0
+fi
+
#some constants
-retrieve_prog="/usr/bin/wget -O - ";
+if [ "x$use_https" = "x1" ]
+then
+ retrieve_prog="/usr/bin/curl "
+ if [ -f "$cacert" ]
+ then
+ retrieve_prog="${retrieve_prog}--cacert $cacert "
+ elif [ -d "$cacert" ]
+ then
+ retrieve_prog="${retrieve_prog}--capath $cacert "
+ fi
+else
+ retrieve_prog="/usr/bin/wget -O - ";
+fi
+
service_file="/usr/lib/ddns/services"
ip_regex="[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}"
IFS=$OLD_IFS
fi
+if [ "x$use_https" = x1 ]
+then
+ update_url=$(echo $update_url | sed -e 's/^http:/https:/')
+fi
verbose_echo "update_url=$update_url"
+#compute retry interval in seconds
+case "$retry_unit" in
+ "days" )
+ retry_interval_seconds=$(($retry_interval*60*60*24))
+ ;;
+ "hours" )
+ retry_interval_seconds=$(($retry_interval*60*60))
+ ;;
+ "minutes" )
+ retry_interval_seconds=$(($retry_interval*60))
+ ;;
+ "seconds" )
+ retry_interval_seconds=$retry_interval
+ ;;
+ * )
+ #default is seconds
+ retry_interval_seconds=$retry_interval
+ ;;
+esac
+
+
+
verbose_echo "force seconds = $force_interval_seconds"
verbose_echo "check seconds = $check_interval_seconds"
#determine when the last update was
-current_time=$(date +%s)
+current_time=$(monotonic_time)
last_update=$(( $current_time - (2*$force_interval_seconds) ))
if [ -e "/var/run/dynamic_dns/$service_id.update" ]
then
-
-registered_ip=$(echo $(nslookup "$domain" 2>/dev/null) | grep -o "Name:.*" | grep -o "$ip_regex")
-
-
#do update and then loop endlessly, checking ip every check_interval and forcing an updating once every force_interval
while [ true ]
do
+ registered_ip=$(echo $(nslookup "$domain" 2>/dev/null) | grep -o "Name:.*" | grep -o "$ip_regex")
current_ip=$(get_current_ip)
- current_time=$(date +%s)
+ current_time=$(monotonic_time)
time_since_update=$(($current_time - $last_update))
-
+
verbose_echo "Running IP check..."
verbose_echo "current system ip = $current_ip"
final_url=$update_url
for option_var in $ALL_OPTION_VARIABLES
do
- replace_name=$(echo "\[$option_var\]" | tr 'a-z' 'A-Z')
- replace_value=$(eval echo "\$$option_var")
- final_url=$(echo $final_url | sed s/"$replace_name"/"$replace_value"/g )
- done
+ if [ "$option_var" != "update_url" ]
+ then
+ replace_name=$(echo "\[$option_var\]" | tr 'a-z' 'A-Z')
+ replace_value=$(eval echo "\$$option_var")
+ replace_value=$(echo $replace_value | sed -f /usr/lib/ddns/url_escape.sed)
+ final_url=$(echo $final_url | sed s^"$replace_name"^"$replace_value"^g )
+ fi
+ done
+ final_url=$(echo $final_url | sed s/"\[HTTPAUTH\]"/"$username${password:+:$password}"/g )
final_url=$(echo $final_url | sed s/"\[IP\]"/"$current_ip"/g )
-
+
verbose_echo "updating with url=\"$final_url\""
#here we actually connect, and perform the update
update_output=$( $retrieve_prog "$final_url" )
+ if [ $? -gt 0 ]
+ then
+ verbose_echo "update failed"
+ sleep $retry_interval_seconds
+ continue
+ fi
verbose_echo "Update Output:"
verbose_echo "$update_output"
verbose_echo ""
#save the time of the update
- current_time=$(date +%s)
+ current_time=$(monotonic_time)
last_update=$current_time
time_since_update='0'
registered_ip=$current_ip
-
+
human_time=$(date)
verbose_echo "update complete, time is: $human_time"
-
+
echo "$last_update" > "/var/run/dynamic_dns/$service_id.update"
else
human_time=$(date)