Merge pull request #1735 from sumpfralle/olsr-jsoninfo-parser-handle-empty-result
[oweals/luci.git] / applications / luci-app-banip / luasrc / model / cbi / banip / overview_tab.lua
1 -- Copyright 2018-2019 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.default = "uclient-fetch"
49 o4.rmempty = false
50         
51 -- Runtime Information
52
53 ds = s:option(DummyValue, "_dummy")
54 ds.template = "banip/runtime"
55
56 -- Source Table
57
58 bl = m:section(TypedSection, "source", translate("IPSet Sources"))
59 bl.template = "banip/sourcelist"
60
61 name_4 = bl:option(Flag, "ban_src_on", translate("enable IPv4"))
62 name_4.rmempty = false
63
64 name_6 = bl:option(Flag, "ban_src_on_6", translate("enable IPv6"))
65 name_6.rmempty = false
66
67 type = bl:option(ListValue, "ban_src_ruletype", translate("SRC/DST"))
68 type:value("src")
69 type:value("dst")
70 type:value("src+dst")
71 type.default = "src"
72 type.rmempty = false
73
74 des = bl:option(DummyValue, "ban_src_desc", translate("Description"))
75
76 cat = bl:option(DynamicList, "ban_src_cat", translate("ASN/Country"))
77 cat.datatype = "uciname"
78 cat.optional = true
79
80 -- Extra options
81
82 e = m:section(NamedSection, "extra", "banip", translate("Extra Options"),
83         translate("Options for further tweaking in case the defaults are not suitable for you."))
84
85 e1 = e:option(Flag, "ban_debug", translate("Verbose Debug Logging"),
86         translate("Enable verbose debug logging in case of any processing error."))
87 e1.rmempty = false
88
89 e2 = e:option(Flag, "ban_nice", translate("Low Priority Service"),
90         translate("Set the nice level to 'low priority' and banIP background processing will take less resources from the system. ")
91         ..translate("This change requires a manual service stop/re-start to take effect."))
92 e2.disabled = "0"
93 e2.enabled = "10"
94 e2.rmempty = false
95
96 e3 = e:option(Value, "ban_backupdir", translate("Backup Directory"),
97         translate("Target directory for banIP backups. Default is '/tmp', please use preferably a non-volatile disk if available."))
98 e3.datatype = "directory"
99 e3.default = "/tmp"
100 e3.rmempty = true
101
102 e4 = e:option(Value, "ban_maxqueue", translate("Max. Download Queue"),
103         translate("Size of the download queue to handle downloads &amp; IPset processing in parallel (default '4'). ")
104         .. translate("For further performance improvements you can raise this value, e.g. '8' or '16' should be safe."))
105 e4.default = 4
106 e4.datatype = "range(1,32)"
107 e4.rmempty = false
108
109 e5 = e:option(ListValue, "ban_sshdaemon", translate("SSH Daemon"),
110         translate("Select the SSH daemon for logfile parsing, to detect break-in events."))
111 e5:value("dropbear")
112 e5:value("sshd")
113 e5.default = "dropbear"
114 e5.rmempty = true
115
116 e6 = e:option(Flag, "ban_autoblacklist", translate("Local Save Blacklist Addons"),
117   translate("Blacklist auto addons are stored temporary in the IPSet and saved permanently in the local blacklist. Disable this option to prevent the local save."))
118 e6.default = e6.enabled
119 e6.rmempty = true
120
121 e7 = e:option(Flag, "ban_autowhitelist", translate("Local Save Whitelist Addons"),
122   translate("Whitelist auto addons are stored temporary in the IPSet and saved permanently in the local whitelist. Disable this option to prevent the local save."))
123 e7.default = e7.enabled
124 e7.rmempty = true
125
126 -- Optional Extra Options
127
128 e20 = e:option(Value, "ban_triggerdelay", translate("Trigger Delay"),
129         translate("Additional trigger delay in seconds before banIP processing begins."))
130 e20.default = 2
131 e20.datatype = "range(1,60)"
132 e20.optional = true
133
134 e21 = e:option(ListValue, "ban_starttype", translate("Start Type"),
135         translate("Select the used start type during boot."))
136 e21:value("start")
137 e21:value("reload")
138 e21.default = "start"
139 e21.optional = true
140
141 e22 = e:option(Value, "ban_fetchparm", translate("Download Options"),
142         translate("Special options for the selected download utility, e.g. '--timeout=20 --no-check-certificate -O'."))
143 e22.optional = true
144
145 e30 = e:option(Value, "ban_wan_input_chain", translate("WAN Input Chain IPv4"))
146 e30.default = "input_wan_rule"
147 e30.datatype = "uciname"
148 e30.optional = true
149
150 e31 = e:option(Value, "ban_wan_forward_chain", translate("WAN Forward Chain IPv4"))
151 e31.default = "forwarding_wan_rule"
152 e31.datatype = "uciname"
153 e31.optional = true
154
155 e32 = e:option(Value, "ban_lan_input_chain", translate("LAN Input Chain IPv4"))
156 e32.default = "input_lan_rule"
157 e32.datatype = "uciname"
158 e32.optional = true
159
160 e33 = e:option(Value, "ban_lan_forward_chain", translate("LAN Forward Chain IPv4"))
161 e33.default = "forwarding_lan_rule"
162 e33.datatype = "uciname"
163 e33.optional = true
164
165 e34 = e:option(ListValue, "ban_target_src", translate("SRC Target IPv4"))
166 e34:value("REJECT")
167 e34:value("DROP")
168 e34.default = "DROP"
169 e34.optional = true
170
171 e35 = e:option(ListValue, "ban_target_dst", translate("DST Target IPv4"))
172 e35:value("REJECT")
173 e35:value("DROP")
174 e35.default = "REJECT"
175 e35.optional = true
176
177 e36 = e:option(Value, "ban_wan_input_chain_6", translate("WAN Input Chain IPv6"))
178 e36.default = "input_wan_rule"
179 e36.datatype = "uciname"
180 e36.optional = true
181
182 e37 = e:option(Value, "ban_wan_forward_chain_6", translate("WAN Forward Chain IPv6"))
183 e37.default = "forwarding_wan_rule"
184 e37.datatype = "uciname"
185 e37.optional = true
186
187 e38 = e:option(Value, "ban_lan_input_chain_6", translate("LAN Input Chain IPv6"))
188 e38.default = "input_lan_rule"
189 e38.datatype = "uciname"
190 e38.optional = true
191
192 e39 = e:option(Value, "ban_lan_forward_chain_6", translate("LAN Forward Chain IPv6"))
193 e39.default = "forwarding_lan_rule"
194 e39.datatype = "uciname"
195 e39.optional = true
196
197 e40 = e:option(ListValue, "ban_target_src_6", translate("SRC Target IPv6"))
198 e40:value("REJECT")
199 e40:value("DROP")
200 e40.default = "DROP"
201 e40.optional = true
202
203 e41 = e:option(ListValue, "ban_target_dst_6", translate("DST Target IPv6"))
204 e41:value("REJECT")
205 e41:value("DROP")
206 e41.default = "REJECT"
207 e41.optional = true
208
209 return m