|
@@ -1,144 +1,715 @@
|
1
|
|
-# /usr/lib/dynamic_dns/dynamic_dns_functions.sh
|
|
1
|
+#!/bin/sh
|
|
2
|
+# /usr/lib/ddns/dynamic_dns_functions.sh
|
2
|
3
|
#
|
3
|
|
-# Written by Eric Paul Bishop, Janary 2008
|
|
4
|
+# Original written by Eric Paul Bishop, January 2008
|
4
|
5
|
# Distributed under the terms of the GNU General Public License (GPL) version 2.0
|
5
|
|
-#
|
6
|
|
-# This script is (loosely) based on the one posted by exobyte in the forums here:
|
|
6
|
+# (Loosely) based on the script on the one posted by exobyte in the forums here:
|
7
|
7
|
# http://forum.openwrt.org/viewtopic.php?id=14040
|
8
|
|
-
|
9
|
|
-
|
|
8
|
+#
|
|
9
|
+# extended and partial rewritten by Christian Schoenebeck in August 2014 to support:
|
|
10
|
+# - IPv6 DDNS services
|
|
11
|
+# - setting DNS Server to retrieve current IP including TCP transport
|
|
12
|
+# - Proxy Server to send out updates or retrieving WEB based IP detection
|
|
13
|
+# - force_interval=0 to run once (usefull for cron jobs etc.)
|
|
14
|
+# - the usage of BIND's host instead of BusyBox's nslookup if installed (DNS via TCP)
|
|
15
|
+# - extended Verbose Mode and log file support for better error detection
|
|
16
|
+#
|
|
17
|
+# function __timeout
|
|
18
|
+# copied from http://www.ict.griffith.edu.au/anthony/software/timeout.sh
|
|
19
|
+# @author Anthony Thyssen 6 April 2011
|
|
20
|
+#
|
|
21
|
+# variables in small chars are read from /etc/config/ddns
|
|
22
|
+# variables in big chars are defined inside these scripts as global vars
|
|
23
|
+# variables in big chars beginning with "__" are local defined inside functions only
|
|
24
|
+#set -vx #script debugger
|
10
|
25
|
|
11
|
26
|
. /lib/functions.sh
|
12
|
27
|
. /lib/functions/network.sh
|
13
|
28
|
|
|
29
|
+# GLOBAL VARIABLES #
|
|
30
|
+SECTION_ID="" # hold config's section name
|
|
31
|
+VERBOSE_MODE=1 # default mode is log to console, but easily changed with parameter
|
|
32
|
+LUCI_HELPER="" # set by dynamic_dns_lucihelper.sh, if filled supress all error logging
|
|
33
|
+
|
|
34
|
+PIDFILE="" # pid file
|
|
35
|
+UPDFILE="" # store UPTIME of last update
|
|
36
|
+
|
|
37
|
+# directory to store run information to.
|
|
38
|
+RUNDIR=$(uci -q get ddns.global.run_dir) || RUNDIR="/var/run/ddns"
|
|
39
|
+# NEW # directory to store log files
|
|
40
|
+LOGDIR=$(uci -q get ddns.global.log_dir) || LOGDIR="/var/log/ddns"
|
|
41
|
+LOGFILE="" # NEW # logfile can be enabled as new option
|
|
42
|
+# number of lines to before rotate logfile
|
|
43
|
+LOGLINES=$(uci -q get ddns.global.log_lines) || LOGLINES=250
|
|
44
|
+
|
|
45
|
+CHECK_SECONDS=0 # calculated seconds out of given
|
|
46
|
+FORCE_SECONDS=0 # interval and unit
|
|
47
|
+RETRY_SECONDS=0 # in configuration
|
|
48
|
+
|
|
49
|
+OLD_PID=0 # Holds the PID of already running process for the same config section
|
|
50
|
+
|
|
51
|
+LAST_TIME=0 # holds the uptime of last successful update
|
|
52
|
+CURR_TIME=0 # holds the current uptime
|
|
53
|
+NEXT_TIME=0 # calculated time for next FORCED update
|
|
54
|
+EPOCH_TIME=0 # seconds since 1.1.1970 00:00:00
|
|
55
|
+
|
|
56
|
+REGISTERED_IP="" # holds the IP read from DNS
|
|
57
|
+LOCAL_IP="" # holds the local IP read from the box
|
|
58
|
+
|
|
59
|
+ERR_LAST=0 # used to save $? return code of program and function calls
|
|
60
|
+ERR_LOCAL_IP=0 # error counter on getting local ip
|
|
61
|
+ERR_REG_IP=0 # error counter on getting DNS registered ip
|
|
62
|
+ERR_SEND=0 # error counter on sending update to DNS provider
|
|
63
|
+ERR_UPDATE=0 # error counter on different local and registered ip
|
|
64
|
+
|
|
65
|
+# format to show date information in log and luci-app-ddns default ISO 8601 format
|
|
66
|
+DATE_FORMAT=$(uci -q get ddns.global.date_format) || DATE_FORMAT="%F %R"
|
|
67
|
+DATE_PROG="date +'$DATE_FORMAT'"
|
|
68
|
+
|
|
69
|
+# regular expression to detect IPv4 / IPv6
|
|
70
|
+# IPv4 0-9 1-3x "." 0-9 1-3x "." 0-9 1-3x "." 0-9 1-3x
|
|
71
|
+IPV4_REGEX="[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}"
|
|
72
|
+# IPv6 ( ( 0-9a-f 1-4char ":") min 1x) ( ( 0-9a-f 1-4char )optional) ( (":" 0-9a-f 1-4char ) min 1x)
|
|
73
|
+IPV6_REGEX="\(\([0-9A-Fa-f]\{1,4\}:\)\{1,\}\)\(\([0-9A-Fa-f]\{1,4\}\)\{0,1\}\)\(\(:[0-9A-Fa-f]\{1,4\}\)\{1,\}\)"
|
14
|
74
|
|
15
|
|
-#loads all options for a given package and section
|
16
|
|
-#also, sets all_option_variables to a list of the variable names
|
|
75
|
+# loads all options for a given package and section
|
|
76
|
+# also, sets all_option_variables to a list of the variable names
|
|
77
|
+# $1 = ddns, $2 = SECTION_ID
|
17
|
78
|
load_all_config_options()
|
18
|
79
|
{
|
19
|
|
- pkg_name="$1"
|
20
|
|
- section_id="$2"
|
21
|
|
-
|
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
|
|
80
|
+ local __PKGNAME="$1"
|
|
81
|
+ local __SECTIONID="$2"
|
|
82
|
+ local __VAR
|
|
83
|
+ local __ALL_OPTION_VARIABLES=""
|
|
84
|
+
|
|
85
|
+ # this callback loads all the variables in the __SECTIONID section when we do
|
|
86
|
+ # config_load. We need to redefine the option_cb for different sections
|
|
87
|
+ # so that the active one isn't still active after we're done with it. For reference
|
|
88
|
+ # the $1 variable is the name of the option and $2 is the name of the section
|
31
|
89
|
config_cb()
|
32
|
90
|
{
|
33
|
|
- if [ ."$2" = ."$section_id" ]; then
|
|
91
|
+ if [ ."$2" = ."$__SECTIONID" ]; then
|
34
|
92
|
option_cb()
|
35
|
93
|
{
|
36
|
|
- ALL_OPTION_VARIABLES="$ALL_OPTION_VARIABLES $1"
|
|
94
|
+ __ALL_OPTION_VARIABLES="$__ALL_OPTION_VARIABLES $1"
|
37
|
95
|
}
|
38
|
96
|
else
|
39
|
97
|
option_cb() { return 0; }
|
40
|
98
|
fi
|
41
|
99
|
}
|
42
|
100
|
|
|
101
|
+ config_load "$__PKGNAME"
|
|
102
|
+
|
|
103
|
+ # Given SECTION_ID not found so no data, so return 1
|
|
104
|
+ [ -z "$__ALL_OPTION_VARIABLES" ] && return 1
|
43
|
105
|
|
44
|
|
- config_load "$pkg_name"
|
45
|
|
- for var in $ALL_OPTION_VARIABLES
|
|
106
|
+ for __VAR in $__ALL_OPTION_VARIABLES
|
46
|
107
|
do
|
47
|
|
- config_get "$var" "$section_id" "$var"
|
|
108
|
+ config_get "$__VAR" "$__SECTIONID" "$__VAR"
|
48
|
109
|
done
|
|
110
|
+ return 0
|
49
|
111
|
}
|
50
|
112
|
|
51
|
|
-
|
52
|
|
-get_current_ip()
|
|
113
|
+# starts updater script for all given sections or only for the one given
|
|
114
|
+# $1 = interface (Optional: when given only scripts are started
|
|
115
|
+# configured for that interface)
|
|
116
|
+start_daemon_for_all_ddns_sections()
|
53
|
117
|
{
|
|
118
|
+ local __EVENTIF="$1"
|
|
119
|
+ local __SECTIONS=""
|
|
120
|
+ local __SECTIONID=""
|
|
121
|
+ local __IFACE=""
|
|
122
|
+
|
|
123
|
+ config_cb()
|
|
124
|
+ {
|
|
125
|
+ # only look for section type "service", ignore everything else
|
|
126
|
+ [ "$1" == "service" ] && __SECTIONS="$__SECTIONS $2"
|
|
127
|
+ }
|
|
128
|
+ config_load "ddns"
|
54
|
129
|
|
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" ]
|
57
|
|
- then
|
58
|
|
- ip_source="network"
|
|
130
|
+ for __SECTIONID in $__SECTIONS
|
|
131
|
+ do
|
|
132
|
+ config_get __IFACE "$__SECTIONID" interface "wan"
|
|
133
|
+ [ -z "$__EVENTIF" -o "$__IFACE" = "$__EVENTIF" ] || continue
|
|
134
|
+ /usr/lib/ddns/dynamic_dns_updater.sh $__SECTIONID 0 > /dev/null 2>&1 &
|
|
135
|
+ done
|
|
136
|
+}
|
|
137
|
+
|
|
138
|
+verbose_echo()
|
|
139
|
+{
|
|
140
|
+ [ -n "$LUCI_HELPER" ] && return # nothing to report when used by LuCI helper script
|
|
141
|
+ [ $VERBOSE_MODE -gt 0 ] && echo -e " $*"
|
|
142
|
+ if [ ${use_logfile:-0} -eq 1 -o $VERBOSE_MODE -gt 1 ]; then
|
|
143
|
+ [ -d $LOGDIR ] || mkdir -p -m 755 $LOGDIR
|
|
144
|
+ echo -e " $*" >> $LOGFILE
|
|
145
|
+ # VERBOSE_MODE > 1 then NO loop so NO truncate log to $LOGLINES lines
|
|
146
|
+ [ $VERBOSE_MODE -gt 1 ] || sed -i -e :a -e '$q;N;'$LOGLINES',$D;ba' $LOGFILE
|
59
|
147
|
fi
|
|
148
|
+ return
|
|
149
|
+}
|
60
|
150
|
|
61
|
|
- if [ "$ip_source" = "network" ]
|
62
|
|
- then
|
63
|
|
- if [ -z "$ip_network" ]
|
64
|
|
- then
|
65
|
|
- ip_network="wan"
|
|
151
|
+syslog_info(){
|
|
152
|
+ [ $use_syslog -eq 1 ] && logger -p user.info -t ddns-scripts[$$] "$SECTION_ID: $*"
|
|
153
|
+ return
|
|
154
|
+}
|
|
155
|
+syslog_notice(){
|
|
156
|
+ [ $use_syslog -ge 1 -a $use_syslog -le 2 ] && logger -p user.notice -t ddns-scripts[$$] "$SECTION_ID: $*"
|
|
157
|
+ return
|
|
158
|
+}
|
|
159
|
+syslog_warn(){
|
|
160
|
+ [ $use_syslog -ge 1 -a $use_syslog -le 3 ] && logger -p user.warn -t ddns-scripts[$$] "$SECTION_ID: $*"
|
|
161
|
+ return
|
|
162
|
+}
|
|
163
|
+syslog_err(){
|
|
164
|
+ [ $use_syslog -ge 1 ] && logger -p user.err -t ddns-scripts[$$] "$SECTION_ID: $*"
|
|
165
|
+ return
|
|
166
|
+}
|
|
167
|
+
|
|
168
|
+critical_error() {
|
|
169
|
+ [ -n "$LUCI_HELPER" ] && return # nothing to report when used by LuCI helper script
|
|
170
|
+ verbose_echo "\n CRITICAL ERROR =: $* - EXITING\n"
|
|
171
|
+ [ $VERBOSE_MODE -eq 0 ] && echo -e "\n$SECTION_ID: CRITICAL ERROR - $* - EXITING\n"
|
|
172
|
+ logger -t ddns-scripts[$$] -p user.crit "$SECTION_ID: CRITICAL ERROR - $* - EXITING"
|
|
173
|
+ exit 1 # critical error -> leave here
|
|
174
|
+}
|
|
175
|
+
|
|
176
|
+# extract update_url for given DDNS Provider from
|
|
177
|
+# file /usr/lib/ddns/services for IPv4 or from
|
|
178
|
+# file /usr/lib/ddns/services_ipv6 for IPv6
|
|
179
|
+get_service_url() {
|
|
180
|
+ # $1 Name of Variable to store url to
|
|
181
|
+ local __LINE __FILE __NAME __URL __SERVICES
|
|
182
|
+ local __OLD_IFS=$IFS
|
|
183
|
+ local __NEWLINE_IFS='
|
|
184
|
+' #__NEWLINE_IFS
|
|
185
|
+
|
|
186
|
+ __FILE="/usr/lib/ddns/services" # IPv4
|
|
187
|
+ [ $use_ipv6 -ne 0 ] && __FILE="/usr/lib/ddns/services_ipv6" # IPv6
|
|
188
|
+
|
|
189
|
+ #remove any lines not containing data, and then make sure fields are enclosed in double quotes
|
|
190
|
+ __SERVICES=$(cat $__FILE | grep "^[\t ]*[^#]" | \
|
|
191
|
+ awk ' gsub("\x27", "\"") { if ($1~/^[^\"]*$/) $1="\""$1"\"" }; { if ( $NF~/^[^\"]*$/) $NF="\""$NF"\"" }; { print $0 }')
|
|
192
|
+
|
|
193
|
+ IFS=$__NEWLINE_IFS
|
|
194
|
+ for __LINE in $__SERVICES
|
|
195
|
+ do
|
|
196
|
+ #grep out proper parts of data and use echo to remove quotes
|
|
197
|
+ __NAME=$(echo $__LINE | grep -o "^[\t ]*\"[^\"]*\"" | xargs -r -n1 echo)
|
|
198
|
+ __URL=$(echo $__LINE | grep -o "\"[^\"]*\"[\t ]*$" | xargs -r -n1 echo)
|
|
199
|
+
|
|
200
|
+ if [ "$__NAME" = "$service_name" ]; then
|
|
201
|
+ break # found so leave for loop
|
66
|
202
|
fi
|
|
203
|
+ done
|
|
204
|
+ IFS=$__OLD_IFS
|
|
205
|
+
|
|
206
|
+ eval "$1='$__URL'"
|
|
207
|
+ return 0
|
|
208
|
+}
|
|
209
|
+
|
|
210
|
+get_seconds() {
|
|
211
|
+ # $1 Name of Variable to store result in
|
|
212
|
+ # $2 Number and
|
|
213
|
+ # $3 Unit of time interval
|
|
214
|
+ case "$3" in
|
|
215
|
+ "days" ) eval "$1=$(( $2 * 86400 ))";;
|
|
216
|
+ "hours" ) eval "$1=$(( $2 * 3600 ))";;
|
|
217
|
+ "minutes" ) eval "$1=$(( $2 * 60 ))";;
|
|
218
|
+ * ) eval "$1=$2";;
|
|
219
|
+ esac
|
|
220
|
+ return 0
|
|
221
|
+}
|
|
222
|
+
|
|
223
|
+__timeout() {
|
|
224
|
+ # copied from http://www.ict.griffith.edu.au/anthony/software/timeout.sh
|
|
225
|
+ # only did the folloing changes
|
|
226
|
+ # - commented out "#!/bin/bash" and usage section
|
|
227
|
+ # - replace exit by return for usage as function
|
|
228
|
+ # - some reformating
|
|
229
|
+ #
|
|
230
|
+ # timeout [-SIG] time [--] command args...
|
|
231
|
+ #
|
|
232
|
+ # Run the given command until completion, but kill it if it runs too long.
|
|
233
|
+ # Specifically designed to exit immediatally (no sleep interval) and clean up
|
|
234
|
+ # nicely without messages or leaving any extra processes when finished.
|
|
235
|
+ #
|
|
236
|
+ # Example use
|
|
237
|
+ # timeout 5 countdown
|
|
238
|
+ #
|
|
239
|
+ ###
|
|
240
|
+ #
|
|
241
|
+ # Based on notes in my "Shell Script Hints", section "Command Timeout"
|
|
242
|
+ # http://www.ict.griffith.edu.au/~anthony/info/shell/script.hints
|
|
243
|
+ #
|
|
244
|
+ # This script uses a lot of tricks to terminate both the background command,
|
|
245
|
+ # the timeout script, and even the sleep process. It also includes trap
|
|
246
|
+ # commands to prevent sub-shells reporting expected "Termination Errors".
|
|
247
|
+ #
|
|
248
|
+ # It took years of occasional trials, errors and testing to get a pure bash
|
|
249
|
+ # timeout command working as well as this does.
|
|
250
|
+ #
|
|
251
|
+ ###
|
|
252
|
+ #
|
|
253
|
+ # Anthony Thyssen 6 April 2011
|
|
254
|
+ #
|
|
255
|
+# PROGNAME=$(type $0 | awk '{print $3}') # search for executable on path
|
|
256
|
+# PROGDIR=$(dirname $PROGNAME) # extract directory of program
|
|
257
|
+# PROGNAME=$(basename $PROGNAME) # base name of program
|
|
258
|
+
|
|
259
|
+ # output the script comments as docs
|
|
260
|
+# Usage() {
|
|
261
|
+# echo >&2 "$PROGNAME:" "$@"
|
|
262
|
+# sed >&2 -n '/^###/q; /^#/!q; s/^#//; s/^ //; 3s/^/Usage: /; 2,$ p' "$PROGDIR/$PROGNAME"
|
|
263
|
+# exit 10;
|
|
264
|
+# }
|
|
265
|
+
|
|
266
|
+ SIG=-TERM
|
|
267
|
+
|
|
268
|
+ while [ $# -gt 0 ]; do
|
|
269
|
+ case "$1" in
|
|
270
|
+ --)
|
|
271
|
+ # forced end of user options
|
|
272
|
+ shift;
|
|
273
|
+ break ;;
|
|
274
|
+# -\?|--help|--doc*)
|
|
275
|
+# Usage ;;
|
|
276
|
+ [0-9]*)
|
|
277
|
+ TIMEOUT="$1" ;;
|
|
278
|
+ -*)
|
|
279
|
+ SIG="$1" ;;
|
|
280
|
+ *)
|
|
281
|
+ # unforced end of user options
|
|
282
|
+ break ;;
|
|
283
|
+ esac
|
|
284
|
+ shift # next option
|
|
285
|
+ done
|
|
286
|
+
|
|
287
|
+ # run main command in backgrouds and get its pid
|
|
288
|
+ "$@" &
|
|
289
|
+ command_pid=$!
|
|
290
|
+
|
|
291
|
+ # timeout sub-process abort countdown after ABORT seconds! also backgrounded
|
|
292
|
+ sleep_pid=0
|
|
293
|
+ (
|
|
294
|
+ # cleanup sleep process
|
|
295
|
+ trap 'kill -TERM $sleep_pid; return 1' 1 2 3 15
|
|
296
|
+ # sleep timeout period in background
|
|
297
|
+ sleep $TIMEOUT &
|
|
298
|
+ sleep_pid=$!
|
|
299
|
+ wait $sleep_pid
|
|
300
|
+ # Abort the command
|
|
301
|
+ kill $SIG $command_pid >/dev/null 2>&1
|
|
302
|
+ return 1
|
|
303
|
+ ) &
|
|
304
|
+ timeout_pid=$!
|
|
305
|
+
|
|
306
|
+ # Wait for main command to finished or be timed out
|
|
307
|
+ wait $command_pid
|
|
308
|
+ status=$?
|
|
309
|
+
|
|
310
|
+ # Clean up timeout sub-shell - if it is still running!
|
|
311
|
+ kill $timeout_pid 2>/dev/null
|
|
312
|
+ wait $timeout_pid 2>/dev/null
|
|
313
|
+
|
|
314
|
+ # Uncomment to check if a LONG sleep still running (no sleep should be)
|
|
315
|
+ # sleep 1
|
|
316
|
+ # echo "-----------"
|
|
317
|
+ # /bin/ps j # uncomment to show if abort "sleep" is still sleeping
|
|
318
|
+
|
|
319
|
+ return $status
|
|
320
|
+}
|
|
321
|
+
|
|
322
|
+__verify_host_port() {
|
|
323
|
+ # $1 Host/IP to verify
|
|
324
|
+ # $2 Port to verify
|
|
325
|
+ local __HOST=$1
|
|
326
|
+ local __PORT=$2
|
|
327
|
+ local __TMP __IP __IPV4 __IPV6 __RUNPROG __ERRPROG __ERR
|
|
328
|
+ # return codes
|
|
329
|
+ # 1 system specific error
|
|
330
|
+ # 2 nslookup error
|
|
331
|
+ # 3 nc (netcat) error
|
|
332
|
+ # 4 unmatched IP version
|
|
333
|
+
|
|
334
|
+ __RUNPROG="nslookup $__HOST 2>/dev/null"
|
|
335
|
+ __ERRPROG="nslookup $__HOST 2>&1"
|
|
336
|
+ verbose_echo " resolver prog =: '$__RUNPROG'"
|
|
337
|
+ __TMP=$(eval $__RUNPROG) # test if nslookup runs without errors
|
|
338
|
+ __ERR=$?
|
|
339
|
+ # command error
|
|
340
|
+ [ $__ERR -gt 0 ] && {
|
|
341
|
+ verbose_echo "\n!!!!!!!!! ERROR =: BusyBox nslookup Error '$__ERR'\n$(eval $__ERRPROG)\n"
|
|
342
|
+ syslog_err "DNS Resolver Error - BusyBox nslookup Error: '$__ERR'"
|
|
343
|
+ return 2
|
|
344
|
+ } || {
|
|
345
|
+ # we need to run twice because multi-line output needs to be directly piped to grep because
|
|
346
|
+ # pipe returns return code of last prog in pipe but we need errors from nslookup command
|
|
347
|
+ __IPV4=$(eval $__RUNPROG | sed '1,2d' | grep -o "Name:\|Address.*" | grep -m 1 -o "$IPV4_REGEX")
|
|
348
|
+ __IPV6=$(eval $__RUNPROG | sed '1,2d' | grep -o "Name:\|Address.*" | grep -m 1 -o "$IPV6_REGEX")
|
|
349
|
+ }
|
|
350
|
+
|
|
351
|
+ # check IP version if forced
|
|
352
|
+ if [ $force_ipversion -ne 0 ]; then
|
|
353
|
+ [ $use_ipv6 -eq 0 -a -z "$__IPV4" ] && return 4
|
|
354
|
+ [ $use_ipv6 -eq 1 -a -z "$__IPV6" ] && return 4
|
67
|
355
|
fi
|
68
|
356
|
|
69
|
|
- current_ip='';
|
70
|
|
- if [ "$ip_source" = "network" ]
|
71
|
|
- then
|
72
|
|
- network_get_ipaddr current_ip "$ip_network" || return
|
73
|
|
- elif [ "$ip_source" = "interface" ]
|
74
|
|
- then
|
75
|
|
- current_ip=$(ifconfig $ip_interface | grep -o 'inet addr:[0-9.]*' | grep -o "$ip_regex")
|
76
|
|
- elif [ "$ip_source" = "script" ]
|
77
|
|
- then
|
78
|
|
- # get ip from script
|
79
|
|
- current_ip=$($ip_script)
|
80
|
|
- else
|
81
|
|
- # get ip from web
|
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
|
84
|
|
- for addr in $ip_url
|
85
|
|
- do
|
86
|
|
- if [ -z "$current_ip" ]
|
87
|
|
- then
|
88
|
|
- current_ip=$(echo $( wget -O - $addr 2>/dev/null) | grep -o "$ip_regex")
|
89
|
|
- fi
|
90
|
|
- done
|
|
357
|
+ # verify nc command
|
|
358
|
+ # busybox nc compiled without -l option "NO OPT l!" -> critical error
|
|
359
|
+ nc --help 2>&1 | grep -iq "NO OPT l!" && \
|
|
360
|
+ critical_error "Busybox nc: netcat compiled with errors"
|
|
361
|
+ # busybox nc compiled with extensions
|
|
362
|
+ nc --help 2>&1 | grep -q "\-w" && __NCEXT="TRUE"
|
91
|
363
|
|
92
|
|
- #here we hard-code the dyndns checkip url in case no url was specified
|
93
|
|
- if [ -z "$current_ip" ]
|
94
|
|
- then
|
95
|
|
- current_ip=$(echo $( wget -O - http://checkip.dyndns.org 2>/dev/null) | grep -o "$ip_regex")
|
96
|
|
- fi
|
|
364
|
+ # connectivity test
|
|
365
|
+ # run busybox nc to HOST PORT
|
|
366
|
+ # busybox might be compiled with "FEATURE_PREFER_IPV4_ADDRESS=n"
|
|
367
|
+ # then nc will try to connect via IPv6 if there is an IPv6 availible for host
|
|
368
|
+ # not worring if there is an IPv6 wan address
|
|
369
|
+ # so if not "forced_ipversion" to use ipv6 then connect test via ipv4 if availible
|
|
370
|
+ [ $force_ipversion -ne 0 -a $use_ipv6 -ne 0 -o -z "$__IPV4" ] && {
|
|
371
|
+ # force IPv6
|
|
372
|
+ __IP=$__IPV6
|
|
373
|
+ } || __IP=$__IPV4
|
|
374
|
+
|
|
375
|
+ if [ -n "$__NCEXT" ]; then # nc compiled with extensions (timeout support)
|
|
376
|
+ __RUNPROG="nc -w 1 $__IP $__PORT </dev/null >/dev/null 2>&1"
|
|
377
|
+ __ERRPROG="nc -vw 1 $__IP $__PORT </dev/null 2>&1"
|
|
378
|
+ verbose_echo " connect prog =: '$__RUNPROG'"
|
|
379
|
+ eval $__RUNPROG
|
|
380
|
+ __ERR=$?
|
|
381
|
+ [ $__ERR -eq 0 ] && return 0
|
|
382
|
+ verbose_echo "\n!!!!!!!!! ERROR =: BusyBox nc Error '$__ERR'\n$(eval $__ERRPROG)\n"
|
|
383
|
+ syslog_err "host verify Error - BusyBox nc Error: '$__ERR'"
|
|
384
|
+ return 3
|
|
385
|
+ else # nc compiled without extensions (no timeout support)
|
|
386
|
+ __RUNPROG="__timeout 2 -- nc $__IP $__PORT </dev/null >/dev/null 2>&1"
|
|
387
|
+ verbose_echo " connect prog =: '$__RUNPROG'"
|
|
388
|
+ eval $__RUNPROG
|
|
389
|
+ __ERR=$?
|
|
390
|
+ [ $__ERR -eq 0 ] && return 0
|
|
391
|
+ verbose_echo "\n!!!!!!!!! ERROR =: BusyBox nc Error '$__ERR' (timeout)"
|
|
392
|
+ syslog_err "host verify Error - BusyBox nc Error: '$__ERR' (timeout)"
|
|
393
|
+ return 3
|
97
|
394
|
fi
|
|
395
|
+}
|
98
|
396
|
|
99
|
|
- echo "$current_ip"
|
|
397
|
+verify_dns() {
|
|
398
|
+ # $1 DNS server to verify
|
|
399
|
+ # we need DNS server to verify otherwise exit with ERROR 1
|
|
400
|
+ [ -z "$1" ] && return 1
|
|
401
|
+
|
|
402
|
+ # DNS uses port 53
|
|
403
|
+ __verify_host_port "$1" "53"
|
100
|
404
|
}
|
101
|
405
|
|
|
406
|
+verify_proxy() {
|
|
407
|
+ # $1 Proxy-String to verify
|
|
408
|
+ # complete entry user:password@host:port
|
|
409
|
+ # host and port only host:port
|
|
410
|
+ # host only host unsupported
|
|
411
|
+ # IPv4 address instead of host 123.234.234.123
|
|
412
|
+ # IPv6 address instead of host [xxxx:....:xxxx] in square bracket
|
|
413
|
+ local __TMP __HOST __PORT
|
102
|
414
|
|
103
|
|
-verbose_echo()
|
104
|
|
-{
|
105
|
|
- if [ "$verbose_mode" = 1 ]
|
106
|
|
- then
|
107
|
|
- echo $1
|
|
415
|
+ # we need Proxy-Sting to verify otherwise exit with ERROR 1
|
|
416
|
+ [ -z "$1" ] && return 1
|
|
417
|
+
|
|
418
|
+ # try to split user:password "@" host:port
|
|
419
|
+ __TMP=$(echo $1 | awk -F "@" '{print $2}')
|
|
420
|
+ # no "@" found - only host:port is given
|
|
421
|
+ [ -z "$__TMP" ] && __TMP="$1"
|
|
422
|
+ # now lets check for IPv6 address
|
|
423
|
+ __HOST=$(echo $__TMP | grep -m 1 -o "$IPV6_REGEX")
|
|
424
|
+ # IPv6 host address found read port
|
|
425
|
+ if [ -n "$__HOST" ]; then
|
|
426
|
+ # IPv6 split at "]:"
|
|
427
|
+ __PORT=$(echo $__TMP | awk -F "]:" '{print $2}')
|
|
428
|
+ else
|
|
429
|
+ __HOST=$(echo $__TMP | awk -F ":" '{print $1}')
|
|
430
|
+ __PORT=$(echo $__TMP | awk -F ":" '{print $2}')
|
108
|
431
|
fi
|
|
432
|
+ # No Port detected ERROR 5
|
|
433
|
+ [ -z "$__PORT" ] && return 5
|
|
434
|
+
|
|
435
|
+ __verify_host_port "$__HOST" "$__PORT"
|
109
|
436
|
}
|
110
|
437
|
|
111
|
|
-syslog_echo()
|
112
|
|
-{
|
113
|
|
- if [ "$use_syslog" = 1 ]
|
114
|
|
- then
|
115
|
|
- echo $1|logger -t ddns-scripts-$service_id
|
|
438
|
+__do_transfer() {
|
|
439
|
+ # $1 # Variable to store Answer of transfer
|
|
440
|
+ # $2 # URL to use
|
|
441
|
+ local __URL="$2"
|
|
442
|
+ local __ERR=0
|
|
443
|
+ local __PROG __RUNPROG __ERRPROG __DATA
|
|
444
|
+
|
|
445
|
+ # lets prefer GNU Wget because it does all for us - IPv4/IPv6/HTTPS/PROXY/force IP version
|
|
446
|
+ if /usr/bin/wget --version 2>&1 | grep -q "\+ssl"; then
|
|
447
|
+ __PROG="/usr/bin/wget -t 2 -O -" # standard output only 2 retrys on error
|
|
448
|
+ # force ip version to use
|
|
449
|
+ if [ $force_ipversion -eq 1 ]; then
|
|
450
|
+ [ $use_ipv6 -eq 0 ] && __PROG="$__PROG -4" || __PROG="$__PROG -6" # force IPv4/IPv6
|
|
451
|
+ fi
|
|
452
|
+ # set certificate parameters
|
|
453
|
+ if [ $use_https -eq 1 ]; then
|
|
454
|
+ if [ "$cacert" = "IGNORE" ]; then # idea from Ticket #15327 to ignore server cert
|
|
455
|
+ __PROG="$__PROG --no-check-certificate"
|
|
456
|
+ elif [ -f "$cacert" ]; then
|
|
457
|
+ __PROG="$__PROG --ca-certificate=${cacert}"
|
|
458
|
+ elif [ -d "$cacert" ]; then
|
|
459
|
+ __PROG="$__PROG --ca-directory=${cacert}"
|
|
460
|
+ else # exit here because it makes no sense to start loop
|
|
461
|
+ critical_error "Wget: No valid certificate(s) found for running HTTPS"
|
|
462
|
+ fi
|
|
463
|
+ fi
|
|
464
|
+ # disable proxy if no set (there might be .wgetrc or .curlrc or wrong environment set)
|
|
465
|
+ [ -z "$proxy" ] && __PROG="$__PROG --no-proxy"
|
|
466
|
+
|
|
467
|
+ __RUNPROG="$__PROG -q '$__URL' 2>/dev/null" # do transfer with "-q" to suppress not needed output
|
|
468
|
+ __ERRPROG="$__PROG -d '$__URL' 2>&1" # do transfer with "-d" for debug mode
|
|
469
|
+ verbose_echo " transfer prog =: $__RUNPROG"
|
|
470
|
+ __DATA=$(eval $__RUNPROG)
|
|
471
|
+ __ERR=$?
|
|
472
|
+ [ $__ERR -gt 0 ] && {
|
|
473
|
+ verbose_echo "\n!!!!!!!!! ERROR =: GNU Wget Error '$__ERR'\n$(eval $__ERRPROG)\n"
|
|
474
|
+ syslog_err "Communication Error - GNU Wget Error: '$__ERR'"
|
|
475
|
+ return 1
|
|
476
|
+ }
|
|
477
|
+
|
|
478
|
+ # 2nd choice is cURL IPv4/IPv6/HTTPS
|
|
479
|
+ # libcurl might be compiled without Proxy Support (default in trunk)
|
|
480
|
+ elif [ -x /usr/bin/curl ]; then
|
|
481
|
+ __PROG="/usr/bin/curl"
|
|
482
|
+ # force ip version to use
|
|
483
|
+ if [ $force_ipversion -eq 1 ]; then
|
|
484
|
+ [ $use_ipv6 -eq 0 ] && __PROG="$__PROG -4" || __PROG="$__PROG -6" # force IPv4/IPv6
|
|
485
|
+ fi
|
|
486
|
+ # set certificate parameters
|
|
487
|
+ if [ $use_https -eq 1 ]; then
|
|
488
|
+ if [ "$cacert" = "IGNORE" ]; then # idea from Ticket #15327 to ignore server cert
|
|
489
|
+ __PROG="$__PROG --insecure" # but not empty better to use "IGNORE"
|
|
490
|
+ elif [ -f "$cacert" ]; then
|
|
491
|
+ __PROG="$__PROG --cacert $cacert"
|
|
492
|
+ elif [ -d "$cacert" ]; then
|
|
493
|
+ __PROG="$__PROG --capath $cacert"
|
|
494
|
+ else # exit here because it makes no sense to start loop
|
|
495
|
+ critical_error "cURL: No valid certificate(s) found for running HTTPS"
|
|
496
|
+ fi
|
|
497
|
+ fi
|
|
498
|
+ # disable proxy if no set (there might be .wgetrc or .curlrc or wrong environment set)
|
|
499
|
+ # or check if libcurl compiled with proxy support
|
|
500
|
+ if [ -z "$proxy" ]; then
|
|
501
|
+ __PROG="$__PROG --noproxy '*'"
|
|
502
|
+ else
|
|
503
|
+ # if libcurl has no proxy support and proxy should be used then force ERROR
|
|
504
|
+ # libcurl currently no proxy support by default
|
|
505
|
+ grep -iq all_proxy /usr/lib/libcurl.so* || \
|
|
506
|
+ critical_error "cURL: libcurl compiled without Proxy support"
|
|
507
|
+ fi
|
|
508
|
+
|
|
509
|
+ __RUNPROG="$__PROG -q '$__URL' 2>/dev/null" # do transfer with "-s" to suppress not needed output
|
|
510
|
+ __ERRPROG="$__PROG -v '$__URL' 2>&1" # do transfer with "-v" for verbose mode
|
|
511
|
+ verbose_echo " transfer prog =: $__RUNPROG"
|
|
512
|
+ __DATA=$(eval $__RUNPROG)
|
|
513
|
+ __ERR=$?
|
|
514
|
+ [ $__ERR -gt 0 ] && {
|
|
515
|
+ verbose_echo "\n!!!!!!!!! ERROR =: cURL Error '$__ERR'\n$(eval $__ERRPROG)\n"
|
|
516
|
+ syslog_err "Communication Error - cURL Error: '$__ERR'"
|
|
517
|
+ return 1
|
|
518
|
+ }
|
|
519
|
+
|
|
520
|
+ # busybox Wget (did not support neither IPv6 nor HTTPS)
|
|
521
|
+ elif [ -x /usr/bin/wget ]; then
|
|
522
|
+ __PROG="/usr/bin/wget -O -"
|
|
523
|
+ # force ip version not supported
|
|
524
|
+ [ $force_ipversion -eq 1 ] && \
|
|
525
|
+ critical_error "BusyBox Wget: can not force IP version to use"
|
|
526
|
+ # https not supported
|
|
527
|
+ [ $use_https -eq 1 ] && \
|
|
528
|
+ critical_error "BusyBox Wget: no HTTPS support"
|
|
529
|
+ # disable proxy if no set (there might be .wgetrc or .curlrc or wrong environment set)
|
|
530
|
+ [ -z "$proxy" ] && __PROG="$__PROG -Y off"
|
|
531
|
+
|
|
532
|
+ __RUNPROG="$__PROG -q '$__URL' 2>/dev/null" # do transfer with "-q" to suppress not needed output
|
|
533
|
+ __ERRPROG="$__PROG '$__URL' 2>&1"
|
|
534
|
+ verbose_echo " transfer prog =: $__RUNPROG"
|
|
535
|
+ __DATA=$(eval $__RUNPROG)
|
|
536
|
+ __ERR=$?
|
|
537
|
+ [ $__ERR -gt 0 ] && {
|
|
538
|
+ verbose_echo "\n!!!!!!!!! ERROR =: BusyBox Wget Error '$__ERR'\n$(eval $__ERRPROG)\n"
|
|
539
|
+ syslog_err "Communication Error - BusyBox Wget Error: '$__ERR'"
|
|
540
|
+ return 1
|
|
541
|
+ }
|
|
542
|
+
|
|
543
|
+ else
|
|
544
|
+ critical_error "Program not found - Neither 'Wget' nor 'cURL' installed or executable"
|
116
|
545
|
fi
|
|
546
|
+
|
|
547
|
+ eval "$1='$__DATA'"
|
|
548
|
+ return 0
|
117
|
549
|
}
|
118
|
550
|
|
119
|
|
-start_daemon_for_all_ddns_sections()
|
120
|
|
-{
|
121
|
|
- local event_interface="$1"
|
|
551
|
+send_update() {
|
|
552
|
+ # $1 # IP to set at DDNS service provider
|
|
553
|
+ local __IP __URL __ANSWER __ERR
|
122
|
554
|
|
123
|
|
- SECTIONS=""
|
124
|
|
- config_cb()
|
125
|
|
- {
|
126
|
|
- SECTIONS="$SECTIONS $2"
|
|
555
|
+ # verify given IP
|
|
556
|
+ [ $use_ipv6 -eq 0 ] && __IP=$(echo $1 | grep -v -E "(^0|^10|^127|^172|^192)") # no private IPv4's
|
|
557
|
+ [ $use_ipv6 -eq 1 ] && __IP=$(echo $1 | grep "^[0-9a-eA-E]") # no IPv6 addr starting with fxxx of with ":"
|
|
558
|
+ [ -z "$__IP" ] && critical_error "Invalid or no IP '$1' given"
|
|
559
|
+
|
|
560
|
+ # do replaces in URL
|
|
561
|
+ __URL=$(echo $update_url | sed -e "s#\[USERNAME\]#$username#g" -e "s#\[PASSWORD\]#$password#g" \
|
|
562
|
+ -e "s#\[DOMAIN\]#$domain#g" -e "s#\[IP\]#$__IP#g")
|
|
563
|
+ [ $use_https -ne 0 ] && __URL=$(echo $__URL | sed -e 's#^http:#https:#')
|
|
564
|
+
|
|
565
|
+ __do_transfer __ANSWER "$__URL"
|
|
566
|
+ __ERR=$?
|
|
567
|
+ [ $__ERR -gt 0 ] && {
|
|
568
|
+ verbose_echo "\n!!!!!!!!! ERROR =: Error sending update to DDNS Provider\n"
|
|
569
|
+ return 1
|
127
|
570
|
}
|
128
|
|
- config_load "ddns"
|
129
|
571
|
|
130
|
|
- for section in $SECTIONS
|
131
|
|
- do
|
132
|
|
- local iface
|
133
|
|
- config_get iface "$section" interface "wan"
|
134
|
|
- [ -z "$event_interface" -o "$iface" = "$event_interface" ] || continue
|
135
|
|
- /usr/lib/ddns/dynamic_dns_updater.sh $section 0 > /dev/null 2>&1 &
|
136
|
|
- done
|
|
572
|
+ verbose_echo " update send =: DDNS Provider answered\n$__ANSWER"
|
|
573
|
+
|
|
574
|
+ return 0
|
137
|
575
|
}
|
138
|
576
|
|
139
|
|
-monotonic_time()
|
140
|
|
-{
|
141
|
|
- local uptime
|
142
|
|
- read uptime < /proc/uptime
|
143
|
|
- echo "${uptime%%.*}"
|
|
577
|
+get_local_ip () {
|
|
578
|
+ # $1 Name of Variable to store local IP (LOCAL_IP)
|
|
579
|
+ local __RUNPROG __IP __URL __ANSWER
|
|
580
|
+
|
|
581
|
+ case $ip_source in
|
|
582
|
+ network )
|
|
583
|
+ # set correct program
|
|
584
|
+ [ $use_ipv6 -eq 0 ] && __RUNPROG="network_get_ipaddr" \
|
|
585
|
+ || __RUNPROG="network_get_ipaddr6"
|
|
586
|
+ $__RUNPROG __IP "$ip_network"
|
|
587
|
+ verbose_echo " local ip =: '$__IP' detected on network '$ip_network'"
|
|
588
|
+ ;;
|
|
589
|
+ interface )
|
|
590
|
+ if [ $use_ipv6 -eq 0 ]; then
|
|
591
|
+ __IP=$(ifconfig $ip_interface | awk '
|
|
592
|
+ /Bcast.*Mask/ { # Filter IPv4
|
|
593
|
+ # inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
|
|
594
|
+ $1=""; # remove inet
|
|
595
|
+ $3=""; # remove Bcast: ...
|
|
596
|
+ $4=""; # remove Mask: ...
|
|
597
|
+ FS=":"; # separator ":"
|
|
598
|
+ $0=$0; # reread to activate separator
|
|
599
|
+ $1=""; # remove addr
|
|
600
|
+ FS=" "; # set back separator to default " "
|
|
601
|
+ $0=$0; # reread to activate separator (remove whitespaces)
|
|
602
|
+ print $1; # print IPv4 addr
|
|
603
|
+ }'
|
|
604
|
+ )
|
|
605
|
+ else
|
|
606
|
+ __IP=$(ifconfig $ip_interface | awk '
|
|
607
|
+ /inet6/ && /: [0-9a-eA-E]/ && !/\/128/ { # Filter IPv6 exclude fxxx and /128 prefix
|
|
608
|
+ # inet6 addr: 2001:db8::xxxx:xxxx/32 Scope:Global
|
|
609
|
+ FS="/"; # separator "/"
|
|
610
|
+ $0=$0; # reread to activate separator
|
|
611
|
+ $2=""; # remove everything behind "/"
|
|
612
|
+ FS=" "; # set back separator to default " "
|
|
613
|
+ $0=$0; # reread to activate separator
|
|
614
|
+ print $3; # print IPv6 addr
|
|
615
|
+ }'
|
|
616
|
+ )
|
|
617
|
+ fi
|
|
618
|
+ verbose_echo " local ip =: '$__IP' detected on interface '$ip_interface'"
|
|
619
|
+ ;;
|
|
620
|
+ script )
|
|
621
|
+ # get ip from script
|
|
622
|
+ __IP=$($ip_script)
|
|
623
|
+ verbose_echo " local ip =: '$__IP' detected via script '$ip_script'"
|
|
624
|
+ ;;
|
|
625
|
+ * )
|
|
626
|
+ for __URL in $ip_url; do
|
|
627
|
+ __do_transfer __ANSWER "$__URL"
|
|
628
|
+ [ -n "$__IP" ] && break # Answer detected, leave for loop
|
|
629
|
+ done
|
|
630
|
+ # use correct regular expression
|
|
631
|
+ [ $use_ipv6 -eq 0 ] \
|
|
632
|
+ && __IP=$(echo "$__ANSWER" | grep -m 1 -o "$IPV4_REGEX") \
|
|
633
|
+ || __IP=$(echo "$__ANSWER" | grep -m 1 -o "$IPV6_REGEX")
|
|
634
|
+ verbose_echo " local ip =: '$__IP' detected via web at '$__URL'"
|
|
635
|
+ ;;
|
|
636
|
+ esac
|
|
637
|
+
|
|
638
|
+ # if NO IP was found
|
|
639
|
+ [ -z "$__IP" ] && return 1
|
|
640
|
+
|
|
641
|
+ eval "$1='$__IP'"
|
|
642
|
+ return 0
|
|
643
|
+}
|
|
644
|
+
|
|
645
|
+get_registered_ip() {
|
|
646
|
+ # $1 Name of Variable to store public IP (REGISTERED_IP)
|
|
647
|
+ local __IP __REGEX __PROG __RUNPROG __ERRPROG __ERR
|
|
648
|
+ # return codes
|
|
649
|
+ # 1 no IP detected
|
|
650
|
+
|
|
651
|
+ # set correct regular expression
|
|
652
|
+ [ $use_ipv6 -eq 0 ] && __REGEX="$IPV4_REGEX" || __REGEX="$IPV6_REGEX"
|
|
653
|
+
|
|
654
|
+ if [ -x /usr/bin/host ]; then # otherwise try to use BIND host
|
|
655
|
+ __PROG="/usr/bin/host"
|
|
656
|
+ [ $use_ipv6 -eq 0 ] && __PROG="$__PROG -t A" || __PROG="$__PROG -t AAAA"
|
|
657
|
+ if [ $force_ipversion -eq 1 ]; then # force IP version
|
|
658
|
+ [ $use_ipv6 -eq 0 ] && __PROG="$__PROG -4" || __PROG="$__PROG -6"
|
|
659
|
+ fi
|
|
660
|
+ [ $force_dnstcp -eq 1 ] && __PROG="$__PROG -T" # force TCP
|
|
661
|
+
|
|
662
|
+ __RUNPROG="$__PROG $domain $dns_server 2>/dev/null"
|
|
663
|
+ __ERRPROG="$__PROG -v $domain $dns_server 2>&1"
|
|
664
|
+ verbose_echo " resolver prog =: $__RUNPROG"
|
|
665
|
+ __IP=$(eval $__RUNPROG)
|
|
666
|
+ __ERR=$?
|
|
667
|
+ # command error
|
|
668
|
+ [ $__ERR -gt 0 ] && {
|
|
669
|
+ verbose_echo "\n!!!!!!!!! ERROR =: BIND host Error '$__ERR'\n$(eval $__ERRPROG)\n"
|
|
670
|
+ syslog_err "DNS Resolver Error - BIND host Error: '$__ERR'"
|
|
671
|
+ return 1
|
|
672
|
+ } || {
|
|
673
|
+ # we need to run twice because multi-line output needs to be directly piped to grep because
|
|
674
|
+ # pipe returns return code of last prog in pipe but we need errors from host command
|
|
675
|
+ __IP=$(eval $__RUNPROG | grep "^$domain" | grep -m 1 -o "$__REGEX")
|
|
676
|
+ }
|
|
677
|
+
|
|
678
|
+ elif [ -x /usr/bin/nslookup ]; then # last use BusyBox nslookup
|
|
679
|
+ [ $force_ipversion -ne 0 -o $force_dnstcp -ne 0 ] && \
|
|
680
|
+ critical_error "nslookup - no support to 'force IP Version' or 'DNS over TCP'"
|
|
681
|
+
|
|
682
|
+ __RUNPROG="nslookup $domain $dns_server 2>/dev/null"
|
|
683
|
+ __ERRPROG="nslookup $domain $dns_server 2>&1"
|
|
684
|
+ verbose_echo " resolver prog =: $__RUNPROG"
|
|
685
|
+ __IP=$(eval $__RUNPROG)
|
|
686
|
+ __ERR=$?
|
|
687
|
+ # command error
|
|
688
|
+ [ $__ERR -gt 0 ] && {
|
|
689
|
+ verbose_echo "\n!!!!!!!!! ERROR =: BusyBox nslookup Error '$__ERR'\n$(eval $__ERRPROG)\n"
|
|
690
|
+ syslog_err "DNS Resolver Error - BusyBox nslookup Error: '$__ERR'"
|
|
691
|
+ return 1
|
|
692
|
+ } || {
|
|
693
|
+ # we need to run twice because multi-line output needs to be directly piped to grep because
|
|
694
|
+ # pipe returns return code of last prog in pipe but we need errors from nslookup command
|
|
695
|
+ __IP=$(eval $__RUNPROG | sed '1,2d' | grep -o "Name:\|Address.*" | grep -m 1 -o "$__REGEX")
|
|
696
|
+ }
|
|
697
|
+
|
|
698
|
+ else # there must be an error
|
|
699
|
+ critical_error "No program found to request public registered IP"
|
|
700
|
+ fi
|
|
701
|
+
|
|
702
|
+ verbose_echo " resolved ip =: '$__IP'"
|
|
703
|
+
|
|
704
|
+ # if NO IP was found
|
|
705
|
+ [ -z "$__IP" ] && return 1
|
|
706
|
+
|
|
707
|
+ eval "$1='$__IP'"
|
|
708
|
+ return 0
|
|
709
|
+}
|
|
710
|
+
|
|
711
|
+get_uptime() {
|
|
712
|
+ # $1 Variable to store result in
|
|
713
|
+ local __UPTIME=$(cat /proc/uptime)
|
|
714
|
+ eval "$1='${__UPTIME%%.*}'"
|
144
|
715
|
}
|