设置语言的流程
一、关联的配置文件
/etc/config/luci
查看配置文件内容如下:
root@hbg:/# cat /etc/config/luci
config core 'main'
option mediaurlbase '/luci-static/openwrt.org'
option resourcebase '/luci-static/resources'
option lang 'zh_cn' // 目前使用的语言zh_cn,中文
config extern 'flash_keep'
option uci '/etc/config/'
option dropbear '/etc/dropbear/'
option openvpn '/etc/openvpn/'
option passwd '/etc/passwd'
option opkg '/etc/opkg.conf'
option firewall '/etc/firewall.user'
option uploads '/lib/uci/upload/'
config internal 'languages' // 语言选项
option zh_cn 'chinese' // 中文
option en 'English' // 英语
config internal 'sauth'
option sessionpath '/tmp/luci-sessions'
option sessiontime '3600'
config internal 'ccache'
option enable '1'
config internal 'themes'
option Bootstrap '/luci-static/bootstrap'
二、调用过程
在dispatcher.lua中httpdispatch() 函数中调用了函数dispatch(),
在dispatch()函数中实现:
local conf = require "luci.config" // 配置文件为/etc/config/luci
assert(conf.main, // 查看配置文件中是否有main段,若无,提示错误。
"/etc/config/luci seems to be corrupt, unable to find section 'main'")
local lang = conf.main.lang
if lang == nil then
lang = "zh_cn"
luci.sys.call("uci set luci.main.lang=zh_cn; uci commit luci")
end
require "luci.i18n".setlanguage(lang) // 设置语言
查找调用dispatch()的地方,可以找到:
1)cgi.lua
2)uhttpd.lua
两个脚本都位 ./feeds/luci/modules/base/luasrc/sgi目录下,
并且都是调用这句
local x = coroutine.create(luci.dispatcher.httpdispatch)
调用cgi.lua脚本的地方为./feeds/luci/modules/base/htdocs/cgi-bin/luci
文件内容如下:
#!/usr/bin/lua
require "luci.cacheloader"
require "luci.sgi.cgi" // 包含头文件cgi.lua
luci.dispatcher.indexcache = "/tmp/luci-indexcache"
luci.sgi.cgi.run() // 调用cgi.lua中的run函数。
三、luci的启动-uhttpd
uhttpd是一个简单的web服务器程序,主要就是cgi的处理,openwrt是利用uhttpd作为web服务器,
实现客户端web页面配置功能。对于request处理方式,采用的是cgi,而所用的cgi程序就是luci.
四、luci的启动-luci
在web server中的cgi-bin目录下,运行 luci 文件(权限一般是 755,luci的代码如下:
#!/usr/bin/lua --cgi的执行命令的路径
require"luci.cacheloader" --导入cacheloader包
require"luci.sgi.cgi" --导入sgi.cgi包
luci.dispatcher.indexcache = "/tmp/luci-indexcache" --cache缓存路径地址
luci.sgi.cgi.run() --执行run,此方法位于*/luci/sgi/cgi.lua
五、Luci-- Web
a.登录
输入: http://x.x.x.x/ 登录LuCI.
调用 /www/cgi-bin/luci.
b. 进入主菜单‘status’
输入: http://x.x.x.x/cgi-bin/luci/admin/status/即可访问status页面。
Luci则会调用 /luci/admin/目录下的status.lua脚本:
module("luci.controller.admin.status", package.seeall)
/usr/lib/lua/luci/controller/admin/status.lua->index()