overview_tab.lua 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. -- Copyright 2017 Dirk Brenken (dev@brenken.org)
  2. -- This is free software, licensed under the Apache License, Version 2.0
  3. local fs = require("nixio.fs")
  4. local uci = require("luci.model.uci").cursor()
  5. local sys = require("luci.sys")
  6. local util = require("luci.util")
  7. local dump = util.ubus("network.interface", "dump", {})
  8. local json = require("luci.jsonc")
  9. local adbinput = uci.get("adblock", "global", "adb_rtfile") or "/tmp/adb_runtime.json"
  10. if not uci:get_first("adblock", "adblock", "adb_trigger") then
  11. m = SimpleForm("error", nil, translate("Please update your adblock config file to use this package. ")
  12. .. translatef("In OPKG use the '--force-maintainer' option to overwrite the pre-existing config file or download a fresh default config from "
  13. .. "<a href=\"%s\" target=\"_blank\">"
  14. .. "here</a>", "https://raw.githubusercontent.com/openwrt/packages/master/net/adblock/files/adblock.conf"))
  15. m.submit = false
  16. m.reset = false
  17. return m
  18. end
  19. m = Map("adblock", translate("Adblock"),
  20. translate("Configuration of the adblock package to block ad/abuse domains by using DNS. ")
  21. .. translatef("For further information "
  22. .. "<a href=\"%s\" target=\"_blank\">"
  23. .. "see online documentation</a>", "https://github.com/openwrt/packages/blob/master/net/adblock/files/README.md"))
  24. function m.on_after_commit(self)
  25. function e4.validate(self, value)
  26. if value == "0" then
  27. luci.sys.call("/etc/init.d/adblock reload >/dev/null 2>&1")
  28. else
  29. luci.sys.call("/etc/init.d/adblock start >/dev/null 2>&1")
  30. end
  31. end
  32. luci.http.redirect(luci.dispatcher.build_url("admin", "services", "adblock"))
  33. end
  34. -- Main adblock options
  35. s = m:section(NamedSection, "global", "adblock")
  36. local parse = json.parse(fs.readfile(adbinput) or "")
  37. if parse then
  38. status = parse.data.adblock_status
  39. version = parse.data.adblock_version
  40. domains = parse.data.blocked_domains
  41. fetch = parse.data.fetch_utility
  42. backend = parse.data.dns_backend
  43. rundate = parse.data.last_rundate
  44. end
  45. o1 = s:option(Flag, "adb_enabled", translate("Enable Adblock"))
  46. o1.default = o1.disabled
  47. o1.rmempty = false
  48. btn = s:option(Button, "", translate("Suspend / Resume Adblock"))
  49. if parse and status == "enabled" then
  50. btn.inputtitle = translate("Suspend")
  51. btn.inputstyle = "reset"
  52. btn.disabled = false
  53. function btn.write()
  54. luci.sys.call("/etc/init.d/adblock suspend >/dev/null 2>&1")
  55. luci.http.redirect(luci.dispatcher.build_url("admin", "services", "adblock"))
  56. end
  57. elseif parse and status == "paused" then
  58. btn.inputtitle = translate("Resume")
  59. btn.inputstyle = "apply"
  60. btn.disabled = false
  61. function btn.write()
  62. luci.sys.call("/etc/init.d/adblock resume >/dev/null 2>&1")
  63. luci.http.redirect(luci.dispatcher.build_url("admin", "services", "adblock"))
  64. end
  65. else
  66. btn.inputtitle = translate("-------")
  67. btn.inputstyle = "button"
  68. btn.disabled = true
  69. end
  70. o2 = s:option(ListValue, "adb_dns", translate("DNS Backend (DNS Directory)"),
  71. translate("List of supported DNS backends with their default list export directory.<br />")
  72. .. translate("To overwrite the default path use the 'DNS Directory' option in the extra section below."))
  73. o2:value("dnsmasq", "dnsmasq (/tmp/dnsmasq.d)")
  74. o2:value("unbound", "unbound (/var/lib/unbound)")
  75. o2:value("named", "bind (/var/lib/bind)")
  76. o2:value("kresd", "kresd (/etc/kresd)")
  77. o2:value("dnscrypt-proxy","dnscrypt-proxy (/tmp)")
  78. o2.default = "dnsmasq"
  79. o2.rmempty = false
  80. o3 = s:option(ListValue, "adb_trigger", translate("Startup Trigger"),
  81. translate("List of available network interfaces. By default the startup will be triggered by the 'wan' interface.<br />")
  82. .. translate("Choose 'none' to disable automatic startups, 'timed' to use a classic timeout (default 30 sec.) or select another trigger interface."))
  83. o3:value("none")
  84. o3:value("timed")
  85. if dump then
  86. local i, v
  87. for i, v in ipairs(dump.interface) do
  88. if v.interface ~= "loopback" then
  89. o3:value(v.interface)
  90. end
  91. end
  92. end
  93. o3.rmempty = false
  94. -- Runtime information
  95. ds = s:option(DummyValue, "", translate("Runtime Information"))
  96. ds.template = "cbi/nullsection"
  97. dv1 = s:option(DummyValue, "", translate("Adblock Status"))
  98. dv1.template = "adblock/runtime"
  99. if parse == nil then
  100. dv1.value = translate("n/a")
  101. else
  102. if status == "error" then
  103. dv1.value = translate("error")
  104. elseif status == "disabled" then
  105. dv1.value = translate("disabled")
  106. elseif status == "paused" then
  107. dv1.value = translate("paused")
  108. else
  109. dv1.value = translate("enabled")
  110. end
  111. end
  112. dv2 = s:option(DummyValue, "", translate("Adblock Version"))
  113. dv2.template = "adblock/runtime"
  114. if parse == nil then
  115. dv2.value = translate("n/a")
  116. else
  117. dv2.value = version
  118. end
  119. dv3 = s:option(DummyValue, "", translate("Download Utility (SSL Library)"),
  120. translate("For SSL protected blocklist sources you need a suitable SSL library, e.g. 'libustream-ssl' or the wget 'built-in'."))
  121. dv3.template = "adblock/runtime"
  122. if parse == nil then
  123. dv3.value = translate("n/a")
  124. else
  125. dv3.value = fetch
  126. end
  127. dv4 = s:option(DummyValue, "", translate("DNS Backend (DNS Directory)"))
  128. dv4.template = "adblock/runtime"
  129. if parse == nil then
  130. dv4.value = translate("n/a")
  131. else
  132. dv4.value = backend
  133. end
  134. dv5 = s:option(DummyValue, "", translate("Overall Blocked Domains"))
  135. dv5.template = "adblock/runtime"
  136. if parse == nil then
  137. dv5.value = translate("n/a")
  138. else
  139. dv5.value = domains
  140. end
  141. dv6 = s:option(DummyValue, "", translate("Last Run"))
  142. dv6.template = "adblock/runtime"
  143. if parse == nil then
  144. dv6.value = translate("n/a")
  145. else
  146. dv6.value = rundate
  147. end
  148. -- Blocklist table
  149. bl = m:section(TypedSection, "source", translate("Blocklist Sources"),
  150. translate("Available blocklist sources. ")
  151. .. translate("List URLs and Shallalist category selections are configurable in the 'Advanced' section.<br />")
  152. .. translate("Caution: Please don't select big lists or many lists at once on low memory devices to prevent OOM exceptions!"))
  153. bl.template = "cbi/tblsection"
  154. name = bl:option(Flag, "enabled", translate("Enabled"))
  155. name.rmempty = false
  156. ssl = bl:option(DummyValue, "adb_src", translate("SSL req."))
  157. function ssl.cfgvalue(self, section)
  158. local source = self.map:get(section, "adb_src")
  159. if source and source:match("https://") then
  160. return translate("Yes")
  161. else
  162. return translate("No")
  163. end
  164. end
  165. des = bl:option(DummyValue, "adb_src_desc", translate("Description"))
  166. -- Extra options
  167. e = m:section(NamedSection, "global", "adblock", translate("Extra Options"),
  168. translate("Options for further tweaking in case the defaults are not suitable for you."))
  169. e1 = e:option(Flag, "adb_debug", translate("Verbose Debug Logging"),
  170. translate("Enable verbose debug logging in case of any processing error."))
  171. e1.default = e1.disabled
  172. e1.rmempty = false
  173. e2 = e:option(Flag, "adb_forcedns", translate("Force Local DNS"),
  174. translate("Redirect all DNS queries from 'lan' zone to the local resolver."))
  175. e2.default = e2.disabled
  176. e2.rmempty = false
  177. e3 = e:option(Flag, "adb_forcesrt", translate("Force Overall Sort"),
  178. translate("Enable memory intense overall sort / duplicate removal on low memory devices (&lt; 64 MB RAM)"))
  179. e3.default = e3.disabled
  180. e3.rmempty = false
  181. e4 = e:option(Flag, "adb_manmode", translate("Manual / Backup mode"),
  182. translate("Do not automatically update blocklists during startup, use blocklist backups instead."))
  183. e4.default = e4.disabled
  184. e4.rmempty = false
  185. e5 = e:option(Flag, "adb_backup", translate("Enable Blocklist Backup"),
  186. translate("Create compressed blocklist backups, they will be used in case of download errors or during startup in manual mode."))
  187. e5.default = e5.disabled
  188. e5.rmempty = false
  189. e6 = e:option(Value, "adb_backupdir", translate("Backup Directory"),
  190. translate("Target directory for adblock backups. Please use only non-volatile disks, no ram/tmpfs drives."))
  191. e6.datatype = "directory"
  192. e6.default = "/mnt"
  193. e6.rmempty = false
  194. e7 = e:option(Value, "adb_dnsdir", translate("DNS Directory"),
  195. translate("Target directory for the generated blocklist 'adb_list.overall'."))
  196. e7.datatype = "directory"
  197. e7.optional = true
  198. e8 = e:option(Value, "adb_triggerdelay", translate("Trigger Delay"),
  199. translate("Additional trigger delay in seconds before adblock processing begins."))
  200. e8.datatype = "range(1,60)"
  201. e8.optional = true
  202. return m