1
0

unbound.lua 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. -- Copyright 2008 Steven Barth <steven@midlink.org>
  2. -- Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
  3. -- Copyright 2017 Eric Luehrsen <ericluehrsen@hotmail.com>
  4. -- Licensed to the public under the Apache License 2.0.
  5. module("luci.controller.unbound", package.seeall)
  6. function index()
  7. local ucl = luci.model.uci.cursor()
  8. local valexp = ucl:get_first("unbound", "unbound", "extended_luci")
  9. local valman = ucl:get_first("unbound", "unbound", "manual_conf")
  10. if not nixio.fs.access("/etc/config/unbound") then
  11. return
  12. end
  13. if valexp == "1" then
  14. -- Expanded View
  15. entry({"admin", "services", "unbound"}, firstchild(), _("Recursive DNS")).dependent = false
  16. -- UCI Tab(s)
  17. entry({"admin", "services", "unbound", "configure"}, cbi("unbound/configure"), _("Settings"), 10)
  18. -- Status Tab(s)
  19. entry({"admin", "services", "unbound", "status"}, firstchild(), _("Status"), 20)
  20. entry({"admin", "services", "unbound", "status", "syslog"}, call("QuerySysLog"), _("Log"), 50).leaf = true
  21. if nixio.fs.access("/usr/sbin/unbound-control") then
  22. -- Require unbound-control to execute
  23. entry({"admin", "services", "unbound", "status", "statistics"}, call("QueryStatistics"), _("Statistics"), 10).leaf = true
  24. entry({"admin", "services", "unbound", "status", "localdata"}, call("QueryLocalData"), _("Local Data"), 20).leaf = true
  25. entry({"admin", "services", "unbound", "status", "localzone"}, call("QueryLocalZone"), _("Local Zones"), 30).leaf = true
  26. else
  27. entry({"admin", "services", "unbound", "status", "statistics"}, call("ShowEmpty"), _("Statistics"), 10).leaf = true
  28. end
  29. -- Raw File Tab(s)
  30. entry({"admin", "services", "unbound", "files"}, firstchild(), _("Files"), 30)
  31. if valman ~= "1" then
  32. entry({"admin", "services", "unbound", "files", "base"}, call("ShowUnboundConf"), _("UCI: Unbound"), 10).leaf = true
  33. else
  34. entry({"admin", "services", "unbound", "files", "base"}, cbi("unbound/manual"), _("Edit: Unbound"), 10).leaf = true
  35. end
  36. entry({"admin", "services", "unbound", "files", "server"}, cbi("unbound/server"), _("Edit: Server"), 20).leaf = true
  37. entry({"admin", "services", "unbound", "files", "extended"}, cbi("unbound/extended"), _("Edit: Extended"), 30).leaf = true
  38. if nixio.fs.access("/var/lib/unbound/unbound_dhcp.conf") then
  39. entry({"admin", "services", "unbound", "files", "dhcp"}, call("ShowDHCPConf"), _("Include: DHCP"), 40).leaf = true
  40. end
  41. if nixio.fs.access("/var/lib/unbound/adb_list.overall") then
  42. entry({"admin", "services", "unbound", "files", "adblock"}, call("ShowAdblock"), _("Include: Adblock"), 50).leaf = true
  43. end
  44. else
  45. -- Simple View to UCI only
  46. entry({"admin", "services", "unbound"}, cbi("unbound/configure"), _("Recursive DNS")).dependent = false
  47. end
  48. end
  49. function ShowEmpty()
  50. local lclhead = "Unbound Control"
  51. local lcldesc = luci.i18n.translate("This could display more statistics with the unbound-control package.")
  52. luci.template.render("unbound/show-empty", {heading = lclhead, description = lcldesc})
  53. end
  54. function QuerySysLog()
  55. local lclhead = "System Log"
  56. local lcldata = luci.util.exec("logread | grep -i unbound")
  57. local lcldesc = luci.i18n.translate("This shows syslog filtered for events involving Unbound.")
  58. luci.template.render("unbound/show-textbox", {heading = lclhead, description = lcldesc, content = lcldata})
  59. end
  60. function QueryStatistics()
  61. local lclhead = "Unbound Control Stats"
  62. local lcldata = luci.util.exec("unbound-control -c /var/lib/unbound/unbound.conf stats_noreset")
  63. local lcldesc = luci.i18n.translate("This shows some performance statistics tracked by Unbound.")
  64. luci.template.render("unbound/show-textbox", {heading = lclhead, description = lcldesc, content = lcldata})
  65. end
  66. function QueryLocalData()
  67. local lclhead = "Unbound Control Local Data"
  68. local lcldata = luci.util.exec("unbound-control -c /var/lib/unbound/unbound.conf list_local_data")
  69. local lcldesc = luci.i18n.translate("This shows local host records that shortcut recursion.")
  70. luci.template.render("unbound/show-textbox", {heading = lclhead, description = lcldesc, content = lcldata})
  71. end
  72. function QueryLocalZone()
  73. local lclhead = "Unbound Control Local Zones"
  74. local lcldata = luci.util.exec("unbound-control -c /var/lib/unbound/unbound.conf list_local_zones")
  75. local lcldesc = luci.i18n.translate("This shows local zone definitions that affect recursion routing or processing. ")
  76. luci.template.render("unbound/show-textbox", {heading = lclhead, description = lcldesc, content = lcldata})
  77. end
  78. function ShowUnboundConf()
  79. local unboundfile = "/var/lib/unbound/unbound.conf"
  80. local lclhead = "Unbound Conf"
  81. local lcldata = nixio.fs.readfile(unboundfile)
  82. local lcldesc = luci.i18n.translate("This shows configuration generated by UCI:")
  83. lcldesc = lcldesc .. " (" .. unboundfile .. ")"
  84. luci.template.render("unbound/show-textbox", {heading = lclhead, description = lcldesc, content = lcldata})
  85. end
  86. function ShowDHCPConf()
  87. local dhcpfile = "/var/lib/unbound/unbound_dhcp.conf"
  88. local lclhead = "DHCP Conf"
  89. local lcldata = nixio.fs.readfile(dhcpfile)
  90. local lcldesc = luci.i18n.translate("This shows LAN hosts added by DHCP hook scripts:")
  91. lcldesc = lcldesc .. " (" .. dhcpfile .. ")"
  92. luci.template.render("unbound/show-textbox", {heading = lclhead, description = lcldesc, content = lcldata})
  93. end
  94. function ShowAdblock()
  95. local adblockfile = "/var/lib/unbound/adb_list.overall"
  96. local lclhead = "Adblock Conf"
  97. local lcldata, lcldesc
  98. if nixio.fs.stat(adblockfile).size > 262144 then
  99. lcldesc = luci.i18n.translate("Adblock domain list is too large for LuCI:")
  100. lcldesc = lcldesc .. " (" .. adblockfile .. ")"
  101. luci.template.render("unbound/show-empty", {heading = lclhead, description = lcldesc})
  102. else
  103. lcldata = nixio.fs.readfile(adblockfile)
  104. lcldesc = luci.i18n.translate("This shows blocked domains provided by Adblock scripts:")
  105. lcldesc = lcldesc .. " (" .. adblockfile .. ")"
  106. luci.template.render("unbound/show-textbox", {heading = lclhead, description = lcldesc, content = lcldata})
  107. end
  108. end