luci-0.9: merge r4886-r4890
This commit is contained in:
parent
2e70805812
commit
2396520413
26 changed files with 153 additions and 296 deletions
|
@ -9,3 +9,5 @@
|
|||
x(self, schemedir or SYSROOT .. "/lib/uci/schema")
|
||||
end
|
||||
|
||||
local sys = require "luci.sys"
|
||||
sys.user.checkpasswd = function() return true end
|
||||
|
|
1
contrib/bitlib/.gitignore
vendored
1
contrib/bitlib/.gitignore
vendored
|
@ -1 +0,0 @@
|
|||
bitlib-*
|
|
@ -1,36 +0,0 @@
|
|||
include ../../build/config.mk
|
||||
include ../../build/gccconfig.mk
|
||||
|
||||
BITLIB_VERSION = 25
|
||||
BITLIB_SITE = http://dev.luci.freifunk-halle.net/sources/
|
||||
BITLIB_DIR = bitlib-$(BITLIB_VERSION)
|
||||
BITLIB_FILE = $(BITLIB_DIR).tar.gz
|
||||
BITLIB_URL = $(BITLIB_SITE)/$(BITLIB_FILE)
|
||||
|
||||
all: compile
|
||||
|
||||
include ../../build/module.mk
|
||||
|
||||
$(BITLIB_FILE):
|
||||
wget -O $@ $(BITLIB_URL) || rm -f $@
|
||||
|
||||
$(BITLIB_DIR)/.prepared: $(BITLIB_FILE)
|
||||
rm -rf $(BITLIB_DIR)
|
||||
tar xvfz $(BITLIB_FILE)
|
||||
test -f $(BITLIB_DIR)/config.h || cp $(BITLIB_DIR)/config.h.in $(BITLIB_DIR)/config.h
|
||||
touch $@
|
||||
|
||||
compile: $(BITLIB_DIR)/.prepared dist$(LUA_LIBRARYDIR)/bit.so
|
||||
|
||||
dist$(LUA_LIBRARYDIR)/bit.so:
|
||||
mkdir -p dist$(LUA_LIBRARYDIR)
|
||||
$(COMPILE) -DHAVE_CONFIG_H -I$(BITLIB_DIR) -O2 -c $(BITLIB_DIR)/lbitlib.c $(FPIC) $(LUA_CFLAGS) -o $(BITLIB_DIR)/lbitlib.o
|
||||
$(LINK) $(SHLIB_FLAGS) $(LDFLAGS) $(BITLIB_DIR)/lbitlib.o $(LUA_SHLIBS) -lm -ldl -o dist$(LUA_LIBRARYDIR)/bit.so
|
||||
|
||||
luasource:
|
||||
luastrip:
|
||||
luacompile:
|
||||
compile-all: compile
|
||||
|
||||
clean:
|
||||
rm -rf $(BITLIB_DIR) $(BITLIB_FILE)
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
local assert, getfenv, ipairs, loadstring, pairs, setfenv, tostring, tonumber, type = assert, getfenv, ipairs, loadstring, pairs, setfenv, tostring, tonumber, type
|
||||
local io = require"io"
|
||||
local posix = require "posix"
|
||||
local posix = require "nixio.fs"
|
||||
local lp = require "luadoc.lp"
|
||||
local luadoc = require"luadoc"
|
||||
local package = package
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
local assert, pairs, tostring, type = assert, pairs, tostring, type
|
||||
local io = require "io"
|
||||
local posix = require "posix"
|
||||
local posix = require "nixio.fs"
|
||||
local luadoc = require "luadoc"
|
||||
local util = require "luadoc.util"
|
||||
local tags = require "luadoc.taglet.standard.tags"
|
||||
|
@ -505,14 +505,14 @@ end
|
|||
-- @return table with documentation
|
||||
|
||||
function directory (path, doc)
|
||||
for f in posix.files(path) do
|
||||
for f in posix.dir(path) do
|
||||
local fullpath = path .. "/" .. f
|
||||
local attr = posix.stat(fullpath)
|
||||
assert(attr, string.format("error stating file `%s'", fullpath))
|
||||
|
||||
if attr.type == "regular" then
|
||||
if attr.type == "reg" then
|
||||
doc = file(fullpath, doc)
|
||||
elseif attr.type == "directory" and f ~= "." and f ~= ".." then
|
||||
elseif attr.type == "dir" and f ~= "." and f ~= ".." then
|
||||
doc = directory(fullpath, doc)
|
||||
end
|
||||
end
|
||||
|
@ -550,9 +550,9 @@ function start (files, doc)
|
|||
local attr = posix.stat(path)
|
||||
assert(attr, string.format("error stating path `%s'", path))
|
||||
|
||||
if attr.type == "regular" then
|
||||
if attr.type == "reg" then
|
||||
doc = file(path, doc)
|
||||
elseif attr.type == "directory" then
|
||||
elseif attr.type == "dir" then
|
||||
doc = directory(path, doc)
|
||||
end
|
||||
end)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
-- @release $Id: util.lua,v 1.16 2008/02/17 06:42:51 jasonsantos Exp $
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
local posix = require "posix"
|
||||
local posix = require "nixio.fs"
|
||||
local type, table, string, io, assert, tostring, setmetatable, pcall = type, table, string, io, assert, tostring, setmetatable, pcall
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
|
3
contrib/luaposix/.gitignore
vendored
3
contrib/luaposix/.gitignore
vendored
|
@ -1,3 +0,0 @@
|
|||
luaposix-*
|
||||
lua-posix_*
|
||||
patches/series
|
|
@ -1,35 +0,0 @@
|
|||
include ../../build/config.mk
|
||||
include ../../build/gccconfig.mk
|
||||
|
||||
LUAPOSIX_VERSION = 5.1.4
|
||||
LUAPOSIX_SITE = http://dev.luci.freifunk-halle.net/sources/
|
||||
LUAPOSIX_DIR = luaposix-$(LUAPOSIX_VERSION)
|
||||
LUAPOSIX_FILE = lua-posix_5.1.4.orig.tar.gz
|
||||
LUAPOSIX_URL = $(LUAPOSIX_SITE)/$(LUAPOSIX_FILE)
|
||||
LUAPOSIX_PATCHDIR = patches
|
||||
|
||||
all: compile
|
||||
|
||||
include ../../build/module.mk
|
||||
|
||||
$(LUAPOSIX_FILE):
|
||||
wget -O $@ $(LUAPOSIX_URL) || rm -f $@
|
||||
|
||||
$(LUAPOSIX_DIR)/.prepared: $(LUAPOSIX_FILE)
|
||||
rm -rf $(LUAPOSIX_DIR)
|
||||
tar xvfz $(LUAPOSIX_FILE)
|
||||
touch $@
|
||||
|
||||
compile: $(LUAPOSIX_DIR)/.prepared
|
||||
$(MAKE) -C $(LUAPOSIX_DIR) CC=$(CC) CFLAGS="$(CFLAGS) $(LUA_CFLAGS)" LDFLAGS="$(LDFLAGS) $(LUA_SHLIBS)" OS="$(OS)"
|
||||
mkdir -p dist$(LUA_LIBRARYDIR)
|
||||
cp $(LUAPOSIX_DIR)/posix.so dist$(LUA_LIBRARYDIR)
|
||||
|
||||
luasource:
|
||||
luastrip:
|
||||
luacompile:
|
||||
compile-all: compile
|
||||
|
||||
clean:
|
||||
rm -rf $(LUAPOSIX_DIR) $(LUAPOSIX_FILE)
|
||||
rm -f $(LUAPOSIX_PATCHDIR)/series
|
|
@ -94,7 +94,7 @@ endef
|
|||
|
||||
define Package/luci-core
|
||||
$(call Package/luci/libtemplate)
|
||||
DEPENDS:=+lua
|
||||
DEPENDS:=+lua +luci-nixio
|
||||
TITLE:=LuCI core libraries
|
||||
endef
|
||||
|
||||
|
@ -242,7 +242,7 @@ NIXIO_TLS:=axtls
|
|||
|
||||
define Package/luci-nixio
|
||||
$(call Package/luci/libtemplate)
|
||||
TITLE:=NIXIO Socket Library
|
||||
TITLE:=NIXIO POSIX Library
|
||||
DEPENDS:=
|
||||
endef
|
||||
|
||||
|
|
|
@ -66,10 +66,10 @@ $Id$
|
|||
local filestat = luci.fs.stat( filepath )
|
||||
local baseurl = luci.dispatcher.build_url('admin', 'filebrowser')
|
||||
|
||||
if filestat and filestat.type == "regular" then
|
||||
if filestat and filestat.type == "reg" then
|
||||
table.remove( path, #path )
|
||||
filepath = table.concat( path, '/' ) .. '/'
|
||||
elseif not ( filestat and filestat.type == "directory" ) then
|
||||
elseif not ( filestat and filestat.type == "dir" ) then
|
||||
path = { '' }
|
||||
filepath = '/'
|
||||
else
|
||||
|
@ -99,7 +99,7 @@ $Id$
|
|||
<ul>
|
||||
<% for _, e in luci.util.vspairs(entries) do
|
||||
local stat = luci.fs.stat(filepath..e)
|
||||
if e ~= '.' and e ~= '..' and stat and stat.type == 'directory' then
|
||||
if e ~= '.' and e ~= '..' and stat and stat.type == 'dir' then
|
||||
-%>
|
||||
<li class="dir">
|
||||
<img src="/luci-static/resources/cbi/folder.png" alt="Directory" />
|
||||
|
@ -109,7 +109,7 @@ $Id$
|
|||
|
||||
<% for _, e in luci.util.vspairs(entries) do
|
||||
local stat = luci.fs.stat(filepath..e)
|
||||
if stat and stat.type ~= 'directory' then
|
||||
if stat and stat.type ~= 'dir' then
|
||||
-%>
|
||||
<li class="file">
|
||||
<img src="/luci-static/resources/cbi/file.png" alt="File" />
|
||||
|
|
|
@ -19,7 +19,7 @@ $Id$
|
|||
-%>
|
||||
<%+cbi/valueheader%>
|
||||
<% if v then %>
|
||||
<%:cbi_upload Uploaded File%> (<%=t.byte_format(luci.fs.stat(v).size or 0)%>)
|
||||
<%:cbi_upload Uploaded File%> (<%=t.byte_format(luci.fs.stat(v, "size") or 0)%>)
|
||||
<input type="hidden"<%= attr("value", v) .. attr("name", cbid) .. attr("id", cbid) %> />
|
||||
<input class="cbi-input-image" type="image" value="<%:cbi_replace%>" name="cbi.rlf.<%=section .. "." .. self.option%>" alt="<%:cbi_replace%>" title="<%:cbi_replace%>" src="<%=resource%>/cbi/reload.gif" />
|
||||
<% else %>
|
||||
|
|
|
@ -14,8 +14,9 @@ $Id$
|
|||
]]--
|
||||
|
||||
local io = require "io"
|
||||
local fs = require "nixio.fs"
|
||||
local util = require "luci.util"
|
||||
local posix = require "posix"
|
||||
local nixio = require "nixio"
|
||||
local debug = require "debug"
|
||||
local string = require "string"
|
||||
local package = require "package"
|
||||
|
@ -36,10 +37,10 @@ function cache_enable(cachepath, mode)
|
|||
mode = mode or "r--r--r--"
|
||||
|
||||
local loader = package.loaders[2]
|
||||
local uid = posix.getpid("uid")
|
||||
local uid = nixio.getpid("uid")
|
||||
|
||||
if not posix.stat(cachepath) then
|
||||
posix.mkdir(cachepath)
|
||||
if not fs.stat(cachepath) then
|
||||
fs.mkdir(cachepath)
|
||||
end
|
||||
|
||||
local function _encode_filename(name)
|
||||
|
@ -51,19 +52,19 @@ function cache_enable(cachepath, mode)
|
|||
end
|
||||
|
||||
local function _load_sane(file)
|
||||
local stat = posix.stat(file)
|
||||
local stat = fs.stat(file)
|
||||
if stat and stat.uid == uid and stat.mode == mode then
|
||||
return loadfile(file)
|
||||
end
|
||||
end
|
||||
|
||||
local function _write_sane(file, func)
|
||||
if posix.getpid("uid") == uid then
|
||||
if nixio.getuid() == uid then
|
||||
local fp = io.open(file, "w")
|
||||
if fp then
|
||||
fp:write(util.get_bytecode(func))
|
||||
fp:close()
|
||||
posix.chmod(file, mode)
|
||||
fs.chmod(file, mode)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,7 +27,8 @@ limitations under the License.
|
|||
local io = require "io"
|
||||
local os = require "os"
|
||||
local ltn12 = require "luci.ltn12"
|
||||
local posix = require "posix"
|
||||
local fs = require "nixio.fs"
|
||||
local nutil = require "nixio.util"
|
||||
|
||||
local type = type
|
||||
|
||||
|
@ -41,7 +42,7 @@ module "luci.fs"
|
|||
-- @return Number containing the return code, 0 on sucess or nil on error
|
||||
-- @return String containing the error description (if any)
|
||||
-- @return Number containing the os specific errno (if any)
|
||||
access = posix.access
|
||||
access = fs.access
|
||||
|
||||
--- Evaluate given shell glob pattern and return a table containing all matching
|
||||
-- file and directory entries.
|
||||
|
@ -51,81 +52,53 @@ access = posix.access
|
|||
-- @return Table containing file and directory entries or nil if no matches
|
||||
-- @return String containing the error description (if no matches)
|
||||
-- @return Number containing the os specific errno (if no matches)
|
||||
glob = posix.glob
|
||||
function glob(...)
|
||||
local iter, code, msg = fs.glob(...)
|
||||
if iter then
|
||||
return nutil.consume(iter)
|
||||
else
|
||||
return nil, code, msg
|
||||
end
|
||||
end
|
||||
|
||||
--- Checks wheather the given path exists and points to a regular file.
|
||||
-- @param filename String containing the path of the file to test
|
||||
-- @return Boolean indicating wheather given path points to regular file
|
||||
function isfile(filename)
|
||||
return posix.stat(filename, "type") == "regular"
|
||||
return fs.stat(filename, "type") == "reg"
|
||||
end
|
||||
|
||||
--- Checks wheather the given path exists and points to a directory.
|
||||
-- @param dirname String containing the path of the directory to test
|
||||
-- @return Boolean indicating wheather given path points to directory
|
||||
function isdirectory(dirname)
|
||||
return posix.stat(dirname, "type") == "directory"
|
||||
return fs.stat(dirname, "type") == "dir"
|
||||
end
|
||||
|
||||
--- Read the whole content of the given file into memory.
|
||||
-- @param filename String containing the path of the file to read
|
||||
-- @return String containing the file contents or nil on error
|
||||
-- @return String containing the error message on error
|
||||
function readfile(filename)
|
||||
local fp, err = io.open(filename)
|
||||
|
||||
if fp == nil then
|
||||
return nil, err
|
||||
end
|
||||
|
||||
local data = fp:read("*a")
|
||||
fp:close()
|
||||
return data
|
||||
end
|
||||
readfile = fs.readfile
|
||||
|
||||
--- Write the contents of given string to given file.
|
||||
-- @param filename String containing the path of the file to read
|
||||
-- @param data String containing the data to write
|
||||
-- @return Boolean containing true on success or nil on error
|
||||
-- @return String containing the error message on error
|
||||
function writefile(filename, data)
|
||||
local fp, err = io.open(filename, "w")
|
||||
|
||||
if fp == nil then
|
||||
return nil, err
|
||||
end
|
||||
|
||||
fp:write(data)
|
||||
fp:close()
|
||||
|
||||
return true
|
||||
end
|
||||
writefile = fs.writefile
|
||||
|
||||
--- Copies a file.
|
||||
-- @param source Source file
|
||||
-- @param dest Destination
|
||||
-- @return Boolean containing true on success or nil on error
|
||||
function copy(source, dest)
|
||||
return ltn12.pump.all(
|
||||
ltn12.source.file(io.open(source)),
|
||||
ltn12.sink.file(io.open(dest, "w"))
|
||||
)
|
||||
end
|
||||
copy = fs.datacopy
|
||||
|
||||
--- Renames a file.
|
||||
-- @param source Source file
|
||||
-- @param dest Destination
|
||||
-- @return Boolean containing true on success or nil on error
|
||||
function rename(source, dest)
|
||||
local stat, err, code = os.rename(source, dest)
|
||||
if code == 18 then
|
||||
stat, err, code = copy(source, dest)
|
||||
if stat then
|
||||
stat, err, code = unlink(source)
|
||||
end
|
||||
end
|
||||
return stat, err, code
|
||||
end
|
||||
rename = fs.move
|
||||
|
||||
--- Get the last modification time of given file path in Unix epoch format.
|
||||
-- @param path String containing the path of the file or directory to read
|
||||
|
@ -133,7 +106,7 @@ end
|
|||
-- @return String containing the error description (if any)
|
||||
-- @return Number containing the os specific errno (if any)
|
||||
function mtime(path)
|
||||
return posix.stat(path, "mtime")
|
||||
return fs.stat(path, "mtime")
|
||||
end
|
||||
|
||||
--- Set the last modification time of given file path in Unix epoch format.
|
||||
|
@ -143,7 +116,9 @@ end
|
|||
-- @return 0 in case of success nil on error
|
||||
-- @return String containing the error description (if any)
|
||||
-- @return Number containing the os specific errno (if any)
|
||||
utime = posix.utime
|
||||
function utime(path, mtime, atime)
|
||||
return fs.utimes(path, atime, mtime)
|
||||
end
|
||||
|
||||
--- Return the last element - usually the filename - from the given path with
|
||||
-- the directory component stripped.
|
||||
|
@ -152,7 +127,7 @@ utime = posix.utime
|
|||
-- @param path String containing the path to strip
|
||||
-- @return String containing the base name of given path
|
||||
-- @see dirname
|
||||
basename = posix.basename
|
||||
basename = fs.basename
|
||||
|
||||
--- Return the directory component of the given path with the last element
|
||||
-- stripped of.
|
||||
|
@ -161,7 +136,7 @@ basename = posix.basename
|
|||
-- @param path String containing the path to strip
|
||||
-- @return String containing the directory component of given path
|
||||
-- @see basename
|
||||
dirname = posix.dirname
|
||||
dirname = fs.dirname
|
||||
|
||||
--- Return a table containing all entries of the specified directory.
|
||||
-- @class function
|
||||
|
@ -170,7 +145,17 @@ dirname = posix.dirname
|
|||
-- @return Table containing file and directory entries or nil on error
|
||||
-- @return String containing the error description on error
|
||||
-- @return Number containing the os specific errno on error
|
||||
dir = posix.dir
|
||||
function dir(...)
|
||||
local iter, code, msg = fs.dir(...)
|
||||
if iter then
|
||||
local t = nutil.consume(iter)
|
||||
t[#t+1] = "."
|
||||
t[#t+1] = ".."
|
||||
return t
|
||||
else
|
||||
return nil, code, msg
|
||||
end
|
||||
end
|
||||
|
||||
--- Create a new directory, recursively on demand.
|
||||
-- @param path String with the name or path of the directory to create
|
||||
|
@ -179,36 +164,7 @@ dir = posix.dir
|
|||
-- @return String containing the error description on error
|
||||
-- @return Number containing the os specific errno on error
|
||||
function mkdir(path, recursive)
|
||||
if recursive then
|
||||
local base = "."
|
||||
|
||||
if path:sub(1,1) == "/" then
|
||||
base = ""
|
||||
path = path:gsub("^/+","")
|
||||
end
|
||||
|
||||
for elem in path:gmatch("([^/]+)/*") do
|
||||
base = base .. "/" .. elem
|
||||
|
||||
local stat = posix.stat( base )
|
||||
|
||||
if not stat then
|
||||
local stat, errmsg, errno = posix.mkdir( base )
|
||||
|
||||
if type(stat) ~= "number" or stat ~= 0 then
|
||||
return stat, errmsg, errno
|
||||
end
|
||||
else
|
||||
if stat.type ~= "directory" then
|
||||
return nil, base .. ": File exists", 17
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return 0
|
||||
else
|
||||
return posix.mkdir( path )
|
||||
end
|
||||
return recursive and fs.mkdirr(path) or fs.mkdir(path)
|
||||
end
|
||||
|
||||
--- Remove the given empty directory.
|
||||
|
@ -218,7 +174,7 @@ end
|
|||
-- @return Number with the return code, 0 on sucess or nil on error
|
||||
-- @return String containing the error description on error
|
||||
-- @return Number containing the os specific errno on error
|
||||
rmdir = posix.rmdir
|
||||
rmdir = fs.rmdir
|
||||
|
||||
--- Get information about given file or directory.
|
||||
-- @class function
|
||||
|
@ -227,7 +183,7 @@ rmdir = posix.rmdir
|
|||
-- @return Table containing file or directory properties or nil on error
|
||||
-- @return String containing the error description on error
|
||||
-- @return Number containing the os specific errno on error
|
||||
stat = posix.stat
|
||||
stat = fs.stat
|
||||
|
||||
--- Set permissions on given file or directory.
|
||||
-- @class function
|
||||
|
@ -237,7 +193,7 @@ stat = posix.stat
|
|||
-- @return Number with the return code, 0 on sucess or nil on error
|
||||
-- @return String containing the error description on error
|
||||
-- @return Number containing the os specific errno on error
|
||||
chmod = posix.chmod
|
||||
chmod = fs.chmod
|
||||
|
||||
--- Create a hard- or symlink from given file (or directory) to specified target
|
||||
-- file (or directory) path.
|
||||
|
@ -249,7 +205,9 @@ chmod = posix.chmod
|
|||
-- @return Number with the return code, 0 on sucess or nil on error
|
||||
-- @return String containing the error description on error
|
||||
-- @return Number containing the os specific errno on error
|
||||
link = posix.link
|
||||
function link(src, dest, sym)
|
||||
return sym and fs.symlink(src, dest) or fs.link(src, dest)
|
||||
end
|
||||
|
||||
--- Remove the given file.
|
||||
-- @class function
|
||||
|
@ -258,7 +216,7 @@ link = posix.link
|
|||
-- @return Number with the return code, 0 on sucess or nil on error
|
||||
-- @return String containing the error description on error
|
||||
-- @return Number containing the os specific errno on error
|
||||
unlink = posix.unlink
|
||||
unlink = fs.unlink
|
||||
|
||||
--- Retrieve target of given symlink.
|
||||
-- @class function
|
||||
|
@ -267,4 +225,4 @@ unlink = posix.unlink
|
|||
-- @return String containing the link target or nil on error
|
||||
-- @return String containing the error description on error
|
||||
-- @return Number containing the os specific errno on error
|
||||
readlink = posix.readlink
|
||||
readlink = fs.readlink
|
||||
|
|
|
@ -114,13 +114,12 @@ end
|
|||
|
||||
local function splice_sync(sock, pipeout, pipein, file, cb)
|
||||
local os = require "os"
|
||||
local posix = require "posix"
|
||||
local ssize = 65536
|
||||
local smode = nixio.splice_flags("move", "more")
|
||||
local stat
|
||||
|
||||
-- This is probably the only forking http-client ;-)
|
||||
local pid, code, msg = posix.fork()
|
||||
local pid, code, msg = nixio.fork()
|
||||
if not pid then
|
||||
return pid, code, msg
|
||||
elseif pid == 0 then
|
||||
|
@ -149,11 +148,11 @@ local function splice_sync(sock, pipeout, pipein, file, cb)
|
|||
file:close()
|
||||
|
||||
if not stat then
|
||||
posix.kill(pid)
|
||||
posix.wait(pid)
|
||||
nixio.kill(pid, 15)
|
||||
nixio.wait(pid)
|
||||
return stat, code, msg
|
||||
else
|
||||
pid, msg, code = posix.wait(pid)
|
||||
pid, msg, code = nixio.wait(pid)
|
||||
if msg == "exited" then
|
||||
if code == 0 then
|
||||
return true
|
||||
|
|
|
@ -66,19 +66,19 @@ function datacopy(src, dest, size)
|
|||
end
|
||||
|
||||
function copy(src, dest)
|
||||
local stat, code, msg, res = nixio.lstat(src)
|
||||
local stat, code, msg, res = nixio.fs.lstat(src)
|
||||
if not stat then
|
||||
return nil, code, msg
|
||||
end
|
||||
|
||||
if stat.type == "dir" then
|
||||
if nixio.stat(dest, type) ~= "dir" then
|
||||
res, code, msg = nixio.mkdir(dest)
|
||||
if nixio.fs.stat(dest, type) ~= "dir" then
|
||||
res, code, msg = nixio.fs.mkdir(dest)
|
||||
else
|
||||
stat = true
|
||||
end
|
||||
elseif stat.type == "lnk" then
|
||||
res, code, msg = nixio.symlink(nixio.readlink(src), dest)
|
||||
res, code, msg = nixio.fs.symlink(nixio.fs.readlink(src), dest)
|
||||
elseif stat.type == "reg" then
|
||||
res, code, msg = datacopy(src, dest)
|
||||
end
|
||||
|
@ -87,39 +87,39 @@ function copy(src, dest)
|
|||
return nil, code, msg
|
||||
end
|
||||
|
||||
nixio.utimes(dest, stat.atime, stat.mtime)
|
||||
nixio.fs.utimes(dest, stat.atime, stat.mtime)
|
||||
|
||||
if nixio.lchown then
|
||||
nixio.lchown(dest, stat.uid, stat.gid)
|
||||
if nixio.fs.lchown then
|
||||
nixio.fs.lchown(dest, stat.uid, stat.gid)
|
||||
end
|
||||
|
||||
if stat.type ~= "lnk" then
|
||||
nixio.chmod(dest, stat.modedec)
|
||||
nixio.fs.chmod(dest, stat.modedec)
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function move(src, dest)
|
||||
local stat, code, msg = nixio.rename(src, dest)
|
||||
local stat, code, msg = nixio.fs.rename(src, dest)
|
||||
if not stat and code == nixio.const.EXDEV then
|
||||
stat, code, msg = nixio.copy(src, dest)
|
||||
stat, code, msg = copy(src, dest)
|
||||
if stat then
|
||||
stat, code, msg = nixio.unlink(src)
|
||||
stat, code, msg = nixio.fs.unlink(src)
|
||||
end
|
||||
end
|
||||
return stat, code, msg
|
||||
end
|
||||
|
||||
function mkdirr(dest, mode)
|
||||
if nixio.stat(dest, "type") == "dir" then
|
||||
if nixio.fs.stat(dest, "type") == "dir" then
|
||||
return true
|
||||
else
|
||||
local stat, code, msg = nixio.mkdir(dest, mode)
|
||||
local stat, code, msg = nixio.fs.mkdir(dest, mode)
|
||||
if not stat and code == nixio.const.ENOENT then
|
||||
stat, code, msg = mkdirr(nixio.dirname(dest), mode)
|
||||
stat, code, msg = mkdirr(nixio.fs.dirname(dest), mode)
|
||||
if stat then
|
||||
stat, code, msg = nixio.mkdir(dest, mode)
|
||||
stat, code, msg = nixio.fs.mkdir(dest, mode)
|
||||
end
|
||||
end
|
||||
return stat, code, msg
|
||||
|
@ -127,7 +127,7 @@ function mkdirr(dest, mode)
|
|||
end
|
||||
|
||||
local function _recurse(cb, src, dest)
|
||||
local type = nixio.lstat(src, "type")
|
||||
local type = nixio.fs.lstat(src, "type")
|
||||
if type ~= "dir" then
|
||||
return cb(src, dest)
|
||||
else
|
||||
|
@ -137,7 +137,7 @@ local function _recurse(cb, src, dest)
|
|||
stat, code, msg = stat and s, c or code, m or msg
|
||||
end
|
||||
|
||||
for e in nixio.dir(src) do
|
||||
for e in nixio.fs.dir(src) do
|
||||
if dest then
|
||||
s, c, m = _recurse(cb, src .. se .. e, dest .. se .. e)
|
||||
else
|
||||
|
@ -160,16 +160,16 @@ function copyr(src, dest)
|
|||
end
|
||||
|
||||
function mover(src, dest)
|
||||
local stat, code, msg = nixio.rename(src, dest)
|
||||
local stat, code, msg = nixio.fs.rename(src, dest)
|
||||
if not stat and code == nixio.const.EXDEV then
|
||||
stat, code, msg = _recurse(copy, src, dest)
|
||||
if stat then
|
||||
stat, code, msg = _recurse(nixio.remove, src)
|
||||
stat, code, msg = _recurse(nixio.fs.remove, src)
|
||||
end
|
||||
end
|
||||
return stat, code, msg
|
||||
end
|
||||
|
||||
function remover(src)
|
||||
return _recurse(nixio.remove, src)
|
||||
return _recurse(nixio.fs.remove, src)
|
||||
end
|
|
@ -254,7 +254,7 @@ static int nixio_link(lua_State *L) {
|
|||
|
||||
static int nixio_utimes(lua_State *L) {
|
||||
const char *path = luaL_checkstring(L, 1);
|
||||
if (lua_gettop(L) < 2) {
|
||||
if (lua_gettop(L) < 2 || (lua_isnoneornil(L, 2) && lua_isnoneornil(L, 3))) {
|
||||
return nixio__pstatus(L, !utimes(path, NULL));
|
||||
} else {
|
||||
double atime = luaL_checknumber(L, 2);
|
||||
|
|
|
@ -27,7 +27,7 @@ limitations under the License.
|
|||
|
||||
local io = require "io"
|
||||
local os = require "os"
|
||||
local posix = require "posix"
|
||||
local nixio = require "nixio"
|
||||
local table = require "table"
|
||||
|
||||
local luci = {}
|
||||
|
@ -128,7 +128,7 @@ end
|
|||
-- @param var Name of the environment variable to retrieve (optional)
|
||||
-- @return String containg the value of the specified variable
|
||||
-- @return Table containing all variables if no variable name is given
|
||||
getenv = posix.getenv
|
||||
getenv = nixio.getenv
|
||||
|
||||
--- Get or set the current hostname.
|
||||
-- @param String containing a new hostname to set (optional)
|
||||
|
@ -138,7 +138,7 @@ function hostname(newname)
|
|||
luci.fs.writefile( "/proc/sys/kernel/hostname", newname .. "\n" )
|
||||
return newname
|
||||
else
|
||||
return posix.uname("%n")
|
||||
return nixio.uname().nodename
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -161,11 +161,9 @@ end
|
|||
-- @return String containing the average load value 1 minute ago
|
||||
-- @return String containing the average load value 5 minutes ago
|
||||
-- @return String containing the average load value 15 minutes ago
|
||||
-- @return String containing the active and total number of processes
|
||||
-- @return String containing the last used pid
|
||||
function loadavg()
|
||||
local loadavg = io.lines("/proc/loadavg")()
|
||||
return loadavg:match("^(.-) (.-) (.-) (.-) (.-)$")
|
||||
local info = nixio.sysinfo()
|
||||
return info.loads[1], info.loads[2], info.loads[3]
|
||||
end
|
||||
|
||||
--- Initiate a system reboot.
|
||||
|
@ -193,7 +191,7 @@ function sysinfo()
|
|||
local membuffers = tonumber(meminfo:match("Buffers:%s*(%d+)"))
|
||||
|
||||
if not system then
|
||||
system = posix.uname("%m")
|
||||
system = nixio.uname().machine
|
||||
model = cpuinfo:match("model name.-:%s*([^\n]+)")
|
||||
if not model then
|
||||
model = cpuinfo:match("Processor.-:%s*([^\n]+)")
|
||||
|
@ -243,18 +241,6 @@ function uptime()
|
|||
return loadavg:match("^(.-) (.-)$")
|
||||
end
|
||||
|
||||
--- LuCI system utilities / POSIX user group related functions.
|
||||
-- @class module
|
||||
-- @name luci.sys.group
|
||||
group = {}
|
||||
|
||||
--- Returns information about a POSIX user group.
|
||||
-- @class function
|
||||
-- @name getgroup
|
||||
-- @param group Group ID or name of a system user group
|
||||
-- @return Table with information about the requested group
|
||||
group.getgroup = posix.getgroup
|
||||
|
||||
|
||||
--- LuCI system utilities / network related functions.
|
||||
-- @class module
|
||||
|
@ -484,7 +470,10 @@ process = {}
|
|||
-- @class function
|
||||
-- @name process.info
|
||||
-- @return Number containing the current pid
|
||||
process.info = posix.getpid
|
||||
function process.info(key)
|
||||
local s = {uid = nixio.getuid(), gid = nixio.getgid()}
|
||||
return not key and s or s[key]
|
||||
end
|
||||
|
||||
--- Retrieve information about currently running processes.
|
||||
-- @return Table containing process information
|
||||
|
@ -527,23 +516,21 @@ function process.list()
|
|||
end
|
||||
|
||||
--- Set the gid of a process identified by given pid.
|
||||
-- @param pid Number containing the process id
|
||||
-- @param gid Number containing the Unix group id
|
||||
-- @return Boolean indicating successful operation
|
||||
-- @return String containing the error message if failed
|
||||
-- @return Number containing the error code if failed
|
||||
function process.setgroup(pid, gid)
|
||||
return posix.setpid("g", pid, gid)
|
||||
function process.setgroup(gid)
|
||||
return nixio.setgid(gid)
|
||||
end
|
||||
|
||||
--- Set the uid of a process identified by given pid.
|
||||
-- @param pid Number containing the process id
|
||||
-- @param uid Number containing the Unix user id
|
||||
-- @return Boolean indicating successful operation
|
||||
-- @return String containing the error message if failed
|
||||
-- @return Number containing the error code if failed
|
||||
function process.setuser(pid, uid)
|
||||
return posix.setpid("u", pid, uid)
|
||||
function process.setuser(uid)
|
||||
return nixio.setuid(uid)
|
||||
end
|
||||
|
||||
--- Send a signal to a process identified by given pid.
|
||||
|
@ -553,7 +540,7 @@ end
|
|||
-- @param sig Signal to send (default: 15 [SIGTERM])
|
||||
-- @return Boolean indicating successful operation
|
||||
-- @return Number containing the error code if failed
|
||||
process.signal = posix.kill
|
||||
process.signal = nixio.kill
|
||||
|
||||
|
||||
--- LuCI system utilities / user related functions.
|
||||
|
@ -567,44 +554,20 @@ user = {}
|
|||
-- @param uid Number containing the Unix user id
|
||||
-- @return Table containing the following fields:
|
||||
-- { "uid", "gid", "name", "passwd", "dir", "shell", "gecos" }
|
||||
user.getuser = posix.getpasswd
|
||||
user.getuser = nixio.getpw
|
||||
|
||||
--- Test whether given string matches the password of a given system user.
|
||||
-- @param username String containing the Unix user name
|
||||
-- @param password String containing the password to compare
|
||||
-- @param pass String containing the password to compare
|
||||
-- @return Boolean indicating wheather the passwords are equal
|
||||
function user.checkpasswd(username, password)
|
||||
local account = user.getuser(username)
|
||||
|
||||
if account then
|
||||
local pwd = account.passwd
|
||||
local shadowpw
|
||||
if #pwd == 1 then
|
||||
if luci.fs.stat("/etc/shadow") then
|
||||
if not pcall(function()
|
||||
for l in io.lines("/etc/shadow") do
|
||||
shadowpw = l:match("^%s:([^:]+)" % username)
|
||||
if shadowpw then
|
||||
pwd = shadowpw
|
||||
break
|
||||
end
|
||||
end
|
||||
end) then
|
||||
return nil, "Unable to access shadow-file"
|
||||
end
|
||||
end
|
||||
|
||||
if pwd == "!" then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
if pwd and #pwd > 0 and password and #password > 0 then
|
||||
return (pwd == posix.crypt(password, pwd))
|
||||
end
|
||||
function user.checkpasswd(username, pass)
|
||||
local pwe = nixio.getsp and nixio.getsp(username) or nixio.getpw(username)
|
||||
local pwh = pwe and (pwe.pwdp or pwe.passwd)
|
||||
if not pwh or #pwh < 1 or pwh ~= "!" and nixio.crypt(pass, pwh) ~= pwh then
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
--- Change the password of given user.
|
||||
|
|
|
@ -144,9 +144,9 @@ function directory( val, seen )
|
|||
|
||||
if s and not seen[s.ino] then
|
||||
seen[s.ino] = true
|
||||
if s.type == "directory" then
|
||||
if s.type == "dir" then
|
||||
return true
|
||||
elseif s.type == "link" then
|
||||
elseif s.type == "lnk" then
|
||||
return directory( fs.readlink(val), seen )
|
||||
end
|
||||
end
|
||||
|
@ -160,9 +160,9 @@ function file( val, seen )
|
|||
|
||||
if s and not seen[s.ino] then
|
||||
seen[s.ino] = true
|
||||
if s.type == "regular" then
|
||||
if s.type == "reg" then
|
||||
return true
|
||||
elseif s.type == "link" then
|
||||
elseif s.type == "lnk" then
|
||||
return file( fs.readlink(val), seen )
|
||||
end
|
||||
end
|
||||
|
@ -176,9 +176,9 @@ function device( val, seen )
|
|||
|
||||
if s and not seen[s.ino] then
|
||||
seen[s.ino] = true
|
||||
if s.type == "character device" or s.type == "block device" then
|
||||
if s.type == "chr" or s.type == "blk" then
|
||||
return true
|
||||
elseif s.type == "link" then
|
||||
elseif s.type == "lnk" then
|
||||
return device( fs.readlink(val), seen )
|
||||
end
|
||||
end
|
||||
|
|
|
@ -30,6 +30,7 @@ local sys = require "luci.sys"
|
|||
local init = require "luci.init"
|
||||
local util = require "luci.util"
|
||||
local http = require "luci.http"
|
||||
local nixio = require "nixio", require "nixio.util"
|
||||
|
||||
module("luci.dispatcher", package.seeall)
|
||||
context = util.threadlocal()
|
||||
|
@ -210,7 +211,8 @@ function dispatch(request)
|
|||
if (c and c.index) or not track.notemplate then
|
||||
local tpl = require("luci.template")
|
||||
local media = track.mediaurlbase or luci.config.main.mediaurlbase
|
||||
if not pcall(tpl.Template, "themes/%s/header" % fs.basename(media)) then
|
||||
if not tpl.Template("themes/%s/header" % fs.basename(media)) then
|
||||
--if not pcall(tpl.Template, "themes/%s/header" % fs.basename(media)) then
|
||||
media = nil
|
||||
for name, theme in pairs(luci.config.themes) do
|
||||
if name:sub(1,1) ~= "." and pcall(tpl.Template,
|
||||
|
@ -411,7 +413,7 @@ function createindex_plain(path, suffixes)
|
|||
if cachedate > realdate then
|
||||
assert(
|
||||
sys.process.info("uid") == fs.stat(indexcache, "uid")
|
||||
and fs.stat(indexcache, "mode") == "rw-------",
|
||||
and fs.stat(indexcache, "modestr") == "rw-------",
|
||||
"Fatal: Indexcache is not sane!"
|
||||
)
|
||||
|
||||
|
@ -438,8 +440,9 @@ function createindex_plain(path, suffixes)
|
|||
end
|
||||
|
||||
if indexcache then
|
||||
fs.writefile(indexcache, util.get_bytecode(index))
|
||||
fs.chmod(indexcache, "a-rwx,u+rw")
|
||||
local f = nixio.open(indexcache, "w", 600)
|
||||
f:writeall(util.get_bytecode(index))
|
||||
f:close()
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@ require("luci.fs")
|
|||
require("luci.util")
|
||||
require("luci.sys")
|
||||
require("luci.config")
|
||||
local nixio = require "nixio", require "nixio.util"
|
||||
local fs = require "nixio.fs"
|
||||
|
||||
|
||||
luci.config.sauth = luci.config.sauth or {}
|
||||
|
@ -37,7 +39,7 @@ function clean()
|
|||
for i, file in pairs(files) do
|
||||
local fname = sessionpath .. "/" .. file
|
||||
local stat = luci.fs.stat(fname)
|
||||
if stat and stat.type == "regular" and stat.atime + sessiontime < now then
|
||||
if stat and stat.type == "reg" and stat.mtime + sessiontime < now then
|
||||
luci.fs.unlink(fname)
|
||||
end
|
||||
end
|
||||
|
@ -45,8 +47,7 @@ end
|
|||
|
||||
--- Prepare session storage by creating the session directory.
|
||||
function prepare()
|
||||
luci.fs.mkdir(sessionpath)
|
||||
luci.fs.chmod(sessionpath, "a-rwx,u+rwx")
|
||||
fs.mkdir(sessionpath, 700)
|
||||
|
||||
if not sane() then
|
||||
error("Security Exception: Session path is not sane!")
|
||||
|
@ -67,6 +68,7 @@ function read(id)
|
|||
if not sane(sessionpath .. "/" .. id) then
|
||||
return
|
||||
end
|
||||
luci.fs.utime(sessionpath .. "/" .. id)
|
||||
return luci.fs.readfile(sessionpath .. "/" .. id)
|
||||
end
|
||||
|
||||
|
@ -76,7 +78,7 @@ end
|
|||
function sane(file)
|
||||
return luci.sys.process.info("uid")
|
||||
== luci.fs.stat(file or sessionpath, "uid")
|
||||
and luci.fs.stat(file or sessionpath, "mode")
|
||||
and luci.fs.stat(file or sessionpath, "modestr")
|
||||
== (file and "rw-------" or "rwx------")
|
||||
end
|
||||
|
||||
|
@ -91,8 +93,10 @@ function write(id, data)
|
|||
if not id:match("^%w+$") then
|
||||
error("Session ID is not sane!")
|
||||
end
|
||||
luci.fs.writefile(sessionpath .. "/" .. id, data)
|
||||
luci.fs.chmod(sessionpath .. "/" .. id, "a-rwx,u+rw")
|
||||
|
||||
local f = nixio.open(sessionpath .. "/" .. id, "w", 600)
|
||||
f:writeall(data)
|
||||
f:close()
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ local table = require "table"
|
|||
local string = require "string"
|
||||
local config = require "luci.config"
|
||||
local coroutine = require "coroutine"
|
||||
local nixio = require "nixio", require "nixio.util"
|
||||
|
||||
local tostring, pairs, loadstring = tostring, pairs, loadstring
|
||||
local setmetatable, loadfile = setmetatable, loadfile
|
||||
|
@ -177,7 +178,7 @@ function Template.__init__(self, name)
|
|||
|
||||
if not fs.mtime(cdir) then
|
||||
fs.mkdir(cdir, true)
|
||||
fs.chmod(fs.dirname(cdir), "a+rxw")
|
||||
fs.chmod(fs.dirname(cdir), 777)
|
||||
end
|
||||
|
||||
assert(tplmt or commt, "No such template: " .. name)
|
||||
|
@ -190,14 +191,15 @@ function Template.__init__(self, name)
|
|||
if source then
|
||||
local compiled, err = compile(source)
|
||||
|
||||
fs.writefile(compiledfile, util.get_bytecode(compiled))
|
||||
fs.chmod(compiledfile, "a-rwx,u+rw")
|
||||
local f = nixio.open(compiledfile, "w", 600)
|
||||
f:writeall(util.get_bytecode(compiled))
|
||||
f:close()
|
||||
self.template = compiled
|
||||
end
|
||||
else
|
||||
assert(
|
||||
sys.process.info("uid") == fs.stat(compiledfile, "uid")
|
||||
and fs.stat(compiledfile, "mode") == "rw-------",
|
||||
and fs.stat(compiledfile, "modestr") == "rw-------",
|
||||
"Fatal: Cachefile is not sane!"
|
||||
)
|
||||
self.template, err = loadfile(compiledfile)
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
require "os"
|
||||
require "io"
|
||||
require "uci"
|
||||
require "posix"
|
||||
local fs = require "nixio.fs"
|
||||
|
||||
if posix.access("/var/run/olsrd.pid") then
|
||||
if fs.access("/var/run/olsrd.pid") then
|
||||
local stamp, intv
|
||||
local x = uci.cursor()
|
||||
|
||||
|
@ -17,7 +17,7 @@ if posix.access("/var/run/olsrd.pid") then
|
|||
end
|
||||
end)
|
||||
|
||||
if intv and posix.access(stamp) then
|
||||
if intv and fs.access(stamp) then
|
||||
local systime = os.time()
|
||||
local wdgtime = tonumber(io.lines(stamp)())
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ require("luci.http").prepare_content("application/xhtml+xml")
|
|||
<h1><%=luci.version.distname%></h1>
|
||||
<p>
|
||||
<%=luci.version.distversion%><br />
|
||||
<%:load%>: <%=load1%> <%=load5%> <%=load15%><br />
|
||||
<%:load%>: <%="%.2f" % load1%> <%="%.2f" % load5%> <%="%.2f" % load15%><br />
|
||||
<%:hostname%>: <%=hostname%>
|
||||
</p>
|
||||
</div>
|
||||
|
|
|
@ -62,7 +62,7 @@ require("luci.http").prepare_content("application/xhtml+xml")
|
|||
<h1><%=luci.version.distname%></h1>
|
||||
<p>
|
||||
: <%=luci.version.distversion%> |
|
||||
<%:load%>: <%=load1%> <%=load5%> <%=load15%> |
|
||||
<%:load%>: <%="%.2f" % load1%> <%="%.2f" % load5%> <%="%.2f" % load15%> |
|
||||
<%:hostname%>: <%=hostname%>
|
||||
</p>
|
||||
</div>
|
||||
|
|
|
@ -64,7 +64,7 @@ require("luci.http").prepare_content("application/xhtml+xml")
|
|||
<h1><%=luci.version.distname%></h1>
|
||||
<p>
|
||||
<%=luci.version.distversion%><br />
|
||||
<%:load%>: <%=load1%> <%=load5%> <%=load15%><br />
|
||||
<%:load%>: <%="%.2f" % load1%> <%="%.2f" % load5%> <%="%.2f" % load15%><br />
|
||||
<%:hostname%>: <%=hostname%>
|
||||
</p>
|
||||
</div>
|
||||
|
|
|
@ -62,7 +62,7 @@ require("luci.http").prepare_content("application/xhtml+xml")
|
|||
<h1><%=luci.version.distname%></h1>
|
||||
<p>
|
||||
<%=luci.version.distversion%><br />
|
||||
<%:load%>: <%=load1%> <%=load5%> <%=load15%><br />
|
||||
<%:load%>: <%="%.2f" % load1%> <%="%.2f" % load5%> <%="%.2f" % load15%><br />
|
||||
<%:hostname%>: <%=hostname%>
|
||||
</p>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue