ddns-scripts: Added support for custom update scripts
authorSteven Barth <redacted>
Mon, 6 Oct 2014 06:39:59 +0000 (08:39 +0200)
committerSteven Barth <redacted>
Mon, 6 Oct 2014 06:39:59 +0000 (08:39 +0200)
Squashed commit of the following:

commit 2701c8868e1ef4949db57e53b27958edba6abb59
Author: Christian Schoenebeck <redacted>
Date:   Sun Oct 5 11:01:57 2014 +0200

    ddns-scripts: Added support for custom update scripts

    Sample script
Signed-off-by: Christian Schoenebeck <redacted>
commit e07ecb90fa2c7404a97cf64024e89bd9d88aacd4
Author: Christian Schoenebeck <redacted>
Date:   Sun Oct 5 11:00:11 2014 +0200

    ddns-scripts: Added support for custom update scripts

    Added support for custom update scripts with new option update_script.
    function get_service_url() renamed to get_service_data() and extended to detect scripts inside service / service_ipv6 for later use
    function send_update() modified to support custom update scripts.
Signed-off-by: Christian Schoenebeck <redacted>
commit 39e41b2151a79a7ace71a9d40b87cd4d6ce09503
Author: Christian Schoenebeck <redacted>
Date:   Sun Oct 5 10:52:44 2014 +0200

    ddns-scripts: Added support for custom update scripts

    Added support for custom update scripts with new option update_script
Signed-off-by: Christian Schoenebeck <redacted>
commit 33f264768e37d8a6fe564faaafa51a7b45a0ee19
Author: Christian Schoenebeck <redacted>
Date:   Sun Oct 5 10:48:21 2014 +0200

    ddns-scripts: Insert description for NEW option update_script

    Insert description for NEW option update_script
Signed-off-by: Christian Schoenebeck <redacted>
commit 6f6a60244df53e0556f5c75845c69aa832f97e4c
Author: Christian Schoenebeck <redacted>
Date:   Sun Oct 5 10:43:52 2014 +0200

    ddns-scripts: Update PKG_RELEASE

    Update_PKG_RELEASE to reflect changes
Signed-off-by: Christian Schoenebeck <redacted>
net/ddns-scripts/Makefile
net/ddns-scripts/files/etc/config/ddns.sample
net/ddns-scripts/files/usr/lib/ddns/dynamic_dns_functions.sh
net/ddns-scripts/files/usr/lib/ddns/dynamic_dns_updater.sh
net/ddns-scripts/files/usr/lib/ddns/update_sample.sh [new file with mode: 0644]

index 25ec773c886e737a94d5a912d8af7aac00465a46..5d2cafce7436bd8014f56a15f5f41246aa64f74b 100644 (file)
@@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=ddns-scripts
 PKG_VERSION:=2.0.1
-PKG_RELEASE:=6
+PKG_RELEASE:=7
 PKG_LICENSE:=GPL-2.0
 
 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
index c207728790c30ef6563f28e09d79d359a1869023..8625b3899850ce81fb4ec1e033237235828859bd 100644 (file)
@@ -91,6 +91,12 @@ config service "myddns"
        # the format of the url to update with.  You can either add an
        # entry to the "/usr/lib/ddns/services" or "services_ipv6" file 
        # or specify this with the "update_url" option.
+       # If your ddns provider doesn't work with ddns-scripts because
+       # there are additional parameters or other special thinks to be done,
+       # then you could write your own script to send updates to your ddns provider.
+       # Have a look into /usr/lib/ddns/update_sample.sh
+       # The script is specified in "update_script"
+       # Either set "service_name" or one of "update_url" and "update_script"
        # default: none
        option service_name "dyndns.org"
 
@@ -98,6 +104,10 @@ config service "myddns"
        # "http://[USERNAME]:[PASSWORD]@members.dyndns.org/nic/update?hostname=[DOMAIN]&myip=[IP]"
 #      option update_url   ""
 
+       # sample: 
+       # "/usr/lib/ddns/update_sample.sh"
+#      option update_script   ""
+
        ###########
        # You must specify your domain/host name, your username and your password
        # as you get from you DDNS provider. Keep an eye on providers help pages.
index b210cbfc7e479dc19f27fe3c23ae9d583784ede0..b2cb237d91e5c0d8b32a8107aa07ebd34c5cecce 100644 (file)
@@ -6,7 +6,9 @@
 # (Loosely) based on the script on the one posted by exobyte in the forums here:
 # http://forum.openwrt.org/viewtopic.php?id=14040
 #
-# extended and partial rewritten by Christian Schoenebeck in August 2014 to support:
+# extended and partial rewritten in August 2014 
+# by Christian Schoenebeck <christian dot schoenebeck at gmail dot com>
+# to support:
 # - IPv6 DDNS services
 # - setting DNS Server to retrieve current IP including TCP transport
 # - Proxy Server to send out updates or retrieving WEB based IP detection
@@ -215,9 +217,11 @@ __urlencode() {
 # extract update_url for given DDNS Provider from
 # file /usr/lib/ddns/services for IPv4 or from
 # file /usr/lib/ddns/services_ipv6 for IPv6
-get_service_url() {
+get_service_data() {
        # $1    Name of Variable to store url to
-       local __LINE __FILE __NAME __URL __SERVICES
+       # $2    Name of Variable to store script to
+       local __LINE __FILE __NAME __URL __SERVICES __DATA
+       local __SCRIPT=""
        local __OLD_IFS=$IFS
        local __NEWLINE_IFS='
 ' #__NEWLINE_IFS
@@ -234,15 +238,20 @@ get_service_url() {
        do
                #grep out proper parts of data and use echo to remove quotes
                __NAME=$(echo $__LINE | grep -o "^[\t ]*\"[^\"]*\"" | xargs -r -n1 echo)
-               __URL=$(echo $__LINE | grep -o "\"[^\"]*\"[\t ]*$" | xargs -r -n1 echo)
+               __DATA=$(echo $__LINE | grep -o "\"[^\"]*\"[\t ]*$" | xargs -r -n1 echo)
 
                if [ "$__NAME" = "$service_name" ]; then
                        break                   # found so leave for loop
                fi
        done
        IFS=$__OLD_IFS
+
+       # check is URL or SCRIPT is given
+       __URL=$(echo "$__URL" | grep "^http:")
+       [ -z "$__URL" ] && __SCRIPT="/usr/lib/ddns/$__DATA"
        
        eval "$1='$__URL'"
+       eval "$2='$__SCRIPT'"
        return 0
 }
 
@@ -589,30 +598,35 @@ __do_transfer() {
 
 send_update() {
        # $1    # IP to set at DDNS service provider
-       local __IP __URL __ANSWER __ERR __USER __PASS
+       local __IP
 
        # verify given IP / no private IPv4's / no IPv6 addr starting with fxxx of with ":"
        [ $use_ipv6 -eq 0 ] && __IP=$(echo $1 | grep -v -E "(^0|^10\.|^127|^172\.1[6-9]\.|^172\.2[0-9]\.|^172\.3[0-1]\.|^192\.168)")
        [ $use_ipv6 -eq 1 ] && __IP=$(echo $1 | grep "^[0-9a-eA-E]")
-       [ -z "$__IP" ] && critical_error "Invalid or no IP '$1' given"
+       [ -z "$__IP" ] && critical_error "Private or invalid or no IP '$1' given"
 
-       # do replaces in URL
-       __urlencode __USER "$username"  # encode username, might be email or something like this
-       __urlencode __PASS "$password"  # encode password, might have special chars for security reason
-       __URL=$(echo $update_url | sed -e "s#\[USERNAME\]#$__USER#g" -e "s#\[PASSWORD\]#$__PASS#g" \
-                                      -e "s#\[DOMAIN\]#$domain#g" -e "s#\[IP\]#$__IP#g")
-       [ $use_https -ne 0 ] && __URL=$(echo $__URL | sed -e 's#^http:#https:#')
+       if [ -n "$update_script" ]; then
+               verbose_echo "        update =: parsing script '$update_script'"
+               . $update_script
+       else
+               local __URL __ANSWER __ERR __USER __PASS
 
-       __do_transfer __ANSWER "$__URL"
-       __ERR=$?
-       [ $__ERR -gt 0 ] && {
-               verbose_echo "\n!!!!!!!!! ERROR =: Error sending update to DDNS Provider\n"
-               return 1
-       }
+               # do replaces in URL
+               __urlencode __USER "$username"  # encode username, might be email or something like this
+               __urlencode __PASS "$password"  # encode password, might have special chars for security reason
+               __URL=$(echo $update_url | sed -e "s#\[USERNAME\]#$__USER#g" -e "s#\[PASSWORD\]#$__PASS#g" \
+                                              -e "s#\[DOMAIN\]#$domain#g" -e "s#\[IP\]#$__IP#g")
+               [ $use_https -ne 0 ] && __URL=$(echo $__URL | sed -e 's#^http:#https:#')
 
-       verbose_echo "   update send =: DDNS Provider answered\n$__ANSWER"
-       
-       return 0
+               __do_transfer __ANSWER "$__URL"
+               __ERR=$?
+               [ $__ERR -gt 0 ] && {
+                       verbose_echo "\n!!!!!!!!! ERROR =: Error sending update to DDNS Provider\n"
+                       return 1
+               }
+               verbose_echo "   update send =: DDNS Provider answered\n$__ANSWER"
+               return 0
+       fi
 }
 
 get_local_ip () {
index 20e40b310de3f4db0ac7e50b61a72182cd56c495..77f9e1ac8c6bad4bac4ea3e6281ea7402cb505ae 100755 (executable)
@@ -6,7 +6,9 @@
 # (Loosely) based on the script on the one posted by exobyte in the forums here:
 # http://forum.openwrt.org/viewtopic.php?id=14040
 #
-# extended and partial rewritten by Christian Schoenebeck in August 2014 to support:
+# extended and partial rewritten in August 2014 
+# by Christian Schoenebeck <christian dot schoenebeck at gmail dot com>
+# to support:
 # - IPv6 DDNS services
 # - DNS Server to retrieve registered IP including TCP transport
 # - Proxy Server to send out updates
@@ -62,6 +64,7 @@ LOGFILE="$LOGDIR/$SECTION_ID.log"     # log file
 #
 # service_name Which DDNS service do you use or "custom"
 # update_url   URL to use to update your "custom" DDNS service
+# update_script SCRIPT to use to update your "custom" DDNS service
 #
 # domain       Your DNS name / replace [DOMAIN] in update_url
 # username     Username of your DDNS service account / replace [USERNAME] in update_url
@@ -161,8 +164,10 @@ verbose_echo " retry counter =: $retry_count times"
 
 # determine what update url we're using if a service_name is supplied
 # otherwise update_url is set inside configuration (custom service)
-[ -n "$service_name" ] && get_service_url update_url
-[ -z "$update_url" ]   && critical_error "no update url found/defined"
+# or update_script is set inside configuration (custom update script)
+[ -n "$service_name" ] && get_service_data update_url update_script
+[ -z "$update_url" -a -z "$update_script" ] && critical_error "no update_url found/defined or no update_script found/defined"
+[ -n "$update_script" -a ! -f "$update_script" ] && critical_error "custom update_script not found"
 
 #kill old process if it exists & set new pid file
 if [ -d $RUNDIR ]; then
diff --git a/net/ddns-scripts/files/usr/lib/ddns/update_sample.sh b/net/ddns-scripts/files/usr/lib/ddns/update_sample.sh
new file mode 100644 (file)
index 0000000..fb69081
--- /dev/null
@@ -0,0 +1,37 @@
+# sample script for sending user defined updates 
+# 2014 Christian Schoenebeck <christian dot schoenebeck at gmail dot com>
+#
+# activated inside /etc/config/ddns by setting
+#
+# option update_script '/usr/lib/ddns/update_sample.sh' 
+#
+# the script is parsed (not executed) inside send_update() function
+# of /usr/lib/ddns/dynamic_dns_functions.sh
+# so you can use all available functions and global variables inside this script
+# already defined in dynamic_dns_updater.sh and dynamic_dns_functions.sh
+#
+# It make sence to define the update url ONLY inside this script 
+# because it's anyway unique to the update script
+# otherwise it should work with the default scripts
+#
+# the code here is the copy of the default used inside send_update()
+#
+local __USER __PASS __ANSWER
+# tested with spdns.de
+local __URL="http://[USERNAME]:[PASSWORD]@update.spdns.de/nic/update?hostname=[DOMAIN]&myip=[IP]"
+
+# do replaces in URL
+__urlencode __USER "$username" # encode username, might be email or something like this
+__urlencode __PASS "$password" # encode password, might have special chars for security reason
+__URL=$(echo $__URL | sed -e "s#\[USERNAME\]#$__USER#g" -e "s#\[PASSWORD\]#$__PASS#g" \
+                              -e "s#\[DOMAIN\]#$domain#g" -e "s#\[IP\]#$__IP#g")
+[ $use_https -ne 0 ] && __URL=$(echo $__URL | sed -e 's#^http:#https:#')
+
+__do_transfer __ANSWER "$__URL"
+__ERR=$?
+[ $__ERR -gt 0 ] && {
+       verbose_echo "\n!!!!!!!!! ERROR =: Error sending update to DDNS Provider\n"
+       return 1
+}
+verbose_echo "   update send =: DDNS Provider answered\n$__ANSWER"
+return 0
git clone https://git.99rst.org/PROJECT