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
17 local fs = require "nixio.fs"
18 local sys = require "luci.sys"
22 for _, name in ipairs(sys.init.names()) do
23 local index = sys.init.index(name)
24 local enabled = sys.init.enabled(name)
27 inits["%02i.%s" % { index, name }] = {
29 index = tostring(index),
36 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>"))
41 s = m:section(Table, inits)
43 i = s:option(DummyValue, "index", translate("Start priority"))
44 n = s:option(DummyValue, "name", translate("Initscript"))
47 e = s:option(Button, "endisable", translate("Enable/Disable"))
49 e.render = function(self, section, scope)
50 if inits[section].enabled then
51 self.title = translate("Enabled")
52 self.inputstyle = "save"
54 self.title = translate("Disabled")
55 self.inputstyle = "reset"
58 Button.render(self, section, scope)
61 e.write = function(self, section)
62 if inits[section].enabled then
63 inits[section].enabled = false
64 return sys.init.disable(inits[section].name)
66 inits[section].enabled = true
67 return sys.init.enable(inits[section].name)
72 start = s:option(Button, "start", translate("Start"))
73 start.inputstyle = "apply"
74 start.write = function(self, section)
75 sys.call("/etc/init.d/%s %s >/dev/null" %{ inits[section].name, self.option })
78 restart = s:option(Button, "restart", translate("Restart"))
79 restart.inputstyle = "reload"
80 restart.write = start.write
82 stop = s:option(Button, "stop", translate("Stop"))
83 stop.inputstyle = "remove"
84 stop.write = start.write
88 f = SimpleForm("rc", translate("Local Startup"),
89 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."))
91 t = f:field(TextValue, "rcs")
96 return fs.readfile("/etc/rc.local") or ""
99 function f.handle(self, state, data)
100 if state == FORM_VALID then
102 fs.writefile("/etc/rc.local", data.rcs:gsub("\r\n", "\n"))