目标:两个用户root和user。Root用户可以通过web界面访问所有内容,但用户只能看到菜单的某些部分。
一种选择是将"sysauth“选项传递给每个有问题的模块。这不是很实际,因为用户将看到每个菜单项,并将获得登录页面的每个菜单,他是不允许的。
我的想法是找出谁登录了,然后在每个受限制模块的index()函数中什么也不做。到目前为止,我还没有在LuCI应用程序接口(http://luci.subsignal.org/api/luci/)中找到这样的函数,它可以返回当前登录的用户。
我知道如何在OpenWrt/LuCI (https://forum.openwrt.org/viewtopic.php?pid=163013#p163013)中添加额外的用户。但这只是解决方案的一部分。
你知道怎么实现我的目标吗?
发布于 2013-09-25 21:23:20
我最终创建了一个如下所述的Lua函数:http://lua-users.org/wiki/SaveTableToFile,用于查找表中不需要的键并将其从表中删除。
function remove_idx( tbl, index )
-- initiate variables for save procedure
local tables,lookup = { tbl },{ [tbl] = 1 }
for idx,t in ipairs( tables ) do
local thandled = {}
for i,v in ipairs( t ) do
thandled[i] = true
local stype = type( v )
-- only handle value
if stype == "table" then
if not lookup[v] then
table.insert( tables, v )
lookup[v] = #tables
end
else
if i == index then
t[i] = nil
return
end
end
end
for i,v in pairs( t ) do
-- escape handled values
if (not thandled[i]) then
local flag = 0
local stype = type( i )
-- handle index
if stype == "table" then
if not lookup[i] then
table.insert( tables,i )
lookup[i] = #tables
end
else
flag = 1
if i == index then
t[i] = nil
return
end
end
if flag == 1 then
stype = type( v )
-- handle value
if stype == "table" then
if not lookup[v] then
table.insert( tables,v )
lookup[v] = #tables
end
else
if i == index then
t[i] = nil
return
end
end
end
end
end
end
end 然后在libs/web/luasrc/dispatcher.lua dispatch()中插入我的用户检查和页面删除:
if c and c.index then
local tpl = require "luci.template"
if util.copcall(tpl.render, "indexer", {}) then
return true
end
end这就是我根据登录用户删除不需要的页面的方式:
if ctx.authuser == "user" then
remove_idx(ctx.tree, "packages")
remove_idx(ctx.tree, "leds")
end它是有点快和脏,但它是有效的。请注意,通过操作URL直接访问仍然是可能的。
更新
LuCI2将提供访问控制列表支持和多用户环境:http://git.openwrt.org/?p=project/luci2/ui.git;a%3Dsummary
发布于 2021-12-21 21:44:59
如果您想创建多个具有不同访问权限的OpenWRT Luci用户,您可以按照以下步骤操作:
的访问级别
参见下面的/etc/ config /rpcd config示例摘录:
config login
option username 'adminuser'
option password '$p$adminuser'
list read '*'
list write '*'
config login
option username 'readonlyuser'
option password '$p$readonlyuser'
list read '*'如果您正在为对Luci的JSON-RPC调用获取身份验证令牌,这也是有效的。
https://stackoverflow.com/questions/18377138
复制相似问题