OpenWRT添加自定义LUCI页面示例
2020-01-15 08:28
3011 查看
1.文档结构
在openwrt源代码目录 /openwrt/feeds/luci/applications/下创建文件夹luci-myapplication。文件夹必须以luci-开头以便make menuconfig识别。按如下目录创建文件夹及文件。
[code]luci-myapplication |---luasrc | |---controller | | |---new_tab.lua | |---model | | |---cbi | | |---cbi_tab.lua | |---view | |---view_tab.htn |---Makefile |---root |---etc |---config |---cbi_file
2.文件内容
2.1 luci-myapplication/luasrc/controller/new_tab.lua
[code]module("luci.controller.myapp.new_tab", package.seeall) --notice that new_tab is the name of the file new_tab.lua function index() entry({"admin", "new_tab"}, firstchild(), "New tab", 60).dependent=false --this adds the top level tab and defaults to the first sub-tab (tab_from_cbi), also it is set to position 30 entry({"admin", "new_tab", "tab_from_cbi"}, cbi("cbi_tab"), "CBI Tab", 1) --this adds the first sub-tab that is located in <luci-path>/luci-myapplication/model/cbi and the file is called cbi_tab.lua, also set to first position entry({"admin", "new_tab", "tab_from_view"}, template("view_tab"), "View Tab", 2) --this adds the second sub-tab that is located in <luci-path>/luci-myapplication/view and the file is called view_tab.htm, also set to the second position end
2.2 luci-myapplication/luasrc/model/cbi/cbi_tab.lua
[code]m = Map("cbi_file", translate("First Tab Form"), translate("Please fill out the form below")) -- cbi_file is the config file in /etc/config d = m:section(TypedSection, "info", "Part A of the form") -- info is the section called info in cbi_file a = d:option(Value, "name", "Name"); a.optional=false; a.rmempty = false; -- name is the option in the cbi_file return m
2.3 luci-myapplication/root/etc/config/cbi_file
[code]config 'info' 'A' option 'name' 'OpenWRT'
2.4 luci-myapplication/luasrc/view/view_tab.lua
[code]<%+header%> <h1><%:Hello World%></h1> <%+footer%>
2.5 luci-myapplication/Makefile
[code]include $(TOPDIR)/rules.mk LUCI_TITLE:=LuCI Support for Test LUCI_DEPENDS:= include ../../luci.mk # call BuildPackage - OpenWrt buildroot signature
3 编译过程
首先在openwrt源代码根目录下运行以下两个命令
[code]./scripts/feeds update luci ./scripts/feeds install -a -p luci
然后运行make menuconfig,选择LuCI --->3. applications --->luci-myapplication,保存配置,编译。
4.测试
将版本下载到设备并重启后,连接电脑和设备,电脑浏览器打开192.168.1.1,输入用户名&密码,进入如下界面
点击CBI_Tab
点击VIEW_Tab
5.遇到的问题
最开始编译完并下载到设备后,连接192.168.1.1能打开首页,但是点开CBI_Tab按钮时,页面加载出现错误,如下所示。
[code]Failed to execute cbi dispatcher target for entry '/admin/new_tab/tab_from_cbi'. The called action terminated with an exception: /usr/lib/lua/luci/dispatcher.lua:938: module 'luci.cbi' not found: no field package.preload['luci.cbi'] no file './luci/cbi.lua' no file '/usr/share/lua/luci/cbi.lua' no file '/usr/share/lua/luci/cbi/init.lua' no file '/usr/lib/lua/luci/cbi.lua' no file '/usr/lib/lua/luci/cbi/init.lua' no file './luci/cbi.so' no file '/usr/lib/lua/luci/cbi.so' no file '/usr/lib/lua/loadall.so' no file './luci.so' no file '/usr/lib/lua/luci.so' no file '/usr/lib/lua/loadall.so' stack traceback: [C]: in function 'require' /usr/lib/lua/luci/dispatcher.lua:938: in function </usr/lib/lua/luci/dispatcher.lua:937>
解决办法1.确保openwrt设备联网,然后输入以下命令:
[code]root@OpenWrt:/# opkg update root@OpenWrt:/# opkg install luci-compat root@OpenWrt:/#
解决办法2.在源代码中将luci-compat编译进去。在源代码根目录输入make menuconfig,然后选择LuCI--->2.Modules --->luci-compat,如下图所示,保存更改,重新编译并下载到设备上即可。
6.参考网址
https://openwrt.org/docs/guide-developer/luci
https://www.geek-share.com/detail/2697725715.html
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- openwrt 为你的固件添加luci aria2设置页面
- iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem 自定义ToolBar以及页面切换
- Laravel5框架自定义错误页面配置操作示例
- Microsoft Dynamics CRM 4.0 文章页面 添加自定义按钮
- openwrt 添加luci选项
- ubuntu 10.10环境下编译openwrt(添加Luci和中文化)笔记
- SugarCRM - 如何在Contact编辑页面,添加自定义代码
- openwrt 添加 应用(luci-application)
- Appfuse:添加自定义页面组件
- openwrt添加页面
- 添加空白页面后继承自定义类提示错误:声明一定不能指定不同的基类
- iOS 为自定义返回按钮的页面添加右滑返回
- iOS 为自定义返回按钮leftBarButtonItem的页面添加右滑返回功能
- Jquery动态添加及删除页面节点元素示例代码
- DotNetNuke系列(一): 如何在DNN中添加自定义的用户注册页面
- [Javascript]在HTML页面中动态添加表格,动态生成行的示例
- 在布局页面“文章页面中”添加,自定义UserControl
- 微信小程序自定义组件传值 页面和组件相互传数据操作示例
- Inno Setup技巧[实例]添加自定义页面
- 自定义iphone页面添加到主屏幕图标