luci-mod-admin-full: limit dns cachesize to 10000
[project/luci.git] / modules / luci-mod-admin-full / luasrc / model / cbi / admin_system / leds.lua
1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Licensed to the public under the Apache License 2.0.
3
4 m = Map("system", translate("<abbr title=\"Light Emitting Diode\">LED</abbr> Configuration"), translate("Customizes the behaviour of the device <abbr title=\"Light Emitting Diode\">LED</abbr>s if possible."))
5
6 local sysfs_path = "/sys/class/leds/"
7 local leds = {}
8
9 local fs   = require "nixio.fs"
10 local nu   = require "nixio.util"
11 local util = require "luci.util"
12
13 if fs.access(sysfs_path) then
14         leds = nu.consume((fs.dir(sysfs_path)))
15 end
16
17 if #leds == 0 then
18         return m
19 end
20
21
22 s = m:section(TypedSection, "led", "")
23 s.anonymous = true
24 s.addremove = true
25
26 function s.parse(self, ...)
27         TypedSection.parse(self, ...)
28         os.execute("/etc/init.d/led enable")
29 end
30
31
32 s:option(Value, "name", translate("Name"))
33
34
35 sysfs = s:option(ListValue, "sysfs", translate("<abbr title=\"Light Emitting Diode\">LED</abbr> Name"))
36 for k, v in ipairs(leds) do
37         sysfs:value(v)
38 end
39
40 s:option(Flag, "default", translate("Default state")).rmempty = false
41
42
43 trigger = s:option(ListValue, "trigger", translate("Trigger"))
44
45 local triggers = fs.readfile(sysfs_path .. leds[1] .. "/trigger")
46 for t in triggers:gmatch("[%w-]+") do
47         trigger:value(t, translate(t:gsub("-", "")))
48 end
49
50
51 delayon = s:option(Value, "delayon", translate ("On-State Delay"))
52 delayon:depends("trigger", "timer")
53
54 delayoff = s:option(Value, "delayoff", translate ("Off-State Delay"))
55 delayoff:depends("trigger", "timer")
56
57
58 dev = s:option(ListValue, "_net_dev", translate("Device"))
59 dev.rmempty = true
60 dev:value("")
61 dev:depends("trigger", "netdev")
62
63 function dev.cfgvalue(self, section)
64         return m.uci:get("system", section, "dev")
65 end
66
67 function dev.write(self, section, value)
68         m.uci:set("system", section, "dev", value)
69 end
70
71 function dev.remove(self, section)
72         local t = trigger:formvalue(section)
73         if t ~= "netdev" and t ~= "usbdev" then
74                 m.uci:delete("system", section, "dev")
75         end
76 end
77
78 for k, v in pairs(luci.sys.net.devices()) do
79         if v ~= "lo" then
80                 dev:value(v)
81         end
82 end
83
84
85 mode = s:option(MultiValue, "mode", translate("Trigger Mode"))
86 mode.rmempty = true
87 mode:depends("trigger", "netdev")
88 mode:value("link", translate("Link On"))
89 mode:value("tx", translate("Transmit"))
90 mode:value("rx", translate("Receive"))
91
92
93 usbdev = s:option(ListValue, "_usb_dev", translate("USB Device"))
94 usbdev:depends("trigger", "usbdev")
95 usbdev.rmempty = true
96 usbdev:value("")
97
98 function usbdev.cfgvalue(self, section)
99         return m.uci:get("system", section, "dev")
100 end
101
102 function usbdev.write(self, section, value)
103         m.uci:set("system", section, "dev", value)
104 end
105
106 function usbdev.remove(self, section)
107         local t = trigger:formvalue(section)
108         if t ~= "netdev" and t ~= "usbdev" then
109                 m.uci:delete("system", section, "dev")
110         end
111 end
112
113
114 usbport = s:option(MultiValue, "port", translate("USB Ports"))
115 usbport:depends("trigger", "usbport")
116 usbport.rmempty = true
117 usbport.widget = "checkbox"
118 usbport.cast = "table"
119 usbport.size = 1
120
121 function usbport.valuelist(self, section)
122         local port, ports = nil, {}
123         for port in util.imatch(m.uci:get("system", section, "port")) do
124                 local b, n = port:match("^usb(%d+)-port(%d+)$")
125                 if not (b and n) then
126                         b, n = port:match("^(%d+)-(%d+)$")
127                 end
128                 if b and n then
129                         ports[#ports+1] = "usb%u-port%u" %{ tonumber(b), tonumber(n) }
130                 end
131         end
132         return ports
133 end
134
135 function usbport.validate(self, value)
136         return type(value) == "string" and { value } or value
137 end
138
139
140 for p in nixio.fs.glob("/sys/bus/usb/devices/[0-9]*/manufacturer") do
141         local id = p:match("%d+-%d+")
142         local mf = nixio.fs.readfile("/sys/bus/usb/devices/" .. id .. "/manufacturer") or "?"
143         local pr = nixio.fs.readfile("/sys/bus/usb/devices/" .. id .. "/product")      or "?"
144         usbdev:value(id, "%s (%s - %s)" %{ id, mf, pr })
145 end
146
147 for p in nixio.fs.glob("/sys/bus/usb/devices/*/usb[0-9]*-port[0-9]*") do
148         local bus, port = p:match("usb(%d+)-port(%d+)")
149         if bus and port then
150                 usbport:value("usb%u-port%u" %{ tonumber(bus), tonumber(port) },
151                               "Hub %u, Port %u" %{ tonumber(bus), tonumber(port) })
152         end
153 end
154
155 port_mask = s:option(Value, "port_mask", translate ("Switch Port Mask"))
156 port_mask:depends("trigger", "switch0")
157
158 return m