overview_tab.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. -- Copyright 2017-2019 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 util = require("luci.util")
  6. local net = require "luci.model.network".init()
  7. local dump = util.ubus("network.interface", "dump", {})
  8. m = Map("adblock", translate("Adblock"),
  9. translate("Configuration of the adblock package to block ad/abuse domains by using DNS. ")
  10. ..translatef("For further information "
  11. .. "<a href=\"%s\" target=\"_blank\">"
  12. .. "check the online documentation</a>", "https://github.com/openwrt/packages/blob/master/net/adblock/files/README.md"))
  13. -- Main adblock options
  14. s = m:section(NamedSection, "global", "adblock")
  15. o1 = s:option(Flag, "adb_enabled", translate("Enable Adblock"))
  16. o1.default = o1.disabled
  17. o1.rmempty = false
  18. o2 = s:option(ListValue, "adb_dns", translate("DNS Backend (DNS Directory)"),
  19. translate("List of supported DNS backends with their default list export directory. ")
  20. ..translate("To overwrite the default path use the 'DNS Directory' option in the extra section below."))
  21. o2:value("dnsmasq", "dnsmasq (/tmp)")
  22. o2:value("unbound", "unbound (/var/lib/unbound)")
  23. o2:value("named", "named (/var/lib/bind)")
  24. o2:value("kresd", "kresd (/etc/kresd)")
  25. o2.default = "dnsmasq (/tmp)"
  26. o2.rmempty = false
  27. o3 = s:option(ListValue, "adb_dnsvariant", translate("DNS Blocking Variant"),
  28. translate("List of supported DNS blocking variants. By default 'nxdomain' will be used for all DNS backends. ")
  29. ..translate("Dnsmasq also supports 'null' block variants, which may provide better response times."))
  30. o3:value("nxdomain", "nxdomain, all DNS backends")
  31. o3:value("null (IPv4)", "null (IPv4), dnsmasq only")
  32. o3:value("null (IPv4/IPv6)", "null (IPv4/IPv6), dnsmasq only")
  33. o3.default = "nxdomain, all DNS backends"
  34. o3.rmempty = false
  35. o4 = s:option(ListValue, "adb_fetchutil", translate("Download Utility"),
  36. translate("List of supported and fully pre-configured download utilities."))
  37. o4:value("uclient-fetch")
  38. o4:value("wget")
  39. o4:value("curl")
  40. o4:value("aria2c")
  41. o4:value("wget-nossl", "wget-nossl (noSSL)")
  42. o4:value("busybox", "wget-busybox (noSSL)")
  43. o4.default = "uclient-fetch"
  44. o4.rmempty = false
  45. o5 = s:option(ListValue, "adb_trigger", translate("Startup Trigger"),
  46. translate("List of available network interfaces. Usually the startup will be triggered by the 'wan' interface. ")
  47. ..translate("Choose 'none' to disable automatic startups, 'timed' to use a classic timeout (default 30 sec.) or select another trigger interface."))
  48. o5:value("none")
  49. o5:value("timed")
  50. if dump then
  51. local i, v
  52. for i, v in ipairs(dump.interface) do
  53. if v.interface ~= "loopback" then
  54. local device = v.l3_device or v.device or "-"
  55. o5:value(v.interface, v.interface.. " (" ..device.. ")")
  56. end
  57. end
  58. end
  59. o5.rmempty = false
  60. -- Runtime information
  61. ds = s:option(DummyValue, "_dummy")
  62. ds.template = "adblock/runtime"
  63. -- Blocklist table
  64. bl = m:section(TypedSection, "source", translate("Blocklist Sources"),
  65. translate("<b>Caution:</b> To prevent OOM exceptions on low memory devices with less than 64 MB free RAM, please only select a few of them!"))
  66. bl.template = "adblock/blocklist"
  67. name = bl:option(Flag, "enabled", translate("Enabled"))
  68. name.rmempty = false
  69. ssl = bl:option(DummyValue, "adb_src", translate("SSL req."))
  70. function ssl.cfgvalue(self, section)
  71. local source = self.map:get(section, "adb_src")
  72. if source and source:match("https://") then
  73. return translate("Yes")
  74. else
  75. return translate("No")
  76. end
  77. end
  78. des = bl:option(DummyValue, "adb_src_desc", translate("Description"))
  79. cat = bl:option(DynamicList, "adb_src_cat", translate("Archive Categories"))
  80. cat.datatype = "uciname"
  81. cat.optional = true
  82. -- Extra options
  83. e = m:section(NamedSection, "extra", "adblock", translate("Extra Options"),
  84. translate("Options for further tweaking in case the defaults are not suitable for you."))
  85. e1 = e:option(Flag, "adb_debug", translate("Verbose Debug Logging"),
  86. translate("Enable verbose debug logging in case of any processing error."))
  87. e1.rmempty = false
  88. e2 = e:option(Flag, "adb_nice", translate("Low Priority Service"),
  89. translate("Set the nice level to 'low priority' and the adblock background processing will take fewer resources from the system. ")
  90. ..translate("This change requires a manual service stop/re-start to take effect."))
  91. e2.disabled = "0"
  92. e2.enabled = "10"
  93. e2.rmempty = false
  94. e3 = e:option(Flag, "adb_forcedns", translate("Force Local DNS"),
  95. translate("Redirect all DNS queries from 'lan' zone to the local resolver, applies to UDP and TCP protocol on port 53, 853 and 5353."))
  96. e3.rmempty = false
  97. e4 = e:option(Value, "adb_maxqueue", translate("Max. Download Queue"),
  98. translate("Size of the download queue to handle downloads &amp; list processing in parallel (default '4'). ")
  99. ..translate("For further performance improvements you can raise this value, e.g. '8' or '16' should be safe."))
  100. e4.default = 4
  101. e4.datatype = "range(1,32)"
  102. e4.rmempty = false
  103. e5 = e:option(Flag, "adb_dnsfilereset", translate("DNS File Reset"),
  104. translate("Resets the final DNS blockfile 'adb_list.overall' after loading through the DNS backend. ")
  105. ..translate("This option saves an enormous amount of storage space, but starts a small ubus/adblock monitor in the background."))
  106. e5.disabled = "false"
  107. e5.enabled = "true"
  108. e5.rmempty = false
  109. e6 = e:option(Flag, "adb_report", translate("DNS Query Report"),
  110. translate("Gather DNS related network traffic via tcpdump to provide a DNS Query Report on demand. ")
  111. ..translate("Please note: this needs manual 'tcpdump-mini' package installation."))
  112. e6.rmempty = false
  113. e7 = e:option(Value, "adb_repdir", translate("Report Directory"),
  114. translate("Target directory for dns related report files. Default is '/tmp', please use preferably a non-volatile disk if available."))
  115. e7:depends("adb_report", 1)
  116. e7.datatype = "directory"
  117. e7.default = "/tmp"
  118. e7.rmempty = true
  119. e8 = e:option(Value, "adb_backupdir", translate("Backup Directory"),
  120. translate("Target directory for adblock source backups. Default is '/tmp', please use preferably a non-volatile disk if available."))
  121. e8.datatype = "directory"
  122. e8.default = "/tmp"
  123. e8.rmempty = true
  124. e9 = e:option(Flag, "adb_mail", translate("E-Mail Notification"),
  125. translate("Send notification e-mails in case of a processing error or if domain count is &le; 0. ")
  126. .. translate("Please note: this needs manual 'msmtp' package installation and setup."))
  127. e9.rmempty = true
  128. e10 = e:option(Value, "adb_mreceiver", translate("E-Mail Receiver Address"),
  129. translate("Receiver address for adblock notification e-mails."))
  130. e10:depends("adb_mail", 1)
  131. e10.rmempty = true
  132. -- Optional Extra Options
  133. e20 = e:option(Value, "adb_dnsdir", translate("DNS Directory"),
  134. translate("Target directory for the generated blocklist 'adb_list.overall'."))
  135. e20.datatype = "directory"
  136. e20.optional = true
  137. e21 = e:option(Value, "adb_blacklist", translate("Blacklist File"),
  138. translate("Full path to the blacklist file."))
  139. e21.datatype = "file"
  140. e21.default = "/etc/adblock/adblock.blacklist"
  141. e21.optional = true
  142. e22 = e:option(Value, "adb_whitelist", translate("Whitelist File"),
  143. translate("Full path to the whitelist file."))
  144. e22.datatype = "file"
  145. e22.default = "/etc/adblock/adblock.whitelist"
  146. e22.optional = true
  147. e23 = e:option(Value, "adb_triggerdelay", translate("Trigger Delay"),
  148. translate("Additional trigger delay in seconds before adblock processing begins."))
  149. e23.datatype = "range(1,60)"
  150. e23.optional = true
  151. e24 = e:option(Value, "adb_maxtld", translate("TLD Compression Threshold"),
  152. translate("Disable the toplevel domain compression, if the number of blocked domains is greater than this threshold."))
  153. e24.datatype = "min(0)"
  154. e24.default = 100000
  155. e24.optional = true
  156. e25 = e:option(Value, "adb_portlist", translate("Local FW/DNS Ports"),
  157. translate("Space separated list of firewall ports which should be redirected locally."))
  158. e25.default = "53 853 5353"
  159. e25.optional = true
  160. e26 = e:option(Flag, "adb_dnsinotify", translate("DNS Inotify"),
  161. translate("Disable adblock triggered restarts and the 'DNS File Reset' for DNS backends with autoload features."))
  162. e26.default = nil
  163. e26.enabled = "true"
  164. e26.optional = true
  165. e27 = e:option(Flag, "adb_dnsflush", translate("Flush DNS Cache"),
  166. translate("Flush DNS cache after adblock processing."))
  167. e27.default = nil
  168. e27.optional = true
  169. e28 = e:option(ListValue, "adb_repiface", translate("Report Interface"),
  170. translate("Reporting interface used by tcpdump, set to 'any' for multiple interfaces (default 'br-lan'). ")
  171. ..translate("This change requires a manual service stop/re-start to take effect."))
  172. if dump then
  173. local i, v
  174. for i, v in ipairs(dump.interface) do
  175. if v.interface ~= "loopback" then
  176. local device = v.device
  177. if device then
  178. e28:value(device)
  179. end
  180. end
  181. end
  182. end
  183. e28:value("any")
  184. e28.optional = true
  185. e29 = e:option(Value, "adb_replisten", translate("Report Listen Port(s)"),
  186. translate("Space separated list of reporting port(s) used by tcpdump (default: '53'). ")
  187. ..translate("This change requires a manual service stop/re-start to take effect."))
  188. e29.default = 53
  189. e29.optional = true
  190. e30 = e:option(Value, "adb_repchunkcnt", translate("Report Chunk Count"),
  191. translate("Report chunk count used by tcpdump (default '5'). ")
  192. ..translate("This change requires a manual service stop/re-start to take effect."))
  193. e30.datatype = "range(1,10)"
  194. e30.default = 5
  195. e30.optional = true
  196. e31 = e:option(Value, "adb_repchunksize", translate("Report Chunk Size"),
  197. translate("Report chunk size used by tcpdump in MB (default '1'). ")
  198. ..translate("This change requires a manual service stop/re-start to take effect."))
  199. e31.datatype = "range(1,10)"
  200. e31.default = 1
  201. e31.optional = true
  202. e32 = e:option(Value, "adb_msender", translate("E-mail Sender Address"),
  203. translate("Sender address for adblock notification e-mails."))
  204. e32.default = "no-reply@adblock"
  205. e32.optional = true
  206. e33 = e:option(Value, "adb_mtopic", translate("E-mail Topic"),
  207. translate("Topic for adblock notification e-mails."))
  208. e33.default = "adblock notification"
  209. e33.optional = true
  210. e34 = e:option(Value, "adb_mprofile", translate("E-mail Profile"),
  211. translate("Mail profile used in 'msmtp' for adblock notification e-mails."))
  212. e34.default = "adb_notify"
  213. e34.optional = true
  214. e35 = e:option(Value, "adb_mcnt", translate("E-mail Notification Count"),
  215. translate("Raise the minimum notification count, to get e-mails if the overall count is less or equal to the given limit (default 0), ")
  216. .. translate("e.g. to receive an e-mail notification with every adblock run set this value to 200000."))
  217. e35.default = 0
  218. e35.datatype = "min(0)"
  219. e35.optional = true
  220. return m