1
0

overview_tab.lua 8.4 KB

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