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-full | |
parent | 6abba6163290b58cd9ebae98d8459ac38ef52a4b (diff) |
convert luci.fs users to nixio.fs api
Diffstat (limited to 'modules/admin-full')
14 files changed, 93 insertions, 80 deletions
diff --git a/modules/admin-full/luasrc/controller/admin/services.lua b/modules/admin-full/luasrc/controller/admin/services.lua index a137377b3..50c79f664 100644 --- a/modules/admin-full/luasrc/controller/admin/services.lua +++ b/modules/admin-full/luasrc/controller/admin/services.lua @@ -28,14 +28,14 @@ function index() page.order = 40 page.index = true - if luci.fs.access("/etc/config/lucittpd") then + if nixio.fs.access("/etc/config/lucittpd") then local page = node("admin", "services", "lucittpd") page.target = cbi("admin_services/lucittpd") page.title = "LuCIttpd" page.order = 10 end - if luci.fs.access("/etc/config/httpd") then + if nixio.fs.access("/etc/config/httpd") then local page = node("admin", "services", "httpd") page.target = cbi("admin_services/httpd") page.title = "Busybox HTTPd" @@ -51,4 +51,4 @@ function index() page.target = cbi("admin_services/dnsmasq") page.title = "Dnsmasq" page.order = 30 -end
\ No newline at end of file +end diff --git a/modules/admin-full/luasrc/controller/admin/system.lua b/modules/admin-full/luasrc/controller/admin/system.lua index 1aabe637a..c90ecc3ce 100644 --- a/modules/admin-full/luasrc/controller/admin/system.lua +++ b/modules/admin-full/luasrc/controller/admin/system.lua @@ -27,7 +27,7 @@ function index() entry({"admin", "system", "processes"}, form("admin_system/processes"), i18n("process_head"), 45) entry({"admin", "system", "fstab"}, cbi("admin_system/fstab"), i18n("a_s_fstab"), 50) - if luci.fs.isdirectory("/sys/class/leds") then + if nixio.fs.access("/sys/class/leds") then entry({"admin", "system", "leds"}, cbi("admin_system/leds"), i18n("leds", "LEDs"), 60) end @@ -124,7 +124,7 @@ function action_packages() -- Remove index cache if changes then - luci.fs.unlink("/tmp/luci-indexcache") + nixio.fs.unlink("/tmp/luci-indexcache") end end @@ -214,7 +214,7 @@ function action_upgrade() local function storage_size() local size = 0 - if luci.fs.access("/proc/mtd") then + if nixio.fs.access("/proc/mtd") then for l in io.lines("/proc/mtd") do local d, s, e, n = l:match('^([^%s]+)%s+([^%s]+)%s+([^%s]+)%s+"([^%s]+)"') if n == "linux" then @@ -222,7 +222,7 @@ function action_upgrade() break end end - elseif luci.fs.access("/proc/partitions") then + elseif nixio.fs.access("/proc/partitions") then for l in io.lines("/proc/partitions") do local x, y, b, n = l:match('^%s*(%d+)%s+(%d+)%s+([^%s]+)%s+([^%s]+)') if b and n and not n:match('[0-9]') then @@ -239,7 +239,7 @@ function action_upgrade() local file luci.http.setfilehandler( function(meta, chunk, eof) - if not luci.fs.access(tmpfile) and not file and chunk and #chunk > 0 then + if not nixio.fs.access(tmpfile) and not file and chunk and #chunk > 0 then file = io.open(tmpfile, "w") end if file and chunk then @@ -255,9 +255,9 @@ function action_upgrade() -- Determine state local keep_avail = true local step = tonumber(luci.http.formvalue("step") or 1) - local has_image = luci.fs.access(tmpfile) + local has_image = nixio.fs.access(tmpfile) local has_support = image_supported() - local has_platform = luci.fs.access("/lib/upgrade/platform.sh") + local has_platform = nixio.fs.access("/lib/upgrade/platform.sh") local has_upload = luci.http.formvalue("image") -- This does the actual flashing which is invoked inside an iframe @@ -298,7 +298,7 @@ function action_upgrade() -- If there is an image but user has requested step 1 -- or type is not supported, then remove it. if has_image then - luci.fs.unlink(tmpfile) + nixio.fs.unlink(tmpfile) end luci.template.render("admin_system/upgrade", { @@ -313,7 +313,7 @@ function action_upgrade() luci.template.render("admin_system/upgrade", { step=2, checksum=image_checksum(), - filesize=luci.fs.stat(tmpfile).size, + filesize=nixio.fs.stat(tmpfile).size, flashsize=storage_size(), keepconfig=(keep_avail and luci.http.formvalue("keepcfg") == "1") } ) @@ -333,7 +333,7 @@ function _keep_pattern() if files then kpattern = "" for k, v in pairs(files) do - if k:sub(1,1) ~= "." and luci.fs.glob(v) then + if k:sub(1,1) ~= "." and nixio.fs.glob(v)() then kpattern = kpattern .. " " .. v end end 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 caf7c9788..30e8ddcc1 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 0b2f55a31..31a27b3f6 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 b9e65fb88..8758f7300 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 300535d6d..8fd536888 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 34992271b..6e9249249 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 521e0a27d..05442dd55 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 1e2a12fec..aa4f12e55 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 fecc294b6..1b540b705 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 5074a7339..71bd7d0bb 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 26410c98a..b7ff48235 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 diff --git a/modules/admin-full/luasrc/view/admin_status/interfaces.htm b/modules/admin-full/luasrc/view/admin_status/interfaces.htm index 5358caeae..720ce9c3d 100644 --- a/modules/admin-full/luasrc/view/admin_status/interfaces.htm +++ b/modules/admin-full/luasrc/view/admin_status/interfaces.htm @@ -15,15 +15,15 @@ $Id$ <%- - require "luci.tools.webadmin" - - local wba = luci.tools.webadmin - local uci = luci.model.uci.cursor_state() + local sys = require "luci.sys" + local wba = require "luci.tools.webadmin" + local uci = require "luci.model.uci".cursor_state() + local fs = require "nixio.fs" local bridge_ifs = { } local single_ifs = { } local wifi_ifs = { } - local devinfo = luci.sys.net.deviceinfo() + local devinfo = sys.net.deviceinfo() uci:foreach("network", "interface", function(s) @@ -86,8 +86,8 @@ $Id$ function get_switch_driver(i) local n, d = i:match("([a-z]+)(%d+)%.%d+$") - local hw = luci.fs.readfile("/proc/switch/%s%s/driver" %{ n, d }) - or luci.fs.readfile("/proc/switch/%s/driver" % d ) + local hw = fs.readfile("/proc/switch/%s%s/driver" %{ n, d }) + or fs.readfile("/proc/switch/%s/driver" % d ) return hw and hw:match("%S+") end diff --git a/modules/admin-full/luasrc/view/admin_status/routes.htm b/modules/admin-full/luasrc/view/admin_status/routes.htm index 7bde82b17..0b37abbdd 100644 --- a/modules/admin-full/luasrc/view/admin_status/routes.htm +++ b/modules/admin-full/luasrc/view/admin_status/routes.htm @@ -15,9 +15,9 @@ $Id$ <%- require "bit" - require "luci.fs" require "luci.sys" require "luci.tools.webadmin" + require "nixio.fs" local style = true -%> @@ -54,7 +54,7 @@ $Id$ </fieldset> <br /> - <% if luci.fs.access("/proc/net/ipv6_route") then style = true %> + <% if fs.access("/proc/net/ipv6_route") then style = true %> <fieldset class="cbi-section" id="cbi-table-table"> <legend><%:a_n_routes_kernel6%></legend> |