luci-0.9: merge r5758
[project/luci.git] / applications / luci-initmgr / luasrc / model / cbi / init / init.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 $Id$
14 ]]--
15
16 require("luci.sys")
17 require("luci.util")
18
19 local inits = { }
20
21 for _, name in ipairs(luci.sys.init.names()) do
22 local index = luci.sys.init.index(name)
23 local enabled = luci.sys.init.enabled(name)
24
25 inits["%02i.%s" % { index, name }] = {
26 name = name,
27 index = tostring(index),
28 enabled = enabled
29 }
30 end
31
32
33 m = SimpleForm("initmgr", translate("initmgr"), translate("initmgr_desc"))
34 m.reset = false
35
36 s = m:section(Table, inits)
37
38 i = s:option(DummyValue, "index", translate("initmgr_index"))
39 n = s:option(DummyValue, "name", translate("initmgr_name"))
40
41 e = s:option(Flag, "enabled", translate("initmgr_enabled"))
42 e.rmempty = false
43
44 e.cfgvalue = function(self, section)
45 return inits[section].enabled and "1" or "0"
46 end
47
48 e.write = function(self, section, value)
49 if value == "1" and not inits[section].enabled then
50 inits[section].enabled = true
51 return luci.sys.init.enable(inits[section].name)
52 elseif value == "0" and inits[section].enabled then
53 inits[section].enabled = false
54 return luci.sys.init.disable(inits[section].name)
55 end
56 return true
57 end
58
59 return m