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.

101 lines
3.3 KiB

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