2 # /usr/lib/ddns/luci_dns_helper.sh
4 # Written by Christian Schoenebeck in August 2014 to support:
5 # this script is used by luci-app-ddns
6 # - getting registered IP
7 # - check if possible to get local IP
8 # - verifing given DNS- or Proxy-Server
10 # variables in small chars are read from /etc/config/ddns
11 # variables in big chars are defined inside these scripts as gloval vars
12 # variables in big chars beginning with "__" are local defined inside functions only
13 # set -vx #script debugger
15 [ $# -lt 2 ] && exit 1
17 . /usr/lib/ddns/dynamic_dns_functions.sh # global vars are also defined here
19 # set -vx #script debugger
21 # preset some variables wrong or not set in dynamic_dns_functions.sh
22 SECTION_ID="dynamic_dns_lucihelper"
23 LOGFILE="$LOGDIR/$SECTION_ID.log"
24 LUCI_HELPER="ACTIV" # supress verbose and critical logging
25 # global variables normally set by reading DDNS UCI configuration
32 domain=$2 # Hostname/Domain
33 use_ipv6=${3:-"0"} # Use IPv6 - default IPv4
34 force_ipversion=${4:-"0"} # Force IP Version - default 0 - No
35 force_dnstcp=${5:-"0"} # Force TCP on DNS - default 0 - No
36 dns_server=${6:-""} # DNS server - default No DNS
39 echo -n "$IP" # suppress LF
42 # $2 == dns-server to verify # no need for force_dnstcp because
43 # verify with nc (netcat) uses tcp anyway
44 use_ipv6=${3:-"0"} # Use IPv6 - default IPv4
45 force_ipversion=${4:-"0"} # Force IP Version - default 0 - No
49 # $2 == proxy string to verify
50 use_ipv6=${3:-"0"} # Use IPv6 - default IPv4
51 force_ipversion=${4:-"0"} # Force IP Version - default 0 - No
56 use_ipv6="$2" # Use IPv6
57 ip_source="$3" # IP source
58 ip_network="$4" # set if source = "network" otherwise "-"
59 ip_url="$5" # set if source = "web" otherwise "-"
60 ip_interface="$6" # set if source = "interface" itherwiase "-"
61 ip_script="$7" # set if source = "script" otherwise "-"
62 proxy="$8" # proxy if set
63 force_ipversion="0" # not needed but must be set
64 use_https="0" # not needed but must be set
65 [ -n "$proxy" -a "$ip_source" == "web" ] && {
66 # proxy defined, used for ip_source=web
67 export HTTP_PROXY="http://$proxy"
68 export HTTPS_PROXY="http://$proxy"
69 export http_proxy="http://$proxy"
70 export https_proxy="http://$proxy"
72 # don't need IP only the return code
73 [ "$ip_source" == "web" -o "$ip_source" == "script"] && {
74 # we wait only 3 seconds for an
75 # answer from "web" or "script"
76 __timeout 3 -- get_local_ip IP