ddns-scripts: Added support for custom update scripts
Squashed commit of the following: commit 2701c8868e1ef4949db57e53b27958edba6abb59 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> commit e07ecb90fa2c7404a97cf64024e89bd9d88aacd4 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> commit 39e41b2151a79a7ace71a9d40b87cd4d6ce09503 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> commit 33f264768e37d8a6fe564faaafa51a7b45a0ee19 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> commit 6f6a60244df53e0556f5c75845c69aa832f97e4c 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>
This commit is contained in:
parent
8a5d30147f
commit
6ab4a265a2
5 changed files with 91 additions and 25 deletions
|
@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=ddns-scripts
|
PKG_NAME:=ddns-scripts
|
||||||
PKG_VERSION:=2.0.1
|
PKG_VERSION:=2.0.1
|
||||||
PKG_RELEASE:=6
|
PKG_RELEASE:=7
|
||||||
PKG_LICENSE:=GPL-2.0
|
PKG_LICENSE:=GPL-2.0
|
||||||
|
|
||||||
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
|
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
|
# the format of the url to update with. You can either add an
|
||||||
# entry to the "/usr/lib/ddns/services" or "services_ipv6" file
|
# entry to the "/usr/lib/ddns/services" or "services_ipv6" file
|
||||||
# or specify this with the "update_url" option.
|
# 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
|
# default: none
|
||||||
option service_name "dyndns.org"
|
option service_name "dyndns.org"
|
||||||
|
|
||||||
|
@ -98,6 +104,10 @@ config service "myddns"
|
||||||
# "http://[USERNAME]:[PASSWORD]@members.dyndns.org/nic/update?hostname=[DOMAIN]&myip=[IP]"
|
# "http://[USERNAME]:[PASSWORD]@members.dyndns.org/nic/update?hostname=[DOMAIN]&myip=[IP]"
|
||||||
# option update_url ""
|
# 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
|
# 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.
|
# 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:
|
# (Loosely) based on the script on the one posted by exobyte in the forums here:
|
||||||
# http://forum.openwrt.org/viewtopic.php?id=14040
|
# 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
|
# - IPv6 DDNS services
|
||||||
# - setting DNS Server to retrieve current IP including TCP transport
|
# - setting DNS Server to retrieve current IP including TCP transport
|
||||||
# - Proxy Server to send out updates or retrieving WEB based IP detection
|
# - 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
|
# extract update_url for given DDNS Provider from
|
||||||
# file /usr/lib/ddns/services for IPv4 or from
|
# file /usr/lib/ddns/services for IPv4 or from
|
||||||
# file /usr/lib/ddns/services_ipv6 for IPv6
|
# file /usr/lib/ddns/services_ipv6 for IPv6
|
||||||
get_service_url() {
|
get_service_data() {
|
||||||
# $1 Name of Variable to store url to
|
# $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 __OLD_IFS=$IFS
|
||||||
local __NEWLINE_IFS='
|
local __NEWLINE_IFS='
|
||||||
' #__NEWLINE_IFS
|
' #__NEWLINE_IFS
|
||||||
|
@ -234,15 +238,20 @@ get_service_url() {
|
||||||
do
|
do
|
||||||
#grep out proper parts of data and use echo to remove quotes
|
#grep out proper parts of data and use echo to remove quotes
|
||||||
__NAME=$(echo $__LINE | grep -o "^[\t ]*\"[^\"]*\"" | xargs -r -n1 echo)
|
__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
|
if [ "$__NAME" = "$service_name" ]; then
|
||||||
break # found so leave for loop
|
break # found so leave for loop
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
IFS=$__OLD_IFS
|
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 "$1='$__URL'"
|
||||||
|
eval "$2='$__SCRIPT'"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -589,30 +598,35 @@ __do_transfer() {
|
||||||
|
|
||||||
send_update() {
|
send_update() {
|
||||||
# $1 # IP to set at DDNS service provider
|
# $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 ":"
|
# 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 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]")
|
[ $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
|
if [ -n "$update_script" ]; then
|
||||||
__urlencode __USER "$username" # encode username, might be email or something like this
|
verbose_echo " update =: parsing script '$update_script'"
|
||||||
__urlencode __PASS "$password" # encode password, might have special chars for security reason
|
. $update_script
|
||||||
__URL=$(echo $update_url | sed -e "s#\[USERNAME\]#$__USER#g" -e "s#\[PASSWORD\]#$__PASS#g" \
|
else
|
||||||
-e "s#\[DOMAIN\]#$domain#g" -e "s#\[IP\]#$__IP#g")
|
local __URL __ANSWER __ERR __USER __PASS
|
||||||
[ $use_https -ne 0 ] && __URL=$(echo $__URL | sed -e 's#^http:#https:#')
|
|
||||||
|
|
||||||
__do_transfer __ANSWER "$__URL"
|
# do replaces in URL
|
||||||
__ERR=$?
|
__urlencode __USER "$username" # encode username, might be email or something like this
|
||||||
[ $__ERR -gt 0 ] && {
|
__urlencode __PASS "$password" # encode password, might have special chars for security reason
|
||||||
verbose_echo "\n!!!!!!!!! ERROR =: Error sending update to DDNS Provider\n"
|
__URL=$(echo $update_url | sed -e "s#\[USERNAME\]#$__USER#g" -e "s#\[PASSWORD\]#$__PASS#g" \
|
||||||
return 1
|
-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"
|
__do_transfer __ANSWER "$__URL"
|
||||||
|
__ERR=$?
|
||||||
return 0
|
[ $__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 () {
|
get_local_ip () {
|
||||||
|
|
|
@ -6,7 +6,9 @@
|
||||||
# (Loosely) based on the script on the one posted by exobyte in the forums here:
|
# (Loosely) based on the script on the one posted by exobyte in the forums here:
|
||||||
# http://forum.openwrt.org/viewtopic.php?id=14040
|
# 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
|
# - IPv6 DDNS services
|
||||||
# - DNS Server to retrieve registered IP including TCP transport
|
# - DNS Server to retrieve registered IP including TCP transport
|
||||||
# - Proxy Server to send out updates
|
# - 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"
|
# service_name Which DDNS service do you use or "custom"
|
||||||
# update_url URL to use to update your "custom" DDNS service
|
# 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
|
# domain Your DNS name / replace [DOMAIN] in update_url
|
||||||
# username Username of your DDNS service account / replace [USERNAME] 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
|
# determine what update url we're using if a service_name is supplied
|
||||||
# otherwise update_url is set inside configuration (custom service)
|
# otherwise update_url is set inside configuration (custom service)
|
||||||
[ -n "$service_name" ] && get_service_url update_url
|
# or update_script is set inside configuration (custom update script)
|
||||||
[ -z "$update_url" ] && critical_error "no update url found/defined"
|
[ -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
|
#kill old process if it exists & set new pid file
|
||||||
if [ -d $RUNDIR ]; then
|
if [ -d $RUNDIR ]; then
|
||||||
|
|
37
net/ddns-scripts/files/usr/lib/ddns/update_sample.sh
Normal file
37
net/ddns-scripts/files/usr/lib/ddns/update_sample.sh
Normal file
|
@ -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 a new issue