路由器:newifi mini
硬件信息:mt7620a +mt7612e+128M DDR+16M flash
固件: Pandorabox
luci theme:lafite
主界面:

winSCP登录
securieCRT 串口登录

/www/index.html:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="refresh" content="0; URL=/cgi-bin/luci" />
</head>
<body style="background-color: white">
<a style="color: black; font-family: arial, helvetica, sans-serif;" href="/cgi-bin/luci">LuCI for PandoraBox</a>
</body>
</html>

在 uhttpd web server 中的 cgi-bin 目录下,运行 luci 文件(权限一般是 755 ) , luci 的代码如下:

#!/usr/bin/lua        #lua脚本,lua执行命令的路径
require "luci.cacheloader"     #导入 cacheloader 包
require "luci.sgi.cgi"         # 导入 sgi.cgi 包
luci.dispatcher.indexcache = "/tmp/luci-indexcache"     #cache 缓存路径地址
luci.sgi.cgi.run()         #执行run方法,此方法位于 /usr/lib/lua/luci/sgi/cgi.lua中

找到lcgi.lua运行文件, /usr/lib/lua/luci/sgi/cgi.lua :

exectime=os.clock()
module("luci.sgi.cgi",package.seeall)
local a=require("luci.ltn12")
require("nixio.util")
require("luci.http")
require("luci.sys")
require("luci.dispatcher")
local function o(t,e)
e=e or 0
local a=a.BLOCKSIZE
return function()
if e<1 then
t:close()
return nil
else
local a=(e>a)and a or e
e=e-a
local e=t:read(a)
if not e then t:close()end
return e
end
end
end
function run()
local t=luci.http.Request(
luci.sys.getenv(),
o(io.stdin,tonumber(luci.sys.getenv("CONTENT_LENGTH"))),
a.sink.file(io.stderr)
)
local e=coroutine.create(luci.dispatcher.httpdispatch)    //开启协助线程---->调用/usr/lib/lua/luci/dispatcher.lua里的httpdispatch函数
local o=""
local i=true
while coroutine.status(e)~="dead"do
local n,e,t,a=coroutine.resume(e,t)
if not n then
print("Status: 500 Internal Server Error")
print("Content-Type: text/plain\n")
print(e)
break;
end
if i then
if e==1 then
io.write("Status: "..tostring(t).." "..a.."\r\n")
elseif e==2 then
o=o..t..": "..a.."\r\n"
elseif e==3 then
io.write(o)
io.write("\r\n")
elseif e==4 then
io.write(tostring(t or""))
elseif e==5 then
io.flush()
io.close()
i=false
elseif e==6 then
t:copyz(nixio.stdout,a)
t:close()
end
end
end
end

连接路由器,浏览器下输入192.168.1.1,转入192.168.1.1/cgi-bin/luci,转入登录页面,调用了/usr/lua/luci/controller/admin/index.html文件:

module("luci.controller.admin.index", package.seeall)function index ()local root = node()if not root.target thenroot.target = alias("admin")root.index  = trueendlocal page                 = node("admin")page.target                = firstchild()         //从dispatcher.lua调firstchild()page.title                 = _("Administration")page.order                 = 10page.sysauth               = "root"page.sysauth_authenticator = "htmlauth"     //从dispatcher.lua调htmlauth()page.ucidata               = truepage.index                 = true-- Empty services menu to be populated by addonsentry({"admin", "services"}, firstchild(), _("Services"), 40).index = trueentry({"admin", "logout"}, call("action_logout"), _("Logout"), 90)
endfunction action_logout ()local dsp = require "luci.dispatcher"local utl = require "luci.util"local sid = dsp.context.authsessionif sid thenutl.ubus("session", "destroy", { ubus_rpc_session = sid })luci.http.header("Set-Cookie", "sysauth=%s; expires=%s; path=%s/" %{sid, 'Thu, 01 Jan 1970 01:00:00 GMT', dsp.build_url()})endluci.http.redirect(dsp.build_url())
end

查看htmlauth()函数:

function authenticator.htmlauth(a,t,o)
local t=e.formvalue("luci_username")
local i=e.formvalue("luci_password")
if t and a(t,i)then
return t
end
require("luci.i18n")
require("luci.template")
context.path={}
e.status(403,"Forbidden")
luci.template.render("sysauth",{duser=o,fuser=t})
return false
end

在dispatcher.lua读取并解析了/etc/config下的luci配置,可以看到读取了theme:

if(t and t.index)or not i.notemplate then
local s=require("luci.template")
local t=i.mediaurlbase or luci.config.main.mediaurlbase
if not pcall(s.Template,"themes/%s/header"%n.basename(t))then
t=nil
for a,e in pairs(luci.config.themes)do
if a:sub(1,1)~="."and pcall(s.Template,
"themes/%s/header"%n.basename(e))then
t=e
end

使用了/usr/lib/lua/luci/viem/theme/lafite
查看/usr/lib/lua/luci/controller/admin/lafite.lua :

module("luci.controller.admin.lafite", package.seeall)function index()local root = node()if not root.target thenroot.target = alias("lafite")root.index = trueendfunction jump ()local uci = require("luci.model.uci").cursor()local themename = uci:get('luci', 'main', 'mediaurlbase') or nilif not themename thenreturn template("jump")endthemename = themename:match('([%da-zA-Z]*)$')if themename == 'lafite' thenreturn template("jump")elselocal list = {}for _, v in ipairs(require('luci.fs').dir('/www/luci-static')) doif v ~= '.' and v ~= '..' thenlist[#list+1] = vendendif #list > 2 thenreturn alias("admin")endendreturn template("jump")endlocal page = entry({"lafite"}, jump(), nil, 0)page.sysauth = falsepage.ucidata = truepage.index = trueentry({"lafite", "change"}, call("action_change"), _("index"), 0)
endfunction action_change()local sauth = require "luci.controller.api.user"local PBUtil = require "luci.pb.PBUtil"local code = PBUtil.message()local _apiAuth = sauth.checkApiAuth()if _apiAuth then return _apiAuth endlocal V = PBUtil.getFormValue({ 'change' })if not V.change thenreturn code.miss('Change+')endif V.change ~= '0' and V.change ~= '1' thenreturn code.error('Change+')endlocal themename = 'lafite'if V.change == '1' thenlocal list = {}for _, v in ipairs(require('luci.fs').dir('/www/luci-static')) doif v ~= '.' and v ~= '..' thenlist[#list+1] = vendendif #list > 2 thenfor _, v in ipairs(list) doif v ~= 'lafite' and v ~= 'resources' thenthemename = vendendendendPBUtil.setUCISection('luci', 'main', {mediaurlbase = '/luci-static/' .. themename})uci:commit('luci')return code.ok()
end

Luci则会calling /luci/admin/目录下的lafite.lua脚本。
模块入口文件lafite.lu中index()函数中,使用entry函数来完成每个模块函数的注册:

local page = entry({"lafite"}, jump(), nil, 0)

转入/www/web/

entry({"lafite", "change"}, call("action_change"), _("index"), 0)

change函数中加入了/usr/lib/lua/luci/pb/目录下文件

openwrt luci web解析相关推荐

  1. luci网页shell_openwrt luci web分析

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

  2. Lean的OpenWrt LuCI应用说明

    Lean的Openwrt LuCI应用说明 这位大佬更全更新:https://www.right.com.cn/forum/thread-3682029-1-1.html #2021-07-14 16 ...

  3. OpenWRT 跨网段解析 mDNS 域名

    OpenWRT 跨网段解析 mDNS 域名 在局域网中,由于 IP 地址都是动态分配的,很难确定每一台电脑的 IP 地址.此时使用 mDNS 使用局域网域名解析就非常方便. 对于 windows10 ...

  4. python初级第三库(人工智能,web解析,人机交互)

    第一章:python必备库-从数据处理到人工智能 第二章:python必备库-从web解析到网络空间 第三章:python必备库-从人机交互到艺术设计第一章 python必备库-从数据处理到人工智能 ...

  5. luci web 界面功能

    一.luci界面 1.学习文档 API : https://htmlpreview.github.io/?https://github.com/openwrt/luci/blob/master/doc ...

  6. OpenWrt Luci编写小技巧

    技巧一:在luci页面中执行shell命令 方法一:获得标准输出流 luci.sys.exec("命令") 然后可以声明一个变量将标准输出内容保存起来,如下 local str = ...

  7. 关于openwrt使用web升级提示固件版本不对的处理方法

    参考资料:https://blog.csdn.net/caoshunxin01/article/details/79355602 当openwrt使用web升级提示固件版本不对: The upload ...

  8. OpenWRT(十)web页面更新固件

    OpenWRT版本:17 当我们的openwrt添加了luci后就可以通过web页面进行固件的升级了,下面我们来看一下具体步骤: 选择文件 点击Proceed 通过上面三个步骤就完成了更新,是不是很简 ...

  9. Linux / openwrt / 安装 Web GUI 和 ftp server

    一.安装 Web GUI opkg update . opkg install luci . (选做,安装中文软件包)opkg install luci-i18n-base-zh-cn . /etc/ ...

  10. openwrt luci中文汉化

    版权声明:本文为博主原创文章,未经博主允许不得转载.    https://blog.csdn.net/u011007991/article/details/70230916 前言 OpenWRT 的 ...

最新文章

  1. caffe prototxt分析
  2. python登陆,注册小程序
  3. mc pe Linux服务器,MC 基岩版(PE) 服务器来了
  4. win7 安装Redis
  5. 通过hibernate去调用存储过程
  6. 如何创建最简单的 ABAP 数据库表,以及编码从数据库表中读取数据 (上) 试读版
  7. 《Adobe InDesign CS6中文版经典教程》—第1课1.5节修改文档的缩放比例
  8. ACM MM2021 | 快手获得Grand Challenge第一名
  9. linux db2表空间目录,db2 表空间的一些知识
  10. oracle 11g nlslang,常用数学符号的 LaTeX 表示方法
  11. [ Python - 6 ] 正则表达式实现计算器功能
  12. 方正电脑如何关闭网络启动计算机,方正电脑怎么进安全模式
  13. 廖雪峰git教程总结
  14. Mac OS怎么删除虚拟机声卡
  15. 【Revit二次开发】族
  16. MySQL 8 安装教程
  17. 网页添加 Live2D 看板娘
  18. 飞猪java怎么样_2021春招面试必看:飞猪/新浪/饿了么内部Java面经手册首次发布...
  19. springMvc中的校验框架@valid和@validated
  20. 华为业务:组织架构和产品矩阵

热门文章

  1. 【Windows Server 2019】DHCP服务器配置与管理——验证DHCP服务 备份与恢复DHCP数据 Ⅲ
  2. php生成海报像素低,TP5.1生成海报
  3. window.onload=function()是什么意思
  4. 一根MicroUSB线完成树莓派zero开机配置(包括SSH以及网络共享)
  5. 搜索引擎Bing必应高级搜索使用技巧荟萃
  6. appid 原始id_微信开发之小程序登录相关的各类ID
  7. php生成appid,请求认证密钥-AppID
  8. form-making爬坑笔记(jeecg项目替换表单设计器)
  9. 基于E-Mail的隐蔽控制:机理与防御
  10. 用java将excel导出成vcf文件