libs/sys: extend luci.sys.hostname() to allow setting a new name

modules/admin-{full,mini}: update the hostname at runtime
This commit is contained in:
Jo-Philipp Wich 2009-02-01 17:08:40 +00:00
parent d7d27ffe6a
commit 4b9f7db1ce
3 changed files with 34 additions and 16 deletions

View file

@ -129,10 +129,16 @@ end
-- @return Table containing all variables if no variable name is given
getenv = posix.getenv
--- Determine the current hostname.
--- Get or set the current hostname.
-- @param String containing a new hostname to set (optional)
-- @return String containing the system hostname
function hostname()
function hostname(newname)
if type(newname) == "string" and #newname > 0 then
luci.fs.writefile( "/proc/sys/kernel/hostname", newname .. "\n" )
return newname
else
return posix.uname("%n")
end
end
--- Returns the contents of a documented referred by an URL.

View file

@ -47,7 +47,13 @@ s:option(DummyValue, "_systime", translate("m_i_systemtime")).value =
s:option(DummyValue, "_uptime", translate("m_i_uptime")).value =
luci.tools.webadmin.date_format(tonumber(uptime))
s:option(Value, "hostname", translate("hostname"))
hn = s:option(Value, "hostname", translate("hostname"))
function hn.write(self, section, value)
Value.write(self, section, value)
luci.sys.hostname(value)
end
tz = s:option(ListValue, "zonename", translate("timezone"))
tz:value("UTC")

View file

@ -50,7 +50,13 @@ s:option(DummyValue, "_systime", translate("m_i_systemtime")).value =
s:option(DummyValue, "_uptime", translate("m_i_uptime")).value =
luci.tools.webadmin.date_format(tonumber(uptime))
s:option(Value, "hostname", translate("hostname"))
hn = s:option(Value, "hostname", translate("hostname"))
function hn.write(self, section, value)
Value.write(self, section, value)
luci.sys.hostname(value)
end
tz = s:option(ListValue, "zonename", translate("timezone"))
tz:value("UTC")