Merge pull request #2245 from Ansuel/fstab
[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 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()
11
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"))
17
18 -- Main banIP Options
19
20 s = m:section(NamedSection, "global", "banip")
21
22 o1 = s:option(Flag, "ban_enabled", translate("Enable banIP"))
23 o1.default = o1.disabled
24 o1.rmempty = false
25
26 o2 = s:option(Flag, "ban_automatic", translate("Automatic WAN Interface Detection"))
27 o2.default = o2.enabled
28 o2.rmempty = false
29
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)
34                 if iface then
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.. ")")
40                                 end
41                         end
42                 end
43         end
44 end
45 o3.default = ban_iface
46 o3.rmempty = false
47
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")
51 o4:value("wget")
52 o4:value("curl")
53 o4:value("aria2c")
54 o4:value("wget-nossl", "wget-nossl (noSSL)")
55 o4:value("busybox", "wget-busybox (noSSL)")
56 o4.default = "uclient-fetch"
57 o4.rmempty = false
58         
59 -- Runtime Information
60
61 ds = s:option(DummyValue, "_dummy")
62 ds.template = "banip/runtime"
63
64 -- Source Table
65
66 bl = m:section(TypedSection, "source", translate("IP Blocklist Sources"))
67 bl.template = "banip/sourcelist"
68
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")
72         if source then
73                 if source:match("https://") then
74                         return translate("Yes")
75                 else
76                         return translate("No")
77                 end
78         end
79         return translate("n/a")
80 end
81
82 name_4 = bl:option(Flag, "ban_src_on", translate("enable IPv4"))
83 name_4.rmempty = false
84
85 name_6 = bl:option(Flag, "ban_src_on_6", translate("enable IPv6"))
86 name_6.rmempty = false
87
88 type = bl:option(ListValue, "ban_src_ruletype", translate("SRC/DST"))
89 type:value("src")
90 type:value("dst")
91 type:value("src+dst")
92 type.default = "src"
93 type.rmempty = false
94
95 des = bl:option(DummyValue, "ban_src_desc", translate("Description"))
96
97 cat = bl:option(DynamicList, "ban_src_cat", translate("ASN/Country"))
98 cat.datatype = "uciname"
99 cat.optional = true
100
101 -- Extra options
102
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."))
105
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
109 e1.rmempty = false
110
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
115 e2.disabled = "0"
116 e2.enabled = "10"
117 e2.rmempty = false
118
119 e3 = e:option(Value, "ban_maxqueue", translate("Max. Download Queue"),
120         translate("Size of the download queue to handle downloads &amp; 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."))
122 e3.default = 8
123 e3.datatype = "range(1,32)"
124 e3.rmempty = false
125
126 e4 = e:option(Value, "ban_triggerdelay", translate("Trigger Delay"),
127         translate("Additional trigger delay in seconds before banIP processing begins."))
128 e4.default = 2
129 e4.datatype = "range(1,60)"
130 e4.optional = true
131
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'."))
134 e5.optional = true
135
136 e10 = e:option(Value, "ban_wan_input_chain", translate("WAN Input Chain IPv4"))
137 e10.default = "input_wan_rule"
138 e10.datatype = "uciname"
139 e10.optional = true
140
141 e11 = e:option(Value, "ban_wan_forward_chain", translate("WAN Forward Chain IPv4"))
142 e11.default = "forwarding_wan_rule"
143 e11.datatype = "uciname"
144 e11.optional = true
145
146 e12 = e:option(Value, "ban_lan_input_chain", translate("LAN Input Chain IPv4"))
147 e12.default = "input_lan_rule"
148 e12.datatype = "uciname"
149 e12.optional = true
150
151 e13 = e:option(Value, "ban_lan_forward_chain", translate("LAN Forward Chain IPv4"))
152 e13.default = "forwarding_lan_rule"
153 e13.datatype = "uciname"
154 e13.optional = true
155
156 e14 = e:option(ListValue, "ban_target_src", translate("SRC Target IPv4"))
157 e14:value("REJECT")
158 e14:value("DROP")
159 e14.default = "DROP"
160 e14.optional = true
161
162 e15 = e:option(ListValue, "ban_target_dst", translate("DST Target IPv4"))
163 e15:value("REJECT")
164 e15:value("DROP")
165 e15.default = "REJECT"
166 e15.optional = true
167
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"
171 e16.optional = true
172
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"
176 e17.optional = true
177
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"
181 e18.optional = true
182
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"
186 e19.optional = true
187
188 e20 = e:option(ListValue, "ban_target_src_6", translate("SRC Target IPv6"))
189 e20:value("REJECT")
190 e20:value("DROP")
191 e20.default = "DROP"
192 e20.optional = true
193
194 e21 = e:option(ListValue, "ban_target_dst_6", translate("DST Target IPv6"))
195 e21:value("REJECT")
196 e21:value("DROP")
197 e21.default = "REJECT"
198 e21.optional = true
199
200 return m