Merge pull request #2384 from davidjb/patch-1
[oweals/luci.git] / applications / luci-app-banip / luasrc / model / cbi / banip / overview_tab.lua
1 -- Copyright 2018 Dirk Brenken (dev@brenken.org)
2 -- This is free software, licensed under the Apache License, Version 2.0
3
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", {})
9
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"))
15
16 -- Main banIP Options
17
18 s = m:section(NamedSection, "global", "banip")
19
20 o1 = s:option(Flag, "ban_enabled", translate("Enable banIP"))
21 o1.default = o1.disabled
22 o1.rmempty = false
23
24 o2 = s:option(Flag, "ban_automatic", translate("Automatic WAN Interface Detection"))
25 o2.default = o2.enabled
26 o2.rmempty = false
27
28 o3 = s:option(MultiValue, "ban_iface", translate("Interface Selection"),
29         translate("Disable the automatic WAN detection and select your preferred interface(s) manually."))
30 if dump then
31         local i, v
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.. ")")
36                 end
37         end
38 end
39 o3.widget = "checkbox"
40 o3.rmempty = false
41
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")
45 o4:value("wget")
46 o4:value("curl")
47 o4:value("aria2c")
48 o4:value("wget-nossl", "wget-nossl (noSSL)")
49 o4:value("busybox", "wget-busybox (noSSL)")
50 o4.default = "uclient-fetch"
51 o4.rmempty = false
52         
53 -- Runtime Information
54
55 ds = s:option(DummyValue, "_dummy")
56 ds.template = "banip/runtime"
57
58 -- Source Table
59
60 bl = m:section(TypedSection, "source", translate("IP Blocklist Sources"))
61 bl.template = "banip/sourcelist"
62
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")
66         if source then
67                 if source:match("https://") then
68                         return translate("Yes")
69                 else
70                         return translate("No")
71                 end
72         end
73         return translate("n/a")
74 end
75
76 name_4 = bl:option(Flag, "ban_src_on", translate("enable IPv4"))
77 name_4.rmempty = false
78
79 name_6 = bl:option(Flag, "ban_src_on_6", translate("enable IPv6"))
80 name_6.rmempty = false
81
82 type = bl:option(ListValue, "ban_src_ruletype", translate("SRC/DST"))
83 type:value("src")
84 type:value("dst")
85 type:value("src+dst")
86 type.default = "src"
87 type.rmempty = false
88
89 des = bl:option(DummyValue, "ban_src_desc", translate("Description"))
90
91 cat = bl:option(DynamicList, "ban_src_cat", translate("ASN/Country"))
92 cat.datatype = "uciname"
93 cat.optional = true
94
95 -- Extra options
96
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."))
99
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
103 e1.rmempty = false
104
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
109 e2.disabled = "0"
110 e2.enabled = "10"
111 e2.rmempty = false
112
113 e3 = e:option(Value, "ban_maxqueue", translate("Max. Download Queue"),
114         translate("Size of the download queue to handle downloads &amp; 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."))
116 e3.default = 8
117 e3.datatype = "range(1,32)"
118 e3.rmempty = false
119
120 e4 = e:option(Value, "ban_triggerdelay", translate("Trigger Delay"),
121         translate("Additional trigger delay in seconds before banIP processing begins."))
122 e4.default = 2
123 e4.datatype = "range(1,60)"
124 e4.optional = true
125
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'."))
128 e5.optional = true
129
130 e10 = e:option(Value, "ban_wan_input_chain", translate("WAN Input Chain IPv4"))
131 e10.default = "input_wan_rule"
132 e10.datatype = "uciname"
133 e10.optional = true
134
135 e11 = e:option(Value, "ban_wan_forward_chain", translate("WAN Forward Chain IPv4"))
136 e11.default = "forwarding_wan_rule"
137 e11.datatype = "uciname"
138 e11.optional = true
139
140 e12 = e:option(Value, "ban_lan_input_chain", translate("LAN Input Chain IPv4"))
141 e12.default = "input_lan_rule"
142 e12.datatype = "uciname"
143 e12.optional = true
144
145 e13 = e:option(Value, "ban_lan_forward_chain", translate("LAN Forward Chain IPv4"))
146 e13.default = "forwarding_lan_rule"
147 e13.datatype = "uciname"
148 e13.optional = true
149
150 e14 = e:option(ListValue, "ban_target_src", translate("SRC Target IPv4"))
151 e14:value("REJECT")
152 e14:value("DROP")
153 e14.default = "DROP"
154 e14.optional = true
155
156 e15 = e:option(ListValue, "ban_target_dst", translate("DST Target IPv4"))
157 e15:value("REJECT")
158 e15:value("DROP")
159 e15.default = "REJECT"
160 e15.optional = true
161
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"
165 e16.optional = true
166
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"
170 e17.optional = true
171
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"
175 e18.optional = true
176
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"
180 e19.optional = true
181
182 e20 = e:option(ListValue, "ban_target_src_6", translate("SRC Target IPv6"))
183 e20:value("REJECT")
184 e20:value("DROP")
185 e20.default = "DROP"
186 e20.optional = true
187
188 e21 = e:option(ListValue, "ban_target_dst_6", translate("DST Target IPv6"))
189 e21:value("REJECT")
190 e21:value("DROP")
191 e21.default = "REJECT"
192 e21.optional = true
193
194 return m