You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
3.3 KiB

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