smartdns.lua 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. --
  2. -- Copyright (C) 2018-2025 Ruilin Peng (Nick) <[email protected]>.
  3. --
  4. -- smartdns is free software: you can redistribute it and/or modify
  5. -- it under the terms of the GNU General Public License as published by
  6. -- the Free Software Foundation, either version 3 of the License, or
  7. -- (at your option) any later version.
  8. --
  9. -- smartdns is distributed in the hope that it will be useful,
  10. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. -- GNU General Public License for more details.
  13. --
  14. -- You should have received a copy of the GNU General Public License
  15. -- along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. module("luci.controller.smartdns", package.seeall)
  17. local smartdns = require "luci.model.smartdns"
  18. function index()
  19. if not nixio.fs.access("/etc/config/smartdns") then
  20. return
  21. end
  22. local page
  23. page = entry({"admin", "services", "smartdns"}, cbi("smartdns/smartdns"), _("SmartDNS"), 60)
  24. page.dependent = true
  25. page = entry({"admin", "services", "smartdns", "status"}, call("act_status"))
  26. page.leaf = true
  27. page = entry({"admin", "services", "smartdns", "upstream"}, cbi("smartdns/upstream"), nil)
  28. page.leaf = true
  29. end
  30. local function is_running()
  31. return luci.sys.call("pidof smartdns >/dev/null") == 0
  32. end
  33. function act_status()
  34. local e={}
  35. local ipv6_server;
  36. local dnsmasq_server = smartdns.get_config_option("dhcp", "dnsmasq", "server", {nil})[1]
  37. local auto_set_dnsmasq = smartdns.get_config_option("smartdns", "smartdns", "auto_set_dnsmasq", nil);
  38. e.auto_set_dnsmasq = auto_set_dnsmasq
  39. e.dnsmasq_server = dnsmasq_server
  40. e.local_port = smartdns.get_config_option("smartdns", "smartdns", "port", nil);
  41. if e.local_port ~= nil and e.local_port ~= "53" and auto_set_dnsmasq ~= nil and auto_set_dnsmasq == "1" then
  42. local str;
  43. str = "127.0.0.1#" .. e.local_port
  44. if dnsmasq_server ~= str then
  45. e.dnsmasq_redirect_failure = 1
  46. end
  47. end
  48. e.running = is_running()
  49. luci.http.prepare_content("application/json")
  50. luci.http.write_json(e)
  51. end