2 # /usr/lib/ddns/luci_dns_helper.sh
4 #.Distributed under the terms of the GNU General Public License (GPL) version 2.0
6 # Written in August 2014 by
7 #.Christian Schoenebeck <christian dot schoenebeck at gmail dot com>
8 # This script is used by luci-app-ddns
9 # - getting registered IP
10 # - check if possible to get local IP
11 # - verifing given DNS- or Proxy-Server
13 # variables in small chars are read from /etc/config/ddns as parameter given here
14 # variables in big chars are defined inside these scripts as gloval vars
15 # variables in big chars beginning with "__" are local defined inside functions only
16 # set -vx #script debugger
18 [ $# -lt 2 ] && exit 1
20 .
/usr
/lib
/ddns
/dynamic_dns_functions.sh
# global vars are also defined here
22 # preset some variables, wrong or not set in dynamic_dns_functions.sh
23 SECTION_ID
="lucihelper"
24 LOGFILE
="$LOGDIR/$SECTION_ID.log"
25 DATFILE
="$RUNDIR/$SECTION_ID.dat" # save stdout data of WGet and other extern programs called
26 ERRFILE
="$RUNDIR/$SECTION_ID.err" # save stderr output of WGet and other extern programs called
27 VERBOSE_MODE
=0 # no console logging
28 # global variables normally set by reading DDNS UCI configuration
29 use_syslog
=0 # no syslog
30 use_logfile
=0 # by default no logfile, can be changed here
36 domain
=$2 # Hostname/Domain
37 use_ipv6
=${3:-"0"} # Use IPv6 - default IPv4
38 force_ipversion
=${4:-"0"} # Force IP Version - default 0 - No
39 force_dnstcp
=${5:-"0"} # Force TCP on DNS - default 0 - No
40 dns_server
=${6:-""} # DNS server - default No DNS
41 write_log
7 "-----> get_registered_ip IP"
44 [ $__RET -ne 0 ] && IP
=""
45 echo -n "$IP" # suppress LF
48 # $2 : dns-server to verify # no need for force_dnstcp because
49 # verify with nc (netcat) uses tcp anyway
50 use_ipv6
=${3:-"0"} # Use IPv6 - default IPv4
51 force_ipversion
=${4:-"0"} # Force IP Version - default 0 - No
52 write_log
7 "-----> verify_dns '$2'"
57 # $2 : proxy string to verify
58 use_ipv6
=${3:-"0"} # Use IPv6 - default IPv4
59 force_ipversion
=${4:-"0"} # Force IP Version - default 0 - No
60 write_log
7 "-----> verify_proxy '$2'"
66 use_ipv6
="$2" # Use IPv6
67 ip_source
="$3" # IP source
68 ip_network
="$4" # set if source = "network" otherwise "-"
69 ip_url
="$5" # set if source = "web" otherwise "-"
70 ip_interface
="$6" # set if source = "interface" itherwiase "-"
71 ip_script
="$7" # set if source = "script" otherwise "-"
72 proxy
="$8" # proxy if set
73 force_ipversion
="0" # not needed but must be set
74 use_https
="0" # not needed but must be set
75 [ -n "$proxy" -a "$ip_source" = "web" ] && {
76 # proxy defined, used for ip_source=web
77 export HTTP_PROXY
="http://$proxy"
78 export HTTPS_PROXY
="http://$proxy"
79 export http_proxy
="http://$proxy"
80 export https_proxy
="http://$proxy"
82 # don't need IP only the return code
83 [ "$ip_source" = "web" -o "$ip_source" = "script" ] && {
84 # we wait only 3 seconds for an
85 # answer from "web" or "script"
86 write_log
7 "-----> timeout 3 -- get_local_ip IP"
87 timeout
3 -- get_local_ip IP
89 write_log
7 "-----> get_local_ip IP"
99 # remove out and err file
100 [ -f $DATFILE ] && rm -f $DATFILE
101 [ -f $ERRFILE ] && rm -f $ERRFILE