system.lua 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. -- Copyright 2008 Steven Barth <steven@midlink.org>
  2. -- Licensed to the public under the Apache License 2.0.
  3. require("luci.sys")
  4. require("luci.sys.zoneinfo")
  5. require("luci.tools.webadmin")
  6. require("luci.util")
  7. m = Map("system", translate("System"), translate("Here you can configure the basic aspects of your device like its hostname or the timezone."))
  8. s = m:section(TypedSection, "system", "")
  9. s.anonymous = true
  10. s.addremove = false
  11. local sysinfo = luci.util.ubus("system", "info") or { }
  12. local boardinfo = luci.util.ubus("system", "board") or { }
  13. local uptime = sysinfo.uptime or 0
  14. local loads = sysinfo.load or { 0, 0, 0 }
  15. local memory = sysinfo.memory or {
  16. total = 0,
  17. free = 0,
  18. buffered = 0,
  19. shared = 0
  20. }
  21. s:option(DummyValue, "_system", translate("Model")).value = boardinfo.model or "?"
  22. s:option(DummyValue, "_cpu", translate("System")).value = boardinfo.system or "?"
  23. s:option(DummyValue, "_la", translate("Load")).value =
  24. string.format("%.2f, %.2f, %.2f", loads[1] / 65535.0, loads[2] / 65535.0, loads[3] / 65535.0)
  25. s:option(DummyValue, "_memtotal", translate("Memory")).value =
  26. string.format("%.2f MB (%.0f%% %s, %.0f%% %s)",
  27. tonumber(memory.total) / 1024 / 1024,
  28. 100 * memory.buffered / memory.total,
  29. tostring(translate("buffered")),
  30. 100 * memory.free / memory.total,
  31. tostring(translate("free"))
  32. )
  33. s:option(DummyValue, "_systime", translate("Local Time")).value =
  34. os.date("%c")
  35. s:option(DummyValue, "_uptime", translate("Uptime")).value =
  36. luci.tools.webadmin.date_format(tonumber(uptime))
  37. hn = s:option(Value, "hostname", translate("Hostname"))
  38. function hn.write(self, section, value)
  39. Value.write(self, section, value)
  40. luci.sys.hostname(value)
  41. end
  42. tz = s:option(ListValue, "zonename", translate("Timezone"))
  43. tz:value("UTC")
  44. for i, zone in ipairs(luci.sys.zoneinfo.TZ) do
  45. tz:value(zone[1])
  46. end
  47. function tz.write(self, section, value)
  48. local function lookup_zone(title)
  49. for _, zone in ipairs(luci.sys.zoneinfo.TZ) do
  50. if zone[1] == title then return zone[2] end
  51. end
  52. end
  53. AbstractValue.write(self, section, value)
  54. self.map.uci:set("system", section, "timezone", lookup_zone(value) or "GMT0")
  55. end
  56. return m