Update qos.lua to add custom QOS classes to luci droplist
[project/luci.git] / applications / luci-app-qos / luasrc / model / cbi / qos / qos.lua
1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Licensed to the public under the Apache License 2.0.
3
4 local wa = require "luci.tools.webadmin"
5 local fs = require "nixio.fs"
6
7 m = Map("qos", translate("Quality of Service"),
8         translate("With <abbr title=\"Quality of Service\">QoS</abbr> you " ..
9                 "can prioritize network traffic selected by addresses, " ..
10                 "ports or services."))
11
12 s = m:section(TypedSection, "interface", translate("Interfaces"))
13 s.addremove = true
14 s.anonymous = false
15
16 e = s:option(Flag, "enabled", translate("Enable"))
17 e.rmempty = false
18
19 c = s:option(ListValue, "classgroup", translate("Classification group"))
20 c:value("Default", translate("default"))
21 c.default = "Default"
22
23 s:option(Flag, "overhead", translate("Calculate overhead"))
24
25 s:option(Flag, "halfduplex", translate("Half-duplex"))
26
27 dl = s:option(Value, "download", translate("Download speed (kbit/s)"))
28 dl.datatype = "and(uinteger,min(1))"
29
30 ul = s:option(Value, "upload", translate("Upload speed (kbit/s)"))
31 ul.datatype = "and(uinteger,min(1))"
32
33 s = m:section(TypedSection, "classify", translate("Classification Rules"))
34 s.template = "cbi/tblsection"
35 s.anonymous = true
36 s.addremove = true
37 s.sortable  = true
38
39 t = s:option(ListValue, "target", translate("Target"))
40 t:value("Priority", translate("priority"))
41 t:value("Express", translate("express"))
42 t:value("Normal", translate("normal"))
43 t:value("Bulk", translate("low"))
44
45 local uci = require "luci.model.uci"
46 uci.cursor():foreach("qos", "class",
47     function (section)
48         local n = section[".name"]
49         if string.sub(n,-string.len("_down"))~="_down" then
50             t:value(n)
51         end
52     end)
53
54 t.default = "Normal"
55
56 srch = s:option(Value, "srchost", translate("Source host"))
57 srch.rmempty = true
58 srch:value("", translate("all"))
59 wa.cbi_add_knownips(srch)
60
61 dsth = s:option(Value, "dsthost", translate("Destination host"))
62 dsth.rmempty = true
63 dsth:value("", translate("all"))
64 wa.cbi_add_knownips(dsth)
65
66 l7 = s:option(ListValue, "layer7", translate("Service"))
67 l7.rmempty = true
68 l7:value("", translate("all"))
69
70 local pats = io.popen("find /etc/l7-protocols/ -type f -name '*.pat'")
71 if pats then
72         local l
73         while true do
74                 l = pats:read("*l")
75                 if not l then break end
76
77                 l = l:match("([^/]+)%.pat$")
78                 if l then
79                         l7:value(l)
80                 end
81         end
82         pats:close()
83 end
84
85 p = s:option(Value, "proto", translate("Protocol"))
86 p:value("", translate("all"))
87 p:value("tcp", "TCP")
88 p:value("udp", "UDP")
89 p:value("icmp", "ICMP")
90 p.rmempty = true
91
92 ports = s:option(Value, "ports", translate("Ports"))
93 ports.rmempty = true
94 ports:value("", translate("all"))
95
96 bytes = s:option(Value, "connbytes", translate("Number of bytes"))
97
98 comment = s:option(Value, "comment", translate("Comment"))
99
100 return m