mirror of https://github.com/openwrt/packages.git
ddns-scripts: Added support for custom update scripts
Squashed commit of the following: commitpull/395/merge2701c8868e
Author: Christian Schoenebeck <christian.schoenebeck@gmail.com> Date: Sun Oct 5 11:01:57 2014 +0200 ddns-scripts: Added support for custom update scripts Sample script Signed-off-by: Christian Schoenebeck <christian.schoenebeck@gmail.com> commite07ecb90fa
Author: Christian Schoenebeck <christian.schoenebeck@gmail.com> 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 <christian.schoenebeck@gmail.com> commit39e41b2151
Author: Christian Schoenebeck <christian.schoenebeck@gmail.com> 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 <christian.schoenebeck@gmail.com> commit33f264768e
Author: Christian Schoenebeck <christian.schoenebeck@gmail.com> 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 <christian.schoenebeck@gmail.com> commit6f6a60244d
Author: Christian Schoenebeck <christian.schoenebeck@gmail.com> 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 <christian.schoenebeck@gmail.com>
parent
8a5d30147f
commit
6ab4a265a2
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 () {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue