X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=modules%2Fadmin-full%2Fluasrc%2Fmodel%2Fcbi%2Fadmin_system%2Fsystem.lua;h=3a884c4813777401e97122fd24a80d1ab7a2bd03;hp=a2bbf29b6732fbce17011db27c1b33adb53f6103;hb=00f8f2fbb0995b1b307f2edcc26379be6fc55425;hpb=103e532246f60ae9f3368fc3be454695ad21cd6e diff --git a/modules/admin-full/luasrc/model/cbi/admin_system/system.lua b/modules/admin-full/luasrc/model/cbi/admin_system/system.lua index a2bbf29b6..3a884c481 100644 --- a/modules/admin-full/luasrc/model/cbi/admin_system/system.lua +++ b/modules/admin-full/luasrc/model/cbi/admin_system/system.lua @@ -2,6 +2,7 @@ LuCI - Lua Configuration Interface Copyright 2008 Steven Barth +Copyright 2011 Jo-Philipp Wich Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -16,56 +17,49 @@ require("luci.sys") require("luci.sys.zoneinfo") require("luci.tools.webadmin") require("luci.fs") +require("luci.config") + +local m, s, o +local has_ntpd = luci.fs.access("/usr/sbin/ntpd") m = Map("system", translate("System"), translate("Here you can configure the basic aspects of your device like its hostname or the timezone.")) +m:chain("luci") + -s = m:section(TypedSection, "system", "") +s = m:section(TypedSection, "system", translate("System Properties")) s.anonymous = true s.addremove = false -local system, model, memtotal, memcached, membuffers, memfree = luci.sys.sysinfo() -local uptime = luci.sys.uptime() - -s:option(DummyValue, "_system", translate("System")).value = system -s:option(DummyValue, "_cpu", translate("Processor")).value = model +s:tab("general", translate("General Settings")) +s:tab("logging", translate("Logging")) +s:tab("language", translate("Language and Style")) -local load1, load5, load15 = luci.sys.loadavg() -s:option(DummyValue, "_la", translate("Load")).value = - string.format("%.2f, %.2f, %.2f", load1, load5, load15) -s:option(DummyValue, "_memtotal", translate("Memory")).value = - string.format("%.2f MB (%.0f%% %s, %.0f%% %s, %.0f%% %s)", - tonumber(memtotal) / 1024, - 100 * memcached / memtotal, - tostring(translate("cached")), - 100 * membuffers / memtotal, - tostring(translate("buffered")), - 100 * memfree / memtotal, - tostring(translate("free")) -) +-- +-- System Properties +-- -s:option(DummyValue, "_systime", translate("Local Time")).value = - os.date("%c") +o = s:taboption("general", DummyValue, "_systime", translate("Local Time")) +o.template = "admin_system/clock_status" -s:option(DummyValue, "_uptime", translate("Uptime")).value = - luci.tools.webadmin.date_format(tonumber(uptime)) -hn = s:option(Value, "hostname", translate("Hostname")) +o = s:taboption("general", Value, "hostname", translate("Hostname")) +o.datatype = "hostname" -function hn.write(self, section, value) +function o.write(self, section, value) Value.write(self, section, value) luci.sys.hostname(value) end -tz = s:option(ListValue, "zonename", translate("Timezone")) -tz:value("UTC") +o = s:taboption("general", ListValue, "zonename", translate("Timezone")) +o:value("UTC") for i, zone in ipairs(luci.sys.zoneinfo.TZ) do - tz:value(zone[1]) + o:value(zone[1]) end -function tz.write(self, section, value) +function o.write(self, section, value) local function lookup_zone(title) for _, zone in ipairs(luci.sys.zoneinfo.TZ) do if zone[1] == title then return zone[2] end @@ -78,8 +72,157 @@ function tz.write(self, section, value) luci.fs.writefile("/etc/TZ", timezone .. "\n") end -s:option(Value, "log_size", nil, "kiB").optional = true -s:option(Value, "log_ip").optional = true -s:option(Value, "conloglevel").optional = true -s:option(Value, "cronloglevel").optional = true + +-- +-- Logging +-- + +o = s:taboption("logging", Value, "log_size", translate("System log buffer size"), "kiB") +o.optional = true +o.placeholder = 16 +o.datatype = "uinteger" + +o = s:taboption("logging", Value, "log_ip", translate("External system log server")) +o.optional = true +o.placeholder = "0.0.0.0" +o.datatype = "ip4addr" + +o = s:taboption("logging", Value, "log_port", translate("External system log server port")) +o.optional = true +o.placeholder = 514 +o.datatype = "port" + +o = s:taboption("logging", ListValue, "conloglevel", translate("Log output level")) +o:value(8, translate("Debug")) +o:value(7, translate("Info")) +o:value(6, translate("Notice")) +o:value(5, translate("Warning")) +o:value(4, translate("Error")) +o:value(3, translate("Critical")) +o:value(2, translate("Alert")) +o:value(1, translate("Emergency")) + +o = s:taboption("logging", ListValue, "cronloglevel", translate("Cron Log Level")) +o.default = 8 +o:value(5, translate("Debug")) +o:value(8, translate("Normal")) +o:value(9, translate("Warning")) + + +-- +-- Langauge & Style +-- + +o = s:taboption("language", ListValue, "_lang", translate("Language")) +o:value("auto") + +local i18ndir = luci.i18n.i18ndir .. "base." +for k, v in luci.util.kspairs(luci.config.languages) do + local file = i18ndir .. k:gsub("_", "-") + if k:sub(1, 1) ~= "." and luci.fs.access(file .. ".lmo") then + o:value(k, v) + end +end + +function o.cfgvalue(...) + return m.uci:get("luci", "main", "lang") +end + +function o.write(self, section, value) + m.uci:set("luci", "main", "lang", value) +end + + +o = s:taboption("language", ListValue, "_mediaurlbase", translate("Design")) +for k, v in pairs(luci.config.themes) do + if k:sub(1, 1) ~= "." then + o:value(v, k) + end +end + +function o.cfgvalue(...) + return m.uci:get("luci", "main", "mediaurlbase") +end + +function o.write(self, section, value) + m.uci:set("luci", "main", "mediaurlbase", value) +end + + +-- +-- NTP +-- + +if has_ntpd then + + -- timeserver setup was requested, create section and reload page + if m:formvalue("cbid.system._timeserver._enable") then + m.uci:section("system", "timeserver", "ntp", + { + server = { "0.openwrt.pool.ntp.org", "1.openwrt.pool.ntp.org", "2.openwrt.pool.ntp.org", "3.openwrt.pool.ntp.org" } + } + ) + + m.uci:save("system") + luci.http.redirect(luci.dispatcher.build_url("admin/system", arg[1])) + return + end + + local has_section = false + m.uci:foreach("system", "timeserver", + function(s) + has_section = true + return false + end) + + if not has_section then + + s = m:section(TypedSection, "timeserver", translate("Time Synchronization")) + s.anonymous = true + s.cfgsections = function() return { "_timeserver" } end + + x = s:option(Button, "_enable") + x.title = translate("Time Synchronization is not configured yet.") + x.inputtitle = translate("Setup Time Synchronization") + x.inputstyle = "apply" + + else + + s = m:section(TypedSection, "timeserver", translate("Time Synchronization")) + s.anonymous = true + s.addremove = false + + o = s:option(Flag, "enable", translate("Enable NTP client")) + o.rmempty = false + + function o.cfgvalue(self) + return luci.sys.init.enabled("sysntpd") + and self.enabled or self.disabled + end + + function o.write(self, section, value) + if value == self.enabled then + luci.sys.init.enable("sysntpd") + luci.sys.call("env -i /etc/init.d/sysntpd start >/dev/null") + else + luci.sys.call("env -i /etc/init.d/sysntpd stop >/dev/null") + luci.sys.init.disable("sysntpd") + end + end + + + o = s:option(Flag, "enable_server", translate("Provide NTP server")) + o:depends("enable", "1") + + + o = s:option(DynamicList, "server", translate("NTP server candidates")) + o.datatype = "host" + o:depends("enable", "1") + + -- retain server list even if disabled + function o.remove() end + + end +end + return m