Browse Source

ddns-scripts: update to version 2.1.0-4

* remove CHANGELOG from distribution
* fix syslog output printing "\n" or other formating chars
* ddns configuration
    - new UCI-config value ddns.global.allow_local_ip "0" or "1"
(default "0") - (OpenWrt Ticket 18642)
* dynamic_dns_functions.sh
- new function split_FQDN() splits a given FQDN into host,
(registerable) domainname, and TLD using
https://publicsuffix.org/list/effective_tld_names.dat
- verify_host_port() use BIND host, if installed
- verify_host_port() not detecting ip, if already given
- fixed regexp for IP detection from nslookup's answer - (OpenWrt
Ticket 16363)
- support ddns.global.allow_local_ip to allow sending non public IP's
to DDNS provider like 127.x, 192.168.x.x or fxxx - (OpenWrt Ticket
18642)
* new file tld_names.dat
- used by dynamic_dns_functions.sh inside split_FQDN() function to
find valid TLD's
* update_cloudflare.sh
- modified subdomain/domain splitting using split_FQDN()
- modified support for AA12.09 (json_get_keys())
- minor fixes and cleanup
- many thanks to Aaron Tanner for testing

Signed-off-by: Christian Schoenebeck <christian.schoenebeck@gmail.com>
Christian Schoenebeck 10 years ago
parent
commit
64250aebc7

+ 0
- 128
net/ddns-scripts/CHANGELOG View File

@@ -1,128 +0,0 @@
1
-Version 2.1.0-3
2
-Date	2014-12-07
3
-
4
-- removed special handling for dynamic_dns_helper.sh and url_escape.sed in Makefile/postinst
5
-- minor fixes in logging
6
-- allow retry_count of "0" to run infinite retrys on error
7
-	-- https://dev.openwrt.org/ticket/18382
8
-- changed naming of .dat and .err file to have one per section, not one per process
9
-- defer hotplug helper from 25-ddns to 95-ddns (according initscript START=95) 
10
-	-- https://github.com/openwrt/packages/issues/568 (#568)
11
-- fix commandline for busybox wget
12
-	-- https://dev.openwrt.org/ticket/18411
13
-	-- https://dev.openwrt.org/ticket/18437
14
-	-- https://github.com/openwrt/packages/issues/605 (#605)
15
-- remove checking answer from ddns provider because there are to many different. 
16
-Many providers did not follow API from dyndns.com 
17
-
18
---------------------------------------------------------------------------------
19
-Version 2.1.0-2
20
-Date	2014-11-15
21
-
22
-- moved /usr/lib/ddns/dynamic_dns_lucihelper.sh from luci-app-ddns into this package
23
-	-- https://github.com/openwrt/luci/issue/251
24
-	-- https://dev.openwrt.org/ticket/18326
25
-	-- https://dev.openwrt.org/ticket/18347
26
-- fix: dynamic_dns_update.sh did not loop
27
-	-- https://dev.openwrt.org/ticket/18336
28
-- add provider cloudflare.com IPv4 and IPv6 (Thanks to Paul for support and testing)
29
-	-- https://dev.openwrt.org/ticket/12500
30
-- modified detection, if dynamic_dns_fuctions are used by dynamic_dns_lucihelper.sh
31
-- redirect stdout of wget,curl,host,nslookup,nc etc to /tmp/ddns_$$.dat and *.err instead of variables
32
-- extended error detection in get_local_ip function
33
-- modified verify of option ip_script to allow parameters, when calling
34
-- add provider selfhost.de IPv4
35
-- add provider no-ip.pl (nothing to do with no-ip.com)
36
-	-- https://github.com/openwrt/packages/issues/542 (#542)
37
-	IPv4 (tested) and also added for
38
-	IPv6 (NOT tested) because client IP is autodetected be provider
39
-- add getlocalip_sample.sh as sample script for usage of
40
-	option ip_source 'script'  together with
41
-	option ip_script '/usr/lib/ddns/getlocalip.sh -4'
42
-- cleanup whitespaces at line ends
43
-
44
---------------------------------------------------------------------------------
45
-Version 2.1.0-1
46
-Date	2014-11-09
47
-
48
-- fixed postinst and prerm in Makefile
49
-- implementation of provider specific update scripts into services and services_ipv6 file.
50
-	first Provider "no-ip.com"	- Thanks to DarkStarXxX for request and testing
51
-- finished uci/ddns wiki at http://wiki.openwrt.org/doc/uci/ddns
52
-- rewritten retry management
53
-- rewritten logging including following Issue 469
54
-	https://github.com/openwrt/packages/issues/469
55
-- stop running sections on hotplug ifdown event (like start on ifup)
56
-- implement trap detection
57
-	also kill "sleep" child processes
58
-	SIGHUP to reload configuration (not really reloading, simply starting a new process)
59
-	/etc/init.d/ddns reload implemented
60
-- code optimization
61
-- new provider LoopiaDNS.se	Issue 494
62
-	https://github.com/openwrt/packages/issues/494
63
-
64
---------------------------------------------------------------------------------
65
-Version 2.0.1-9
66
-Date	2014-10-11
67
-
68
-- add retry loop to verify dns and proxy when script starts
69
-
70
---------------------------------------------------------------------------------
71
-Version 2.0.1-8
72
-Date	2014-10-06
73
-
74
-- fixes problem CRITICAL ERROR - custom update_script not found
75
-
76
---------------------------------------------------------------------------------
77
-Version 2.0.1-7
78
-Date	2014-10-05
79
-
80
-- Added support for custom update scripts with new option update_script
81
-
82
---------------------------------------------------------------------------------
83
-Version 2.0.1-6
84
-Date	2014-10-01
85
-
86
-- url encode USERNAME and PASSWORD in update url
87
-
88
---------------------------------------------------------------------------------
89
-Version 2.0.1-5
90
-Date	2014-09-30
91
-
92
-- fix send_update() detection of private IPv4
93
-
94
---------------------------------------------------------------------------------
95
-Version 2.0.1-4
96
-Date	2014-09-29
97
-
98
-- fix ticket #17998: wrongly detect ipv4 start with 10x.x.x.x
99
-
100
---------------------------------------------------------------------------------
101
-Version 2.0.1-3
102
-Date	2014-09-28
103
-
104
-- add service two-dns.de
105
-
106
---------------------------------------------------------------------------------
107
-Version 2.0.1-2
108
-Date	2014-09-22
109
-
110
-- fix issue (#337) current/registered ip
111
-	https://github.com/openwrt/packages/issues/337
112
-
113
---------------------------------------------------------------------------------
114
-Version 2.0.1-1
115
-Date	2014-09-20
116
-
117
-- 1st published version via github
118
-
119
---------------------------------------------------------------------------------
120
-Version 2.0.0
121
-Date	2014-07-16
122
-
123
-- published via OpenWrt TRAC system as zip-file for testing
124
-	- IPv6 address support
125
-	- log file support
126
-	- syslog support for various error levels
127
-	- verify all given parameters before starting main loop
128
-	- retry max retry_counter times before terminating scripts

+ 3
- 2
net/ddns-scripts/Makefile View File

@@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk
2 2
 
3 3
 PKG_NAME:=ddns-scripts
4 4
 PKG_VERSION:=2.1.0
5
-PKG_RELEASE:=3
5
+PKG_RELEASE:=4
6 6
 PKG_LICENSE:=GPL-2.0
7 7
 
8 8
 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
@@ -55,7 +55,7 @@ define Package/ddns-scripts/install
55 55
 	$(INSTALL_BIN) ./files/etc/init.d/* $(1)/etc/init.d/
56 56
 
57 57
 	$(INSTALL_DIR) $(1)/usr/lib/ddns
58
-	$(INSTALL_DATA) ./files/usr/lib/ddns/service* $(1)/usr/lib/ddns
58
+	$(INSTALL_DATA) ./files/usr/lib/ddns/* $(1)/usr/lib/ddns
59 59
 	$(INSTALL_BIN)  ./files/usr/lib/ddns/*.sh $(1)/usr/lib/ddns
60 60
 endef
61 61
 
@@ -68,6 +68,7 @@ define Package/ddns-scripts/postinst
68 68
 	uci -q get ddns.global > /dev/null || uci -q set ddns.global='ddns'
69 69
 	uci -q get ddns.global.date_format > /dev/null || uci -q set ddns.global.date_format='%F %R'
70 70
 	uci -q get ddns.global.log_lines > /dev/null || uci -q set ddns.global.log_lines='250'
71
+	uci -q get ddns.global.allow_local_ip > /dev/null || uci -q set ddns.global.allow_local_ip='0'
71 72
 	uci -q commit ddns
72 73
 
73 74
 	# clear LuCI indexcache

+ 3
- 2
net/ddns-scripts/files/etc/config/ddns View File

@@ -7,11 +7,12 @@ config ddns "global"
7 7
 #	option run_dir "/var/run/ddns"
8 8
 #	option log_dir "/var/log/ddns"
9 9
 	option log_lines "250"
10
+	option allow_local_ip "0"
10 11
 
11 12
 
12 13
 config service "myddns_ipv4"
13 14
 	option service_name	"example.org"
14
-	option domain		"yourhost.example.org"
15
+	option domain		"yourhost.example.com"
15 16
 	option username		"your_username"
16 17
 	option password		"your_password"
17 18
 	option interface	"wan"
@@ -20,7 +21,7 @@ config service "myddns_ipv4"
20 21
 
21 22
 config service "myddns_ipv6"
22 23
 	option update_url	"http://[USERNAME]:[PASSWORD]@your.provider.net/nic/update?hostname=[DOMAIN]&myip=[IP]"
23
-	option domain		"yourhost.dyndns.org"
24
+	option domain		"yourhost.example.com"
24 25
 	option username		"your_username"
25 26
 	option password		"your_password"
26 27
 	option use_ipv6		"1"

+ 6
- 0
net/ddns-scripts/files/etc/config/ddns.sample View File

@@ -48,6 +48,12 @@ config ddns "global"
48 48
 	# default: "250" lines
49 49
 #	option log_lines "250"
50 50
 
51
+	###########
52
+	# Whether to allow to send Private/Special IP's to the DDNS provider
53
+	# IPv4: 0.x, 10.x, 127.x, 172.16.x-172.31.x, 192.168.x
54
+	# IPv6: ::, Fxxx:
55
+	# default: "0"	disabled
56
+#	option allow_local_ip "0"
51 57
 
52 58
 #####################################################################
53 59
 # DDNS service settings

+ 114
- 38
net/ddns-scripts/files/usr/lib/ddns/dynamic_dns_functions.sh View File

@@ -12,7 +12,7 @@
12 12
 # - IPv6 DDNS services
13 13
 # - setting DNS Server to retrieve current IP including TCP transport
14 14
 # - Proxy Server to send out updates or retrieving WEB based IP detection
15
-# - force_interval=0 to run once (usefull for cron jobs etc.)
15
+# - force_interval=0 to run once (useful for cron jobs etc.)
16 16
 # - the usage of BIND's host instead of BusyBox's nslookup if installed (DNS via TCP)
17 17
 # - extended Verbose Mode and log file support for better error detection
18 18
 #
@@ -32,17 +32,20 @@
32 32
 SECTION_ID=""		# hold config's section name
33 33
 VERBOSE_MODE=1		# default mode is log to console, but easily changed with parameter
34 34
 
35
+# allow NON-public IP's
36
+ALLOW_LOCAL_IP=$(uci -q get ddns.global.allow_local_ip) || ALLOW_LOCAL_IP=0
35 37
 # directory to store run information to.
36 38
 RUNDIR=$(uci -q get ddns.global.run_dir) || RUNDIR="/var/run/ddns"
37 39
 [ -d $RUNDIR ] || mkdir -p -m755 $RUNDIR
38
-# NEW # directory to store log files
40
+# directory to store log files
39 41
 LOGDIR=$(uci -q get ddns.global.log_dir) || LOGDIR="/var/log/ddns"
40 42
 [ -d $LOGDIR ] || mkdir -p -m755 $LOGDIR
41
-LOGFILE=""		# NEW # logfile can be enabled as new option
43
+LOGFILE=""		# logfile - all files are set in dynamic_dns_updater.sh
42 44
 PIDFILE=""		# pid file
43 45
 UPDFILE=""		# store UPTIME of last update
44
-DATFILE=""		# save stdout data of WGet and other extern programs called
45
-ERRFILE=""		# save stderr output of WGet and other extern programs called
46
+DATFILE=""		# save stdout data of WGet and other external programs called
47
+ERRFILE=""		# save stderr output of WGet and other external programs called
48
+TLDFILE=/usr/lib/ddns/tld_names.dat	# TLD file used by split_FQDN
46 49
 
47 50
 # number of lines to before rotate logfile
48 51
 LOGLINES=$(uci -q get ddns.global.log_lines) || LOGLINES=250
@@ -314,8 +317,8 @@ get_service_data() {
314 317
 	done
315 318
 	IFS=$__OLD_IFS
316 319
 
317
-	# check is URL or SCRIPT is given
318
-	__URL=$(echo "$__DATA" | grep "^http:")
320
+	# check if URL or SCRIPT is given
321
+	__URL=$(echo "$__DATA" | grep "^http")
319 322
 	[ -z "$__URL" ] && __SCRIPT="/usr/lib/ddns/$__DATA"
320 323
 
321 324
 	eval "$1=\"$__URL\""
@@ -340,15 +343,15 @@ get_seconds() {
340 343
 
341 344
 timeout() {
342 345
 	# copied from http://www.ict.griffith.edu.au/anthony/software/timeout.sh
343
-	# only did the folloing changes
346
+	# only did the following changes
344 347
 	#	- commented out "#!/bin/bash" and usage section
345 348
 	#	- replace exit by return for usage as function
346
-	#	- some reformating
349
+	#	- some reformatting
347 350
 	#
348 351
 	# timeout [-SIG] time [--] command args...
349 352
 	#
350 353
 	# Run the given command until completion, but kill it if it runs too long.
351
-	# Specifically designed to exit immediatally (no sleep interval) and clean up
354
+	# Specifically designed to exit immediately (no sleep interval) and clean up
352 355
 	# nicely without messages or leaving any extra processes when finished.
353 356
 	#
354 357
 	# Example use
@@ -402,7 +405,7 @@ timeout() {
402 405
 		shift	# next option
403 406
 	done
404 407
 
405
-	# run main command in backgrouds and get its pid
408
+	# run main command in backgrounds and get its pid
406 409
 	"$@" &
407 410
 	command_pid=$!
408 411
 
@@ -443,28 +446,45 @@ timeout() {
443 446
 verify_host_port() {
444 447
 	local __HOST=$1
445 448
 	local __PORT=$2
446
-	local __IP __IPV4 __IPV6 __RUNPROG __ERR
449
+	local __IP __IPV4 __IPV6 __RUNPROG __PROG __ERR
447 450
 	# return codes
448 451
 	# 1	system specific error
449
-	# 2	nslookup error
452
+	# 2	nslookup/host error
450 453
 	# 3	nc (netcat) error
451 454
 	# 4	unmatched IP version
452 455
 
453 456
 	[ $# -ne 2 ] && write_log 12 "Error calling 'verify_host_port()' - wrong number of parameters"
454 457
 
455
-	__RUNPROG="/usr/bin/nslookup $__HOST >$DATFILE 2>$ERRFILE"
456
-	write_log 7 "#> $__RUNPROG"
457
-	eval $__RUNPROG
458
-	__ERR=$?
459
-	# command error
460
-	[ $__ERR -gt 0 ] && {
461
-		write_log 3 "DNS Resolver Error - BusyBox nslookup Error '$__ERR'"
462
-		write_log 7 "$(cat $ERRFILE)"
463
-		return 2
458
+	# check if ip or FQDN was given
459
+	__IPV4=$(echo $__HOST | grep -m 1 -o "$IPV4_REGEX$")	# do not detect ip in 0.0.0.0.example.com
460
+	__IPV6=$(echo $__HOST | grep -m 1 -o "$IPV6_REGEX")
461
+	# if FQDN given get IP address
462
+	[ -z "$__IPV4" -a -z "$__IPV6" ] && {
463
+		if [ -x /usr/bin/host ]; then	# use BIND host if installed
464
+			__PROG="BIND host"
465
+			__RUNPROG="/usr/bin/host -t ANY $__HOST >$DATFILE 2>$ERRFILE"
466
+		else	# use BusyBox nslookup
467
+			__PROG="BusyBox nslookup"
468
+			__RUNPROG="/usr/bin/nslookup $__HOST >$DATFILE 2>$ERRFILE"
469
+		fi
470
+		write_log 7 "#> $__RUNPROG"
471
+		eval $__RUNPROG
472
+		__ERR=$?
473
+		# command error
474
+		[ $__ERR -gt 0 ] && {
475
+			write_log 3 "DNS Resolver Error - $__PROG Error '$__ERR'"
476
+			write_log 7 "$(cat $ERRFILE)"
477
+			return 2
478
+		}
479
+		# extract IP address
480
+		if [ -x /usr/bin/host ]; then	# use BIND host if installed
481
+			__IPV4=$(cat $DATFILE | awk -F "address " '/has address/ {print $2; exit}' )
482
+			__IPV6=$(cat $DATFILE | awk -F "address " '/has IPv6/ {print $2; exit}' )
483
+		else	# use BusyBox nslookup
484
+			__IPV4=$(cat $DATFILE | sed -ne "3,\$ { s/^Address[0-9 ]\{0,\}: \($IPV4_REGEX\).*$/\\1/p }")
485
+			__IPV6=$(cat $DATFILE | sed -ne "3,\$ { s/^Address[0-9 ]\{0,\}: \($IPV6_REGEX\).*$/\\1/p }")
486
+		fi
464 487
 	}
465
-	# extract IP address
466
-	__IPV4=$(cat $DATFILE | sed -ne "3,\$ { s/^Address [0-9]*: \($IPV4_REGEX\).*$/\\1/p }")
467
-	__IPV6=$(cat $DATFILE | sed -ne "3,\$ { s/^Address [0-9]*: \($IPV6_REGEX\).*$/\\1/p }")
468 488
 
469 489
 	# check IP version if forced
470 490
 	if [ $force_ipversion -ne 0 ]; then
@@ -487,9 +507,9 @@ verify_host_port() {
487 507
 	# connectivity test
488 508
 	# run busybox nc to HOST PORT
489 509
 	# busybox might be compiled with "FEATURE_PREFER_IPV4_ADDRESS=n"
490
-	# then nc will try to connect via IPv6 if there is any IPv6 availible on any host interface
491
-	# not worring, if there is an IPv6 wan address
492
-	# so if not "force_ipversion" to use_ipv6 then connect test via ipv4, if availible
510
+	# then nc will try to connect via IPv6 if there is any IPv6 available on any host interface
511
+	# not worrying, if there is an IPv6 wan address
512
+	# so if not "force_ipversion" to use_ipv6 then connect test via ipv4, if available
493 513
 	[ $force_ipversion -ne 0 -a $use_ipv6 -ne 0 -o -z "$__IPV4" ] && __IP=$__IPV6 || __IP=$__IPV4
494 514
 
495 515
 	if [ -n "$__NCEXT" ]; then	# BusyBox nc compiled with extensions (timeout support)
@@ -512,7 +532,7 @@ verify_host_port() {
512 532
 	fi
513 533
 }
514 534
 
515
-# verfiy given DNS server if connectable
535
+# verify given DNS server if connectable
516 536
 # $1	DNS server to verify
517 537
 verify_dns() {
518 538
 	local __ERR=255	# last error buffer
@@ -546,7 +566,7 @@ verify_dns() {
546 566
 	return 0
547 567
 }
548 568
 
549
-# analyse and verfiy given proxy string
569
+# analyze and verify given proxy string
550 570
 # $1	Proxy-String to verify
551 571
 verify_proxy() {
552 572
 	#	complete entry		user:password@host:port
@@ -643,7 +663,7 @@ do_transfer() {
643 663
 	# 2nd choice is cURL IPv4/IPv6/HTTPS
644 664
 	# libcurl might be compiled without Proxy Support (default in trunk)
645 665
 	elif [ -x /usr/bin/curl ]; then
646
-		__PROG="/usr/bin/curl -sS -o $DATFILE --stderr $ERRFILE"
666
+		__PROG="/usr/bin/curl -RsS -o $DATFILE --stderr $ERRFILE"
647 667
 		# force ip version to use
648 668
 		if [ $force_ipversion -eq 1 ]; then
649 669
 			[ $use_ipv6 -eq 0 ] && __PROG="$__PROG -4" || __PROG="$__PROG -6"	# force IPv4/IPv6
@@ -730,10 +750,14 @@ send_update() {
730 750
 
731 751
 	[ $# -ne 1 ] && write_log 12 "Error calling 'send_update()' - wrong number of parameters"
732 752
 
733
-	# verify given IP / no private IPv4's / no IPv6 addr starting with fxxx of with ":"
734
-	[ $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)")
735
-	[ $use_ipv6 -eq 1 ] && __IP=$(echo $1 | grep "^[0-9a-eA-E]")
736
-	[ -z "$__IP" ] && write_log 4 "Private or invalid or no IP '$1' given"
753
+	if [ $ALLOW_LOCAL_IP -eq 0 ]; then
754
+		# verify given IP / no private IPv4's / no IPv6 addr starting with fxxx of with ":"
755
+		[ $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)")
756
+		[ $use_ipv6 -eq 1 ] && __IP=$(echo $1 | grep "^[0-9a-eA-E]")
757
+		[ -z "$__IP" ] && write_log 14 "Private or invalid or no IP '$1' given! Please check your configuration"
758
+	else
759
+		__IP="$1"
760
+	fi
737 761
 
738 762
 	if [ -n "$update_script" ]; then
739 763
 		write_log 7 "parsing script '$update_script'"
@@ -751,7 +775,7 @@ send_update() {
751 775
 		write_log 7 "DDNS Provider answered:\n$(cat $DATFILE)"
752 776
 
753 777
 		return 0
754
-		# TODO analyse providers answer
778
+		# TODO analyze providers answer
755 779
 		# "good" or "nochg"		= dyndns.com compatible API
756 780
 		# grep -i -E "good|nochg" $DATFILE >/dev/null 2>&1
757 781
 		# return $?	# "0" if found
@@ -915,7 +939,7 @@ get_registered_ip() {
915 939
 			if [ "$__PROG" = "BIND host" ]; then
916 940
 				__DATA=$(cat $DATFILE | awk -F "address " '/has/ {print $2; exit}' )
917 941
 			else
918
-				__DATA=$(cat $DATFILE | sed -ne "3,\$ { s/^Address [0-9]*: \($__REGEX\).*$/\\1/p }" )
942
+				__DATA=$(cat $DATFILE | sed -ne "3,\$ { s/^Address[0-9 ]\{0,\}: \($__REGEX\).*$/\\1/p }" )
919 943
 			fi
920 944
 			[ -n "$__DATA" ] && {
921 945
 				write_log 7 "Registered IP '$__DATA' detected"
@@ -974,7 +998,7 @@ trap_handler() {
974 998
 				write_log 4 "PID '$$' exit WITH ERROR '$__ERR' at $(eval $DATE_PROG)\n"
975 999
 			fi ;;
976 1000
 		 1)	write_log 6 "PID '$$' received 'SIGHUP' at $(eval $DATE_PROG)"
977
-			# reload config via starting the script again 
1001
+			# reload config via starting the script again
978 1002
 			eval "/usr/lib/ddns/dynamic_dns_updater.sh $SECTION_ID $VERBOSE_MODE &"
979 1003
 			exit 0 ;;	# and leave this one
980 1004
 		 2)	write_log 5 "PID '$$' terminated by 'SIGINT' at $(eval $DATE_PROG)\n";;
@@ -999,3 +1023,55 @@ trap_handler() {
999 1023
 	trap - 0 1 2 3 15
1000 1024
 	[ $1 -gt 0 ] && kill -$1 $$
1001 1025
 }
1026
+
1027
+split_FQDN() {
1028
+	# $1	FQDN to split
1029
+	# $2	name of variable to store TLD
1030
+	# $3	name of variable to store (reg)Domain
1031
+	# $4	name of variable to store Host/Subdomain
1032
+
1033
+	[ $# -ne 4 ] && write_log 12 "Error calling 'split_FQDN()' - wrong number of parameters"
1034
+
1035
+	_SET="$@"					# save given parameters
1036
+	local _FHOST _FTLD _FOUND
1037
+	local _FDOM=$(echo "$1" | tr [A-Z] [a-z])	# to lower
1038
+
1039
+	set -- $(echo "$_FDOM" | tr "." " ")		# replace DOT with SPACE and set as script parameters
1040
+	_FDOM=""					# clear variable for later reuse
1041
+
1042
+	while [ -n "$1" ] ; do				# as long we have parameters
1043
+		_FTLD=$(echo $@ | tr " " ".")		# build back dot separated as TLD
1044
+		# look if match excludes "!" in tld_names.dat
1045
+		grep -E "^!$_FTLD$" $TLDFILE >/dev/null 2>&1 || {
1046
+			# Don't match excludes
1047
+			# check if match any "*" in tld_names.dat
1048
+			grep -E "^*.$_FTLD$" $TLDFILE >/dev/null 2>&1 && {
1049
+				_FOUND="VALID"
1050
+				break	# found leave while
1051
+			}
1052
+			# check if exact match in tld_names.dat
1053
+			grep -E "^$_FTLD$" $TLDFILE >/dev/null 2>&1 && {
1054
+				_FOUND="VALID"
1055
+				break	# found leave while
1056
+			}
1057
+		}
1058
+		# nothing match so
1059
+		_FHOST="$_FHOST $_FDOM"		# append DOMAIN to last found HOST
1060
+		_FDOM="$1"			# set 1st parameter as DOMAIN
1061
+		_FTLD=""			# clear TLD
1062
+		shift				# delete 1st parameter and retry with the rest
1063
+	done
1064
+
1065
+	set -- $_SET				# set back parameters from function call
1066
+	[ -n "$_FHOST" ] && _FHOST=$(echo $_FHOST | tr " " ".")	# put dots back into HOST
1067
+	[ -n "$_FOUND" ] && {
1068
+		eval "$2=$_FTLD"	# set found TLD
1069
+		eval "$3=$_FDOM"	# set found registrable domain
1070
+		eval "$4=$_FHOST"	# set found HOST/SUBDOMAIN
1071
+		return 0
1072
+	}
1073
+	eval "$2=''"		# clear TLD
1074
+	eval "$3=''"		# clear registrable domain
1075
+	eval "$4=''"		# clear HOST/SUBDOMAIN
1076
+	return 1
1077
+}

+ 2
- 1
net/ddns-scripts/files/usr/lib/ddns/dynamic_dns_updater.sh View File

@@ -116,7 +116,7 @@ trap "trap_handler 15" 15	# SIGTERM	Termination
116 116
 ################################################################################
117 117
 
118 118
 # verify and load SECTION_ID is exists
119
-[ "$(uci_get ddns $SECTION_ID)" != "service" ] && {
119
+[ "$(uci -q get ddns.$SECTION_ID)" != "service" ] && {
120 120
 	[ $VERBOSE_MODE -le 1 ] && VERBOSE_MODE=2	# force console out and logfile output
121 121
 	[ -f $LOGFILE ] && rm -f $LOGFILE		# clear logfile before first entry
122 122
 	write_log  7 "************ ************** ************** **************"
@@ -129,6 +129,7 @@ load_all_config_options "ddns" "$SECTION_ID"
129 129
 write_log 7 "************ ************** ************** **************"
130 130
 write_log 5 "PID '$$' started at $(eval $DATE_PROG)"
131 131
 write_log 7 "uci configuraion:\n$(uci -q show ddns.$SECTION_ID | sort)"
132
+write_log 7 "ddns version  : $(opkg list-installed ddns-scripts | awk '{print $3}')"
132 133
 case $VERBOSE_MODE in
133 134
 	0) write_log  7 "verbose mode  : 0 - run normal, NO console output";;
134 135
 	1) write_log  7 "verbose mode  : 1 - run normal, console mode";;

+ 9884
- 0
net/ddns-scripts/files/usr/lib/ddns/tld_names.dat
File diff suppressed because it is too large
View File


+ 27
- 27
net/ddns-scripts/files/usr/lib/ddns/update_cloudflare.sh View File

@@ -11,17 +11,19 @@
11 11
 # option domain   - your full hostname to update, in cloudflare its subdomain.domain
12 12
 #			i.e. myhost.example.com where myhost is the subdomain and example.com is your domain
13 13
 #
14
-# Attention !!! script will only work if there is only one subdomain-level at your domain
15
-# subdomain2.subdomain1.domain i.e. mail.host.example.com will not work
16
-#
17 14
 # variable __IP already defined with the ip-address to use for update
18 15
 #
19 16
 [ $use_https -eq 0 ] && write_log 14 "Cloudflare only support updates via Secure HTTP (HTTPS). Please correct configuration!"
20 17
 
21
-local __RECID __URL __KEY __KEYS __FOUND __DOMREC
22
-local __SUBDOM=$(echo $domain | awk -F "." '{print $1}')
23
-local __DOMAIN=$(echo $domain | awk -F "${__SUBDOM}." '{print $2}')
24
-local __TMP="/tmp/$$.json"
18
+local __RECID __URL __KEY __KEYS __FOUND __SUBDOM __DOMAIN __TLD
19
+
20
+# split given Host/Domain into TLD, registrable domain, and subdomain
21
+split_FQDN $domain __TLD __DOMAIN __SUBDOM
22
+[ $? -ne 0 -o -z "$__DOMAIN" ] && \
23
+	write_log 14 "Wrong Host/Domain configuration ($domain). Please correct configuration!"
24
+
25
+# put together what we need
26
+__DOMAIN="$__DOMAIN.$__TLD"
25 27
 
26 28
 # parse OpenWrt script with
27 29
 # functions for parsing and generating json
@@ -29,17 +31,17 @@ local __TMP="/tmp/$$.json"
29 31
 
30 32
 # function copied from /usr/share/libubox/jshn.sh
31 33
 # from BB14.09 for backward compatibility to AA12.09
32
-json_get_keys() {
33
-	local __dest="$1"
34
-	local _tbl_cur
35
-
36
-	if [ -n "$2" ]; then
37
-		json_get_var _tbl_cur "$2"
38
-	else
39
-		_json_get_var _tbl_cur JSON_CUR
40
-	fi
41
-	local __var="${JSON_PREFIX}KEYS_${_tbl_cur}"
42
-	eval "export -- \"$__dest=\${$__var}\"; [ -n \"\${$__var+x}\" ]"
34
+grep -i "json_get_keys" /usr/share/libubox/jshn.sh >/dev/null 2>&1 || json_get_keys() {
35
+		local __dest="$1"
36
+		local _tbl_cur
37
+
38
+		if [ -n "$2" ]; then
39
+			json_get_var _tbl_cur "$2"
40
+		else
41
+			_json_get_var _tbl_cur JSON_CUR
42
+		fi
43
+		local __var="${JSON_PREFIX}KEYS_${_tbl_cur}"
44
+		eval "export -- \"$__dest=\${$__var}\"; [ -n \"\${$__var+x}\" ]"
43 45
 }
44 46
 
45 47
 # function to "sed" unwanted string parts from DATFILE
@@ -77,15 +79,13 @@ json_select "recs"
77 79
 json_select "objs"
78 80
 json_get_keys __KEYS
79 81
 for __KEY in $__KEYS; do
80
-	local __ZONE __NAME __DISPLAY __TYPE
82
+	local __ZONE __DISPLAY __NAME __TYPE
81 83
 	json_select "$__KEY"
82
-	json_get_var __ZONE "zone_name"
84
+#	json_get_var __ZONE "zone_name"		# for debugging
85
+#	json_get_var __DISPLAY "display_name"	# for debugging
83 86
 	json_get_var __NAME "name"
84
-	json_get_var __DISPLAY "display_name"
85 87
 	json_get_var __TYPE "type"
86
-	# if "zone_name" == "name" == "display_name" == $domain, then we found a valid domain record
87 88
 	if [ "$__NAME" = "$domain" ]; then
88
-		[ "$__DISPLAY" = "$__ZONE" ] && __DOMREC=1 || __DOMREC=0
89 89
 		# we must verify IPv4 and IPv6 because there might be both for the same host
90 90
 		[ \( $use_ipv6 -eq 0 -a "$__TYPE" = "A" \) -o \( $use_ipv6 -eq 1 -a "$__TYPE" = "AAAA" \) ] && {
91 91
 			__FOUND=1	# mark found
@@ -110,14 +110,14 @@ __URL="${__URL}?a=rec_edit"				#  -d 'a=rec_edit'
110 110
 __URL="${__URL}&tkn=$password"				#  -d 'tkn=8afbe6dea02407989af4dd4c97bb6e25'
111 111
 __URL="${__URL}&id=$__RECID"				#  -d 'id=9001'
112 112
 __URL="${__URL}&email=$username"			#  -d 'email=sample@example.com'
113
-[ $__DOMREC -eq 0 ] && __URL="${__URL}&z=$__DOMAIN"	#  -d 'z=example.com'
114
-[ $__DOMREC -eq 1 ] && __URL="${__URL}&z=$domain"	#  -d 'z=example.com'
113
+__URL="${__URL}&z=$__DOMAIN"				#  -d 'z=example.com'
115 114
 
116 115
 [ $use_ipv6 -eq 0 ] && __URL="${__URL}&type=A"		#  -d 'type=A'		(IPv4)
117 116
 [ $use_ipv6 -eq 1 ] && __URL="${__URL}&type=AAAA"	#  -d 'type=AAAA'	(IPv6)
118 117
 
119
-[ $__DOMREC -eq 0 ] && __URL="${__URL}&name=$__SUBDOM"	#  -d 'name=sub'	(HOST/SUBDOMAIN)
120
-[ $__DOMREC -eq 1 ] && __URL="${__URL}&name=$domain"	#  -d 'name=example.com'(DOMAIN)
118
+# handle subdomain or domain record
119
+[ -n "$__SUBDOM" ] && __URL="${__URL}&name=$__SUBDOM"	#  -d 'name=sub'	(HOST/SUBDOMAIN)
120
+[ -z "$__SUBDOM" ] && __URL="${__URL}&name=$__DOMAIN"	#  -d 'name=example.com'(DOMAIN)
121 121
 
122 122
 __URL="${__URL}&content=$__IP"				#  -d 'content=1.2.3.4'
123 123
 __URL="${__URL}&service_mode=0"				#  -d 'service_mode=0'