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"
12 for _, name in ipairs(sys.init.names()) do
13 local index = sys.init.index(name)
14 local enabled = sys.init.enabled(name)
17 inits["%02i.%s" % { index, name }] = {
19 index = tostring(index),
26 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>"))
31 s = m:section(Table, inits)
33 i = s:option(DummyValue, "index", translate("Start priority"))
34 n = s:option(DummyValue, "name", translate("Initscript"))
37 e = s:option(Button, "endisable", translate("Enable/Disable"))
39 e.render = function(self, section, scope)
40 if inits[section].enabled then
41 self.title = translate("Enabled")
42 self.inputstyle = "save"
44 self.title = translate("Disabled")
45 self.inputstyle = "reset"
48 Button.render(self, section, scope)
51 e.write = function(self, section)
52 if inits[section].enabled then
54 inits[section].enabled = false
55 return sys.init.disable(inits[section].name)
58 inits[section].enabled = true
59 return sys.init.enable(inits[section].name)
64 start = s:option(Button, "start", translate("Start"))
65 start.inputstyle = "apply"
66 start.write = function(self, section)
68 sys.call("/etc/init.d/%s %s >/dev/null" %{ inits[section].name, self.option })
71 restart = s:option(Button, "restart", translate("Restart"))
72 restart.inputstyle = "reload"
73 restart.write = start.write
75 stop = s:option(Button, "stop", translate("Stop"))
76 stop.inputstyle = "remove"
77 stop.write = start.write
81 f = SimpleForm("rc", translate("Local Startup"),
82 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."))
84 t = f:field(TextValue, "rcs")
90 return fs.readfile("/etc/rc.local") or ""
93 function f.handle(self, state, data)
94 if not handled and state == FORM_VALID then
96 fs.writefile("/etc/rc.local", data.rcs:gsub("\r\n", "\n"))
98 fs.writefile("/etc/rc.local", "")