1 # /usr/lib/dynamic_dns/dynamic_dns_functions.sh
3 # Written by Eric Paul Bishop, Janary 2008
4 # Distributed under the terms of the GNU General Public License (GPL) version 2.0
6 # This script is (loosely) based on the one posted by exobyte in the forums here:
7 # http://forum.openwrt.org/viewtopic.php?id=14040
15 #loads all options for a given package and section
16 #also, sets all_option_variables to a list of the variable names
17 load_all_config_options
()
22 ALL_OPTION_VARIABLES
=""
23 # this callback loads all the variables
24 # in the section_id section when we do
25 # config_load. We need to redefine
26 # the option_cb for different sections
27 # so that the active one isn't still active
28 # after we're done with it. For reference
29 # the $1 variable is the name of the option
30 # and $2 is the name of the section
33 if [ .
"$2" = .
"$section_id" ]; then
36 ALL_OPTION_VARIABLES
="$ALL_OPTION_VARIABLES $1"
39 option_cb
() { return 0; }
44 config_load
"$pkg_name"
45 for var
in $ALL_OPTION_VARIABLES
47 config_get
"$var" "$section_id" "$var"
55 #if ip source is not defined, assume we want to get ip from wan
56 if [ "$ip_source" != "interface" ] && [ "$ip_source" != "web" ] && [ "$ip_source" != "script" ]
61 if [ "$ip_source" = "network" ]
63 if [ -z "$ip_network" ]
68 config_load
/var
/state
/network
69 config_get ip_interface
$ip_network ifname
73 if [ "$ip_source" = "network" ] ||
[ "$ip_source" = "interface" ]
75 current_ip
=$
(ifconfig
$ip_interface |
grep -o 'inet addr:[0-9.]*' |
grep -o "$ip_regex")
76 elif [ "$ip_source" = "script" ]
79 current_ip
=$
($ip_script)
82 # we check each url in order in ip_url variable, and if no ips are found we use dyndns ip checker
83 # ip is set to FIRST expression in page that matches the ip_regex regular expression
86 if [ -z "$current_ip" ]
88 current_ip
=$
(echo $
( wget
-O - $addr 2>/dev
/null
) |
grep -o "$ip_regex")
92 #here we hard-code the dyndns checkip url in case no url was specified
93 if [ -z "$current_ip" ]
95 current_ip
=$
(echo $
( wget
-O - http
://checkip.dyndns.org
2>/dev
/null
) |
grep -o "$ip_regex")
105 if [ "$verbose_mode" = 1 ]
111 start_daemon_for_all_ddns_sections
()
113 local event_interface
="$1"
118 SECTIONS
="$SECTIONS $2"
122 for section
in $SECTIONS
125 config_get iface
"$section" interface
"wan"
126 [ "$iface" = "$event_interface" ] ||
continue
127 /usr
/lib
/ddns
/dynamic_dns_updater.sh
$section 0 > /dev
/null
2>&1 &
134 read uptime
< /proc
/uptime