ed7701222e90ed2092e132e1d9e88dffa444c47b
[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 m = Map("system", translate("System"), translate("Here you can configure the basic aspects of your device like its hostname or the timezone."))
23 m:chain("luci")
24
25 local has_rdate = false
26
27 m.uci:foreach("system", "rdate",
28         function()
29                 has_rdate = true
30                 return false
31         end)
32
33
34 s = m:section(TypedSection, "system", translate("System Properties"))
35 s.anonymous = true
36 s.addremove = false
37
38 s:tab("general",  translate("General Settings"))
39 s:tab("logging",  translate("Logging"))
40 s:tab("language", translate("Language and Style"))
41
42
43 --
44 -- System Properties
45 --
46
47 clock = s:taboption("general", DummyValue, "_systime", translate("Local Time"))
48 clock.template = "admin_system/clock_status"
49
50
51 hn = s:taboption("general", Value, "hostname", translate("Hostname"))
52 hn.datatype = "hostname"
53
54 function hn.write(self, section, value)
55         Value.write(self, section, value)
56         luci.sys.hostname(value)
57 end
58
59
60 tz = s:taboption("general", ListValue, "zonename", translate("Timezone"))
61 tz:value("UTC")
62
63 for i, zone in ipairs(luci.sys.zoneinfo.TZ) do
64         tz:value(zone[1])
65 end
66
67 function tz.write(self, section, value)
68         local function lookup_zone(title)
69                 for _, zone in ipairs(luci.sys.zoneinfo.TZ) do
70                         if zone[1] == title then return zone[2] end
71                 end
72         end
73
74         AbstractValue.write(self, section, value)
75         local timezone = lookup_zone(value) or "GMT0"
76         self.map.uci:set("system", section, "timezone", timezone)
77         luci.fs.writefile("/etc/TZ", timezone .. "\n")
78 end
79
80
81 --
82 -- Logging
83 --
84
85 o = s:taboption("logging", Value, "log_size", translate("System log buffer size"), "kiB")
86 o.optional    = true
87 o.placeholder = 16
88 o.datatype    = "uinteger"
89
90 o = s:taboption("logging", Value, "log_ip", translate("External system log server"))
91 o.optional    = true
92 o.placeholder = "0.0.0.0"
93 o.datatype    = "ip4addr"
94
95 o = s:taboption("logging", Value, "log_port", translate("External system log server port"))
96 o.optional    = true
97 o.placeholder = 514
98 o.datatype    = "port"
99
100 o = s:taboption("logging", ListValue, "conloglevel", translate("Log output level"))
101 o:value(8, translate("Debug"))
102 o:value(7, translate("Info"))
103 o:value(6, translate("Notice"))
104 o:value(5, translate("Warning"))
105 o:value(4, translate("Error"))
106 o:value(3, translate("Critical"))
107 o:value(2, translate("Alert"))
108 o:value(1, translate("Emergency"))
109
110 o = s:taboption("logging", ListValue, "cronloglevel", translate("Cron Log Level"))
111 o.default = 8
112 o:value(5, translate("Debug"))
113 o:value(8, translate("Normal"))
114 o:value(9, translate("Warning"))
115
116
117 --
118 -- Langauge & Style
119 --
120
121 o = s:taboption("language", ListValue, "_lang", translate("Language"))
122 o:value("auto")
123
124 local i18ndir = luci.i18n.i18ndir .. "base."
125 for k, v in luci.util.kspairs(luci.config.languages) do
126         local file = i18ndir .. k:gsub("_", "-")
127         if k:sub(1, 1) ~= "." and luci.fs.access(file .. ".lmo") then
128                 o:value(k, v)
129         end
130 end
131
132 function o.cfgvalue(...)
133         return m.uci:get("luci", "main", "lang")
134 end
135
136 function o.write(self, section, value)
137         m.uci:set("luci", "main", "lang", value)
138 end
139
140
141 o = s:taboption("language", ListValue, "_mediaurlbase", translate("Design"))
142 for k, v in pairs(luci.config.themes) do
143         if k:sub(1, 1) ~= "." then
144                 o:value(v, k)
145         end
146 end
147
148 function o.cfgvalue(...)
149         return m.uci:get("luci", "main", "mediaurlbase")
150 end
151
152 function o.write(self, section, value)
153         m.uci:set("luci", "main", "mediaurlbase", value)
154 end
155
156
157 --
158 -- Rdate
159 --
160
161 if has_rdate then
162         m2 = Map("timeserver", translate("Time Server (rdate)"))
163         s = m2:section(TypedSection, "timeserver")
164         s.anonymous = true
165         s.addremove = true
166         s.template = "cbi/tblsection"
167
168         h = s:option(Value, "hostname", translate("Name"))
169         h.rmempty = true
170         h.datatype = host
171         i = s:option(ListValue, "interface", translate("Interface"))
172         i.rmempty = true
173         i:value("", translate("Default"))
174         m2.uci:foreach("network", "interface",
175                 function (section)
176                         local ifc = section[".name"]
177                         if ifc ~= "loopback" then
178                                 i:value(ifc)
179                         end
180                 end
181         )
182 end
183
184
185 return m, m2