中文总结:
1. 安装包对应目录:
ipkg   -- ipkg安装包配置
htdocs -- /www
luasrc -- /usr/lib/lua/luci
root -- linux根目录
src -- C code
lua -- /usr/lib/lua
dist --
2. Makefile:
$(eval $(call BuildPackage,luci-app-YOURMODULE))
define Package/luci-app-YOURMODULE
$(call Package/luci/webtemplate)
DEPENDS+=+some-package +some-other-package
TITLE:=SHORT DESCRIPTION OF YOURMODULE
endef
3. entry(path, target, title, order)
英文原版:
http://luci.subsignal.org/trac/wiki/Documentation/ModulesHowTo

HowTo: Write Modules

Note: If you plan to integrate your module into LuCI, you should read the Module Reference before.

This tutorial describes how to write your own modules for the LuCI WebUI. For this tutorial we refer to your LuCI installation directory as lucidir (/usr/lib/lua/luci if you are working with an installed version) and assume your LuCI installation is reachable through your webserver via /cgi-bin/luci.

If you are working with the development environment replace lucidir with /path/to/your/luci/checkout/applications/myapplication/luasrc (this is a default empty module you can use for your experiments) and your LuCI installation can probably be reached via  http://localhost:8080/luci/ after you ran make runhttpd.

Show me the way (The dispatching process)

To write a module you need to understand the basics of the dispatching process in LuCI. LuCI uses a dispatching tree that will be built by executing the index-Function of every available controller. The CGI-environment variablePATH_INFO will be used as the path in this dispatching tree, e.g.: /cgi-bin/luci/foo/bar/baz will be resolved to foo.bar.baz

To register a function in the dispatching tree, you can use the entry-function of luci.dispatcher. entry takes 4 arguments (2 are optional):

entry(path, target, title=nil, order=nil)
  • path is a table that describes the position in the dispatching tree: For example a path of {"foo", "bar", "baz"} would insert your node in foo.bar.baz.
  • target describes the action that will be taken when a user requests the node. There are several predefined ones of which the 3 most important (call, template, cbi) are described later on on this page
  • title defines the title that will be visible to the user in the menu (optional)
  • order is a number with which nodes on the same level will be sorted in the menu (optional)

You can assign more attributes by manipulating the node table returned by the entry-function. A few example attributes:

  • i18n defines which translation file should be automatically loaded when the page gets requested
  • dependent protects plugins to be called out of their context if a parent node is missing
  • leaf stops parsing the request at this node and goes no further in the dispatching tree
  • sysauth requires the user to authenticate with a given system user account

It's all about names (Naming and the module file)

Now that you know the basics about dispatching, we can start writing modules. But before you have to choose the category and name of your new digital child.

We assume you want to create a new application "myapp" with a module "mymodule".

So you have to create a new subdirectory lucidir/controller/myapp with a file mymodule.lua with the following content:

module("luci.controller.myapp.mymodule", package.seeall)function index()end

The first line is required for Lua to correctly identify the module and create its scope. The index-Function will be used to register actions in the dispatching tree.

Teaching your new child (Actions)

So it is there and has a name but it has no actions.

We assume you want to reuse your module myapp.mymodule that you begun in the last step.

Actions

Reopen lucidir/controller/myapp/mymodule.lua and just add a function to it so that its content looks like this example:

module("luci.controller.myapp.mymodule", package.seeall)function index()entry({"click", "here", "now"}, call("action_tryme"), "Click here", 10).dependent=false
endfunction action_tryme()luci.http.prepare_content("text/plain")luci.http.write("Haha, rebooting now...")luci.sys.reboot()
end

And now type /cgi-bin/luci/click/here/now ( http://localhost:8080/luci/click/here/now if you are using the development environment) in your browser.

You see these action functions simple have to be added to a dispatching entry.

As you might or might not know: CGI specification requires you to send a Content-Type header before you can send your content. You will find several shortcuts (like the one used above) as well as redirecting functions in the module luci.http

Views

If you only want to show the user a text or some interesting familiy photos it may be enough to use a HTML-template. These templates can also include some Lua code but be aware that writing whole office suites by only using these templates might be called "dirty" by other developers.

Now let's create a little template lucidir/view/myapp-mymodule/helloworld.htm with the content:

<%+header%>
<h1><%:Hello World%></h1>
<%+footer%>

and add the following line to the index-Function of your module file.

entry({"my", "new", "template"}, template("myapp-mymodule/helloworld"), "Hello world", 20).dependent=false

Now type /cgi-bin/luci/my/new/template ( http://localhost:8080/luci/my/new/template if you are using the development environment) in your browser.

You may notice those fancy <% %>-Tags, these are markups? used by the LuCI template processor. It is always good to include header and footer at the beginning and end of a template as those create the default design and menu.

CBI models

The CBI is one of the uber coolest features of LuCI. It creates a formular based user interface and saves its contents to a specific UCI config file. You only have to describe the structure of the configuration file in a CBI model file and Luci does the rest of the work. This includes generating, parsing and validating a XHTML form and reading and writing the UCI file.

So let's be serious at least for this paragraph and create a real pratical example lucidir/model/cbi/myapp-mymodule/netifaces.lua with the following contents:

m = Map("network", "Network") -- We want to edit the uci config file /etc/config/networks = m:section(TypedSection, "interface", "Interfaces") -- Especially the "interface"-sections
s.addremove = true -- Allow the user to create and remove the interfaces
function s:filter(value)return value ~= "loopback" and value -- Don't touch loopback
end
s:depends("proto", "static") -- Only show those with "static"
s:depends("proto", "dhcp") -- or "dhcp" as protocol and leave PPPoE and PPTP alonep = s:option(ListValue, "proto", "Protocol") -- Creates an element list (select box)
p:value("static", "static") -- Key and value pairs
p:value("dhcp", "DHCP")
p.default = "static"s:option(Value, "ifname", "interface", "the physical interface to be used") -- This will give a simple textboxs:option(Value, "ipaddr", translate("ip", "IP Address")) -- Ja, das ist eine i18n-Funktion ;-)s:option(Value, "netmask", "Netmask"):depends("proto", "static") -- You may remember this "depends" function from abovemtu = s:option(Value, "mtu", "MTU")
mtu.optional = true -- This one is very optionaldns = s:option(Value, "dns", "DNS-Server")
dns:depends("proto", "static")
dns.optional = true
function dns:validate(value) -- Now, that's nifty, eh?return value:match("[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+") -- Returns nil if it doesn't match otherwise returns match
endgw = s:option(Value, "gateway", "Gateway")
gw:depends("proto", "static")
gw.rmempty = true -- Remove entry if it is emptyreturn m -- Returns the map

and of course don't forget to add something like this to your module's index-Function.

entry({"admin", "network", "interfaces"}, cbi("myapp-mymodule/netifaces"), "Network interfaces", 30).dependent=false

There are many more features, see the CBI reference and the modules shipped with LuCI.

http://luci.subsignal.org/trac/wiki/Documentation/Modules

Reference: LuCI Modules

Categories

The LuCI modules are divided into several category directories, namely:

  • applications (Single applications or plugins for other modules or applications)
  • i18n (Translation files)
  • libs (Independent libraries)
  • modules (Collections of applications)
  • themes (Frontend themes)

Each module goes into a subdirectory of any of this category-directories.

Module directory

The contents of a module directory are as follows:

Makefile

This is the module's makefile. If the module just contains Lua sourcecode or resources then the following Makefile should suffice.

include ../../build/config.mk
include ../../build/module.mk

If you have C(++) code in your module your Makefile should at least contain the following things.

include ../../build/config.mk
include ../../build/gccconfig.mk
include ../../build/module.mkcompile:# Commands to compile and link your C-code# and to install them under the dist/ hierarchyclean: luaclean# Commands to clean your compiled objects

src

The src directory is reserved for C sourcecode.

luasrc

luasrc contains all Lua sourcecode files. These will automatically be stripped or compiled depending on the Make target and are installed in the LuCI installation directory.

lua

lua is equivalent to luasrc but containing Lua files will be installed in the Lua document root.

htdocs

All files under htdocs will be copied to the document root of the target webserver.

root

All directories and files under root will be copied to the installation target as they are.

dist

dist is reserved for the builder to create a working installation tree that will represent the filesystem on the target machine. DO NOT put any files there as they will get deleted.

ipkg

ipkg contains IPKG package control files, like preinstposinstprermpostrmconffiles. See IPKG documentation for details.

OpenWRT feed integration

If you want to add your module to the LuCI OpenWRT feed you have to add several sections to the contrib/package/luci/Makefile.

For a Web UI applications this is:

A package description:

define Package/luci-app-YOURMODULE$(call Package/luci/webtemplate)DEPENDS+=+some-package +some-other-packageTITLE:=SHORT DESCRIPTION OF YOURMODULE
endef

A package installation target:

define Package/luci-app-YOURMODULE/install$(call Package/luci/install/template,$(1),applications/YOURMODULE)
endef

A module build instruction:

ifneq ($(CONFIG_PACKAGE_luci-app-YOURMODULE),)PKG_SELECTED_MODULES+=applications/YOURMODULE
endif

A build package call:

$(eval $(call BuildPackage,luci-app-YOURMODULE))

一、我来说LuCI: LuCI官方----3. Theme and Modules相关推荐

  1. 一、我来说LuCI: LuCI官方----1. 概述

    中文总结: 1. LuCI 是2008年3月专为OpenWrt创建的项目: 2. LuCI保证了更高性能,更小size, 更好的可维护性--这是最重要的: 3. LuCI的MVC框架,包括libs, ...

  2. 一、我来说LuCI: LuCI官方----2.UCI

    中文总结: 1. UCI是基于NVRAM的系统配置工具: 2. UCI的语法格式, /etc/config: package 'example' config 'example' 'test'     ...

  3. luci编程 openwrt_openwrt开源系统LUCI配置界面

    转自:http://www.right.com.cn/forum/thread-131035-1-1.html 本人菜鸟,最近在学习这方面的知识,在参考资料的基础上总结如下内容. 这篇文章针对如何对o ...

  4. luci网页shell_openwrt luci web分析

    openwrt luci web分析 www/cbi-bin/luci run方法的主要任务就是在安全的环境中打开开始页面(登录页面),在run中,最主要的功能还是在dispatch.lua中完成. ...

  5. 智能路由器-OpenWRT 系列三 (OpenWRT安装LuCI网络配置)

    OpenWRT 安装 LUCI 每次ssh登陆OpenWRT安装新软件时,都必须更新opkg opkg update 安装LUCI opkg install luci 安装luci中文语言包, 不同O ...

  6. 有关lua,luci的介绍

    一颗璀璨的月光宝石--Lua Lua语言简介 1993 年在巴西里约热内卢天主教大学(Pontifical Catholic University of Rio de Janeiro in Brazi ...

  7. OpenWrt路由器上的LuCI模块开发

    [一.LuCI配置界面开发的框架] LuCI是OpenWrt上的Web管理界面,LuCI采用了MVC三层架构,同时其使用Lua脚本开发,所以开发LuCI的配置界面不需要编辑任何的Html代码,除非想自 ...

  8. luci框架-LUA的一个web框架使用

    转自:http://blog.csdn.net/initphp/article/details/17527639 LUCI 这个在百度上搜索除了一篇我的百度文库 luci 的介绍文章之外,前三页都是些 ...

  9. luci实现的wifidog认证服务

    返回博客列表 原 luci实现的wifidog认证服务 娱乐你我 发布时间: 2014/12/26 11:05 阅读: 4234 收藏: 7 点赞: 2 评论: 1 利用luci写了个wifidog认 ...

最新文章

  1. H - Parity game-poj1733(需要离散化)
  2. Linux设备文件简介。
  3. 弧度转为角分秒的c语言程序_用弧度表示角度
  4. circRNA研究相关数据库,riboCIRC使用指南
  5. python signal模块作用_如何理解python中信号Signal?
  6. [css] 使用css如何设置背景虚化?
  7. python安装好的界面_手把手教你配置最漂亮的PyCharm界面,Python程序员必备!
  8. 边缘计算高考题!全答对就可以去华为上班!
  9. 查看scala变量数据类型_Scala文字,变量和数据类型| Scala编程教程
  10. leetcode 354. 俄罗斯套娃信封问题(二维排序有关)
  11. 快速开发平台learun7.0.3发布,看看各版本有什么更新吧
  12. 基于Python的QQ空间相册中的所有照片下载器
  13. 如何用chrome浏览器 开发插件 自动答题 自动抢票 自动选课
  14. 什么牌子真无线蓝牙耳机适合运动,高续航舒适小巧这五款蓝牙耳机不要错过
  15. dingo php,Laravel Lumen RESTFul API 扩展包:Dingo API(一) —— 安装配置篇
  16. php上传文件到指定文件夹
  17. 计算机专业有非全日制研究生,计算机专业有双证在职研究生吗?
  18. 使用ElementUi的tabs切换组件时下拉选择器出现破板情况
  19. 网站制作店铺 陆廉绿环
  20. 中国社会信任的解体及其结果(zt)

热门文章

  1. 深圳小众爬山点推荐 人少景美周末必备
  2. 自已开发IM有那么难吗?手把手教你自撸一个Andriod版简易IM (有源码)
  3. STM32物联网项目-ADC采集实验板板温度(NTC热敏电阻)
  4. HTML5音频可视化频谱跳动代码
  5. 卡奴、车奴、房奴,你是哪种?
  6. 如何理解wordcount
  7. 2022育婴员(五级)试题及答案
  8. Oracle 中经常遇到的一些问题
  9. MADDPG论文中文翻译
  10. grafana配置仪表盘