Advertisement
Guest User

system.lua - vargalex 1.1.7

a guest
Feb 17th, 2015
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.43 KB | None | 0 0
  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: system.lua 9339 2012-09-28 19:08:47Z jow $
  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. m = Map("system", translate("System"), translate("Here you can configure the basic aspects of your device like its hostname or the timezone."))
  26. m:chain("luci")
  27.  
  28.  
  29. s = m:section(TypedSection, "system", translate("System Properties"))
  30. s.anonymous = true
  31. s.addremove = false
  32.  
  33. s:tab("general",  translate("General Settings"))
  34. s:tab("logging",  translate("Logging"))
  35. s:tab("language", translate("Language and Style"))
  36.  
  37.  
  38. --
  39. -- System Properties
  40. --
  41.  
  42. o = s:taboption("general", DummyValue, "_systime", translate("Local Time"))
  43. o.template = "admin_system/clock_status"
  44.  
  45.  
  46. o = s:taboption("general", Value, "hostname", translate("Hostname"))
  47. o.datatype = "hostname"
  48.  
  49. function o.write(self, section, value)
  50.     Value.write(self, section, value)
  51.     luci.sys.hostname(value)
  52. end
  53.  
  54.  
  55. o = s:taboption("general", ListValue, "zonename", translate("Timezone"))
  56. o:value("UTC")
  57.  
  58. for i, zone in ipairs(luci.sys.zoneinfo.TZ) do
  59.     o:value(zone[1])
  60. end
  61.  
  62. function o.write(self, section, value)
  63.     local function lookup_zone(title)
  64.         for _, zone in ipairs(luci.sys.zoneinfo.TZ) do
  65.             if zone[1] == title then return zone[2] end
  66.         end
  67.     end
  68.  
  69.     AbstractValue.write(self, section, value)
  70.     local timezone = lookup_zone(value) or "GMT0"
  71.     self.map.uci:set("system", section, "timezone", timezone)
  72.     luci.fs.writefile("/etc/TZ", timezone .. "\n")
  73. end
  74.  
  75.  
  76. --
  77. -- Logging
  78. --
  79.  
  80. o = s:taboption("logging", ListValue, "log_type", translate("System log type"), translate("Circular for log to RAM, file to save the logs."))
  81. o:value("circular")
  82. o:value("file")
  83. o.optional = true
  84.  
  85. o = s:taboption("logging", Value, "log_file", translate("System log file"), translate("Set system log filename with full path"))
  86. o:depends("log_type", "file")
  87. o.optional = true
  88. o.placeholder = "/var/log/messages"
  89.  
  90. o = s:taboption("logging", Value, "log_keep", translate("Rotated logs to keep"), translate("N rotated logs to keep (default:1, max=99, 0=purge)"))
  91. o.optional = true
  92. o.placeholder = 1
  93. o.datatype = "uinteger"
  94. o:depends("log_type", "file")
  95.  
  96. o = s:taboption("logging", Value, "log_size", translate("System log buffer size"), "kiB")
  97. o.optional    = true
  98. o.placeholder = 16
  99. o.datatype    = "uinteger"
  100.  
  101. o = s:taboption("logging", Value, "log_ip", translate("External system log server"))
  102. o.optional    = true
  103. o.placeholder = "0.0.0.0"
  104. o.datatype    = "ip4addr"
  105.  
  106. o = s:taboption("logging", Value, "log_port", translate("External system log server port"))
  107. o.optional    = true
  108. o.placeholder = 514
  109. o.datatype    = "port"
  110.  
  111. o = s:taboption("logging", ListValue, "conloglevel", translate("Log output level"))
  112. o:value(8, translate("Debug"))
  113. o:value(7, translate("Info"))
  114. o:value(6, translate("Notice"))
  115. o:value(5, translate("Warning"))
  116. o:value(4, translate("Error"))
  117. o:value(3, translate("Critical"))
  118. o:value(2, translate("Alert"))
  119. o:value(1, translate("Emergency"))
  120.  
  121. o = s:taboption("logging", ListValue, "cronloglevel", translate("Cron Log Level"))
  122. o.default = 8
  123. o:value(5, translate("Debug"))
  124. o:value(8, translate("Normal"))
  125. o:value(9, translate("Warning"))
  126.  
  127.  
  128. --
  129. -- Langauge & Style
  130. --
  131.  
  132. o = s:taboption("language", ListValue, "_lang", translate("Language"))
  133. o:value("auto")
  134.  
  135. local i18ndir = luci.i18n.i18ndir .. "base."
  136. for k, v in luci.util.kspairs(luci.config.languages) do
  137.     local file = i18ndir .. k:gsub("_", "-")
  138.     if k:sub(1, 1) ~= "." and luci.fs.access(file .. ".lmo") then
  139.         o:value(k, v)
  140.     end
  141. end
  142.  
  143. function o.cfgvalue(...)
  144.     return m.uci:get("luci", "main", "lang")
  145. end
  146.  
  147. function o.write(self, section, value)
  148.     m.uci:set("luci", "main", "lang", value)
  149. end
  150.  
  151.  
  152. o = s:taboption("language", ListValue, "_mediaurlbase", translate("Design"))
  153. for k, v in pairs(luci.config.themes) do
  154.     if k:sub(1, 1) ~= "." then
  155.         o:value(v, k)
  156.     end
  157. end
  158.  
  159. function o.cfgvalue(...)
  160.     return m.uci:get("luci", "main", "mediaurlbase")
  161. end
  162.  
  163. function o.write(self, section, value)
  164.     m.uci:set("luci", "main", "mediaurlbase", value)
  165. end
  166.  
  167.  
  168. --
  169. -- NTP
  170. --
  171.  
  172. if has_ntpd then
  173.  
  174.     -- timeserver setup was requested, create section and reload page
  175.     if m:formvalue("cbid.system._timeserver._enable") then
  176.         m.uci:section("system", "timeserver", "ntp",
  177.             {
  178.                     server = { "0.openwrt.pool.ntp.org", "1.openwrt.pool.ntp.org", "2.openwrt.pool.ntp.org", "3.openwrt.pool.ntp.org" }
  179.             }
  180.         )
  181.  
  182.         m.uci:save("system")
  183.         luci.http.redirect(luci.dispatcher.build_url("admin/system", arg[1]))
  184.         return
  185.     end
  186.  
  187.     local has_section = false
  188.     m.uci:foreach("system", "timeserver",
  189.         function(s)
  190.             has_section = true
  191.             return false
  192.     end)
  193.  
  194.     if not has_section then
  195.  
  196.         s = m:section(TypedSection, "timeserver", translate("Time Synchronization"))
  197.         s.anonymous   = true
  198.         s.cfgsections = function() return { "_timeserver" } end
  199.  
  200.         x = s:option(Button, "_enable")
  201.         x.title      = translate("Time Synchronization is not configured yet.")
  202.         x.inputtitle = translate("Setup Time Synchronization")
  203.         x.inputstyle = "apply"
  204.  
  205.     else
  206.        
  207.         s = m:section(TypedSection, "timeserver", translate("Time Synchronization"))
  208.         s.anonymous = true
  209.         s.addremove = false
  210.  
  211.         o = s:option(Flag, "enable", translate("Enable NTP client"))
  212.         o.rmempty = false
  213.  
  214.         function o.cfgvalue(self)
  215.             return luci.sys.init.enabled("sysntpd")
  216.                 and self.enabled or self.disabled
  217.         end
  218.  
  219.         function o.write(self, section, value)
  220.             if value == self.enabled then
  221.                 luci.sys.init.enable("sysntpd")
  222.                 luci.sys.call("env -i /etc/init.d/sysntpd start >/dev/null")
  223.             else
  224.                 luci.sys.call("env -i /etc/init.d/sysntpd stop >/dev/null")
  225.                 luci.sys.init.disable("sysntpd")
  226.             end
  227.         end
  228.  
  229.  
  230.         o = s:option(Flag, "enable_server", translate("Provide NTP server"))
  231.         o:depends("enable", "1")
  232.  
  233.  
  234.         o = s:option(DynamicList, "server", translate("NTP server candidates"))
  235.         o.datatype = "host"
  236.         o:depends("enable", "1")
  237.  
  238.         -- retain server list even if disabled
  239.         function o.remove() end
  240.  
  241.     end
  242. end
  243.  
  244. return m
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement