1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Copyright 2010-2012 Jo-Philipp Wich <jow@openwrt.org>
3 -- Copyright 2010 Manuel Munz <freifunk at somakoma dot de>
4 -- Licensed to the public under the Apache License 2.0.
6 local fs = require "nixio.fs"
7 local sys = require "luci.sys"
11 for _, name in ipairs(sys.init.names()) do
12 local index = sys.init.index(name)
13 local enabled = sys.init.enabled(name)
16 inits["%02i.%s" % { index, name }] = {
18 index = tostring(index),
25 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>"))
30 s = m:section(Table, inits)
32 i = s:option(DummyValue, "index", translate("Start priority"))
33 n = s:option(DummyValue, "name", translate("Initscript"))
36 e = s:option(Button, "endisable", translate("Enable/Disable"))
38 e.render = function(self, section, scope)
39 if inits[section].enabled then
40 self.title = translate("Enabled")
41 self.inputstyle = "save"
43 self.title = translate("Disabled")
44 self.inputstyle = "reset"
47 Button.render(self, section, scope)
50 e.write = function(self, section)
51 if inits[section].enabled then
52 inits[section].enabled = false
53 return sys.init.disable(inits[section].name)
55 inits[section].enabled = true
56 return sys.init.enable(inits[section].name)
61 start = s:option(Button, "start", translate("Start"))
62 start.inputstyle = "apply"
63 start.write = function(self, section)
64 sys.call("/etc/init.d/%s %s >/dev/null" %{ inits[section].name, self.option })
67 restart = s:option(Button, "restart", translate("Restart"))
68 restart.inputstyle = "reload"
69 restart.write = start.write
71 stop = s:option(Button, "stop", translate("Stop"))
72 stop.inputstyle = "remove"
73 stop.write = start.write
77 f = SimpleForm("rc", translate("Local Startup"),
78 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."))
80 t = f:field(TextValue, "rcs")
86 return fs.readfile("/etc/rc.local") or ""
89 function f.handle(self, state, data)
90 if state == FORM_VALID then
92 fs.writefile("/etc/rc.local", data.rcs:gsub("\r\n", "\n"))
94 fs.writefile("/etc/rc.local", "")