e0e2b1cbcefb45333ff7b8040863274baecc5d09
[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
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10         http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13 ]]--
14 require("luci.http.protocol.date")
15 require("luci.sys")
16 require("luci.tools.webadmin")
17
18 m = Map("system", translate("system"), translate("a_s_desc"))
19
20 s = m:section(TypedSection, "system", "")
21 s.anonymous = true
22
23 local system, model, memtotal, memcached, membuffers, memfree = luci.sys.sysinfo()
24 local uptime = luci.sys.uptime()
25
26 s:option(DummyValue, "_system", translate("system")).value = system
27 s:option(DummyValue, "_cpu", translate("m_i_processor")).value = model
28
29 local load1, load5, load15 = luci.sys.loadavg()
30 s:option(DummyValue, "_la", translate("load")).value = 
31  string.format("%.2f, %.2f, %.2f", load1, load5, load15)
32  
33 s:option(DummyValue, "_memtotal", translate("m_i_memory")).value = 
34  string.format("%.2f MB (%.0f%% %s, %.0f%% %s, %.0f%% %s)",
35   tonumber(memtotal) / 1024,
36   100 * memcached / memtotal,
37   translate("mem_cached") or "",
38   100 * membuffers / memtotal,
39   translate("mem_buffered") or "",
40   100 * memfree / memtotal,
41   translate("mem_free") or "")
42
43 s:option(DummyValue, "_systime", translate("m_i_systemtime")).value =
44  os.date("%c")
45  
46 s:option(DummyValue, "_uptime", translate("m_i_uptime")).value = 
47  luci.tools.webadmin.date_format(tonumber(uptime))
48
49 s:option(Value, "hostname", translate("hostname"))
50
51 tz = s:option(Value, "timezone", translate("timezone"))
52 for k, offset in luci.util.vspairs(luci.http.protocol.date.TZ) do
53         local zone = k:upper()  
54         local osgn = (offset >= 0 and "" or "+")
55         local ohrs = math.floor(-offset / 3600)
56         local omin = (offset % 3600) / 60
57         
58         local ptz = zone .. osgn .. (ohrs ~= 0 and ohrs or "") .. (omin ~= 0 and ":" .. omin or "")
59         local dtz = string.format("%+03d:%02d ", ohrs, omin) .. zone
60         
61         tz:value(ptz, dtz)
62 end
63
64 s:option(Value, "log_size", nil, "kiB").optional = true
65 s:option(Value, "log_ip").optional = true
66 s:option(Value, "conloglevel").optional = true
67 return m