openwrt luci管理的Web介面執行個體

來源:互聯網
上載者:User

標籤: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介面執行個體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.