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.

99 lines
2.8 KiB

  1. #!/bin/sh
  2. # using function to not confuse function calls with existing ones inside /lib/functions.sh
  3. update_ddns_config() {
  4. udc_uci="$(which uci) -q" # ignore errors
  5. udc_pkg="ddns"
  6. udc_cfg=""
  7. udc_name=""
  8. udc_var=""
  9. udc_val=""
  10. package() { return 0; }
  11. config () {
  12. udc_cfg="$1"
  13. udc_name="$2"
  14. # Type = ddns Name = global
  15. if [ "$udc_cfg" = "$udc_pkg" -a "$udc_name" = "global" ]; then
  16. option() { return 0; }
  17. # rename options
  18. $udc_uci rename $udc_pkg.$udc_name.allow_local_ip="upd_privateip"
  19. $udc_uci rename $udc_pkg.$udc_name.date_format="ddns_dateformat"
  20. $udc_uci rename $udc_pkg.$udc_name.log_dir="ddns_logdir"
  21. $udc_uci rename $udc_pkg.$udc_name.log_lines="ddns_loglines"
  22. $udc_uci rename $udc_pkg.$udc_name.run_dir="ddns_rundir"
  23. # Type = service Name = ???
  24. elif [ "$udc_cfg" = "service" ]; then
  25. option() {
  26. udc_var="$1"; shift
  27. udc_val="$*"
  28. # fix some option service_name values
  29. case "$udc_var" in
  30. service_name)
  31. case "$udc_val" in
  32. freedns\.afraid\.org|afraid\.org)
  33. $udc_uci set $udc_pkg.$udc_name.$udc_var="afraid.org-keyauth";;
  34. Bind-nsupdate)
  35. $udc_uci set $udc_pkg.$udc_name.$udc_var="bind-nsupdate";;
  36. CloudFlare|cloudflare\.com)
  37. $udc_uci set $udc_pkg.$udc_name.$udc_var="cloudflare.com-v1";;
  38. dyndns\.org|dyndns\.com)
  39. $udc_uci set $udc_pkg.$udc_name.$udc_var="dyn.com";;
  40. free\.editdns\.net)
  41. $udc_uci set $udc_pkg.$udc_name.$udc_var="editdns.net";;
  42. domains\.google\.com)
  43. $udc_uci set $udc_pkg.$udc_name.$udc_var="google.com";;
  44. loopia\.com)
  45. $udc_uci set $udc_pkg.$udc_name.$udc_var="loopia.se";;
  46. NoIP\.com|No-IP\.com)
  47. $udc_uci set $udc_pkg.$udc_name.$udc_var="no-ip.com";;
  48. spdns\.de)
  49. $udc_uci set $udc_pkg.$udc_name.$udc_var="spdyn.de";;
  50. strato\.de)
  51. $udc_uci set $udc_pkg.$udc_name.$udc_var="strato.com";;
  52. *)
  53. # all others leave unchanged
  54. ;;
  55. esac
  56. # rename option service_name to option upd_provider
  57. # $udc_uci rename $udc_pkg.$udc_name.$udc_var="upd_provider"
  58. ;;
  59. *)
  60. # leave all other options currently unchanged
  61. ;;
  62. esac
  63. return 0
  64. }
  65. return 0
  66. # ignore unknown
  67. else
  68. return 0
  69. fi
  70. }
  71. # read package config file
  72. udc_data=$($udc_uci -S -n export "$udc_pkg")
  73. udc_ret="$?"
  74. # No error and udc_data then execute (eval)
  75. # this will call functions defined above
  76. [ "$udc_ret" -eq 0 -a -n "$udc_data" ] && eval "$udc_data"
  77. # add config ddns "global" (ignore error if exists)
  78. $udc_uci set ddns.global="$udc_pkg"
  79. # write changes to config file
  80. $udc_uci commit "$udc_pkg"
  81. unset udc_uci udc_pkg udc_cfg udc_name udc_var udc_val udc_ret udc_data
  82. return 0
  83. }
  84. # do existing config update
  85. update_ddns_config
  86. # clear Ludc_uci indexcache
  87. rm -f /tmp/luci-indexcache >/dev/null 2>&1
  88. return 0