1 -- Copyright 2018 Dirk Brenken (dev@brenken.org)
2 -- This is free software, licensed under the Apache License, Version 2.0
4 local fs = require("nixio.fs")
5 local uci = require("luci.model.uci").cursor()
6 local net = require "luci.model.network".init()
7 local util = require("luci.util")
8 local dump = util.ubus("network.interface", "dump", {})
10 m = Map("banip", translate("banIP"),
11 translate("Configuration of the banIP package to block ip adresses/subnets via IPSet. ")
12 ..translatef("For further information "
13 .. "<a href=\"%s\" target=\"_blank\">"
14 .. "check the online documentation</a>", "https://github.com/openwrt/packages/blob/master/net/banip/files/README.md"))
18 s = m:section(NamedSection, "global", "banip")
20 o1 = s:option(Flag, "ban_enabled", translate("Enable banIP"))
21 o1.default = o1.disabled
24 o2 = s:option(Flag, "ban_automatic", translate("Automatic WAN Interface Detection"))
25 o2.default = o2.enabled
28 o3 = s:option(MultiValue, "ban_iface", translate("Interface Selection"),
29 translate("Disable the automatic WAN detection and select your preferred interface(s) manually."))
32 for i, v in ipairs(dump.interface) do
33 if v.interface ~= "loopback" and v.interface ~= "lan" then
34 local device = v.l3_device or v.device or "-"
35 o3:value(v.interface, v.interface.. " (" ..device.. ")")
39 o3.widget = "checkbox"
42 o4 = s:option(ListValue, "ban_fetchutil", translate("Download Utility"),
43 translate("List of supported and fully pre-configured download utilities."))
44 o4:value("uclient-fetch")
48 o4:value("wget-nossl", "wget-nossl (noSSL)")
49 o4:value("busybox", "wget-busybox (noSSL)")
50 o4.default = "uclient-fetch"
53 -- Runtime Information
55 ds = s:option(DummyValue, "_dummy")
56 ds.template = "banip/runtime"
60 bl = m:section(TypedSection, "source", translate("IP Blocklist Sources"))
61 bl.template = "banip/sourcelist"
63 ssl = bl:option(DummyValue, "ban_src", translate("SSL req."))
64 function ssl.cfgvalue(self, section)
65 local source = self.map:get(section, "ban_src") or self.map:get(section, "ban_src_6")
67 if source:match("https://") then
68 return translate("Yes")
70 return translate("No")
73 return translate("n/a")
76 name_4 = bl:option(Flag, "ban_src_on", translate("enable IPv4"))
77 name_4.rmempty = false
79 name_6 = bl:option(Flag, "ban_src_on_6", translate("enable IPv6"))
80 name_6.rmempty = false
82 type = bl:option(ListValue, "ban_src_ruletype", translate("SRC/DST"))
89 des = bl:option(DummyValue, "ban_src_desc", translate("Description"))
91 cat = bl:option(DynamicList, "ban_src_cat", translate("ASN/Country"))
92 cat.datatype = "uciname"
97 e = m:section(NamedSection, "extra", "banip", translate("Extra Options"),
98 translate("Options for further tweaking in case the defaults are not suitable for you."))
100 e1 = e:option(Flag, "ban_debug", translate("Verbose Debug Logging"),
101 translate("Enable verbose debug logging in case of any processing error."))
102 e1.default = e1.disabled
105 e2 = e:option(Flag, "ban_nice", translate("Low Priority Service"),
106 translate("Set the nice level to 'low priority' and banIP background processing will take less resources from the system. ")
107 ..translate("This change requires a manual service stop/re-start to take effect."))
108 e2.default = e2.disabled
113 e3 = e:option(Value, "ban_maxqueue", translate("Max. Download Queue"),
114 translate("Size of the download queue to handle downloads & IPset processing in parallel (default '8'). ")
115 .. translate("For further performance improvements you can raise this value, e.g. '16' or '32' should be safe."))
117 e3.datatype = "range(1,32)"
120 e4 = e:option(Value, "ban_triggerdelay", translate("Trigger Delay"),
121 translate("Additional trigger delay in seconds before banIP processing begins."))
123 e4.datatype = "range(1,60)"
126 e5 = e:option(Value, "ban_fetchparm", translate("Download Options"),
127 translate("Special options for the selected download utility, e.g. '--timeout=20 --no-check-certificate -O'."))
130 e10 = e:option(Value, "ban_wan_input_chain", translate("WAN Input Chain IPv4"))
131 e10.default = "input_wan_rule"
132 e10.datatype = "uciname"
135 e11 = e:option(Value, "ban_wan_forward_chain", translate("WAN Forward Chain IPv4"))
136 e11.default = "forwarding_wan_rule"
137 e11.datatype = "uciname"
140 e12 = e:option(Value, "ban_lan_input_chain", translate("LAN Input Chain IPv4"))
141 e12.default = "input_lan_rule"
142 e12.datatype = "uciname"
145 e13 = e:option(Value, "ban_lan_forward_chain", translate("LAN Forward Chain IPv4"))
146 e13.default = "forwarding_lan_rule"
147 e13.datatype = "uciname"
150 e14 = e:option(ListValue, "ban_target_src", translate("SRC Target IPv4"))
156 e15 = e:option(ListValue, "ban_target_dst", translate("DST Target IPv4"))
159 e15.default = "REJECT"
162 e16 = e:option(Value, "ban_wan_input_chain_6", translate("WAN Input Chain IPv6"))
163 e16.default = "input_wan_rule"
164 e16.datatype = "uciname"
167 e17 = e:option(Value, "ban_wan_forward_chain_6", translate("WAN Forward Chain IPv6"))
168 e17.default = "forwarding_wan_rule"
169 e17.datatype = "uciname"
172 e18 = e:option(Value, "ban_lan_input_chain_6", translate("LAN Input Chain IPv6"))
173 e18.default = "input_lan_rule"
174 e18.datatype = "uciname"
177 e19 = e:option(Value, "ban_lan_forward_chain_6", translate("LAN Forward Chain IPv6"))
178 e19.default = "forwarding_lan_rule"
179 e19.datatype = "uciname"
182 e20 = e:option(ListValue, "ban_target_src_6", translate("SRC Target IPv6"))
188 e21 = e:option(ListValue, "ban_target_dst_6", translate("DST Target IPv6"))
191 e21.default = "REJECT"