summaryrefslogtreecommitdiffhomepage
path: root/modules/admin-full/luasrc/model
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2009-07-19 00:24:58 +0000
committerJo-Philipp Wich <jow@openwrt.org>2009-07-19 00:24:58 +0000
commit8fcd841aa9af96c8a4a4d3c1a555d2d1ed42332c (patch)
treecf6466b373236442e63742cb4f73b22579940784 /modules/admin-full/luasrc/model
parent6abba6163290b58cd9ebae98d8459ac38ef52a4b (diff)
convert luci.fs users to nixio.fs api
Diffstat (limited to 'modules/admin-full/luasrc/model')
-rw-r--r--modules/admin-full/luasrc/model/cbi/admin_index/luci.lua6
-rw-r--r--modules/admin-full/luasrc/model/cbi/admin_network/dhcpleases.lua28
-rw-r--r--modules/admin-full/luasrc/model/cbi/admin_network/ifaces.lua18
-rw-r--r--modules/admin-full/luasrc/model/cbi/admin_network/network.lua21
-rw-r--r--modules/admin-full/luasrc/model/cbi/admin_network/wifi.lua13
-rw-r--r--modules/admin-full/luasrc/model/cbi/admin_services/crontab.lua6
-rw-r--r--modules/admin-full/luasrc/model/cbi/admin_system/fstab.lua14
-rw-r--r--modules/admin-full/luasrc/model/cbi/admin_system/ipkg.lua4
-rw-r--r--modules/admin-full/luasrc/model/cbi/admin_system/leds.lua15
-rw-r--r--modules/admin-full/luasrc/model/cbi/admin_system/sshkeys.lua4
10 files changed, 71 insertions, 58 deletions
diff --git a/modules/admin-full/luasrc/model/cbi/admin_index/luci.lua b/modules/admin-full/luasrc/model/cbi/admin_index/luci.lua
index caf7c97889..30e8ddcc17 100644
--- a/modules/admin-full/luasrc/model/cbi/admin_index/luci.lua
+++ b/modules/admin-full/luasrc/model/cbi/admin_index/luci.lua
@@ -15,6 +15,8 @@ require("luci.config")
m = Map("luci", translate("webui"), translate("a_i_luci1",
"Hier können Eigenschaften und die Funktionalität der Oberfläche angepasst werden."))
+local fs = require "nixio.fs"
+
-- force reload of global luci config namespace to reflect the changes
function m.commit_handler(self)
package.loaded["luci.config"] = nil
@@ -31,8 +33,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-full/luasrc/model/cbi/admin_network/dhcpleases.lua b/modules/admin-full/luasrc/model/cbi/admin_network/dhcpleases.lua
index 0b2f55a31d..31a27b3f66 100644
--- a/modules/admin-full/luasrc/model/cbi/admin_network/dhcpleases.lua
+++ b/modules/admin-full/luasrc/model/cbi/admin_network/dhcpleases.lua
@@ -11,17 +11,21 @@ You may obtain a copy of the License at
$Id$
]]--
-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"
+
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
@@ -38,9 +42,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
@@ -51,11 +53,13 @@ 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
+sys.net.arptable(function(entry)
+ ip:value(entry["IP address"])
+ mac:value(
+ entry["HW address"],
+ entry["HW address"] .. " (" .. entry["IP address"] .. ")"
+ )
+end)
return m2
diff --git a/modules/admin-full/luasrc/model/cbi/admin_network/ifaces.lua b/modules/admin-full/luasrc/model/cbi/admin_network/ifaces.lua
index b9e65fb889..8758f7300c 100644
--- a/modules/admin-full/luasrc/model/cbi/admin_network/ifaces.lua
+++ b/modules/admin-full/luasrc/model/cbi/admin_network/ifaces.lua
@@ -13,14 +13,16 @@ You may obtain a copy of the License at
$Id$
]]--
-require("luci.tools.webadmin")
+local wa = require "luci.tools.webadmin"
+local fs = require "nixio.fs"
+
arg[1] = arg[1] or ""
-local has_3g = luci.fs.mtime("/usr/bin/gcom")
-local has_pptp = luci.fs.mtime("/usr/sbin/pptp")
-local has_pppd = luci.fs.mtime("/usr/sbin/pppd")
-local has_pppoe = luci.fs.glob("/usr/lib/pppd/*/rp-pppoe.so")
-local has_pppoa = luci.fs.glob("/usr/lib/pppd/*/pppoatm.so")
+local has_3g = fs.access("/usr/bin/gcom")
+local has_pptp = fs.access("/usr/sbin/pptp")
+local has_pppd = fs.access("/usr/sbin/pppd")
+local has_pppoe = fs.glob("/usr/lib/pppd/*/rp-pppoe.so")()
+local has_pppoa = fs.glob("/usr/lib/pppd/*/pppoatm.so")()
m = Map("network", translate("interfaces"), translate("a_n_ifaces1"))
@@ -64,7 +66,7 @@ for i,d in ipairs(luci.sys.net.devices()) do
end
end
-local zones = luci.tools.webadmin.network_get_zones(arg[1])
+local zones = wa.network_get_zones(arg[1])
if zones then
if #zones == 0 then
m:chain("firewall")
@@ -83,7 +85,7 @@ if zones then
)
function fwzone.write(self, section, value)
- local zone = luci.tools.webadmin.firewall_find_zone(value)
+ local zone = wa.firewall_find_zone(value)
local stat
if not zone then
diff --git a/modules/admin-full/luasrc/model/cbi/admin_network/network.lua b/modules/admin-full/luasrc/model/cbi/admin_network/network.lua
index 300535d6da..8fd5368884 100644
--- a/modules/admin-full/luasrc/model/cbi/admin_network/network.lua
+++ b/modules/admin-full/luasrc/model/cbi/admin_network/network.lua
@@ -12,14 +12,16 @@ You may obtain a copy of the License at
$Id$
]]--
-require("luci.sys")
-require("luci.tools.webadmin")
+
+local sys = require "luci.sys"
+local wa = require "luci.tools.webadmin"
+local fs = require "nixio.fs"
local netstate = luci.model.uci.cursor_state():get_all("network")
m = Map("network", translate("interfaces"))
local created
-local netstat = luci.sys.net.deviceinfo()
+local netstat = sys.net.deviceinfo()
s = m:section(TypedSection, "interface", "")
s.addremove = true
@@ -76,25 +78,22 @@ if luci.model.uci.cursor():load("firewall") then
zone.titleref = luci.dispatcher.build_url("admin", "network", "firewall", "zones")
function zone.cfgvalue(self, section)
- local zones = luci.tools.webadmin.network_get_zones(section)
- return zones and table.concat(zones, ", ") or "-"
+ return table.concat(wa.network_get_zones(section) or { "-" }, ", ")
end
end
hwaddr = s:option(DummyValue, "_hwaddr")
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
ipaddr = s:option(DummyValue, "ipaddr", translate("addresses"))
function ipaddr.cfgvalue(self, section)
- local addr = luci.tools.webadmin.network_get_addresses(section)
- return table.concat(addr, ", ")
+ return table.concat(wa.network_get_addresses(section), ", ")
end
txrx = s:option(DummyValue, "_txrx")
@@ -103,10 +102,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
diff --git a/modules/admin-full/luasrc/model/cbi/admin_network/wifi.lua b/modules/admin-full/luasrc/model/cbi/admin_network/wifi.lua
index 34992271b2..6e9249249c 100644
--- a/modules/admin-full/luasrc/model/cbi/admin_network/wifi.lua
+++ b/modules/admin-full/luasrc/model/cbi/admin_network/wifi.lua
@@ -11,7 +11,10 @@ You may obtain a copy of the License at
$Id$
]]--
-require("luci.tools.webadmin")
+
+local wa = require "luci.tools.webadmin"
+local fs = require "nixio.fs"
+
arg[1] = arg[1] or ""
m = Map("wireless", translate("networks"), translate("a_w_networks1"))
@@ -143,7 +146,7 @@ network = s:option(Value, "network", translate("network"), translate("a_w_networ
network.rmempty = true
network:value("")
network.combobox_manual = translate("a_w_netmanual")
-luci.tools.webadmin.cbi_add_networks(network)
+wa.cbi_add_networks(network)
function network.write(self, section, value)
if not m.uci:get("network", value) then
@@ -173,7 +176,7 @@ bssid = s:option(Value, "bssid", translate("wifi_bssid"))
-------------------- MAC80211 Interface ----------------------
if hwtype == "mac80211" then
- if luci.fs.mtime("/usr/sbin/iw") then
+ if fs.access("/usr/sbin/iw") then
mode:value("mesh", "802.11s")
end
@@ -322,8 +325,8 @@ encr:value("none", "No Encryption")
encr:value("wep", "WEP")
if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" 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")
diff --git a/modules/admin-full/luasrc/model/cbi/admin_services/crontab.lua b/modules/admin-full/luasrc/model/cbi/admin_services/crontab.lua
index 521e0a27d3..05442dd55f 100644
--- a/modules/admin-full/luasrc/model/cbi/admin_services/crontab.lua
+++ b/modules/admin-full/luasrc/model/cbi/admin_services/crontab.lua
@@ -12,6 +12,8 @@ You may obtain a copy of the License at
$Id$
]]--
+
+local fs = require "nixio.fs"
local cronfile = "/etc/crontabs/root"
f = SimpleForm("crontab", translate("a_s_crontab"), translate("a_s_crontab1"))
@@ -20,13 +22,13 @@ t = f:field(TextValue, "crons")
t.rmempty = true
t.rows = 10
function t.cfgvalue()
- return luci.fs.readfile(cronfile) or ""
+ return fs.readfile(cronfile) or ""
end
function f.handle(self, state, data)
if state == FORM_VALID then
if data.crons then
- luci.fs.writefile(cronfile, data.crons:gsub("\r\n", "\n"))
+ fs.writefile(cronfile, data.crons:gsub("\r\n", "\n"))
end
end
return true
diff --git a/modules/admin-full/luasrc/model/cbi/admin_system/fstab.lua b/modules/admin-full/luasrc/model/cbi/admin_system/fstab.lua
index 1e2a12fec1..aa4f12e554 100644
--- a/modules/admin-full/luasrc/model/cbi/admin_system/fstab.lua
+++ b/modules/admin-full/luasrc/model/cbi/admin_system/fstab.lua
@@ -13,16 +13,18 @@ $Id$
]]--
require("luci.tools.webadmin")
-local fs = require "luci.fs"
+local fs = require "nixio.fs"
+local util = require "nixio.util"
+
local devices = {}
-luci.util.update(devices, fs.glob("/dev/sd*") or {})
-luci.util.update(devices, fs.glob("/dev/hd*") or {})
-luci.util.update(devices, fs.glob("/dev/scd*") or {})
-luci.util.update(devices, fs.glob("/dev/mmc*") or {})
+util.consume((fs.glob("/dev/sd*")), devices)
+util.consume((fs.glob("/dev/hd*")), devices)
+util.consume((fs.glob("/dev/scd*")), devices)
+util.consume((fs.glob("/dev/mmc*")), devices)
local size = {}
for i, dev in ipairs(devices) do
- local s = tonumber((luci.fs.readfile("/sys/class/block/%s/size" % dev:sub(6))))
+ local s = tonumber((fs.readfile("/sys/class/block/%s/size" % dev:sub(6))))
size[dev] = s and math.floor(s / 2048)
end
diff --git a/modules/admin-full/luasrc/model/cbi/admin_system/ipkg.lua b/modules/admin-full/luasrc/model/cbi/admin_system/ipkg.lua
index fecc294b68..1b540b7051 100644
--- a/modules/admin-full/luasrc/model/cbi/admin_system/ipkg.lua
+++ b/modules/admin-full/luasrc/model/cbi/admin_system/ipkg.lua
@@ -19,11 +19,11 @@ f = SimpleForm("ipkgconf", translate("a_s_p_ipkg"))
t = f:field(TextValue, "lines")
t.rows = 10
function t.cfgvalue()
- return luci.fs.readfile(ipkgfile) or ""
+ return nixio.fs.readfile(ipkgfile) or ""
end
function t.write(self, section, data)
- return luci.fs.writefile(ipkgfile, data:gsub("\r\n", "\n"))
+ return nixio.fs.writefile(ipkgfile, data:gsub("\r\n", "\n"))
end
f:append(Template("admin_system/ipkg"))
diff --git a/modules/admin-full/luasrc/model/cbi/admin_system/leds.lua b/modules/admin-full/luasrc/model/cbi/admin_system/leds.lua
index 5074a73396..71bd7d0bb1 100644
--- a/modules/admin-full/luasrc/model/cbi/admin_system/leds.lua
+++ b/modules/admin-full/luasrc/model/cbi/admin_system/leds.lua
@@ -16,12 +16,11 @@ m = Map("system", translate("leds"), translate("leds_desc"))
local sysfs_path = "/sys/class/leds/"
local leds = {}
-if luci.fs.access(sysfs_path) then
- for k, v in pairs(luci.fs.dir(sysfs_path)) do
- if v ~= "." and v ~= ".." then
- table.insert(leds, v)
- end
- end
+local fs = require "nixio.fs"
+local util = require "nixio.util"
+
+if fs.access(sysfs_path) then
+ leds = util.consume((fs.dir(sysfs_path)))
end
if #leds == 0 then
@@ -52,7 +51,7 @@ s:option(Flag, "default").rmempty = true
trigger = s:option(ListValue, "trigger")
-local triggers = luci.fs.readfile(sysfs_path .. leds[1] .. "/trigger")
+local triggers = fs.readfile(sysfs_path .. leds[1] .. "/trigger")
for t in triggers:gmatch("[%w-]+") do
trigger:value(t, translate("system_led_trigger_" .. t:gsub("-", "")))
end
@@ -83,4 +82,4 @@ mode:value("link", translate("system_led_mode_link"))
mode:value("tx", translate("system_led_mode_tx"))
mode:value("rx", translate("system_led_mode_rx"))
-return m \ No newline at end of file
+return m
diff --git a/modules/admin-full/luasrc/model/cbi/admin_system/sshkeys.lua b/modules/admin-full/luasrc/model/cbi/admin_system/sshkeys.lua
index 26410c98a1..b7ff482353 100644
--- a/modules/admin-full/luasrc/model/cbi/admin_system/sshkeys.lua
+++ b/modules/admin-full/luasrc/model/cbi/admin_system/sshkeys.lua
@@ -20,13 +20,13 @@ t = f:field(TextValue, "keys")
t.rmempty = true
t.rows = 10
function t.cfgvalue()
- return luci.fs.readfile(keyfile) or ""
+ return nixio.fs.readfile(keyfile) or ""
end
function f.handle(self, state, data)
if state == FORM_VALID then
if data.keys then
- luci.fs.writefile(keyfile, data.keys:gsub("\r\n", "\n"))
+ nixio.fs.writefile(keyfile, data.keys:gsub("\r\n", "\n"))
end
end
return true