modules/admin-full: unify style of headings accross system menus, remove orphaned...
[project/luci.git] / modules / admin-full / luasrc / model / cbi / admin_system / system.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2011 Jo-Philipp Wich <xm@subsignal.org>
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11         http://www.apache.org/licenses/LICENSE-2.0
12
13 $Id$
14 ]]--
15
16 require("luci.sys")
17 require("luci.sys.zoneinfo")
18 require("luci.tools.webadmin")
19 require("luci.fs")
20 require("luci.config")
21
22 local m, s, o
23 local has_ntpd = luci.fs.access("/usr/sbin/ntpd")
24
25
26 m = Map("system", translate("System"), translate("Here you can configure the basic aspects of your device like its hostname or the timezone."))
27 m:chain("luci")
28
29
30 s = m:section(TypedSection, "system", translate("System Properties"))
31 s.anonymous = true
32 s.addremove = false
33
34 s:tab("general",  translate("General Settings"))
35 s:tab("logging",  translate("Logging"))
36 s:tab("language", translate("Language and Style"))
37
38
39 --
40 -- System Properties
41 --
42
43 o = s:taboption("general", DummyValue, "_systime", translate("Local Time"))
44 o.template = "admin_system/clock_status"
45
46
47 o = s:taboption("general", Value, "hostname", translate("Hostname"))
48 o.datatype = "hostname"
49
50 function o.write(self, section, value)
51         Value.write(self, section, value)
52         luci.sys.hostname(value)
53 end
54
55
56 o = s:taboption("general", ListValue, "zonename", translate("Timezone"))
57 o:value("UTC")
58
59 for i, zone in ipairs(luci.sys.zoneinfo.TZ) do
60         o:value(zone[1])
61 end
62
63 function o.write(self, section, value)
64         local function lookup_zone(title)
65                 for _, zone in ipairs(luci.sys.zoneinfo.TZ) do
66                         if zone[1] == title then return zone[2] end
67                 end
68         end
69
70         AbstractValue.write(self, section, value)
71         local timezone = lookup_zone(value) or "GMT0"
72         self.map.uci:set("system", section, "timezone", timezone)
73         luci.fs.writefile("/etc/TZ", timezone .. "\n")
74 end
75
76
77 --
78 -- Logging
79 --
80
81 o = s:taboption("logging", Value, "log_size", translate("System log buffer size"), "kiB")
82 o.optional    = true
83 o.placeholder = 16
84 o.datatype    = "uinteger"
85
86 o = s:taboption("logging", Value, "log_ip", translate("External system log server"))
87 o.optional    = true
88 o.placeholder = "0.0.0.0"
89 o.datatype    = "ip4addr"
90
91 o = s:taboption("logging", Value, "log_port", translate("External system log server port"))
92 o.optional    = true
93 o.placeholder = 514
94 o.datatype    = "port"
95
96 o = s:taboption("logging", ListValue, "conloglevel", translate("Log output level"))
97 o:value(8, translate("Debug"))
98 o:value(7, translate("Info"))
99 o:value(6, translate("Notice"))
100 o:value(5, translate("Warning"))
101 o:value(4, translate("Error"))
102 o:value(3, translate("Critical"))
103 o:value(2, translate("Alert"))
104 o:value(1, translate("Emergency"))
105
106 o = s:taboption("logging", ListValue, "cronloglevel", translate("Cron Log Level"))
107 o.default = 8
108 o:value(5, translate("Debug"))
109 o:value(8, translate("Normal"))
110 o:value(9, translate("Warning"))
111
112
113 --
114 -- Langauge & Style
115 --
116
117 o = s:taboption("language", ListValue, "_lang", translate("Language"))
118 o:value("auto")
119
120 local i18ndir = luci.i18n.i18ndir .. "base."
121 for k, v in luci.util.kspairs(luci.config.languages) do
122         local file = i18ndir .. k:gsub("_", "-")
123         if k:sub(1, 1) ~= "." and luci.fs.access(file .. ".lmo") then
124                 o:value(k, v)
125         end
126 end
127
128 function o.cfgvalue(...)
129         return m.uci:get("luci", "main", "lang")
130 end
131
132 function o.write(self, section, value)
133         m.uci:set("luci", "main", "lang", value)
134 end
135
136
137 o = s:taboption("language", ListValue, "_mediaurlbase", translate("Design"))
138 for k, v in pairs(luci.config.themes) do
139         if k:sub(1, 1) ~= "." then
140                 o:value(v, k)
141         end
142 end
143
144 function o.cfgvalue(...)
145         return m.uci:get("luci", "main", "mediaurlbase")
146 end
147
148 function o.write(self, section, value)
149         m.uci:set("luci", "main", "mediaurlbase", value)
150 end
151
152
153 --
154 -- NTP
155 --
156
157 if has_ntpd then
158         s = m:section(TypedSection, "timeserver", translate("Time Synchronization"))
159         s.anonymous = true
160         s.addremove = false
161
162         o = s:option(Flag, "enable", translate("Enable builtin NTP server"))
163         o.rmempty = false
164
165         function o.cfgvalue(self)
166                 return luci.sys.init.enabled("sysntpd")
167                         and self.enabled or self.disabled
168         end
169
170         function o.write(self, section, value)
171                 if value == self.enabled then
172                         luci.sys.init.enable("sysntpd")
173                         luci.sys.call("env -i /etc/init.d/sysntpd start >/dev/null")
174                 else
175                         luci.sys.call("env -i /etc/init.d/sysntpd stop >/dev/null")
176                         luci.sys.init.disable("sysntpd")
177                 end
178         end
179
180
181         o = s:option(DynamicList, "server", translate("NTP server candidates"))
182         o.datatype = "host"
183         o:depends("enable", "1")
184
185         -- retain server list even if disabled
186         function o.remove() end
187 end
188
189
190 return m