template的方式实现网页显示hello world
如下图:

第一步:/usr/lib/lua/luci/controller/admin/system.lua
中注册选项:
1 | entry({ "admin, system" , "test-template" }, template ( "test/hello" ), _( "test" ), 3).dependent = false |
第二步:在view目录下添加相应的test/hello.htm文件:
1 2 3 4 5 | root@OpenWrt:~# cat /usr/lib/lua/luci/view/test/hello.htm <%+header%> <%:hello world%> <%+footer%> |
第三步:将上面文件添加完成后,保存登录路由后台可以看到结果(有时可能需要先退出再登录)
cbi的方式实现ip地址的设置
如图所示:
第一步:/usr/lib/lua/luci/controller/admin/system.lua
中注册选项:
1 | entry({ "admin" , "system" , "test-cbi" }, cbi( "admin_system/test" ), _( "test-cbi" ), 4).dependent = false |
第二步:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 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文件后面添加:
1 | config netset |
保存后登录设置ip地址,再看/etc/config/network文件的变化,如下:
1 2 3 4 | config netset option ipaddr1 '192.168.1.100' option netmask1 '255.255.255.0' option gateway1 '192.168.1.1' |
本站的文章和资源来自互联网或者站长的原创,按照 CC BY -NC -SA 3.0 CN协议发布和共享,转载或引用本站文章应遵循相同协议。如果有侵犯版权的资 源请尽快联系站长,我们会在24h内删除有争议的资源。欢迎大家多多交流,期待共同学习进步。