luci-app-olsr: handle empty result for non-status tables
[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: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.rmempty = false
103
104 e2 = e:option(Flag, "ban_nice", translate("Low Priority Service"),
105         translate("Set the nice level to 'low priority' and banIP background processing will take less resources from the system. ")
106         ..translate("This change requires a manual service stop/re-start to take effect."))
107 e2.disabled = "0"
108 e2.enabled = "10"
109 e2.rmempty = false
110
111 e3 = e:option(Flag, "ban_backup", translate("Enable Blocklist Backup"),
112         translate("Create compressed blocklist backups, they will be used in case of download errors or during startup in 'backup mode'."))
113 e3.rmempty = false
114
115 e4 = e:option(Value, "ban_backupdir", translate("Backup Directory"),
116         translate("Target directory for banIP backups. Please use preferably a non-volatile disk, e.g. an external usb stick."))
117 e4:depends("ban_backup", 1)
118 e4.datatype = "directory"
119 e4.default = "/mnt"
120 e4.rmempty = true
121
122 e5 = e:option(Flag, "ban_backupboot", translate("Backup Mode"),
123         translate("Do not automatically update blocklists during startup, use their backups instead."))
124 e5:depends("ban_backup", 1)
125 e5.rmempty = true
126
127 e6 = e:option(Value, "ban_maxqueue", translate("Max. Download Queue"),
128         translate("Size of the download queue to handle downloads &amp; IPset processing in parallel (default '4'). ")
129         .. translate("For further performance improvements you can raise this value, e.g. '8' or '16' should be safe."))
130 e6.default = 4
131 e6.datatype = "range(1,32)"
132 e6.rmempty = false
133
134 -- Optional Extra Options
135
136 e20 = e:option(Value, "ban_triggerdelay", translate("Trigger Delay"),
137         translate("Additional trigger delay in seconds before banIP processing begins."))
138 e20.default = 2
139 e20.datatype = "range(1,60)"
140 e20.optional = true
141
142 e21 = e:option(Value, "ban_fetchparm", translate("Download Options"),
143         translate("Special options for the selected download utility, e.g. '--timeout=20 --no-check-certificate -O'."))
144 e21.optional = true
145
146 e22 = e:option(Value, "ban_wan_input_chain", translate("WAN Input Chain IPv4"))
147 e22.default = "input_wan_rule"
148 e22.datatype = "uciname"
149 e22.optional = true
150
151 e23 = e:option(Value, "ban_wan_forward_chain", translate("WAN Forward Chain IPv4"))
152 e23.default = "forwarding_wan_rule"
153 e23.datatype = "uciname"
154 e23.optional = true
155
156 e24 = e:option(Value, "ban_lan_input_chain", translate("LAN Input Chain IPv4"))
157 e24.default = "input_lan_rule"
158 e24.datatype = "uciname"
159 e24.optional = true
160
161 e25 = e:option(Value, "ban_lan_forward_chain", translate("LAN Forward Chain IPv4"))
162 e25.default = "forwarding_lan_rule"
163 e25.datatype = "uciname"
164 e25.optional = true
165
166 e26 = e:option(ListValue, "ban_target_src", translate("SRC Target IPv4"))
167 e26:value("REJECT")
168 e26:value("DROP")
169 e26.default = "DROP"
170 e26.optional = true
171
172 e27 = e:option(ListValue, "ban_target_dst", translate("DST Target IPv4"))
173 e27:value("REJECT")
174 e27:value("DROP")
175 e27.default = "REJECT"
176 e27.optional = true
177
178 e28 = e:option(Value, "ban_wan_input_chain_6", translate("WAN Input Chain IPv6"))
179 e28.default = "input_wan_rule"
180 e28.datatype = "uciname"
181 e28.optional = true
182
183 e29 = e:option(Value, "ban_wan_forward_chain_6", translate("WAN Forward Chain IPv6"))
184 e29.default = "forwarding_wan_rule"
185 e29.datatype = "uciname"
186 e29.optional = true
187
188 e30 = e:option(Value, "ban_lan_input_chain_6", translate("LAN Input Chain IPv6"))
189 e30.default = "input_lan_rule"
190 e30.datatype = "uciname"
191 e30.optional = true
192
193 e31 = e:option(Value, "ban_lan_forward_chain_6", translate("LAN Forward Chain IPv6"))
194 e31.default = "forwarding_lan_rule"
195 e31.datatype = "uciname"
196 e31.optional = true
197
198 e32 = e:option(ListValue, "ban_target_src_6", translate("SRC Target IPv6"))
199 e32:value("REJECT")
200 e32:value("DROP")
201 e32.default = "DROP"
202 e32.optional = true
203
204 e33 = e:option(ListValue, "ban_target_dst_6", translate("DST Target IPv6"))
205 e33:value("REJECT")
206 e33:value("DROP")
207 e33.default = "REJECT"
208 e33.optional = true
209
210 return m