流程为以下:
1、映射UCI文件
2、生成section
3、生成option
原config文件如下:
config login
option username ''
option password ''
option ifname 'eth0'
option domain ''
直接上代码:
require("luci.sys")
--[[
Map("配置文件文件名", "配置页面标题", "配置页面说明"),对应到配置文件/etc/config/testclient
]]--m = Map("testclient", "the title of testclient", "the shuoming of testclient")
--[[
获取所有类型为login的section并生成html
section
class可以是TypedSection表示根据类型获取section
NamedSection表示根据名字获取section
]]--
s = m:section(TypedSection, "login", "")
s.addremove = false
s.anonymous = true
--[[
生成option
class可以是:
Value:input控件
ListValue:下拉列表
Flag:选择框
MultiValue:
DummyValue:纯文本
TextValue:多行input
Button:按钮
StaticList:
DynamicList:
下代码为每个section生成可选项控件,映射到proto字段
p= s:option(ListValue, “proto”, “Protocol”)
p:value(“static”, “static”)
p:value(“dhcp”, “DHCP”)
p.default = “static”
enable = s:option(Flag, "enable", translate("Enable"))
name = s:option(Value, "username", translate("Username"))
pass = s:option(Value, "password", translate("Password"))
pass.password = true
domain = s:option(Value, "domain", translate("Domain"))
ifname = s:option(ListValue, "ifname", translate("Interfaces"))
for k, v in ipairs(luci.sys.net.devices()) do
if v ~= "lo" then
ifname:value(v)
end
end
local apply = luci.http.formvalue("cbi.apply")
if apply then
io.popen("/etc/init.d/njitclient restart")
end
return m
控件对应的html文件在luasrc\view\cbi目录下
参考文章:
http://www.sharegogo.com/?p=568
http://www.cnblogs.com/mayswind/p/3468124.html#para2
http://luci.subsignal.org/trac/wiki/Documentation/CBI