OpenWrt ddns-scripts

OpenWrt 10.03-1 RC5 verzióval szenvedek a ddns-scripts csomaggal és a dyndns-sel.A dyndns.com -on átírtam a hosztomhoz tartozó IP-t egy random másik IP-re, ami -elvileg- tekinthető úgy mintha a saját dinamikus IP-m változott volna meg.

A naplófájlból az látszik hogy valamiért ha "$current_ip" != "$registered_ip", akkor is a

/usr/lib/ddns/dynamic_dns_updater.sh

szkript else ágába kerül a vezérlés, és ezért nem megy a frissítés.

Hogyan teszteltem:

Ezeket a fájlokat rakta fel a ddns-scripts:

# opkg files ddns-scripts 
Package ddns-scripts (1.0.0-14) is installed on root and has the following files:
/etc/hotplug.d/iface/25-ddns
/usr/lib/ddns/url_escape.sed
/usr/lib/ddns/dynamic_dns_updater.sh
/usr/lib/ddns/services
/etc/config/ddns
/usr/lib/ddns/dynamic_dns_functions.sh

Az

/usr/lib/ddns/dynamic_dns_updater.sh

fájlhoz naplózást adtam hozzá:


@@ -264,11 +264,19 @@
 	verbose_echo "current system ip = $current_ip"
 	verbose_echo "registered domain ip = $registered_ip"
 
+	logger -t dynamic_dns_updater.sh "Running IP check..."
+	logger -t dynamic_dns_updater.sh "Current IP: $current_ip"
+	logger -t dynamic_dns_updater.sh "Registered IP: $registered_ip"
+	logger -t dynamic_dns_updater.sh "Comparing Current IP and Registered IP ..."
+	
 
 	if [ "$current_ip" != "$registered_ip" ]  || [ $force_interval_seconds -lt $time_since_update ]
 	then
 		verbose_echo "update necessary, performing update ..."
 
+		logger -t dynamic_dns_updater.sh "They are different."
+		logger -t dynamic_dns_updater.sh "$( echo "$service_id" | tr '[a-z]' '[A-Z]' ): Update necessary, performing update ..."
+
 		#do replacement
 		final_url=$update_url
 		for option_var in $ALL_OPTION_VARIABLES
@@ -293,6 +301,7 @@
 		verbose_echo "Update Output:"
 		verbose_echo "$update_output"
 		verbose_echo ""
+		logger -t dynamic_dns_updater.sh "Update output for ddns-scripts service $( echo "$service_id" | tr '[a-z]' '[A-Z]' ) is: $update_output."
 
 		#save the time of the update
 		current_time=$(monotonic_time)
@@ -310,6 +319,12 @@
 		verbose_echo "update unnecessary"
 		verbose_echo "time since last update = $human_time_since_update hours"
 		verbose_echo "the time is now $human_time"
+
+		logger -t dynamic_dns_updater.sh "They are equal."
+		logger -t dynamic_dns_updater.sh "$( echo "$service_id" | tr '[a-z]' '[A-Z]' ): Update UNnecessary." 
+		logger -t dynamic_dns_updater.sh "Time since last update: $human_time_since_update hours."
+		logger -t dynamic_dns_updater.sh "Time is now: $human_time."
+
 	fi
 
 	#sleep for 10 minutes, then re-check ip && time since last update

A következő a szituáció:

A frissítés működik, ha az

ACTION=ifup INTERFACE=wan /sbin/hotplug-call iface

paranccsal újrainicializálom a WAN interfészt. (Hotplug event.)

Ekkor -gondolom- ez hajtódik végre:

# cat /etc/hotplug.d/iface/25-ddns
#!/bin/sh

. /usr/lib/ddns/dynamic_dns_functions.sh

if [ "$INTERFACE" = "wan" ] && [ "$ACTION" = "ifup" ]
then
	start_daemon_for_all_ddns_sections
fi

Normál üzem esetén úgy csinálták az OpenWrt -sek hogy cron helyett a

/bin/sh /usr/lib/ddns/dynamic_dns_updater.sh dyndns_szappantarto 0

elmegy sleep-be

$check_interval_seconds

időre (

/usr/lib/ddns/dynamic_dns_updater.sh

).

Ilyenkor, bár az

nslookup $domainem

már a webes felületen módosított IP-t adja vissza, a frissítés nem történik meg.

A saját IP-met (Current IP) ezzel tudom meg:

# cat /etc/getwanip.sh 
#!/bin/sh

wget -qO- ifconfig.me/ip

A router így tudja meg a Registered IP-t (

/usr/lib/ddns/dynamic_dns_updater.sh

):

registered_ip=$(echo $(nslookup "$domain" 2>/dev/null) |  grep -o "Name:.*" | grep -o "$ip_regex") 

)

Olyan emberek segítségét szeretném kérni, akinek van OpenWrt-je és tesztelni is tud, ugyanis a vonatkozó szkriptek más fájlokat is source -olnak, így nem láttam értelmét hogy ide beilleszek vagy 10 oldalnyi kódot.

Hozzászólások

-a getwanip.sh futtatható
-a ddns config így néz ki:

# cat /etc/config/ddns

config 'service' 'dyndns_szappantarto'
	option 'service_name' 'dyndns.org'
	option 'domain' 'szappantarto.dyndns.org'
	option 'username' '**********'
	option 'password' '**********'
	option 'ip_source' 'script'
	option 'ip_script' '/etc/getwanip.sh'
	option 'force_interval' '7'
	option 'force_unit' 'days'
	option 'check_interval' '10'
	option 'check_unit' 'minutes'
	option 'enabled' '1'
	option 'use_https' '1'

- a naplózást rendes módon a

/usr/lib/ddns/dynamic_dns_functions.sh

módosításával kellett volna megcsinálni, hogy a

/usr/lib/ddns/dynamic_dns_updater.sh

-ban a

verbose_echo

kezdetű sorok életre keljenek

Meg tudom kerülni a problémát, az viszont még mindig nagyon érdekel hogy a szkript van-e elcsesszintve, vagy én vagyok a béna...

Lehet hogy megvan a hiba.

A

registered_ip=$(echo $(nslookup "$domain" 2>/dev/null) | grep -o "Name:.*" | grep -o "$ip_regex")

sort át kell rakni a

 while [true] ...

belsejébe.

OK, a http://hup.hu/node/108926#comment-1376766 hozzászólásom után átírtam erre amit javasoltál. Aztán kiadtam ezt a parancsot:

ACTION=ifup INTERFACE=wan /sbin/hotplug-call iface

Nov 21 13:03:21 szappantarto user.notice ddns-scripts: update_url=https://[USERNAME]:[PASSWORD]@members.dyndns.org/nic/update?hostname=[DOMAIN]&myip=[IP]
Nov 21 13:03:21 szappantarto user.notice ddns-scripts: force seconds = 604800
Nov 21 13:03:21 szappantarto user.notice ddns-scripts: check seconds = 600
Nov 21 13:03:21 szappantarto user.notice ddns-scripts: old process id (if it exists) = " 1124 root 1448 S /bin/sh /usr/lib/ddns/dynamic_dns_updater.sh dyndns_s"
Nov 21 13:03:21 szappantarto user.notice ddns-scripts: time_since_update = 0 hours
Nov 21 13:03:22 szappantarto user.notice ddns-scripts: Running IP check...
Nov 21 13:03:22 szappantarto user.notice ddns-scripts: current system ip = 94.248.229.181
Nov 21 13:03:22 szappantarto user.notice ddns-scripts: registered domain ip = 94.248.231.236
Nov 21 13:03:22 szappantarto user.notice ddns-scripts: update necessary, performing update ...
Nov 21 13:03:22 szappantarto user.notice ddns-scripts: updating with url="https://******:***********@members.dyndns.org/nic/update?hostname=szappantarto.dyndns.org&myip=94.248.229.181"
Nov 21 13:03:23 szappantarto user.notice ddns-scripts: Update Output:
Nov 21 13:03:23 szappantarto user.notice ddns-scripts: good 94.248.229.181
Nov 21 13:03:23 szappantarto user.notice ddns-scripts: update complete, time is: Mon Nov 21 13:03:23 CET 2011

Szóval nem oldódott meg!

Figy, nekem ennyi van benne es megy (bar nem frissitett amiota downgradeltem, lasd masik topic, de elott ez a config volt, holnap telik le a 72 ora, vagy 3 nap mulva, mert az elobb probakepp ujrainditottam :):


root@kraken:~# cat /etc/config/ddns

config 'service' 'myddns'
option 'ip_source' 'network'
option 'ip_network' 'wan'
option 'check_interval' '10'
option 'check_unit' 'minutes'
option 'domain' 'domain'
option 'username' 'username'
option 'password' 'password'
option 'service_name' 'dyndns.org'
option 'force_interval' '72'
option 'force_unit' 'hours'
option 'enabled' '1'

root@kraken:~# opkg list_installed|grep ddns
ddns-scripts - 1.0.0-14
luci-app-ddns - 0.10+svn7292-1

root@kraken:/usr/lib/ddns# ls -al
drwxr-xr-x 2 root root 0 Nov 20 21:33 .
drwxr-xr-x 5 root root 0 Jul 13 17:00 ..
-rw-r--r-- 1 root root 2842 Jul 12 01:26 dynamic_dns_functions.sh
-rwxr-xr-x 1 root root 7645 Jul 12 01:26 dynamic_dns_updater.sh
-rw-r--r-- 1 root root 2890 Jul 12 01:26 services
-rw-r--r-- 1 root root 266 Jul 12 01:26 url_escape.sed

Szerintem takaritsd le a csomagokat konfigokkal egyutt es probald ujra.

Éjjelre áramtalanítottam a berendezéseket. Reggel új IP-t kaptam.

Sajnos nem működik a frissítés.

Annyit változtattam még, hogy a loggolást a nyitóposzttal ellentétben kulturáltabb módon oldottam meg:

@@ -104,7 +104,7 @@
 {
     if [ "$verbose_mode" = 1 ]
     then
-        echo $1
+        logger -t ddns-scripts $1
     fi
 }
@@ -119,7 +119,7 @@
 
     for section in $SECTIONS
     do
-        /usr/lib/ddns/dynamic_dns_updater.sh $section 0 > /dev/null 2>&1 &
+        /usr/lib/ddns/dynamic_dns_updater.sh $section 1 > /dev/null 2>&1 &
     done
 } 
# nslookup szappantarto.dyndns.org 
Server:    212.24.188.130
Address 1: 212.24.188.130 proxy.juropnet.hu

Name:      szappantarto.dyndns.org
Address 1: 94.248.231.236
~# nslookup szappantarto.dyndns.org 8.8.8.8
Server:    8.8.8.8
Address 1: 8.8.8.8 google-public-dns-a.google.com

Name:      szappantarto.dyndns.org
Address 1: 94.248.231.236
# nslookup szappantarto.dyndns.org 208.67.222.222
Server:    208.67.222.222
Address 1: 208.67.222.222 resolver1.opendns.com

Name:      szappantarto.dyndns.org
Address 1: 94.248.231.236
 
# uci -P/var/state get network.wan.ipaddr
94.248.229.181
 

A DNS rendszerben még mindig a régi IP-m szerepel.

A naplófájl a következőt tartalmazza:

(A privát részeket csillagoztam.)

Nov 21 12:34:46 szappantarto user.notice ddns-scripts: Running IP check...
Nov 21 12:34:46 szappantarto user.notice ddns-scripts: current system ip = 94.248.229.181
Nov 21 12:34:46 szappantarto user.notice ddns-scripts: registered domain ip = 94.248.231.236
Nov 21 12:34:46 szappantarto user.notice ddns-scripts: update necessary, performing update ...
Nov 21 12:34:46 szappantarto user.notice ddns-scripts: updating with url="https://*******:***************@members.dyndns.org/nic/update?hostname=szappantarto.dyndns.org&myip=94.248.229.181"
Nov 21 12:34:47 szappantarto user.notice ddns-scripts: Update Output:
Nov 21 12:34:47 szappantarto user.notice ddns-scripts: update complete, time is: Mon Nov 21 12:34:47 CET 2011

Az látszik, hogy a kurrens IP címemet helyesen állapítja meg.

Az is látszik, hogy az Update Output résznél nem ad választ a dyndns.

Ezek közül kellene ott szerepelnie valaminek: http://dyn.com/support/developers/api/return-codes/

Hogyan tovább???

Ma éjjel ugyanúgy kikapcsoltam az eszközöket, reggel be (megint új IP-t kaptam), majd visszatekertem a napló megfelelő részéhez:

Nov 22 09:20:43 ddns-scripts: Running IP check...
Nov 22 09:20:43 ddns-scripts: current system ip =
Nov 22 09:20:43 ddns-scripts: registered domain ip =
Nov 22 09:20:43 ddns-scripts: update unnecessary
Nov 22 09:20:43 ddns-scripts: time since last update = 0 hours
Nov 22 09:20:43 ddns-scripts: the time is now Tue Nov 22 09:20:43 CET 2011
Nov 22 09:21:46 kernel: IN: IN=eth0.2 OUT= MAC=ff:ff:ff:ff:ff:ff:00:17:10:01:ab:b4:08:00:45:00:01:3b SRC=10.250.0.1 DST=255.255.255.255 LEN=315 TOS=0x00 PREC=0x00 TTL=64 ID=0 PROTO=UDP SPT=67 DPT=68 LEN=295 
Nov 22 09:21:46 kernel: IN: IN=eth0.2 OUT= MAC=ff:ff:ff:ff:ff:ff:00:17:10:01:ab:b4:08:00:45:00:01:3b SRC=10.250.0.1 DST=255.255.255.255 LEN=315 TOS=0x00 PREC=0x00 TTL=64 ID=0 PROTO=UDP SPT=67 DPT=68 LEN=295 
Nov 22 09:22:31 kernel: IN: IN=eth0.2 OUT= MAC=01:00:5e:00:00:01:00:17:10:01:ab:b4:08:00:46:00:00:20 SRC=79.121.103.97 DST=224.0.0.1 LEN=32 TOS=0x00 PREC=0x00 TTL=1 ID=0 PROTO=2 
Nov 22 09:24:39 kernel: IN: IN=eth0.2 OUT= MAC=01:00:5e:00:00:01:00:17:10:01:ab:b4:08:00:46:00:00:20 SRC=79.121.103.97 DST=224.0.0.1 LEN=32 TOS=0x00 PREC=0x00 TTL=1 ID=0 PROTO=2 
Nov 22 09:26:42 kernel: IN: IN=eth0.2 OUT= MAC=01:00:5e:00:00:01:00:17:10:01:ab:b4:08:00:46:00:00:20 SRC=79.121.103.97 DST=224.0.0.1 LEN=32 TOS=0x00 PREC=0x00 TTL=1 ID=0 PROTO=2 
Nov 22 09:28:50 kernel: IN: IN=eth0.2 OUT= MAC=01:00:5e:00:00:01:00:17:10:01:ab:b4:08:00:46:00:00:20 SRC=79.121.103.97 DST=224.0.0.1 LEN=32 TOS=0x00 PREC=0x00 TTL=1 ID=0 PROTO=2 
Nov 22 09:30:43 ddns-scripts: Running IP check...
Nov 22 09:30:43 ddns-scripts: current system ip =
Nov 22 09:30:43 ddns-scripts: registered domain ip =
Nov 22 09:30:43 ddns-scripts: update unnecessary
Nov 22 09:30:43 ddns-scripts: time since last update = 0 hours
Nov 22 09:30:43 ddns-scripts: the time is now Tue Nov 22 09:30:43 CET 2011
Nov 22 09:30:53 kernel: IN: IN=eth0.2 OUT= MAC=01:00:5e:00:00:01:00:17:10:01:ab:b4:08:00:46:00:00:20 SRC=79.121.103.97 DST=224.0.0.1 LEN=32 TOS=0x00 PREC=0x00 TTL=1 ID=0 PROTO=2 
Nov 22 09:32:58 kernel: IN: IN=eth0.2 OUT= MAC=01:00:5e:00:00:01:00:17:10:01:ab:b4:08:00:46:00:00:20 SRC=79.121.103.97 DST=224.0.0.1 LEN=32 TOS=0x00 PREC=0x00 TTL=1 ID=0 PROTO=2 
Nov 22 09:33:41 kernel: IN: IN=eth0.2 OUT= MAC=ff:ff:ff:ff:ff:ff:00:17:10:01:ab:b4:08:00:45:00:01:3b SRC=10.250.0.1 DST=255.255.255.255 LEN=315 TOS=0x00 PREC=0x00 TTL=64 ID=0 PROTO=UDP SPT=67 DPT=68 LEN=295 
Nov 22 09:33:41 kernel: IN: IN=eth0.2 OUT= MAC=ff:ff:ff:ff:ff:ff:00:17:10:01:ab:b4:08:00:45:00:01:3b SRC=10.250.0.1 DST=255.255.255.255 LEN=315 TOS=0x00 PREC=0x00 TTL=64 ID=0 PROTO=UDP SPT=67 DPT=68 LEN=295 
Nov 22 09:34:23 kernel: IN: IN=eth0.2 OUT= MAC=ff:ff:ff:ff:ff:ff:00:17:10:01:ab:b4:08:00:45:00:01:3b SRC=10.250.0.1 DST=255.255.255.255 LEN=315 TOS=0x00 PREC=0x00 TTL=64 ID=0 PROTO=UDP SPT=67 DPT=68 LEN=295 
Nov 22 09:34:23 kernel: IN: IN=eth0.2 OUT= MAC=ff:ff:ff:ff:ff:ff:00:17:10:01:ab:b4:08:00:45:00:01:3b SRC=10.250.0.1 DST=255.255.255.255 LEN=315 TOS=0x00 PREC=0x00 TTL=64 ID=0 PROTO=UDP SPT=67 DPT=68 LEN=295 
Nov 22 09:35:04 kernel: IN: IN=eth0.2 OUT= MAC=01:00:5e:00:00:01:00:17:10:01:ab:b4:08:00:46:00:00:20 SRC=79.121.103.97 DST=224.0.0.1 LEN=32 TOS=0x00 PREC=0x00 TTL=1 ID=0 PROTO=2 
Nov 22 09:35:22 ifup: Allowing Router Advertisements on wan (eth0.2)
Nov 22 09:35:23 root: starting ntpclient
Nov 22 09:35:23 ddns-scripts: update_url=https://[USERNAME]:[PASSWORD]@members.dyndns.org/nic/update?hostname=[DOMAIN]&myip=[IP]
Nov 22 09:35:23 ddns-scripts: force seconds = 604800
Nov 22 09:35:23 ddns-scripts: check seconds = 600
Nov 22 09:35:23 ddns-scripts: old process id (if it exists) = " 5919 root 1448 S /bin/sh /usr/lib/ddns/dynamic_dns_updater.sh dyndns_s"
Nov 22 09:35:23 ddns-scripts: time_since_update = 0 hours
Nov 22 09:35:24 ddns-scripts: Running IP check...
Nov 22 09:35:24 ddns-scripts: current system ip = 94.248.229.222
Nov 22 09:35:24 ddns-scripts: registered domain ip = 94.248.229.181
Nov 22 09:35:24 ddns-scripts: update necessary, performing update ...
Nov 22 09:35:24 ddns-scripts: updating with url="https://******:****************@members.dyndns.org/nic/update?hostname=szappantarto.dyndns.org&myip=94.248.229.222"
Nov 22 09:35:24 ddns-scripts: Update Output:
Nov 22 09:35:24 ddns-scripts: update complete, time is: Tue Nov 22 09:35:24 CET 2011

Továbbra is üres az Update Output, tehát a naplótól egyelőre nem lettünk okosabbak.

Úgy tűnik, hogy a probléma meg van oldva.

Ha azt szeretnénk (ritka igény...) hogy a dinamikus dns szolgáltató web-felületén átírva az IP címünket is triggerelődjön egy frissítés a ddns kliens által (az update URL meglátogatása) akkor szükség van erre a patch-re:

/usr/lib/ddns/dynamic_dns_updater.sh
@@ -246,7 +246,6 @@
 
 
 
-registered_ip=$(echo $(nslookup "$domain" 2>/dev/null) |  grep -o "Name:.*" | grep -o "$ip_regex")
 
 
 #do update and then loop endlessly, checking ip every check_interval and forcing an updating once every force_interval
@@ -254,6 +253,7 @@
 while [ true ]
 do
 	current_ip=$(get_current_ip)
+        registered_ip=$(echo $(nslookup "$domain" 2>/dev/null) |  grep -o "Name:.*" | grep -o "$ip_regex")
 
 
 	current_time=$(monotonic_time)

Nekem ez a tesztelés miatt kellett volna, mert sokkal könnyebb mint lokálisan, a routeren publikus IP-t "változtatni".

Kiderült tehát hogy a frissítés sikertelenségének valódi oka nem erre vezethető vissza, hanem a lentebb leírtakra.

Ha https-t használunk, mert nem szeretnénk hogy a jelszavunk plan-text-ben utazzon (az update URL része) akkor a standard beállításokon túl ezekre van szükség:

opkg update && opkg install curl
mkdir -p /etc/ssl/certs
cd /etc/ssl/certs
wget http://curl.haxx.se/ca/cacert.pem

A

/etc/profile

-ban hiába van megadva a curl -re vonatkozó

export CURL_CA_BUNDLE=/etc/ssl/certs/cacert.pem

sor, a ddns frissítő daemon nem source-olja.

Így, a

#some constants

if [ "x$use_https" = "x1" ]
then
	retrieve_prog="/usr/bin/curl "
	if [ -f "$cacert" ]
	then
		retrieve_prog="${retrieve_prog}--cacert $cacert "
	elif [ -d "$cacert" ]
	then
		retrieve_prog="${retrieve_prog}--capath $cacert "
	fi
else
	retrieve_prog="/usr/bin/wget -O - ";
fi
 

kódrészlet (

/usr/lib/ddns/dynamic_dns_updater.sh

) alapján az _egyik_ lehetőség a megoldásra, hogy a

/etc/config/ddns

fájlba beillesztjük a következő sort is:


option cacert /etc/ssl/certs/cacert.pem

Az update output VALÓSZÍNŰLEG azért volt üres, mert a bőbeszédű mód bekapcsolása ellenére a curl standard output és/vagy standard error kimenete nem jelent meg a logban.

Összefoglalva, legalább 3 dolog kell a https működéséhez:

-CA bundle berakása a megfelelő helyre

option 'use_https' '1'
option 'cacert' '/etc/ssl/certs/cacert.pem'

És ez a /usr/lib/ddns/dynamic_dns_updater.sh script minek a hatására fut le?

Nálam egyébként (ugyanez az Openwrt) van egy "tartalék" script is, crontab futtatja 10 percenként:


#!/bin/sh
# File: dyndns.sh

# User configurable
hostname="xxxxxx.homelinux.net"
username="xxxxxxxx"
password="xxxxxxxx"

# Get IP comparison
current_ip=`ifconfig pppoe-wan | grep inet | cut -d ':' -f 2 | cut -d ' ' -f 1`
lookup_ip=`nslookup $hostname | grep Address | cut -d ' ' -f 3 | awk 'NR==2{print $1}'`

URL="http://$username:$password@members.dyndns.org/nic/update?hostname=$hostname&myip=$current_ip&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
if [ "$current_ip" != "$lookup_ip" ]; then wget -O- $URL > /dev/null; fi

exit 0

Nem okoz fölösleges update-elési kísérletet, és bár nem https-en megy, lehet, hogy azt is bele lehetne okosítani.

:wq

subscribe
-------------------------------------------------------------------------------
Az életben csak egy dolog a szép, de az épp nem jut eszembe.

Slackware Linux 13.37 | 2.6.39.3-janos