X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=libs%2Fsys%2Fluasrc%2Fsys.lua;h=1ecd5d25a994e08c7aefb0e1090cdae66f2b2828;hp=fee1feeafd46e09239ccfbf4b4124281808b749c;hb=e401b4a620ee968d4a191cb9c86ff0adde215a1e;hpb=46bb17c2d22c93c09b627062866e9ef599540687 diff --git a/libs/sys/luasrc/sys.lua b/libs/sys/luasrc/sys.lua index fee1feeaf..1ecd5d25a 100644 --- a/libs/sys/luasrc/sys.lua +++ b/libs/sys/luasrc/sys.lua @@ -35,7 +35,8 @@ luci.util = require "luci.util" luci.fs = require "luci.fs" luci.ip = require "luci.ip" -local tonumber, ipairs, pairs, pcall = tonumber, ipairs, pairs, pcall +local tonumber, ipairs, pairs, pcall, type = + tonumber, ipairs, pairs, pcall, type --- LuCI Linux and POSIX system utilities. @@ -129,10 +130,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() - return posix.uname("%n") +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. @@ -627,7 +634,7 @@ wifi = {} --- Get iwconfig output for all wireless devices. -- @return Table of tables containing the iwconfing output for each wifi device function wifi.getiwconfig() - local cnt = luci.util.exec("/usr/sbin/iwconfig 2>/dev/null") + local cnt = luci.util.exec("PATH=/sbin:/usr/sbin iwconfig 2>/dev/null") local iwc = {} for i, l in pairs(luci.util.split(luci.util.trim(cnt), "\n\n")) do