diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2009-07-19 00:24:58 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2009-07-19 00:24:58 +0000 |
commit | 8fcd841aa9af96c8a4a4d3c1a555d2d1ed42332c (patch) | |
tree | cf6466b373236442e63742cb4f73b22579940784 /modules/admin-mini/luasrc/model/cbi | |
parent | 6abba6163290b58cd9ebae98d8459ac38ef52a4b (diff) |
convert luci.fs users to nixio.fs api
Diffstat (limited to 'modules/admin-mini/luasrc/model/cbi')
-rw-r--r-- | modules/admin-mini/luasrc/model/cbi/mini/dhcp.lua | 32 | ||||
-rw-r--r-- | modules/admin-mini/luasrc/model/cbi/mini/luci.lua | 11 | ||||
-rw-r--r-- | modules/admin-mini/luasrc/model/cbi/mini/network.lua | 20 | ||||
-rw-r--r-- | modules/admin-mini/luasrc/model/cbi/mini/wifi.lua | 13 |
4 files changed, 42 insertions, 34 deletions
diff --git a/modules/admin-mini/luasrc/model/cbi/mini/dhcp.lua b/modules/admin-mini/luasrc/model/cbi/mini/dhcp.lua index 2aadded3ee..5817a93d77 100644 --- a/modules/admin-mini/luasrc/model/cbi/mini/dhcp.lua +++ b/modules/admin-mini/luasrc/model/cbi/mini/dhcp.lua @@ -12,9 +12,11 @@ You may obtain a copy of the License at $Id$ ]]-- -require("luci.model.uci") -require("luci.sys") -require("luci.tools.webadmin") + +local uci = require "luci.model.uci".cursor() +local sys = require "luci.sys" +local wa = require "luci.tools.webadmin" +local fs = require "nixio.fs" m = Map("dhcp", "DHCP") @@ -61,12 +63,12 @@ time.rmempty = true m2 = Map("luci_ethers", translate("dhcp_leases")) local leasefn, leasefp, leases -luci.model.uci.cursor():foreach("dhcp", "dnsmasq", +uci:foreach("dhcp", "dnsmasq", function(section) leasefn = section.leasefile end ) -local leasefp = leasefn and luci.fs.access(leasefn) and io.lines(leasefn) +local leasefp = leasefn and fs.access(leasefn) and io.lines(leasefn) if leasefp then leases = {} for lease in leasefp do @@ -83,9 +85,7 @@ if leases then ltime = v:option(DummyValue, 1, translate("dhcp_timeremain")) function ltime.cfgvalue(self, ...) local value = DummyValue.cfgvalue(self, ...) - return luci.tools.webadmin.date_format( - os.difftime(tonumber(value), os.time()) - ) + return wa.date_format(os.difftime(tonumber(value), os.time())) end end @@ -96,10 +96,12 @@ s.template = "cbi/tblsection" mac = s:option(Value, "macaddr", translate("macaddress")) ip = s:option(Value, "ipaddr", translate("ipaddress")) -for i, dataset in ipairs(luci.sys.net.arptable()) do - ip:value(dataset["IP address"]) - mac:value(dataset["HW address"], - dataset["HW address"] .. " (" .. dataset["IP address"] .. ")") -end - -return m, m2
\ No newline at end of file +sys.net.arptable(function(entry) + ip:value(entry["IP address"]) + mac:value( + entry["HW address"], + entry["HW address"] .. " (" .. entry["IP address"] .. ")" + ) +end) + +return m, m2 diff --git a/modules/admin-mini/luasrc/model/cbi/mini/luci.lua b/modules/admin-mini/luasrc/model/cbi/mini/luci.lua index 0a57b30569..d358c8a0b4 100644 --- a/modules/admin-mini/luasrc/model/cbi/mini/luci.lua +++ b/modules/admin-mini/luasrc/model/cbi/mini/luci.lua @@ -12,13 +12,16 @@ You may obtain a copy of the License at $Id$ ]]-- -require("luci.config") + +require "luci.config" +local fs = require "nixio.fs" + m = Map("luci", translate("webui"), translate("a_i_luci1")) -- force reload of global luci config namespace to reflect the changes function m.commit_handler(self) package.loaded["luci.config"] = nil - require("luci.config") + require "luci.config" end @@ -31,8 +34,8 @@ local i18ndir = luci.i18n.i18ndir .. "default." 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 .. ".lua") or - luci.fs.access(file .. ".lua.gz") + fs.access(file .. ".lua") or + fs.access(file .. ".lua.gz") ) then l:value(k, v) end diff --git a/modules/admin-mini/luasrc/model/cbi/mini/network.lua b/modules/admin-mini/luasrc/model/cbi/mini/network.lua index 508bac155c..14414e999e 100644 --- a/modules/admin-mini/luasrc/model/cbi/mini/network.lua +++ b/modules/admin-mini/luasrc/model/cbi/mini/network.lua @@ -13,16 +13,16 @@ You may obtain a copy of the License at $Id$ ]]-- -require("luci.tools.webadmin") -require("luci.sys") -require("luci.fs") +local wa = require "luci.tools.webadmin" +local sys = require "luci.sys" +local fs = require "nixio.fs" -local has_pptp = luci.fs.mtime("/usr/sbin/pptp") -local has_pppoe = luci.fs.glob("/usr/lib/pppd/*/rp-pppoe.so") +local has_pptp = fs.access("/usr/sbin/pptp") +local has_pppoe = fs.glob("/usr/lib/pppd/*/rp-pppoe.so")() local network = luci.model.uci.cursor_state():get_all("network") -local netstat = luci.sys.net.deviceinfo() +local netstat = sys.net.deviceinfo() local ifaces = {} for k, v in pairs(network) do @@ -41,7 +41,7 @@ hwaddr = s:option(DummyValue, "_hwaddr", translate("network_interface_hwaddr"), translate("network_interface_hwaddr_desc")) function hwaddr.cfgvalue(self, section) local ix = self.map:get(section, "ifname") or "" - return luci.fs.readfile("/sys/class/net/" .. ix .. "/address") + return fs.readfile("/sys/class/net/" .. ix .. "/address") or luci.util.exec("ifconfig " .. ix):match(" ([A-F0-9:]+)%s*\n") or "n/a" end @@ -59,10 +59,10 @@ function txrx.cfgvalue(self, section) local ix = self.map:get(section, "ifname") local rx = netstat and netstat[ix] and netstat[ix][1] - rx = rx and luci.tools.webadmin.byte_format(tonumber(rx)) or "-" + rx = rx and wa.byte_format(tonumber(rx)) or "-" local tx = netstat and netstat[ix] and netstat[ix][9] - tx = tx and luci.tools.webadmin.byte_format(tonumber(tx)) or "-" + tx = tx and wa.byte_format(tonumber(tx)) or "-" return string.format("%s / %s", tx, rx) end @@ -150,7 +150,7 @@ pwd:depends("proto", "pptp") -- Allow user to set MSS correction here if the UCI firewall is installed -- This cures some cancer for providers with pre-war routers -if luci.fs.access("/etc/config/firewall") then +if fs.access("/etc/config/firewall") then mssfix = s:option(Flag, "_mssfix", translate("m_n_mssfix"), translate("m_n_mssfix_desc")) mssfix.rmempty = false diff --git a/modules/admin-mini/luasrc/model/cbi/mini/wifi.lua b/modules/admin-mini/luasrc/model/cbi/mini/wifi.lua index ee423f3b4c..98f66972a3 100644 --- a/modules/admin-mini/luasrc/model/cbi/mini/wifi.lua +++ b/modules/admin-mini/luasrc/model/cbi/mini/wifi.lua @@ -15,7 +15,10 @@ $Id$ -- Data init -- -local uci = luci.model.uci.cursor() +local fs = require "nixio.fs" +local sys = require "luci.sys" +local uci = require "luci.model.uci".cursor() + if not uci:get("network", "wan") then uci:section("network", "interface", "wan", {proto="none", ifname=" "}) uci:save("network") @@ -24,7 +27,7 @@ end local wlcursor = luci.model.uci.cursor_state() local wireless = wlcursor:get_all("wireless") -local wifidata = luci.sys.wifi.getiwconfig() +local wifidata = sys.wifi.getiwconfig() local wifidevs = {} local ifaces = {} @@ -99,7 +102,7 @@ function scan.write(self, section) m.autoapply = false t2.render = t2._render local ifname = self.map:get(section, "ifname") - luci.util.update(t2.data, luci.sys.wifi.iwscan(ifname)) + luci.util.update(t2.data, sys.wifi.iwscan(ifname)) end t2._render = t2.render @@ -218,8 +221,8 @@ encr:value("none", "No Encryption") encr:value("wep", "WEP") if hwtype == "atheros" or hwtype == "mac80211" then - local supplicant = luci.fs.mtime("/usr/sbin/wpa_supplicant") - local hostapd = luci.fs.mtime("/usr/sbin/hostapd") + local supplicant = fs.access("/usr/sbin/wpa_supplicant") + local hostapd = fs.access("/usr/sbin/hostapd") if hostapd and supplicant then encr:value("psk", "WPA-PSK") |