標籤:openwrt luci web template cbi
第一部分:
template的方式實現網頁顯示hello world,顯示:
第一步:/usr/lib/lua/luci/controller/admin/system.lua中註冊選項:
entry({"admin", "system", "test-template"}, template("test/hello"), _("test"), 3).dependent = false
第二步:在view目錄下添加相應的test/hello.htm檔案:
[email protected]:~# cat /usr/lib/lua/luci/view/test/hello.htm
<%+header%>
<h1><%:hello world%></h1>
<%+footer%>
第三步:將上面檔案添加完成後,儲存登入路由後台可以看到結果(有時可能需要先退出再登入)
第二部分:
cbi的方式實現ip地址的設定,:
第一步:/usr/lib/lua/luci/controller/admin/system.lua中註冊選項:
entry({"admin", "system", "test-cbi"}, cbi("admin_system/test"), _("test-cbi"), 4).dependent = false
第二步:
[email protected]:~# cat /usr/lib/lua/luci/model/cbi/admin_system/test.lua
m = Map("network", translate("Test Page by Wayne"), translate("On this page we can learn how the .lua work"))
m:chain("luci")
s = m:section(TypedSection, "netset", translate("Network Configuration"))
s.anonymous = true
s.addremove = true
s:tab("wan1", translate("Config wan1"))
ipaddr1 = s:taboption("wan1", Value, "ipaddr1", translate("address"))
ipaddr1.datatype = "ip4addr"
netmask1 = s:taboption("wan1", Value, "netmask1", translate("netmask"))
netmask1.datatype = "ip4addr"
netmask1:value("255.255.255.0")
netmask1:value("255.255.0.0")
netmask1:value("255.0.0.0")
gateway1 = s:taboption("wan1", Value, "gateway1", translate("gateway"))
gateway1.datatype = "ip4addr"
return m
第三步,在/etc/config/network檔案後面添加:
config netset
儲存後登入設定ip地址,再看/etc/config/network檔案的變化,如下:
config netset
option ipaddr1 ‘192.168.1.11‘
option netmask1 ‘255.255.255.0‘
option gateway1 ‘192.168.1.1‘
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。
openwrt luci管理的Web介面執行個體