2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2010-2012 Jo-Philipp Wich <xm@subsignal.org>
6 Copyright 2010 Manuel Munz <freifunk at somakoma dot de>
8 Licensed under the Apache License, Version 2.0 (the "License");
9 you may not use this file except in compliance with the License.
10 You may obtain a copy of the License at
12 http://www.apache.org/licenses/LICENSE-2.0
23 for _, name in ipairs(luci.sys.init.names()) do
24 local index = luci.sys.init.index(name)
25 local enabled = luci.sys.init.enabled(name)
28 inits["%02i.%s" % { index, name }] = {
30 index = tostring(index),
37 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 inaccessible!</strong>"))
42 s = m:section(Table, inits)
44 i = s:option(DummyValue, "index", translate("Start priority"))
45 n = s:option(DummyValue, "name", translate("Initscript"))
48 e = s:option(Button, "endisable", translate("Enable/Disable"))
50 e.render = function(self, section, scope)
51 if inits[section].enabled then
52 self.title = translate("Enabled")
53 self.inputstyle = "save"
55 self.title = translate("Disabled")
56 self.inputstyle = "reset"
59 Button.render(self, section, scope)
62 e.write = function(self, section)
63 if inits[section].enabled then
64 inits[section].enabled = false
65 return luci.sys.init.disable(inits[section].name)
67 inits[section].enabled = true
68 return luci.sys.init.enable(inits[section].name)
73 start = s:option(Button, "start", translate("Start"))
74 start.inputstyle = "apply"
75 start.write = function(self, section)
76 luci.sys.call("/etc/init.d/%s %s >/dev/null" %{ inits[section].name, self.option })
79 restart = s:option(Button, "restart", translate("Restart"))
80 restart.inputstyle = "reload"
81 restart.write = start.write
83 stop = s:option(Button, "stop", translate("Stop"))
84 stop.inputstyle = "remove"
85 stop.write = start.write
89 f = SimpleForm("rc", translate("Local Startup"),
90 translate("This is the content of /etc/rc.local. Insert your own commands here (in front of 'exit 0') to execute them at the end of the boot process."))
92 t = f:field(TextValue, "rcs")
97 return luci.fs.readfile("/etc/rc.local") or ""
100 function f.handle(self, state, data)
101 if state == FORM_VALID then
103 luci.fs.writefile("/etc/rc.local", data.rcs:gsub("\r\n", "\n"))