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 sys = require("luci.sys")
7 local net = require "luci.model.network".init()
8 local util = require("luci.util")
9 local dump = util.ubus("network.interface", "dump", {})
10 local devices = sys.net:devices()
12 m = Map("banip", translate("banIP"),
13 translate("Configuration of the banIP package to block ip adresses/subnets via IPSet. ")
14 .. translatef("For further information "
15 .. "<a href=\"%s\" target=\"_blank\">"
16 .. "check the online documentation</a>", "https://github.com/openwrt/packages/blob/master/net/banip/files/README.md"))
20 s = m:section(NamedSection, "global", "banip")
22 o1 = s:option(Flag, "ban_enabled", translate("Enable banIP"))
23 o1.default = o1.disabled
26 o2 = s:option(Flag, "ban_automatic", translate("Automatic WAN Interface Detection"))
27 o2.default = o2.enabled
30 o3 = s:option(ListValue, "ban_iface", " ")
31 for _, dev in ipairs(devices) do
32 if dev ~= "lo" and dev ~= "br-lan" then
33 local iface = net:get_interface(dev)
35 iface = iface:get_networks() or {}
36 for k, v in pairs(iface) do
37 iface[k] = iface[k].sid
38 if iface[k] ~= "lan" then
39 o3:value(iface[k], iface[k].. " (" ..dev.. ")")
45 o3.default = ban_iface
48 o4 = s:option(ListValue, "ban_fetchutil", translate("Download Utility"),
49 translate("List of supported and fully pre-configured download utilities."))
50 o4:value("uclient-fetch")
54 o4:value("wget-nossl", "wget-nossl (noSSL)")
55 o4:value("busybox", "wget-busybox (noSSL)")
56 o4.default = "uclient-fetch"
59 -- Runtime Information
61 ds = s:option(DummyValue, "_dummy")
62 ds.template = "banip/runtime"
66 bl = m:section(TypedSection, "source", translate("IP Blocklist Sources"))
67 bl.template = "banip/sourcelist"
69 ssl = bl:option(DummyValue, "ban_src", translate("SSL req."))
70 function ssl.cfgvalue(self, section)
71 local source = self.map:get(section, "ban_src") or self.map:get(section, "ban_src_6")
73 if source:match("https://") then
74 return translate("Yes")
76 return translate("No")
79 return translate("n/a")
82 name_4 = bl:option(Flag, "ban_src_on", translate("enable IPv4"))
83 name_4.rmempty = false
85 name_6 = bl:option(Flag, "ban_src_on_6", translate("enable IPv6"))
86 name_6.rmempty = false
88 type = bl:option(ListValue, "ban_src_ruletype", translate("SRC/DST"))
95 des = bl:option(DummyValue, "ban_src_desc", translate("Description"))
97 cat = bl:option(DynamicList, "ban_src_cat", translate("ASN/Country"))
98 cat.datatype = "uciname"
103 e = m:section(NamedSection, "extra", "banip", translate("Extra Options"),
104 translate("Options for further tweaking in case the defaults are not suitable for you."))
106 e1 = e:option(Flag, "ban_debug", translate("Verbose Debug Logging"),
107 translate("Enable verbose debug logging in case of any processing error."))
108 e1.default = e1.disabled
111 e2 = e:option(Flag, "ban_nice", translate("Low Priority Service"),
112 translate("Set the nice level to 'low priority' and banIP background processing will take less resources from the system. ")
113 ..translate("This change requires a manual service stop/re-start to take effect."))
114 e2.default = e2.disabled
119 e3 = e:option(Value, "ban_maxqueue", translate("Max. Download Queue"),
120 translate("Size of the download queue to handle downloads & IPset processing in parallel (default '8'). ")
121 .. translate("For further performance improvements you can raise this value, e.g. '16' or '32' should be safe."))
123 e3.datatype = "range(1,32)"
126 e4 = e:option(Value, "ban_triggerdelay", translate("Trigger Delay"),
127 translate("Additional trigger delay in seconds before banIP processing begins."))
129 e4.datatype = "range(1,60)"
132 e5 = e:option(Value, "ban_fetchparm", translate("Download Options"),
133 translate("Special options for the selected download utility, e.g. '--timeout=20 --no-check-certificate -O'."))
136 e10 = e:option(Value, "ban_wan_input_chain", translate("WAN Input Chain IPv4"))
137 e10.default = "input_wan_rule"
138 e10.datatype = "uciname"
141 e11 = e:option(Value, "ban_wan_forward_chain", translate("WAN Forward Chain IPv4"))
142 e11.default = "forwarding_wan_rule"
143 e11.datatype = "uciname"
146 e12 = e:option(Value, "ban_lan_input_chain", translate("LAN Input Chain IPv4"))
147 e12.default = "input_lan_rule"
148 e12.datatype = "uciname"
151 e13 = e:option(Value, "ban_lan_forward_chain", translate("LAN Forward Chain IPv4"))
152 e13.default = "forwarding_lan_rule"
153 e13.datatype = "uciname"
156 e14 = e:option(ListValue, "ban_target_src", translate("SRC Target IPv4"))
162 e15 = e:option(ListValue, "ban_target_dst", translate("DST Target IPv4"))
165 e15.default = "REJECT"
168 e16 = e:option(Value, "ban_wan_input_chain_6", translate("WAN Input Chain IPv6"))
169 e16.default = "input_wan_rule"
170 e16.datatype = "uciname"
173 e17 = e:option(Value, "ban_wan_forward_chain_6", translate("WAN Forward Chain IPv6"))
174 e17.default = "forwarding_wan_rule"
175 e17.datatype = "uciname"
178 e18 = e:option(Value, "ban_lan_input_chain_6", translate("LAN Input Chain IPv6"))
179 e18.default = "input_lan_rule"
180 e18.datatype = "uciname"
183 e19 = e:option(Value, "ban_lan_forward_chain_6", translate("LAN Forward Chain IPv6"))
184 e19.default = "forwarding_lan_rule"
185 e19.datatype = "uciname"
188 e20 = e:option(ListValue, "ban_target_src_6", translate("SRC Target IPv6"))
194 e21 = e:option(ListValue, "ban_target_dst_6", translate("DST Target IPv6"))
197 e21.default = "REJECT"