luci-appnft-qos: add missing translation wrapper
[project/luci.git] / applications / luci-app-nft-qos / luasrc / model / cbi / nft-qos / nft-qos.lua
1 -- Copyright 2018 Rosy Song <rosysong@rosinson.com>
2 -- Licensed to the public under the Apache License 2.0.
3
4 local uci = require("luci.model.uci").cursor()
5 local wa = require("luci.tools.webadmin")
6 local fs = require("nixio.fs")
7 local ipc = require("luci.ip")
8
9 local def_rate_dl = uci:get("nft-qos", "default", "static_rate_dl")
10 local def_rate_ul = uci:get("nft-qos", "default", "static_rate_ul")
11 local def_unit_dl = uci:get("nft-qos", "default", "static_unit_dl")
12 local def_unit_ul = uci:get("nft-qos", "default", "static_unit_ul")
13
14 local def_up = uci:get("nft-qos", "default", "dynamic_bw_up")
15 local def_down = uci:get("nft-qos", "default", "dynamic_bw_down")
16
17 local limit_enable = uci:get("nft-qos", "default", "limit_enable")
18 local limit_mac_enable = uci:get("nft-qos", "default", "limit_mac_enable")
19 local limit_type = uci:get("nft-qos", "default", "limit_type")
20 local enable_priority = uci:get("nft-qos", "default", "priority_enable")
21
22 local has_ipv6 = fs.access("/proc/net/ipv6_route")
23
24 m = Map("nft-qos", translate("QoS over Nftables"))
25
26 --
27 -- Taboptions
28 --
29 s = m:section(TypedSection, "default", translate("NFT-QoS Settings"))
30 s.addremove = false
31 s.anonymous = true
32
33 s:tab("limit", translate("Limit Rate by IP Address"))
34 s:tab("limitmac", translate("Limit Rate by Mac Address"))
35 s:tab("priority", translate("Traffic Priority"))
36
37 --
38 -- Static
39 --
40 o = s:taboption("limit", Flag, "limit_enable", translate("Limit Enable"), translate("Enable Limit Rate Feature"))
41 o.default = limit_enable or o.enabled
42 o.rmempty = false
43
44 o = s:taboption("limit", ListValue, "limit_type", translate("Limit Type"), translate("Type of Limit Rate"))
45 o.default = limit_static or "static"
46 o:depends("limit_enable","1")
47 o:value("static", "Static")
48 o:value("dynamic", "Dynamic")
49
50 o = s:taboption("limit", Value, "static_rate_dl", translate("Default Download Rate"), translate("Default value for download rate"))
51 o.datatype = "uinteger"
52 o.default = def_rate_dl or '50'
53 o:depends("limit_type","static")
54
55 o = s:taboption("limit", ListValue, "static_unit_dl", translate("Default Download Unit"), translate("Default unit for download rate"))
56 o.default = def_unit_dl or "kbytes"
57 o:depends("limit_type","static")
58 o:value("bytes", "Bytes/s")
59 o:value("kbytes", "KBytes/s")
60 o:value("mbytes", "MBytes/s")
61
62 o = s:taboption("limit", Value, "static_rate_ul", translate("Default Upload Rate"), translate("Default value for upload rate"))
63 o.datatype = "uinteger"
64 o.default = def_rate_ul or '50'
65 o:depends("limit_type","static")
66
67 o = s:taboption("limit", ListValue, "static_unit_ul", translate("Default Upload Unit"), translate("Default unit for upload rate"))
68 o.default = def_unit_ul or "kbytes"
69 o:depends("limit_type","static")
70 o:value("bytes", "Bytes/s")
71 o:value("kbytes", "KBytes/s")
72 o:value("mbytes", "MBytes/s")
73
74 --
75 -- Dynamic
76 --
77 o = s:taboption("limit", Value, "dynamic_bw_down", translate("Download Bandwidth (Mbps)"), translate("Default value for download bandwidth"))
78 o.default = def_up or '100'
79 o.datatype = "uinteger"
80 o:depends("limit_type","dynamic")
81
82 o = s:taboption("limit", Value, "dynamic_bw_up", translate("Upload Bandwidth (Mbps)"), translate("Default value for upload bandwidth"))
83 o.default = def_down or '100'
84 o.datatype = "uinteger"
85 o:depends("limit_type","dynamic")
86
87 o = s:taboption("limit", Value, "dynamic_cidr", translate("Target Network (IPv4/MASK)"), translate("Network to be applied, e.g. 192.168.1.0/24, 10.2.0.0/16, etc."))
88 o.datatype = "cidr4"
89 ipc.routes({ family = 4, type = 1 }, function(rt) o.default = rt.dest end)
90 o:depends("limit_type","dynamic")
91
92 if has_ipv6 then
93 o = s:taboption("limit", Value, "dynamic_cidr6", translate("Target Network6 (IPv6/MASK)"), translate("Network to be applied, e.g. AAAA::BBBB/64, CCCC::1/128, etc."))
94 o.datatype = "cidr6"
95 o:depends("limit_type","dynamic")
96 end
97
98 o = s:taboption("limit", DynamicList, "limit_whitelist", translate("White List for Limit Rate"))
99 o.datatype = "ipaddr"
100 o:depends("limit_enable","1")
101
102 --
103 -- limit speed by mac address
104 --
105 o = s:taboption("limitmac", Flag, "limit_mac_enable", translate("Limit Enable"), translate("Enable Limit Rate Feature"))
106 o.default = limit_mac_enable or o.enabled
107 o.rmempty = false
108
109 --
110 -- Priority
111 --
112 o = s:taboption("priority", Flag, "priority_enable", translate("Enable Traffic Priority"), translate("Enable this feature"))
113 o.default = enable_priority or o.enabled
114 o.rmempty = false
115
116 o = s:taboption("priority", ListValue, "priority_netdev", translate("Default Network Interface"), translate("Network Interface for Traffic Shaping, e.g. br-lan, eth0.1, eth0, etc."))
117 o:depends("priority_enable", "1")
118 wa.cbi_add_networks(o)
119
120 --
121 -- Static Limit Rate - Download Rate
122 --
123 if limit_enable == "1" and limit_type == "static" then
124
125 x = m:section(TypedSection, "download", translate("Static QoS-Download Rate"))
126 x.anonymous = true
127 x.addremove = true
128 x.template = "cbi/tblsection"
129
130 o = x:option(Value, "hostname", translate("Hostname"))
131 o.datatype = "hostname"
132 o.default = 'undefined'
133
134 if has_ipv6 then
135 o = x:option(Value, "ipaddr", translate("IP Address (v4 / v6)"))
136 else
137 o = x:option(Value, "ipaddr", translate("IP Address (v4 Only)"))
138 end
139 o.datatype = "ipaddr"
140 if nixio.fs.access("/tmp/dhcp.leases") or nixio.fs.access("/var/dhcp6.leases") then
141 o.titleref = luci.dispatcher.build_url("admin", "status", "overview")
142 end
143
144 o = x:option(Value, "rate", translate("Rate"))
145 o.default = def_rate_dl or '50'
146 o.size = 4
147 o.datatype = "uinteger"
148
149 o = x:option(ListValue, "unit", translate("Unit"))
150 o.default = def_unit_dl or "kbytes"
151 o:value("bytes", "Bytes/s")
152 o:value("kbytes", "KBytes/s")
153 o:value("mbytes", "MBytes/s")
154
155 --
156 -- Static Limit Rate - Upload Rate
157 --
158 y = m:section(TypedSection, "upload", translate("Static QoS-Upload Rate"))
159 y.anonymous = true
160 y.addremove = true
161 y.template = "cbi/tblsection"
162
163 o = y:option(Value, "hostname", translate("Hostname"))
164 o.datatype = "hostname"
165 o.default = 'undefined'
166
167 if has_ipv6 then
168 o = y:option(Value, "ipaddr", translate("IP Address (v4 / v6)"))
169 else
170 o = y:option(Value, "ipaddr", translate("IP Address (v4 Only)"))
171 end
172 o.datatype = "ipaddr"
173 if nixio.fs.access("/tmp/dhcp.leases") or nixio.fs.access("/var/dhcp6.leases") then
174 o.titleref = luci.dispatcher.build_url("admin", "status", "overview")
175 end
176
177 o = y:option(Value, "macaddr", translate("MAC (optional)"))
178 o.rmempty = true
179 o.datatype = "macaddr"
180
181 o = y:option(Value, "rate", translate("Rate"))
182 o.default = def_rate_ul or '50'
183 o.size = 4
184 o.datatype = "uinteger"
185
186 o = y:option(ListValue, "unit", translate("Unit"))
187 o.default = def_unit_ul or "kbytes"
188 o:value("bytes", "Bytes/s")
189 o:value("kbytes", "KBytes/s")
190 o:value("mbytes", "MBytes/s")
191
192 end
193
194 --
195 -- Traffic Priority Settings
196 --
197 if enable_priority == "1" then
198
199 s = m:section(TypedSection, "priority", translate("Traffic Priority Settings"))
200 s.anonymous = true
201 s.addremove = true
202 s.template = "cbi/tblsection"
203
204 o = s:option(ListValue, "protocol", translate("Protocol"))
205 o.default = "tcp"
206 o:value("tcp", "TCP")
207 o:value("udp", "UDP")
208 o:value("udplite", "UDP-Lite")
209 o:value("sctp", "SCTP")
210 o:value("dccp", "DCCP")
211
212 o = s:option(ListValue, "priority", translate("Priority"))
213 o.default = "1"
214 o:value("-400", "1")
215 o:value("-300", "2")
216 o:value("-225", "3")
217 o:value("-200", "4")
218 o:value("-150", "5")
219 o:value("-100", "6")
220 o:value("0", "7")
221 o:value("50", "8")
222 o:value("100", "9")
223 o:value("225", "10")
224 o:value("300", "11")
225
226 o = s:option(Value, "service", translate("Service"), translate("e.g. https, 23, (separator is comma)"))
227 o.default = '?'
228
229 o = s:option(Value, "comment", translate("Comment"))
230 o.default = '?'
231
232 end
233
234 --
235 -- Static By Mac Address
236 --
237 if limit_mac_enable == "1" then
238
239 x = m:section(TypedSection, "client", translate("Limit Traffic Rate By Mac Address"))
240 x.anonymous = true
241 x.addremove = true
242 x.template = "cbi/tblsection"
243
244 o = x:option(Value, "hostname", translate("Hostname"))
245 o.datatype = "hostname"
246 o.default = ''
247
248 o = x:option(Value, "macaddr", translate("MAC Address"))
249 o.rmempty = true
250 o.datatype = "macaddr"
251
252 o = x:option(Value, "drate", translate("Download Rate"))
253 o.default = def_rate_dl or '50'
254 o.size = 4
255 o.datatype = "uinteger"
256
257 o = x:option(ListValue, "drunit", translate("Unit"))
258 o.default = def_unit_dl or "kbytes"
259 o:value("bytes", "Bytes/s")
260 o:value("kbytes", "KBytes/s")
261 o:value("mbytes", "MBytes/s")
262
263 o = x:option(Value, "urate", translate("Upload Rate"))
264 o.default = def_rate_ul or '50'
265 o.size = 4
266 o.datatype = "uinteger"
267
268 o = x:option(ListValue, "urunit", translate("Unit"))
269 o.default = def_unit_ul or "kbytes"
270 o:value("bytes", "Bytes/s")
271 o:value("kbytes", "KBytes/s")
272 o:value("mbytes", "MBytes/s")
273
274 end
275
276 return m