luci-mod-admin-full: switch to nixio.fs
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
This commit is contained in:
parent
9780ee382e
commit
b7f80a98d8
6 changed files with 61 additions and 66 deletions
|
@ -16,13 +16,15 @@ $Id$
|
||||||
module("luci.controller.admin.system", package.seeall)
|
module("luci.controller.admin.system", package.seeall)
|
||||||
|
|
||||||
function index()
|
function index()
|
||||||
|
local fs = require "nixio.fs"
|
||||||
|
|
||||||
entry({"admin", "system"}, alias("admin", "system", "system"), _("System"), 30).index = true
|
entry({"admin", "system"}, alias("admin", "system", "system"), _("System"), 30).index = true
|
||||||
entry({"admin", "system", "system"}, cbi("admin_system/system"), _("System"), 1)
|
entry({"admin", "system", "system"}, cbi("admin_system/system"), _("System"), 1)
|
||||||
entry({"admin", "system", "clock_status"}, call("action_clock_status"))
|
entry({"admin", "system", "clock_status"}, call("action_clock_status"))
|
||||||
|
|
||||||
entry({"admin", "system", "admin"}, cbi("admin_system/admin"), _("Administration"), 2)
|
entry({"admin", "system", "admin"}, cbi("admin_system/admin"), _("Administration"), 2)
|
||||||
|
|
||||||
if nixio.fs.access("/bin/opkg") then
|
if fs.access("/bin/opkg") then
|
||||||
entry({"admin", "system", "packages"}, call("action_packages"), _("Software"), 10)
|
entry({"admin", "system", "packages"}, call("action_packages"), _("Software"), 10)
|
||||||
entry({"admin", "system", "packages", "ipkg"}, form("admin_system/ipkg"))
|
entry({"admin", "system", "packages", "ipkg"}, form("admin_system/ipkg"))
|
||||||
end
|
end
|
||||||
|
@ -30,13 +32,13 @@ function index()
|
||||||
entry({"admin", "system", "startup"}, form("admin_system/startup"), _("Startup"), 45)
|
entry({"admin", "system", "startup"}, form("admin_system/startup"), _("Startup"), 45)
|
||||||
entry({"admin", "system", "crontab"}, form("admin_system/crontab"), _("Scheduled Tasks"), 46)
|
entry({"admin", "system", "crontab"}, form("admin_system/crontab"), _("Scheduled Tasks"), 46)
|
||||||
|
|
||||||
if nixio.fs.access("/etc/config/fstab") then
|
if fs.access("/etc/config/fstab") then
|
||||||
entry({"admin", "system", "fstab"}, cbi("admin_system/fstab"), _("Mount Points"), 50)
|
entry({"admin", "system", "fstab"}, cbi("admin_system/fstab"), _("Mount Points"), 50)
|
||||||
entry({"admin", "system", "fstab", "mount"}, cbi("admin_system/fstab/mount"), nil).leaf = true
|
entry({"admin", "system", "fstab", "mount"}, cbi("admin_system/fstab/mount"), nil).leaf = true
|
||||||
entry({"admin", "system", "fstab", "swap"}, cbi("admin_system/fstab/swap"), nil).leaf = true
|
entry({"admin", "system", "fstab", "swap"}, cbi("admin_system/fstab/swap"), nil).leaf = true
|
||||||
end
|
end
|
||||||
|
|
||||||
if nixio.fs.access("/sys/class/leds") then
|
if fs.access("/sys/class/leds") then
|
||||||
entry({"admin", "system", "leds"}, cbi("admin_system/leds"), _("<abbr title=\"Light Emitting Diode\">LED</abbr> Configuration"), 60)
|
entry({"admin", "system", "leds"}, cbi("admin_system/leds"), _("<abbr title=\"Light Emitting Diode\">LED</abbr> Configuration"), 60)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -142,12 +144,11 @@ function action_packages()
|
||||||
-- List state
|
-- List state
|
||||||
local no_lists = true
|
local no_lists = true
|
||||||
local old_lists = false
|
local old_lists = false
|
||||||
local tmp = nixio.fs.dir("/var/opkg-lists/")
|
if fs.access("/var/opkg-lists/") then
|
||||||
if tmp then
|
local list
|
||||||
for tmp in tmp do
|
for list in fs.dir("/var/opkg-lists/") do
|
||||||
no_lists = false
|
no_lists = false
|
||||||
tmp = nixio.fs.stat("/var/opkg-lists/"..tmp)
|
if (fs.stat("/var/opkg-lists/"..list, "mtime") or 0) < (os.time() - (24 * 60 * 60)) then
|
||||||
if tmp and tmp.mtime < (os.time() - (24 * 60 * 60)) then
|
|
||||||
old_lists = true
|
old_lists = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
@ -171,15 +172,15 @@ function action_packages()
|
||||||
|
|
||||||
-- Remove index cache
|
-- Remove index cache
|
||||||
if changes then
|
if changes then
|
||||||
nixio.fs.unlink("/tmp/luci-indexcache")
|
fs.unlink("/tmp/luci-indexcache")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function action_flashops()
|
function action_flashops()
|
||||||
local sys = require "luci.sys"
|
local sys = require "luci.sys"
|
||||||
local fs = require "luci.fs"
|
local fs = require "nixio.fs"
|
||||||
|
|
||||||
local upgrade_avail = nixio.fs.access("/lib/upgrade/platform.sh")
|
local upgrade_avail = fs.access("/lib/upgrade/platform.sh")
|
||||||
local reset_avail = os.execute([[grep '"rootfs_data"' /proc/mtd >/dev/null 2>&1]]) == 0
|
local reset_avail = os.execute([[grep '"rootfs_data"' /proc/mtd >/dev/null 2>&1]]) == 0
|
||||||
|
|
||||||
local restore_cmd = "tar -xzC/ >/dev/null 2>&1"
|
local restore_cmd = "tar -xzC/ >/dev/null 2>&1"
|
||||||
|
@ -202,7 +203,7 @@ function action_flashops()
|
||||||
|
|
||||||
local function storage_size()
|
local function storage_size()
|
||||||
local size = 0
|
local size = 0
|
||||||
if nixio.fs.access("/proc/mtd") then
|
if fs.access("/proc/mtd") then
|
||||||
for l in io.lines("/proc/mtd") do
|
for l in io.lines("/proc/mtd") do
|
||||||
local d, s, e, n = l:match('^([^%s]+)%s+([^%s]+)%s+([^%s]+)%s+"([^%s]+)"')
|
local d, s, e, n = l:match('^([^%s]+)%s+([^%s]+)%s+([^%s]+)%s+"([^%s]+)"')
|
||||||
if n == "linux" or n == "firmware" then
|
if n == "linux" or n == "firmware" then
|
||||||
|
@ -210,7 +211,7 @@ function action_flashops()
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif nixio.fs.access("/proc/partitions") then
|
elseif fs.access("/proc/partitions") then
|
||||||
for l in io.lines("/proc/partitions") do
|
for l in io.lines("/proc/partitions") do
|
||||||
local x, y, b, n = l:match('^%s*(%d+)%s+(%d+)%s+([^%s]+)%s+([^%s]+)')
|
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
|
if b and n and not n:match('[0-9]') then
|
||||||
|
@ -270,11 +271,11 @@ function action_flashops()
|
||||||
luci.template.render("admin_system/upgrade", {
|
luci.template.render("admin_system/upgrade", {
|
||||||
checksum = image_checksum(),
|
checksum = image_checksum(),
|
||||||
storage = storage_size(),
|
storage = storage_size(),
|
||||||
size = nixio.fs.stat(image_tmp).size,
|
size = (fs.stat(image_tmp, "size") or 0),
|
||||||
keep = (not not luci.http.formvalue("keep"))
|
keep = (not not luci.http.formvalue("keep"))
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
nixio.fs.unlink(image_tmp)
|
fs.unlink(image_tmp)
|
||||||
luci.template.render("admin_system/flashops", {
|
luci.template.render("admin_system/flashops", {
|
||||||
reset_avail = reset_avail,
|
reset_avail = reset_avail,
|
||||||
upgrade_avail = upgrade_avail,
|
upgrade_avail = upgrade_avail,
|
||||||
|
|
|
@ -14,15 +14,14 @@ You may obtain a copy of the License at
|
||||||
$Id$
|
$Id$
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
require "luci.fs"
|
local fs = require "nixio.fs"
|
||||||
require "luci.sys"
|
local sys = require "luci.sys"
|
||||||
require "luci.util"
|
|
||||||
|
|
||||||
local inits = { }
|
local inits = { }
|
||||||
|
|
||||||
for _, name in ipairs(luci.sys.init.names()) do
|
for _, name in ipairs(sys.init.names()) do
|
||||||
local index = luci.sys.init.index(name)
|
local index = sys.init.index(name)
|
||||||
local enabled = luci.sys.init.enabled(name)
|
local enabled = sys.init.enabled(name)
|
||||||
|
|
||||||
if index < 255 then
|
if index < 255 then
|
||||||
inits["%02i.%s" % { index, name }] = {
|
inits["%02i.%s" % { index, name }] = {
|
||||||
|
@ -62,10 +61,10 @@ end
|
||||||
e.write = function(self, section)
|
e.write = function(self, section)
|
||||||
if inits[section].enabled then
|
if inits[section].enabled then
|
||||||
inits[section].enabled = false
|
inits[section].enabled = false
|
||||||
return luci.sys.init.disable(inits[section].name)
|
return sys.init.disable(inits[section].name)
|
||||||
else
|
else
|
||||||
inits[section].enabled = true
|
inits[section].enabled = true
|
||||||
return luci.sys.init.enable(inits[section].name)
|
return sys.init.enable(inits[section].name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -73,7 +72,7 @@ end
|
||||||
start = s:option(Button, "start", translate("Start"))
|
start = s:option(Button, "start", translate("Start"))
|
||||||
start.inputstyle = "apply"
|
start.inputstyle = "apply"
|
||||||
start.write = function(self, section)
|
start.write = function(self, section)
|
||||||
luci.sys.call("/etc/init.d/%s %s >/dev/null" %{ inits[section].name, self.option })
|
sys.call("/etc/init.d/%s %s >/dev/null" %{ inits[section].name, self.option })
|
||||||
end
|
end
|
||||||
|
|
||||||
restart = s:option(Button, "restart", translate("Restart"))
|
restart = s:option(Button, "restart", translate("Restart"))
|
||||||
|
@ -94,13 +93,13 @@ t.rmempty = true
|
||||||
t.rows = 20
|
t.rows = 20
|
||||||
|
|
||||||
function t.cfgvalue()
|
function t.cfgvalue()
|
||||||
return luci.fs.readfile("/etc/rc.local") or ""
|
return fs.readfile("/etc/rc.local") or ""
|
||||||
end
|
end
|
||||||
|
|
||||||
function f.handle(self, state, data)
|
function f.handle(self, state, data)
|
||||||
if state == FORM_VALID then
|
if state == FORM_VALID then
|
||||||
if data.rcs then
|
if data.rcs then
|
||||||
luci.fs.writefile("/etc/rc.local", data.rcs:gsub("\r\n", "\n"))
|
fs.writefile("/etc/rc.local", data.rcs:gsub("\r\n", "\n"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -13,14 +13,13 @@ You may obtain a copy of the License at
|
||||||
$Id$
|
$Id$
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
require("luci.sys")
|
local sys = require "luci.sys"
|
||||||
require("luci.sys.zoneinfo")
|
local zones = require "luci.sys.zoneinfo"
|
||||||
require("luci.tools.webadmin")
|
local fs = require "nixio.fs"
|
||||||
require("luci.fs")
|
local conf = require "luci.config"
|
||||||
require("luci.config")
|
|
||||||
|
|
||||||
local m, s, o
|
local m, s, o
|
||||||
local has_ntpd = luci.fs.access("/usr/sbin/ntpd")
|
local has_ntpd = fs.access("/usr/sbin/ntpd")
|
||||||
|
|
||||||
m = Map("system", translate("System"), translate("Here you can configure the basic aspects of your device like its hostname or the timezone."))
|
m = Map("system", translate("System"), translate("Here you can configure the basic aspects of your device like its hostname or the timezone."))
|
||||||
m:chain("luci")
|
m:chain("luci")
|
||||||
|
@ -48,20 +47,20 @@ o.datatype = "hostname"
|
||||||
|
|
||||||
function o.write(self, section, value)
|
function o.write(self, section, value)
|
||||||
Value.write(self, section, value)
|
Value.write(self, section, value)
|
||||||
luci.sys.hostname(value)
|
sys.hostname(value)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
o = s:taboption("general", ListValue, "zonename", translate("Timezone"))
|
o = s:taboption("general", ListValue, "zonename", translate("Timezone"))
|
||||||
o:value("UTC")
|
o:value("UTC")
|
||||||
|
|
||||||
for i, zone in ipairs(luci.sys.zoneinfo.TZ) do
|
for i, zone in ipairs(zones.TZ) do
|
||||||
o:value(zone[1])
|
o:value(zone[1])
|
||||||
end
|
end
|
||||||
|
|
||||||
function o.write(self, section, value)
|
function o.write(self, section, value)
|
||||||
local function lookup_zone(title)
|
local function lookup_zone(title)
|
||||||
for _, zone in ipairs(luci.sys.zoneinfo.TZ) do
|
for _, zone in ipairs(zones.TZ) do
|
||||||
if zone[1] == title then return zone[2] end
|
if zone[1] == title then return zone[2] end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -69,7 +68,7 @@ function o.write(self, section, value)
|
||||||
AbstractValue.write(self, section, value)
|
AbstractValue.write(self, section, value)
|
||||||
local timezone = lookup_zone(value) or "GMT0"
|
local timezone = lookup_zone(value) or "GMT0"
|
||||||
self.map.uci:set("system", section, "timezone", timezone)
|
self.map.uci:set("system", section, "timezone", timezone)
|
||||||
luci.fs.writefile("/etc/TZ", timezone .. "\n")
|
fs.writefile("/etc/TZ", timezone .. "\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,9 +116,9 @@ o = s:taboption("language", ListValue, "_lang", translate("Language"))
|
||||||
o:value("auto")
|
o:value("auto")
|
||||||
|
|
||||||
local i18ndir = luci.i18n.i18ndir .. "base."
|
local i18ndir = luci.i18n.i18ndir .. "base."
|
||||||
for k, v in luci.util.kspairs(luci.config.languages) do
|
for k, v in luci.util.kspairs(conf.languages) do
|
||||||
local file = i18ndir .. k:gsub("_", "-")
|
local file = i18ndir .. k:gsub("_", "-")
|
||||||
if k:sub(1, 1) ~= "." and luci.fs.access(file .. ".lmo") then
|
if k:sub(1, 1) ~= "." and fs.access(file .. ".lmo") then
|
||||||
o:value(k, v)
|
o:value(k, v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -134,7 +133,7 @@ end
|
||||||
|
|
||||||
|
|
||||||
o = s:taboption("language", ListValue, "_mediaurlbase", translate("Design"))
|
o = s:taboption("language", ListValue, "_mediaurlbase", translate("Design"))
|
||||||
for k, v in pairs(luci.config.themes) do
|
for k, v in pairs(conf.themes) do
|
||||||
if k:sub(1, 1) ~= "." then
|
if k:sub(1, 1) ~= "." then
|
||||||
o:value(v, k)
|
o:value(v, k)
|
||||||
end
|
end
|
||||||
|
@ -196,17 +195,17 @@ if has_ntpd then
|
||||||
o.rmempty = false
|
o.rmempty = false
|
||||||
|
|
||||||
function o.cfgvalue(self)
|
function o.cfgvalue(self)
|
||||||
return luci.sys.init.enabled("sysntpd")
|
return sys.init.enabled("sysntpd")
|
||||||
and self.enabled or self.disabled
|
and self.enabled or self.disabled
|
||||||
end
|
end
|
||||||
|
|
||||||
function o.write(self, section, value)
|
function o.write(self, section, value)
|
||||||
if value == self.enabled then
|
if value == self.enabled then
|
||||||
luci.sys.init.enable("sysntpd")
|
sys.init.enable("sysntpd")
|
||||||
luci.sys.call("env -i /etc/init.d/sysntpd start >/dev/null")
|
sys.call("env -i /etc/init.d/sysntpd start >/dev/null")
|
||||||
else
|
else
|
||||||
luci.sys.call("env -i /etc/init.d/sysntpd stop >/dev/null")
|
sys.call("env -i /etc/init.d/sysntpd stop >/dev/null")
|
||||||
luci.sys.init.disable("sysntpd")
|
sys.init.disable("sysntpd")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ You may obtain a copy of the License at
|
||||||
<%-
|
<%-
|
||||||
|
|
||||||
local sys = require "luci.sys"
|
local sys = require "luci.sys"
|
||||||
local fs = require "luci.fs"
|
local fs = require "nixio.fs"
|
||||||
local utl = require "luci.util"
|
local utl = require "luci.util"
|
||||||
local uci = require "luci.model.uci".cursor()
|
local uci = require "luci.model.uci".cursor()
|
||||||
local ntm = require "luci.model.network"
|
local ntm = require "luci.model.network"
|
||||||
|
@ -86,7 +86,7 @@ You may obtain a copy of the License at
|
||||||
return translate("Hermes 802.11b Wireless Controller")
|
return translate("Hermes 802.11b Wireless Controller")
|
||||||
|
|
||||||
-- hostap
|
-- hostap
|
||||||
elseif name == "wlan" and fs.isdirectory("/proc/net/hostap/" .. ifname) then
|
elseif name == "wlan" and fs.stat("/proc/net/hostap/" .. ifname, "type") == "dir" then
|
||||||
return translate("Prism2/2.5/3 802.11b Wireless Controller")
|
return translate("Prism2/2.5/3 802.11b Wireless Controller")
|
||||||
|
|
||||||
-- dunno yet
|
-- dunno yet
|
||||||
|
|
|
@ -12,13 +12,13 @@ You may obtain a copy of the License at
|
||||||
-%>
|
-%>
|
||||||
|
|
||||||
<%
|
<%
|
||||||
require "luci.fs"
|
local fs = require "nixio.fs"
|
||||||
require "luci.tools.status"
|
local util = require "luci.util"
|
||||||
|
local stat = require "luci.tools.status"
|
||||||
|
|
||||||
local has_ipv6 = luci.fs.access("/proc/net/ipv6_route")
|
local has_ipv6 = fs.access("/proc/net/ipv6_route")
|
||||||
local has_dhcp = luci.fs.access("/etc/config/dhcp")
|
local has_dhcp = fs.access("/etc/config/dhcp")
|
||||||
local has_wifi = luci.fs.stat("/etc/config/wireless")
|
local has_wifi = ((fs.stat("/etc/config/wireless", "size") or 0) > 0)
|
||||||
has_wifi = has_wifi and has_wifi.size > 0
|
|
||||||
|
|
||||||
local sysinfo = luci.util.ubus("system", "info") or { }
|
local sysinfo = luci.util.ubus("system", "info") or { }
|
||||||
local boardinfo = luci.util.ubus("system", "board") or { }
|
local boardinfo = luci.util.ubus("system", "board") or { }
|
||||||
|
@ -35,7 +35,7 @@ You may obtain a copy of the License at
|
||||||
free = 0
|
free = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
local has_dsl = luci.fs.stat("/etc/init.d/dsl_control")
|
local has_dsl = fs.access("/etc/init.d/dsl_control")
|
||||||
|
|
||||||
if luci.http.formvalue("status") == "1" then
|
if luci.http.formvalue("status") == "1" then
|
||||||
local ntm = require "luci.model.network".init()
|
local ntm = require "luci.model.network".init()
|
||||||
|
@ -60,9 +60,9 @@ You may obtain a copy of the License at
|
||||||
swap = swapinfo,
|
swap = swapinfo,
|
||||||
connmax = conn_max,
|
connmax = conn_max,
|
||||||
conncount = conn_count,
|
conncount = conn_count,
|
||||||
leases = luci.tools.status.dhcp_leases(),
|
leases = stat.dhcp_leases(),
|
||||||
leases6 = luci.tools.status.dhcp6_leases(),
|
leases6 = stat.dhcp6_leases(),
|
||||||
wifinets = luci.tools.status.wifi_networks()
|
wifinets = stat.wifi_networks()
|
||||||
}
|
}
|
||||||
|
|
||||||
if wan then
|
if wan then
|
||||||
|
@ -695,13 +695,10 @@ You may obtain a copy of the License at
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%-
|
<%-
|
||||||
require "luci.util"
|
local incdir = util.libpath() .. "/view/admin_status/index/"
|
||||||
require "nixio.fs"
|
if fs.access(incdir) then
|
||||||
|
|
||||||
local plugins = nixio.fs.dir(luci.util.libpath() .. "/view/admin_status/index")
|
|
||||||
if plugins then
|
|
||||||
local inc
|
local inc
|
||||||
for inc in plugins do
|
for inc in fs.dir(incdir) do
|
||||||
if inc:match("%.htm$") then
|
if inc:match("%.htm$") then
|
||||||
include("admin_status/index/" .. inc:gsub("%.htm$", ""))
|
include("admin_status/index/" .. inc:gsub("%.htm$", ""))
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,10 +16,10 @@ $Id$
|
||||||
<%-
|
<%-
|
||||||
|
|
||||||
require "luci.sys.iptparser"
|
require "luci.sys.iptparser"
|
||||||
require "luci.tools.webadmin"
|
local wba = require "luci.tools.webadmin"
|
||||||
require "luci.fs"
|
local fs = require "nixio.fs"
|
||||||
|
|
||||||
local has_ip6tables = luci.fs.access("/usr/sbin/ip6tables")
|
local has_ip6tables = fs.access("/usr/sbin/ip6tables")
|
||||||
local mode = 4
|
local mode = 4
|
||||||
|
|
||||||
if has_ip6tables then
|
if has_ip6tables then
|
||||||
|
@ -28,7 +28,6 @@ $Id$
|
||||||
end
|
end
|
||||||
|
|
||||||
local ipt = luci.sys.iptparser.IptParser(mode)
|
local ipt = luci.sys.iptparser.IptParser(mode)
|
||||||
local wba = luci.tools.webadmin
|
|
||||||
|
|
||||||
local rowcnt = 1
|
local rowcnt = 1
|
||||||
function rowstyle()
|
function rowstyle()
|
||||||
|
|
Loading…
Reference in a new issue