d988b3a332a8c8acd7b0af3d1b84e8bffdff77d4
[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("Initscripts"), translate("You can enable or disable installed init scripts here. Changes will applied after a device reboot.<br /><strong>Warning: If you disable essential init scripts like \"network\", your device might become inaccesable!</strong>"))
34 m.reset = false
35 m.submit = false
36
37
38 s = m:section(Table, inits)
39
40 i = s:option(DummyValue, "index", translate("Start priority"))
41 n = s:option(DummyValue, "name", translate("Initscript"))
42
43
44 e = s:option(Button, "endisable", translate("Enable/Disable"))
45
46 e.render = function(self, section, scope)
47         if inits[section].enabled then
48                 self.title = translate("Enabled")
49                 self.inputstyle = "save"
50         else
51                 self.title = translate("Disabled")
52                 self.inputstyle = "reset"
53         end
54
55         Button.render(self, section, scope)
56 end
57
58 e.write = function(self, section)
59         if inits[section].enabled then
60                 inits[section].enabled = false
61                 return luci.sys.init.disable(inits[section].name)
62         else
63                 inits[section].enabled = true
64                 return luci.sys.init.enable(inits[section].name)
65         end
66 end
67
68
69 start = s:option(Button, "start", translate("Start"))
70 start.inputstyle = "apply"
71 start.write = function(self, section)
72         luci.sys.call("/etc/init.d/%s %s" %{ inits[section].name, self.option })
73 end
74
75 restart = s:option(Button, "restart", translate("Restart"))
76 restart.inputstyle = "reload"
77 restart.write = start.write
78
79 stop = s:option(Button, "stop", translate("Stop"))
80 stop.inputstyle = "remove"
81 stop.write = start.write
82
83
84 return m