OpenWRT添加自定义LUCI页面示例
1.文档结构
在openwrt源代码目录 /openwrt/feeds/luci/applications/下创建文件夹luci-myapplication。文件夹必须以luci-开头以便make menuconfig识别。按如下目录创建文件夹及文件。
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
module("luci.controller.myapp.new_tab", package.seeall) --notice that new_tab is the name of the file new_tab.luafunction 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 30entry({"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 positionentry({"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
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
config 'info' 'A' option 'name' 'OpenWRT'
2.4 luci-myapplication/luasrc/view/view_tab.lua
<%+header%>
<h1><%:Hello World%></h1>
<%+footer%>
2.5 luci-myapplication/Makefile
include $(TOPDIR)/rules.mkLUCI_TITLE:=LuCI Support for Test
LUCI_DEPENDS:=include ../../luci.mk# call BuildPackage - OpenWrt buildroot signature
3 编译过程
首先在openwrt源代码根目录下运行以下两个命令
./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按钮时,页面加载出现错误,如下所示。
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设备联网,然后输入以下命令:
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://blog.csdn.net/u012041204/article/details/54973395
OpenWRT添加自定义LUCI页面示例相关推荐
- 智能路由器-OpenWRT 系列三 (OpenWRT安装LuCI网络配置)
OpenWRT 安装 LUCI 每次ssh登陆OpenWRT安装新软件时,都必须更新opkg opkg update 安装LUCI opkg install luci 安装luci中文语言包, 不同O ...
- 40 个信息丰富且有趣的 CSS 404 错误页面示例
404 是一个 HTTP 响应代码,指示服务器找不到请求的页面.404 错误页面通知用户他们点击了不存在的链接或键入了不存在的地址.发生这种情况时,用户可能会感到不安.创建交互式错误页面非常适合吸引用 ...
- JS实现获取word文档内容并输出显示到html页面示例,和将页面数据写入txt文件
JS实现获取word文档内容并输出显示到html页面示例 注意:这里使用了ActiveXObject组建,因此需要使用IE内核浏览器运行本代码. <!DOCTYPE html> <h ...
- Openwrt中luci配置页面cbi小记
先看看network的配置文件: [html] view plaincopy config interface 'loopback' option ifname 'lo' option proto ' ...
- openwrt的luci应用ipk包开发(一)
一.LUCI界面 OpenWrt 的界面其实就是网页界面,默认是由 uhttpd 服务器承载,之所以叫做 LUCI ,因为这是使用 Lua 脚本编写的控制界面,全称 Lua Unified Confi ...
- OpenWRT(十)web页面更新固件
OpenWRT版本:17 当我们的openwrt添加了luci后就可以通过web页面进行固件的升级了,下面我们来看一下具体步骤: 选择文件 点击Proceed 通过上面三个步骤就完成了更新,是不是很简 ...
- [转]Hexo博客添加自定义HTML页面
改 "友链" 为 "ZONE" ,增加了一些以前收藏的特效页面. 顺便说说怎么往博客添加自定义的HTML文件. 首先,在博客根目录的source文件夹下,新建文 ...
- 3个必看的常见问题解答页面示例,帮您重做产品FAQ页面F
成功的企业都有个共性特点,永远将客户体验放在第一位.95%的消费者认为良好的客户体验对品牌忠诚度很重要. 提供一流的客户体验可能是费时费钱且复杂但确实很有必要执行.但其中有一项被遗忘的客户服务策略是经 ...
- openwrt的luci应用ipk包开发(三)
luci配置页面修改配置文件 先看看network的配置文件: config interface 'loopback' option ifname 'lo'option proto 'static' ...
最新文章
- ajax图书管理案例
- python3 requirements使用方法 ~= >= <
- python里none什么意思_python中stream=None什么意思?
- linux 压缩 解压zip 命令
- java 中组合与复用_可复用性和组合
- 【网址收藏】k8s zookeeper-operator示例
- view渐变色,透明度渐变
- 【Spring】Spring第二天 - AOP 详解、动态代理设计模式(JDK和cglib)
- 响应式关系数据库处理R2DBC
- websphere内存设置_WebSphere Classloader内存泄漏预防
- 纯新手入门机器/深度学习自学指南(附一个月速成方案)
- 超级PK:Sybase与Oracle的十二场性能比拼
- wm_copydata不等返回值处理 SendMessage SendMessageTimeout
- WordPress 简约大气昼夜免费导航-NDNAV主题
- BIM+3DGIS的行业应用探讨
- 图片占内存容量计算公式
- 中国一线二线三线城市名单
- zookeeper详解
- 对话系统综述 *Advances and Challenges in Conversational Recommender Systems: A Survey*
- 【重要公告】包头市新型冠状病毒感染肺炎防控工作指挥部公告(2022年第4、5、6、7号)
热门文章
- 日志文件系统是怎样工作的
- 2023.4.5.吉林长春.雾霾.
- Unity3D 简易Dock栏制作
- 高德坐标与谷歌坐标互相转换
- Three.js_解决谍影锯齿闪烁重影模型的方法
- COCO目标检测数据集的读取方法与Python工具脚本
- ok6410如何驱动NW336无线网卡.更新zd1211b到kernel 2.6.15上.成功在Linux下安装TP-LINK TL-WN322G+ 54M无线USB网卡驱动
- 多个exe程序一起打包,按顺序安装
- THz:在IoT上的应用
- 银联+移动+三星PK微信、余额宝