|
@@ -10,11 +10,12 @@
|
10
|
10
|
# by Christian Schoenebeck <christian dot schoenebeck at gmail dot com>
|
11
|
11
|
# to support:
|
12
|
12
|
# - IPv6 DDNS services
|
13
|
|
-# - DNS Server to retrieve registered IP including TCP transport
|
|
13
|
+# - DNS Server to retrieve registered IP including TCP transport (Ticket 7820)
|
14
|
14
|
# - Proxy Server to send out updates
|
15
|
|
-# - force_interval=0 to run once
|
|
15
|
+# - force_interval=0 to run once (Luci Ticket 538)
|
16
|
16
|
# - the usage of BIND's host command instead of BusyBox's nslookup if installed
|
17
|
17
|
# - extended Verbose Mode and log file support for better error detection
|
|
18
|
+# - wait for interface to fully come up, before the first update is done
|
18
|
19
|
#
|
19
|
20
|
# variables in small chars are read from /etc/config/ddns
|
20
|
21
|
# variables in big chars are defined inside these scripts as global vars
|
|
@@ -38,7 +39,7 @@
|
38
|
39
|
. /usr/lib/ddns/dynamic_dns_functions.sh # global vars are also defined here
|
39
|
40
|
|
40
|
41
|
SECTION_ID="$1"
|
41
|
|
-VERBOSE_MODE=${2:-1} #default mode is log to console
|
|
42
|
+VERBOSE_MODE=${2:-1} # default mode is log to console
|
42
|
43
|
|
43
|
44
|
# set file names
|
44
|
45
|
PIDFILE="$RUNDIR/$SECTION_ID.pid" # Process ID file
|
|
@@ -47,15 +48,23 @@ LOGFILE="$LOGDIR/$SECTION_ID.log" # log file
|
47
|
48
|
|
48
|
49
|
# VERBOSE_MODE > 1 delete logfile if exist to create an empty one
|
49
|
50
|
# only with this data of this run for easier diagnostic
|
50
|
|
-# new one created by verbose_echo function
|
|
51
|
+# new one created by write_log function
|
51
|
52
|
[ $VERBOSE_MODE -gt 1 -a -f $LOGFILE ] && rm -f $LOGFILE
|
52
|
53
|
|
|
54
|
+# TRAP handler
|
|
55
|
+trap "trap_handler 0 \$?" 0 # handle script exit with exit status
|
|
56
|
+trap "trap_handler 1" 1 # SIGHUP Hangup / reload config
|
|
57
|
+trap "trap_handler 2" 2 # SIGINT Terminal interrupt
|
|
58
|
+trap "trap_handler 3" 3 # SIGQUIT Terminal quit
|
|
59
|
+#trap "trap_handler 9" 9 # SIGKILL no chance to trap
|
|
60
|
+trap "trap_handler 15" 15 # SIGTERM Termination
|
|
61
|
+
|
53
|
62
|
################################################################################
|
54
|
63
|
# Leave this comment here, to clearly document variable names that are expected/possible
|
55
|
64
|
# Use load_all_config_options to load config options, which is a much more flexible solution.
|
56
|
65
|
#
|
57
|
66
|
# config_load "ddns"
|
58
|
|
-# config_get <variable> $SECTION_ID <option]>
|
|
67
|
+# config_get <variable> $SECTION_ID <option>
|
59
|
68
|
#
|
60
|
69
|
# defined options (also used as variable):
|
61
|
70
|
#
|
|
@@ -108,23 +117,23 @@ LOGFILE="$LOGDIR/$SECTION_ID.log" # log file
|
108
|
117
|
[ "$(uci_get ddns $SECTION_ID)" != "service" ] && {
|
109
|
118
|
[ $VERBOSE_MODE -le 1 ] && VERBOSE_MODE=2 # force console out and logfile output
|
110
|
119
|
[ -f $LOGFILE ] && rm -f $LOGFILE # clear logfile before first entry
|
111
|
|
- verbose_echo "\n ************** =: ************** ************** **************"
|
112
|
|
- verbose_echo " STARTED =: PID '$$' at $(eval $DATE_PROG)"
|
113
|
|
- verbose_echo " UCI CONFIG =:\n$(uci -q show ddns | grep '=service' | sort)"
|
114
|
|
- critical_error "Service '$SECTION_ID' not defined"
|
|
120
|
+ write_log 7 "************ ************** ************** **************"
|
|
121
|
+ write_log 5 "PID '$$' started at $(eval $DATE_PROG)"
|
|
122
|
+ write_log 7 "uci configuration:\n$(uci -q show ddns | grep '=service' | sort)"
|
|
123
|
+ write_log 14 "Service section '$SECTION_ID' not defined"
|
115
|
124
|
}
|
116
|
125
|
load_all_config_options "ddns" "$SECTION_ID"
|
117
|
126
|
|
118
|
|
-verbose_echo "\n ************** =: ************** ************** **************"
|
119
|
|
-verbose_echo " STARTED =: PID '$$' at $(eval $DATE_PROG)"
|
|
127
|
+write_log 7 "************ ************** ************** **************"
|
|
128
|
+write_log 5 "PID '$$' started at $(eval $DATE_PROG)"
|
120
|
129
|
case $VERBOSE_MODE in
|
121
|
|
- 0) verbose_echo " verbose mode =: '0' - run normal, NO console output";;
|
122
|
|
- 1) verbose_echo " verbose mode =: '1' - run normal, console mode";;
|
123
|
|
- 2) verbose_echo " verbose mode =: '2' - run once, NO retry on error";;
|
124
|
|
- 3) verbose_echo " verbose mode =: '3' - run once, NO retry on error, NOT sending update";;
|
125
|
|
- *) critical_error "ERROR detecting VERBOSE_MODE '$VERBOSE_MODE'"
|
|
130
|
+ 0) write_log 7 "verbose mode '0' - run normal, NO console output";;
|
|
131
|
+ 1) write_log 7 "verbose mode '1' - run normal, console mode";;
|
|
132
|
+ 2) write_log 7 "verbose mode '2' - run once, NO retry on error";;
|
|
133
|
+ 3) write_log 7 "verbose mode '3' - run once, NO retry on error, NOT sending update";;
|
|
134
|
+ *) write_log 14 "error detecting VERBOSE_MODE '$VERBOSE_MODE'";;
|
126
|
135
|
esac
|
127
|
|
-verbose_echo " UCI CONFIG =:\n$(uci -q show ddns.$SECTION_ID | sort)"
|
|
136
|
+write_log 7 "uci configuraion:\n$(uci -q show ddns.$SECTION_ID | sort)"
|
128
|
137
|
|
129
|
138
|
# set defaults if not defined
|
130
|
139
|
[ -z "$enabled" ] && enabled=0
|
|
@@ -142,48 +151,47 @@ verbose_echo " UCI CONFIG =:\n$(uci -q show ddns.$SECTION_ID | sort)"
|
142
|
151
|
[ "$ip_source" = "web" -a -z "$ip_url" -a $use_ipv6 -eq 1 ] && ip_url="http://checkipv6.dyndns.com"
|
143
|
152
|
[ "$ip_source" = "interface" -a -z "$ip_interface" ] && ip_interface="eth1"
|
144
|
153
|
|
145
|
|
-# check configuration and enabled state
|
146
|
|
-[ -z "$domain" -o -z "$username" -o -z "$password" ] && critical_error "Service Configuration not correctly configured"
|
147
|
|
-[ $enabled -eq 0 ] && critical_error "Service Configuration is disabled"
|
|
154
|
+# check enabled state otherwise we don't need to continue
|
|
155
|
+[ $enabled -eq 0 ] && write_log 14 "Service section disabled!"
|
|
156
|
+
|
|
157
|
+# without domain or username or password we can do nothing for you
|
|
158
|
+[ -z "$domain" -o -z "$username" -o -z "$password" ] && write_log 14 "Service section not correctly configured!"
|
|
159
|
+urlencode URL_USER "$username" # encode username, might be email or something like this
|
|
160
|
+urlencode URL_PASS "$password" # encode password, might have special chars for security reason
|
148
|
161
|
|
149
|
|
-# verify script if configured and executable
|
|
162
|
+# verify ip_source script if configured and executable
|
150
|
163
|
if [ "$ip_source" = "script" ]; then
|
151
|
|
- [ -z "$ip_script" ] && critical_error "No script defined to detect local IP"
|
152
|
|
- [ -x "$ip_script" ] || critical_error "Script to detect local IP not found or not executable"
|
|
164
|
+ [ -z "$ip_script" ] && write_log 14 "No script defined to detect local IP!"
|
|
165
|
+ [ -x "$ip_script" ] || write_log 14 "Script to detect local IP not found or not executable!"
|
153
|
166
|
fi
|
154
|
167
|
|
155
|
168
|
# compute update interval in seconds
|
156
|
169
|
get_seconds CHECK_SECONDS ${check_interval:-10} ${check_unit:-"minutes"} # default 10 min
|
157
|
170
|
get_seconds FORCE_SECONDS ${force_interval:-72} ${force_unit:-"hours"} # default 3 days
|
158
|
171
|
get_seconds RETRY_SECONDS ${retry_interval:-60} ${retry_unit:-"seconds"} # default 60 sec
|
159
|
|
-verbose_echo "check interval =: $CHECK_SECONDS seconds"
|
160
|
|
-verbose_echo "force interval =: $FORCE_SECONDS seconds"
|
161
|
|
-verbose_echo "retry interval =: $RETRY_SECONDS seconds"
|
162
|
|
-verbose_echo " retry counter =: $retry_count times"
|
|
172
|
+[ $CHECK_SECONDS -lt 300 ] && CHECK_SECONDS=300 # minimum 5 minutes
|
|
173
|
+[ $FORCE_SECONDS -gt 0 -a $FORCE_SECONDS -lt $CHECK_SECONDS ] && FORCE_SECONDS=$CHECK_SECONDS # FORCE_SECONDS >= CHECK_SECONDS or 0
|
|
174
|
+write_log 7 "check interval: $CHECK_SECONDS seconds"
|
|
175
|
+write_log 7 "force interval: $FORCE_SECONDS seconds"
|
|
176
|
+write_log 7 "retry interval: $RETRY_SECONDS seconds"
|
|
177
|
+write_log 7 "retry counter : $retry_count times"
|
163
|
178
|
|
164
|
179
|
# determine what update url we're using if a service_name is supplied
|
165
|
|
-# otherwise update_url is set inside configuration (custom service)
|
|
180
|
+# otherwise update_url is set inside configuration (custom update url)
|
166
|
181
|
# or update_script is set inside configuration (custom update script)
|
167
|
182
|
[ -n "$service_name" ] && get_service_data update_url update_script
|
168
|
|
-[ -z "$update_url" -a -z "$update_script" ] && critical_error "no update_url found/defined or no update_script found/defined"
|
169
|
|
-[ -n "$update_script" -a ! -f "$update_script" ] && critical_error "custom update_script not found"
|
|
183
|
+[ -z "$update_url" -a -z "$update_script" ] && write_log 14 "No update_url found/defined or no update_script found/defined!"
|
|
184
|
+[ -n "$update_script" -a ! -f "$update_script" ] && write_log 14 "Custom update_script not found!"
|
170
|
185
|
|
171
|
186
|
#kill old process if it exists & set new pid file
|
172
|
187
|
if [ -d $RUNDIR ]; then
|
173
|
|
- #if process is already running, stop it
|
174
|
|
- if [ -e "$PIDFILE" ]; then
|
175
|
|
- OLD_PID=$(cat $PIDFILE)
|
176
|
|
- ps | grep -q "^[\t ]*$OLD_PID" && {
|
177
|
|
- verbose_echo " old process =: PID '$OLD_PID'"
|
178
|
|
- kill $OLD_PID
|
179
|
|
- } || verbose_echo "old process id =: PID 'none'"
|
180
|
|
- else
|
181
|
|
- verbose_echo "old process id =: PID 'none'"
|
182
|
|
- fi
|
|
188
|
+ #if process for section is already running, stop it
|
|
189
|
+ stop_section_processes "$SECTION_ID"
|
|
190
|
+ [ $? -gt 0 ] && write_log 7 "Send 'SIGTERM' to old process" || write_log 7 "No old process"
|
183
|
191
|
else
|
184
|
192
|
#make dir since it doesn't exist
|
185
|
193
|
mkdir -p $RUNDIR
|
186
|
|
- verbose_echo "old process id =: PID 'none'"
|
|
194
|
+ write_log 7 "No old process"
|
187
|
195
|
fi
|
188
|
196
|
echo $$ > $PIDFILE
|
189
|
197
|
|
|
@@ -201,242 +209,118 @@ get_uptime CURR_TIME
|
201
|
209
|
[ $LAST_TIME -gt $CURR_TIME ] && LAST_TIME=0
|
202
|
210
|
}
|
203
|
211
|
if [ $LAST_TIME -eq 0 ]; then
|
204
|
|
- verbose_echo " last update =: never"
|
|
212
|
+ write_log 7 "last update: never"
|
205
|
213
|
else
|
206
|
214
|
EPOCH_TIME=$(( $(date +%s) - CURR_TIME + LAST_TIME ))
|
207
|
215
|
EPOCH_TIME="date -d @$EPOCH_TIME +'$DATE_FORMAT'"
|
208
|
|
- verbose_echo " last update =: $(eval $EPOCH_TIME)"
|
|
216
|
+ write_log 7 "last update: $(eval $EPOCH_TIME)"
|
209
|
217
|
fi
|
210
|
218
|
|
211
|
219
|
# we need time here because hotplug.d is fired by netifd
|
212
|
220
|
# but IP addresses are not set by DHCP/DHCPv6 etc.
|
213
|
|
-verbose_echo " waiting =: 10 seconds for interfaces to fully come up"
|
214
|
|
-sleep 10
|
215
|
|
-
|
216
|
|
-# verify DNS server:
|
217
|
|
-# do with retry's because there might be configurations
|
218
|
|
-# not directly could connect to outside dns when interface is already up
|
219
|
|
-ERR_VERIFY=0 # reset err counter
|
220
|
|
-while [ -n "$dns_server" ]; do
|
221
|
|
- [ $ERR_VERIFY -eq 0 ] && verbose_echo "******* VERIFY =: DNS server '$dns_server'"
|
222
|
|
- verify_dns "$dns_server"
|
223
|
|
- ERR_LAST=$? # save return value
|
224
|
|
- [ $ERR_LAST -eq 0 ] && break # everything ok leave while loop
|
225
|
|
- ERR_VERIFY=$(( $ERR_VERIFY + 1 ))
|
226
|
|
- # if error count > retry_count leave here with critical error
|
227
|
|
- [ $ERR_VERIFY -gt $retry_count ] && {
|
228
|
|
- case $ERR_LAST in
|
229
|
|
- 2) critical_error "Invalid DNS server Error: '2' - nslookup can not resolve host";;
|
230
|
|
- 3) critical_error "Invalid DNS server Error: '3' - nc (netcat) can not connect";;
|
231
|
|
- *) critical_error "Invalid DNS server Error: '$ERR_LAST' - unspecific error";;
|
232
|
|
- esac
|
233
|
|
- }
|
234
|
|
- case $ERR_LAST in
|
235
|
|
- 2) syslog_err "Invalid DNS server Error: '2' - nslookup can not resolve host - retry $ERR_VERIFY/$retry_count in $RETRY_SECONDS seconds\n";;
|
236
|
|
- 3) syslog_err "Invalid DNS server Error: '3' - nc (netcat) can not connect - retry $ERR_VERIFY/$retry_count in $RETRY_SECONDS seconds\n";;
|
237
|
|
- *) syslog_err "Invalid DNS server Error: '$ERR_LAST' - unspecific error - retry $ERR_VERIFY/$retry_count in $RETRY_SECONDS seconds\n";;
|
238
|
|
- esac
|
239
|
|
- [ $VERBOSE_MODE -gt 1 ] && {
|
240
|
|
- # VERBOSE_MODE > 1 then NO retry
|
241
|
|
- verbose_echo "\n!!!!!!!!! ERROR =: Verbose Mode - NO retry\n"
|
242
|
|
- break
|
243
|
|
- }
|
244
|
|
- verbose_echo "******** RETRY =: DNS server '$dns_server' - retry $ERR_VERIFY/$retry_count in $RETRY_SECONDS seconds"
|
245
|
|
- sleep $RETRY_SECONDS
|
246
|
|
-done
|
|
221
|
+write_log 7 "Waiting 10 seconds for interfaces to fully come up"
|
|
222
|
+sleep 10 &
|
|
223
|
+PID_SLEEP=$!
|
|
224
|
+wait $PID_SLEEP # enable trap-handler
|
|
225
|
+PID_SLEEP=0
|
|
226
|
+
|
|
227
|
+# verify DNS server
|
|
228
|
+[ -n "$dns_server" ] && verify_dns "$dns_server"
|
247
|
229
|
|
248
|
230
|
# verify Proxy server and set environment
|
249
|
|
-# do with retry's because there might be configurations
|
250
|
|
-# not directly could connect to outside dns when interface is already up
|
251
|
|
-ERR_VERIFY=0 # reset err counter
|
252
|
231
|
[ -n "$proxy" ] && {
|
253
|
|
- [ $ERR_VERIFY -eq 0 ] && verbose_echo "******* VERIFY =: Proxy server 'http://$proxy'"
|
254
|
|
- verify_proxy "$proxy"
|
255
|
|
- ERR_LAST=$? # save return value
|
256
|
|
- [ $ERR_LAST -eq 0 ] && {
|
257
|
|
- # everything ok set proxy and leave while loop
|
|
232
|
+ verify_proxy "$proxy" && {
|
|
233
|
+ # everything ok set proxy
|
258
|
234
|
export HTTP_PROXY="http://$proxy"
|
259
|
235
|
export HTTPS_PROXY="http://$proxy"
|
260
|
236
|
export http_proxy="http://$proxy"
|
261
|
237
|
export https_proxy="http://$proxy"
|
262
|
|
- break
|
263
|
238
|
}
|
264
|
|
- ERR_VERIFY=$(( $ERR_VERIFY + 1 ))
|
265
|
|
- # if error count > retry_count leave here with critical error
|
266
|
|
- [ $ERR_VERIFY -gt $retry_count ] && {
|
267
|
|
- case $ERR_LAST in
|
268
|
|
- 2) critical_error "Invalid Proxy server Error '2' - nslookup can not resolve host";;
|
269
|
|
- 3) critical_error "Invalid Proxy server Error '3' - nc (netcat) can not connect";;
|
270
|
|
- *) critical_error "Invalid Proxy server Error '$ERR_LAST' - unspecific error";;
|
271
|
|
- esac
|
272
|
|
- }
|
273
|
|
- case $ERR_LAST in
|
274
|
|
- 2) syslog_err "Invalid Proxy server Error '2' - nslookup can not resolve host - retry $ERR_VERIFY/$retry_count in $RETRY_SECONDS seconds\n";;
|
275
|
|
- 3) syslog_err "Invalid Proxy server Error '3' - nc (netcat) can not connect - retry $ERR_VERIFY/$retry_count in $RETRY_SECONDS seconds\n";;
|
276
|
|
- *) syslog_err "Invalid Proxy server Error '$ERR_LAST' - unspecific error - retry $ERR_VERIFY/$retry_count in $RETRY_SECONDS seconds\n";;
|
277
|
|
- esac
|
278
|
|
- [ $VERBOSE_MODE -gt 1 ] && {
|
279
|
|
- # VERBOSE_MODE > 1 then NO retry
|
280
|
|
- verbose_echo "\n!!!!!!!!! ERROR =: Verbose Mode - NO retry\n"
|
281
|
|
- break
|
282
|
|
- }
|
283
|
|
- verbose_echo "******** RETRY =: Proxy server 'http://$proxy' - retry $ERR_VERIFY/$retry_count in $RETRY_SECONDS seconds"
|
284
|
|
- sleep $RETRY_SECONDS
|
285
|
239
|
}
|
286
|
240
|
|
287
|
241
|
# let's check if there is already an IP registered at the web
|
288
|
242
|
# but ignore errors if not
|
289
|
|
-verbose_echo "******* DETECT =: Registered IP"
|
290
|
|
-get_registered_ip REGISTERED_IP
|
|
243
|
+get_registered_ip REGISTERED_IP "NO_RETRY"
|
291
|
244
|
|
292
|
245
|
# loop endlessly, checking ip every check_interval and forcing an updating once every force_interval
|
293
|
|
-# NEW: ### Luci Ticket 538
|
294
|
|
-# a "force_interval" of "0" will run this script only once
|
295
|
|
-# the update is only done once when an interface goes up
|
296
|
|
-# or you run /etc/init.d/ddns start or you can use a cron job
|
297
|
|
-# it will force an update without check when lastupdate happen
|
298
|
|
-# but it will verify after "check_interval" if update is seen in the web
|
299
|
|
-# and retries on error retry_count times
|
300
|
|
-# CHANGES: ### Ticket 16363
|
301
|
|
-# modified nslookup / sed / grep to detect registered ip
|
302
|
|
-# NEW: ### Ticket 7820
|
303
|
|
-# modified nslookup to support non standard dns_server (needs to be defined in /etc/config/ddns)
|
304
|
|
-# support for BIND host command.
|
305
|
|
-# Wait for interface to fully come up, before the first update is done
|
306
|
|
-verbose_echo "*** START LOOP =: $(eval $DATE_PROG)"
|
307
|
|
-# we run NOT once
|
308
|
|
-[ $FORCE_SECONDS -gt 0 -o $VERBOSE_MODE -le 1 ] && syslog_info "Starting main loop"
|
309
|
|
-
|
|
246
|
+write_log 6 "Starting main loop at $(eval $DATE_PROG)"
|
310
|
247
|
while : ; do
|
311
|
248
|
|
312
|
|
- # read local IP
|
313
|
|
- verbose_echo "******* DETECT =: Local IP"
|
314
|
|
- get_local_ip LOCAL_IP
|
315
|
|
- ERR_LAST=$? # save return value
|
316
|
|
- # Error in function
|
317
|
|
- [ $ERR_LAST -gt 0 ] && {
|
318
|
|
- if [ $VERBOSE_MODE -le 1 ]; then # VERBOSE_MODE <= 1 then retry
|
319
|
|
- # we can't read local IP
|
320
|
|
- ERR_LOCAL_IP=$(( $ERR_LOCAL_IP + 1 ))
|
321
|
|
- [ $ERR_LOCAL_IP -gt $retry_count ] && critical_error "Can not detect local IP"
|
322
|
|
- verbose_echo "\n!!!!!!!!! ERROR =: detecting local IP - retry $ERR_LOCAL_IP/$retry_count in $RETRY_SECONDS seconds\n"
|
323
|
|
- syslog_err "Error detecting local IP - retry $ERR_LOCAL_IP/$retry_count in $RETRY_SECONDS seconds"
|
324
|
|
- sleep $RETRY_SECONDS
|
325
|
|
- continue # jump back to the beginning of while loop
|
326
|
|
- else
|
327
|
|
- verbose_echo "\n!!!!!!!!! ERROR =: detecting local IP - NO retry\n"
|
328
|
|
- fi
|
329
|
|
- }
|
330
|
|
- ERR_LOCAL_IP=0 # reset err counter
|
|
249
|
+ get_local_ip LOCAL_IP # read local IP
|
331
|
250
|
|
332
|
251
|
# prepare update
|
333
|
|
- # never updated or forced immediate then NEXT_TIME = 0
|
|
252
|
+ # never updated or forced immediate then NEXT_TIME = 0
|
334
|
253
|
[ $FORCE_SECONDS -eq 0 -o $LAST_TIME -eq 0 ] \
|
335
|
254
|
&& NEXT_TIME=0 \
|
336
|
255
|
|| NEXT_TIME=$(( $LAST_TIME + $FORCE_SECONDS ))
|
337
|
|
- # get current uptime
|
338
|
|
- get_uptime CURR_TIME
|
339
|
|
-
|
340
|
|
- # send update when current time > next time or local ip different from registered ip (as loop on error)
|
341
|
|
- ERR_SEND=0
|
342
|
|
- while [ $CURR_TIME -ge $NEXT_TIME -o "$LOCAL_IP" != "$REGISTERED_IP" ]; do
|
|
256
|
+
|
|
257
|
+ get_uptime CURR_TIME # get current uptime
|
|
258
|
+
|
|
259
|
+ # send update when current time > next time or local ip different from registered ip
|
|
260
|
+ if [ $CURR_TIME -ge $NEXT_TIME -o "$LOCAL_IP" != "$REGISTERED_IP" ]; then
|
343
|
261
|
if [ $VERBOSE_MODE -gt 2 ]; then
|
344
|
|
- verbose_echo " VERBOSE MODE =: NO UPDATE send to DDNS provider"
|
|
262
|
+ write_log 7 "Verbose Mode: $VERBOSE_MODE - NO UPDATE send"
|
345
|
263
|
elif [ "$LOCAL_IP" != "$REGISTERED_IP" ]; then
|
346
|
|
- verbose_echo "******* UPDATE =: LOCAL: '$LOCAL_IP' <> REGISTERED: '$REGISTERED_IP'"
|
|
264
|
+ write_log 7 "Update needed - L: '$LOCAL_IP' <> R: '$REGISTERED_IP'"
|
347
|
265
|
else
|
348
|
|
- verbose_echo "******* FORCED =: LOCAL: '$LOCAL_IP' == REGISTERED: '$REGISTERED_IP'"
|
|
266
|
+ write_log 7 "Forced Update - L: '$LOCAL_IP' == R: '$REGISTERED_IP'"
|
349
|
267
|
fi
|
350
|
|
- # only send if VERBOSE_MODE < 3
|
|
268
|
+
|
351
|
269
|
ERR_LAST=0
|
352
|
270
|
[ $VERBOSE_MODE -lt 3 ] && {
|
353
|
|
- send_update "$LOCAL_IP"
|
|
271
|
+ # only send if VERBOSE_MODE < 3
|
|
272
|
+ send_update "$LOCAL_IP"
|
354
|
273
|
ERR_LAST=$? # save return value
|
355
|
274
|
}
|
356
|
275
|
|
357
|
|
- # Error in function
|
358
|
|
- if [ $ERR_LAST -gt 0 ]; then
|
359
|
|
- if [ $VERBOSE_MODE -le 1 ]; then # VERBOSE_MODE <=1 then retry
|
360
|
|
- # error sending local IP
|
361
|
|
- ERR_SEND=$(( $ERR_SEND + 1 ))
|
362
|
|
- [ $ERR_SEND -gt $retry_count ] && critical_error "can not send update to DDNS Provider"
|
363
|
|
- verbose_echo "\n!!!!!!!!! ERROR =: sending update - retry $ERR_SEND/$retry_count in $RETRY_SECONDS seconds\n"
|
364
|
|
- syslog_err "Error sending update - retry $ERR_SEND/$retry_count in $RETRY_SECONDS seconds"
|
365
|
|
- sleep $RETRY_SECONDS
|
366
|
|
- continue # re-loop
|
367
|
|
- else
|
368
|
|
- verbose_echo "\n!!!!!!!!! ERROR =: sending update to DDNS service - NO retry\n"
|
369
|
|
- break
|
370
|
|
- fi
|
371
|
|
- else
|
372
|
|
- # we send data so save "last time"
|
373
|
|
- get_uptime LAST_TIME
|
|
276
|
+ # error sending local IP to provider
|
|
277
|
+ # we have no communication error (handled inside send_update/do_transfer)
|
|
278
|
+ # but update was not recognized
|
|
279
|
+ # do NOT retry after RETRY_SECONDS, do retry after CHECK_SECONDS
|
|
280
|
+ # to early retrys will block most DDNS provider
|
|
281
|
+ # providers answer is checked inside send_update() function
|
|
282
|
+ [ $ERR_LAST -eq 0 ] && {
|
|
283
|
+ get_uptime LAST_TIME # we send update, so
|
374
|
284
|
echo $LAST_TIME > $UPDFILE # save LASTTIME to file
|
375
|
285
|
[ "$LOCAL_IP" != "$REGISTERED_IP" ] \
|
376
|
|
- && syslog_notice "Changed IP: '$LOCAL_IP' successfully send" \
|
377
|
|
- || syslog_notice "Forced Update: IP: '$LOCAL_IP' successfully send"
|
378
|
|
- break # leave while
|
379
|
|
- fi
|
380
|
|
- done
|
|
286
|
+ && write_log 6 "Update successful - IP '$LOCAL_IP' send" \
|
|
287
|
+ || write_log 6 "Forced update successful - IP: '$LOCAL_IP' send"
|
|
288
|
+ } || write_log 3 "Can not update IP at DDNS Provider"
|
|
289
|
+ fi
|
381
|
290
|
|
382
|
291
|
# now we wait for check interval before testing if update was recognized
|
383
|
|
- # only sleep if VERBOSE_MODE <= 2 because nothing send so do not wait
|
|
292
|
+ # only sleep if VERBOSE_MODE <= 2 because otherwise nothing was send
|
384
|
293
|
[ $VERBOSE_MODE -le 2 ] && {
|
385
|
|
- verbose_echo "****** WAITING =: $CHECK_SECONDS seconds (Check Interval) before continue"
|
386
|
|
- sleep $CHECK_SECONDS
|
387
|
|
- } || verbose_echo " VERBOSE MODE =: NO WAITING for Check Interval\n"
|
388
|
|
-
|
389
|
|
- # read at DDNS service registered IP (in loop on error)
|
390
|
|
- REGISTERED_IP=""
|
391
|
|
- ERR_REG_IP=0
|
392
|
|
- while : ; do
|
393
|
|
- verbose_echo "******* DETECT =: Registered IP"
|
394
|
|
- get_registered_ip REGISTERED_IP
|
395
|
|
- ERR_LAST=$? # save return value
|
396
|
|
-
|
397
|
|
- # No Error in function we leave while loop
|
398
|
|
- [ $ERR_LAST -eq 0 ] && break
|
399
|
|
-
|
400
|
|
- # we can't read Registered IP
|
401
|
|
- if [ $VERBOSE_MODE -le 1 ]; then # VERBOSE_MODE <=1 then retry
|
402
|
|
- ERR_REG_IP=$(( $ERR_REG_IP + 1 ))
|
403
|
|
- [ $ERR_REG_IP -gt $retry_count ] && critical_error "can not detect registered local IP"
|
404
|
|
- verbose_echo "\n!!!!!!!!! ERROR =: detecting Registered IP - retry $ERR_REG_IP/$retry_count in $RETRY_SECONDS seconds\n"
|
405
|
|
- syslog_err "Error detecting Registered IP - retry $ERR_REG_IP/$retry_count in $RETRY_SECONDS seconds"
|
406
|
|
- sleep $RETRY_SECONDS
|
407
|
|
- else
|
408
|
|
- verbose_echo "\n!!!!!!!!! ERROR =: detecting Registered IP - NO retry\n"
|
409
|
|
- break # leave while loop
|
410
|
|
- fi
|
411
|
|
- done
|
|
294
|
+ write_log 7 "Waiting $CHECK_SECONDS seconds (Check Interval)"
|
|
295
|
+ sleep $CHECK_SECONDS &
|
|
296
|
+ PID_SLEEP=$!
|
|
297
|
+ wait $PID_SLEEP # enable trap-handler
|
|
298
|
+ PID_SLEEP=0
|
|
299
|
+ } || write_log 7 "Verbose Mode: $VERBOSE_MODE - NO Check Interval waiting"
|
|
300
|
+
|
|
301
|
+ REGISTERED_IP="" # clear variable
|
|
302
|
+ get_registered_ip REGISTERED_IP # get registered/public IP
|
412
|
303
|
|
413
|
304
|
# IP's are still different
|
414
|
305
|
if [ "$LOCAL_IP" != "$REGISTERED_IP" ]; then
|
415
|
306
|
if [ $VERBOSE_MODE -le 1 ]; then # VERBOSE_MODE <=1 then retry
|
416
|
307
|
ERR_UPDATE=$(( $ERR_UPDATE + 1 ))
|
417
|
|
- [ $ERR_UPDATE -gt $retry_count ] && critical_error "Registered IP <> Local IP - LocalIP: '$LOCAL_IP' - RegisteredIP: '$REGISTERED_IP'"
|
418
|
|
- verbose_echo "\n!!!!!!!!! ERROR =: Registered IP <> Local IP - starting retry $ERR_UPDATE/$retry_count\n"
|
419
|
|
- syslog_warn "Warning: Registered IP <> Local IP - starting retry $ERR_UPDATE/$retry_count"
|
|
308
|
+ [ $ERR_UPDATE -gt $retry_count ] && write_log 14 "Updating IP at DDNS provider failed after $retry_count retries"
|
|
309
|
+ write_log 4 "Updating IP at DDNS provider failed - starting retry $ERR_UPDATE/$retry_count"
|
420
|
310
|
continue # loop to beginning
|
421
|
311
|
else
|
422
|
|
- verbose_echo "\n!!!!!!!!! ERROR =: Registered IP <> Local IP - LocalIP: '$LOCAL_IP' - RegisteredIP: '$REGISTERED_IP' - NO retry\n"
|
|
312
|
+ write_log 4 "Updating IP at DDNS provider failed"
|
|
313
|
+ write_log 7 "Verbose Mode: $VERBOSE_MODE - NO retry"; exit 1
|
423
|
314
|
fi
|
424
|
|
- fi
|
425
|
|
-
|
426
|
|
- # we checked successful the last update
|
427
|
|
- ERR_UPDATE=0 # reset error counter
|
|
315
|
+ else
|
|
316
|
+ # we checked successful the last update
|
|
317
|
+ ERR_UPDATE=0 # reset error counter
|
|
318
|
+ fi
|
428
|
319
|
|
429
|
|
- # force_update=0 or VERBOSE_MODE > 1 - leave the main loop
|
430
|
|
- [ $FORCE_SECONDS -eq 0 -o $VERBOSE_MODE -gt 1 ] && {
|
431
|
|
- verbose_echo "****** LEAVING =: $(eval $DATE_PROG)"
|
432
|
|
- syslog_info "Leaving"
|
433
|
|
- break
|
434
|
|
- }
|
435
|
|
- verbose_echo "********* LOOP =: $(eval $DATE_PROG)"
|
436
|
|
- syslog_info "Rerun IP check"
|
|
320
|
+ # force_update=0 or VERBOSE_MODE > 1 - leave here
|
|
321
|
+ [ $VERBOSE_MODE -gt 1 ] && write_log 7 "Verbose Mode: $VERBOSE_MODE - NO reloop"; exit 0
|
|
322
|
+ [ $FORCE_SECONDS -eq 0 ] && write_log 6 "Configured to run once"; exit 0
|
|
323
|
+ write_log 6 "Rerun IP check at $(eval $DATE_PROG)"
|
437
|
324
|
done
|
438
|
|
-
|
439
|
|
-verbose_echo "****** STOPPED =: PID '$$' at $(eval $DATE_PROG)\n"
|
440
|
|
-syslog_info "Done"
|
441
|
|
-
|
442
|
|
-exit 0
|
|
325
|
+# we should never come here there must be a programming error
|
|
326
|
+write_log 12 "Error in 'dynamic_dns_updater.sh - program coding error"
|