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.

98 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. lookup_host=$2 # FQDN of host registered at DDNS
  27. use_ipv6=${3:-"0"} # Use IPv6 - default IPv4
  28. force_ipversion=${4:-"0"} # Force IP Version - default 0 - No
  29. force_dnstcp=${5:-"0"} # Force TCP on DNS - default 0 - No
  30. is_glue=${6:-"0"} # Is glue record - default 0 - No
  31. dns_server=${7:-""} # DNS server - default No DNS
  32. write_log 7 "-----> get_registered_ip IP"
  33. IP=""
  34. get_registered_ip IP
  35. __RET=$?
  36. [ $__RET -ne 0 ] && IP=""
  37. echo -n "$IP" # suppress LF
  38. ;;
  39. verify_dns)
  40. # $2 : dns-server to verify # no need for force_dnstcp because
  41. # verify with nc (netcat) uses tcp anyway
  42. use_ipv6=${3:-"0"} # Use IPv6 - default IPv4
  43. force_ipversion=${4:-"0"} # Force IP Version - default 0 - No
  44. write_log 7 "-----> verify_dns '$2'"
  45. verify_dns "$2"
  46. __RET=$?
  47. ;;
  48. verify_proxy)
  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
  52. write_log 7 "-----> verify_proxy '$2'"
  53. verify_proxy "$2"
  54. __RET=$?
  55. ;;
  56. get_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=""
  75. [ "$ip_source" = "web" -o "$ip_source" = "script" ] && {
  76. # we wait only 3 seconds for an
  77. # answer from "web" or "script"
  78. write_log 7 "-----> timeout 3 -- get_local_ip IP"
  79. timeout 3 -- get_local_ip IP
  80. } || {
  81. write_log 7 "-----> get_local_ip IP"
  82. get_local_ip IP
  83. }
  84. __RET=$?
  85. ;;
  86. *)
  87. __RET=255
  88. ;;
  89. esac
  90. # remove out and err file
  91. [ -f $DATFILE ] && rm -f $DATFILE
  92. [ -f $ERRFILE ] && rm -f $ERRFILE
  93. return $__RET