Globally reduce copyright headers
[project/luci.git] / modules / luci-mod-admin-full / luasrc / model / cbi / admin_system / startup.lua
1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Copyright 2010-2012 Jo-Philipp Wich <xm@subsignal.org>
3 -- Copyright 2010 Manuel Munz <freifunk at somakoma dot de>
4 -- Licensed to the public under the Apache License 2.0.
5
6 local fs = require "nixio.fs"
7 local sys = require "luci.sys"
8
9 local inits = { }
10
11 for _, name in ipairs(sys.init.names()) do
12 local index = sys.init.index(name)
13 local enabled = sys.init.enabled(name)
14
15 if index < 255 then
16 inits["%02i.%s" % { index, name }] = {
17 name = name,
18 index = tostring(index),
19 enabled = enabled
20 }
21 end
22 end
23
24
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>"))
26 m.reset = false
27 m.submit = false
28
29
30 s = m:section(Table, inits)
31
32 i = s:option(DummyValue, "index", translate("Start priority"))
33 n = s:option(DummyValue, "name", translate("Initscript"))
34
35
36 e = s:option(Button, "endisable", translate("Enable/Disable"))
37
38 e.render = function(self, section, scope)
39 if inits[section].enabled then
40 self.title = translate("Enabled")
41 self.inputstyle = "save"
42 else
43 self.title = translate("Disabled")
44 self.inputstyle = "reset"
45 end
46
47 Button.render(self, section, scope)
48 end
49
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)
54 else
55 inits[section].enabled = true
56 return sys.init.enable(inits[section].name)
57 end
58 end
59
60
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 })
65 end
66
67 restart = s:option(Button, "restart", translate("Restart"))
68 restart.inputstyle = "reload"
69 restart.write = start.write
70
71 stop = s:option(Button, "stop", translate("Stop"))
72 stop.inputstyle = "remove"
73 stop.write = start.write
74
75
76
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."))
79
80 t = f:field(TextValue, "rcs")
81 t.rmempty = true
82 t.rows = 20
83
84 function t.cfgvalue()
85 return fs.readfile("/etc/rc.local") or ""
86 end
87
88 function f.handle(self, state, data)
89 if state == FORM_VALID then
90 if data.rcs then
91 fs.writefile("/etc/rc.local", data.rcs:gsub("\r\n", "\n"))
92 end
93 end
94 return true
95 end
96
97 return m, f