mirror of
https://github.com/openwrt/packages.git
synced 2025-12-16 23:51:18 +00:00
ddns-scripts: Added support for custom update scripts
Squashed commit of the following: commit2701c8868eAuthor: 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> commite07ecb90faAuthor: 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> commit39e41b2151Author: 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> commit33f264768eAuthor: 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> commit6f6a60244dAuthor: 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:
@@ -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
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user