luci网页shell_openwrt luci管理的Web界面实例

本文介绍了如何在OpenWrt的Luci界面中通过template和cbi方式实现网页功能。首先展示了使用template展示"Hello World"的步骤,包括在controller中注册选项和创建对应的视图文件。接着,通过cbi方式演示了设置IP地址的过程,包括在controller中注册选项,编写model文件以及配置网络设置,并说明了保存设置后对/etc/config/network文件的影响。
摘要由CSDN通过智能技术生成

template的方式实现网页显示hello world

如下图:

1b58c17eb974

QQ图片20180714172246.png

第一步:/usr/lib/lua/luci/controller/admin/system.lua中注册选项:

entry({"admin, system", "test-template"}, template("test/hello"), _("test"), 3).dependent = false

第二步:在view目录下添加相应的test/hello.htm文件:

root@OpenWrt:~# cat /usr/lib/lua/luci/view/test/hello.htm

第三步:将上面文件添加完成后,保存登录路由后台可以看到结果(有时可能需要先退出再登录)

cbi的方式实现ip地址的设置

如图所示:

1b58c17eb974

QQ图片20180714172648.png

第一步:/usr/lib/lua/luci/controller/admin/system.lua中注册选项:

entry({"admin", "system", "test-cbi"}, cbi("admin_system/test"), _("test-cbi"), 4).dependent = false

第二步:

root@OpenWrt:~# cat /usr/lib/lua/luci/model/cbi/admin_system/test.lua

m = Map("network", translate("Test Page by hades"), 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.100'

option netmask1 '255.255.255.0'

option gateway1 '192.168.1.1'

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值