ILD

openwrt luci分析
作者:Yuan Jianpeng 邮箱:yuanjp89@163.comyu
发布时间:2021-7-3 站点:Inside Linux Development

    Luci是 Lua ConfigurationInterface的简称,就是用lua实现的cgi程序。


    luci程序位于/www/cgi-bin/luci,它只是个入口,代码如下:

1
2
3
4
5
#!/usr/bin/lua
require "luci.cacheloader"
require "luci.sgi.cgi"
luci.dispatcher.indexcache = "/tmp/luci-indexcache"
luci.sgi.cgi.run()


指定了indexcache的路径为/tmp/luci-indexcache,所以我们修改lua的时候,要删除这个目录生效。

它引用了cgi模块,lua的module位于/usr/lib/lua/。所以luci.sgi.cgi,对应的是/usr/lib/lua/luci/sgi/cgi.lua。


cgi.lua先解析http 请求,然后用coroutine的方式执行luci.dispatcher.httpdispatch。代码:luci/dispatcher.lua。


调用createtree生成目录项,目录项json格式,位于/usr/share/luci/menu.d/目录下


uhttpd还有一个ubus接口,比如扫描ssid,就是请求的/ubus。


http://lua-users.org/wiki/CoroutinesTutorial


Copyright © linuxdev.cc 2017-2024. Some Rights Reserved.