From deb4ff1c07d891bd012d2a637519a511213c54d0 Mon Sep 17 00:00:00 2001 From: tripolar Date: Sun, 27 Oct 2013 22:12:10 +0000 Subject: [PATCH] [packages] ddns-scripts: add option use_syslog to enable logging to syslog use wget when it's compiled with ssl support Signed-off-by: Peter Wagner git-svn-id: svn://svn.openwrt.org/openwrt/packages@38548 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- net/ddns-scripts/Makefile | 2 +- net/ddns-scripts/files/etc/config/ddns | 2 + .../usr/lib/ddns/dynamic_dns_functions.sh | 8 +++ .../files/usr/lib/ddns/dynamic_dns_updater.sh | 52 +++++++++++-------- 4 files changed, 40 insertions(+), 24 deletions(-) diff --git a/net/ddns-scripts/Makefile b/net/ddns-scripts/Makefile index 0e9f0f3dc..4b50e8d8d 100644 --- a/net/ddns-scripts/Makefile +++ b/net/ddns-scripts/Makefile @@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=ddns-scripts PKG_VERSION:=1.0.0 -PKG_RELEASE:=21 +PKG_RELEASE:=22 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) diff --git a/net/ddns-scripts/files/etc/config/ddns b/net/ddns-scripts/files/etc/config/ddns index 740f87fdb..e7337b5ff 100644 --- a/net/ddns-scripts/files/etc/config/ddns +++ b/net/ddns-scripts/files/etc/config/ddns @@ -65,11 +65,13 @@ config service "myddns" option enabled "0" option interface "wan" + option use_syslog "1" option service_name "dyndns.org" option domain "mypersonaldomain.dyndns.org" option username "myusername" option password "mypassword" + option use_https "0" option force_interval "72" option force_unit "hours" diff --git a/net/ddns-scripts/files/usr/lib/ddns/dynamic_dns_functions.sh b/net/ddns-scripts/files/usr/lib/ddns/dynamic_dns_functions.sh index 3d435d3e7..a59693210 100644 --- a/net/ddns-scripts/files/usr/lib/ddns/dynamic_dns_functions.sh +++ b/net/ddns-scripts/files/usr/lib/ddns/dynamic_dns_functions.sh @@ -108,6 +108,14 @@ verbose_echo() fi } +syslog_echo() +{ + if [ "$use_syslog" = 1 ] + then + echo $1|logger -t ddns-scripts-$service_id + fi +} + start_daemon_for_all_ddns_sections() { local event_interface="$1" diff --git a/net/ddns-scripts/files/usr/lib/ddns/dynamic_dns_updater.sh b/net/ddns-scripts/files/usr/lib/ddns/dynamic_dns_updater.sh index 580bed84f..e6d298740 100755 --- a/net/ddns-scripts/files/usr/lib/ddns/dynamic_dns_updater.sh +++ b/net/ddns-scripts/files/usr/lib/ddns/dynamic_dns_updater.sh @@ -46,6 +46,7 @@ fi # # #config_get use_https $service_id use_https +#config_get use_syslog $service_id use_syslog #config_get cacert $service_id cacert # #config_get ip_source $service_id ip_source @@ -78,7 +79,6 @@ then check_unit="seconds" fi - if [ -z "$force_interval" ] then force_interval=72 @@ -89,29 +89,45 @@ then force_unit="hours" fi +if [ -z $use_syslog ] +then + use_syslog=0 +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" ] + /usr/bin/wget --version 2>&1 |grep -q "\+ssl" + if [ $? -eq 0 ] then - retrieve_prog="${retrieve_prog}--cacert $cacert " - elif [ -d "$cacert" ] - then - retrieve_prog="${retrieve_prog}--capath $cacert " + if [ -f "$cacert" ] + then + retrieve_prog="${retrieve_prog}--ca-certificate=${cacert} " + elif [ -d "$cacert" ] + then + retrieve_prog="${retrieve_prog}--ca-directory=${cacert} " + fi + else + 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 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\}" @@ -119,7 +135,6 @@ ip_regex="[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}" NEWLINE_IFS=' ' - #determine what update url we're using if the service_name is supplied if [ -n "$service_name" ] then @@ -149,21 +164,14 @@ then update_url=$(echo $update_url | sed -e 's/^http:/https:/') fi - verbose_echo "update_url=$update_url" - - #if this service isn't enabled then quit if [ "$enabled" != "1" ] then return 0 fi - - - - #compute update interval in seconds case "$force_unit" in "days" ) @@ -185,7 +193,6 @@ case "$force_unit" in esac - #compute check interval in seconds case "$check_unit" in "days" ) @@ -207,7 +214,6 @@ case "$check_unit" in esac - #compute retry interval in seconds case "$retry_unit" in "days" ) @@ -229,7 +235,6 @@ case "$retry_unit" in esac - verbose_echo "force seconds = $force_interval_seconds" verbose_echo "check seconds = $check_interval_seconds" @@ -283,7 +288,7 @@ do current_time=$(monotonic_time) time_since_update=$(($current_time - $last_update)) - + syslog_echo "Running IP check ..." verbose_echo "Running IP check..." verbose_echo "current system ip = $current_ip" verbose_echo "registered domain ip = $registered_ip" @@ -315,11 +320,12 @@ do update_output=$( $retrieve_prog "$final_url" ) if [ $? -gt 0 ] then + syslog_echo "update failed, retrying in $retry_interval_seconds seconds" verbose_echo "update failed" sleep $retry_interval_seconds continue fi - + syslog_echo "Update successful" verbose_echo "Update Output:" verbose_echo "$update_output" verbose_echo ""