OpenWrt网页支持升级本地package
来源:互联网 发布:碧欧泉淘宝是正品吗 编辑:程序博客网 时间:2024/05/05 00:47
Install packages via web interface
Trigger to send file
in file of packages.htm(View), which represent the apperance at Client’s site, use method of POST , and input of FILE and SUBMIT . the following code can be add to packages.htm
Note: .tar.gz file should be used.
example:
<form method="post" action="<%=REQUEST_URI%>" enctype="multipart/form-data">
<!-- show feedback ---->
<% if (install and next(install)) or (remove and next(remove)) or update or upgrade then %>
<div class="cbi-value">
<% if #stdout > 0 then %><pre><%=pcdata(stdout)%></pre><% end %>
<% if #stderr > 0 then %><pre class="error"><%=pcdata(stderr)%></pre><% end %>
</div>
<% end %>
<!-- send post ---->
<div class="cbi-section-descr"><%:To install a package from local PC, you can choose a package file here.%></div>
<div class="cbi-section-node">
<div class="cbi-value cbi-value-last">
<label class="cbi-value-title" for=" ipk"><%:Transfer and install package%>:</label>
<div class="cbi-value-field">
<input type="file" name="ipk" id=" ipk" size="30"/>
<input type="submit" class="cbi-button cbi-input-apply" name="restore" value="<%:Start transfer...%>" />
</div>
</div>
</div>
</form>
Receive the request
system.lua(Controller), which defined a structure corresponding to the behavior options on the web page, points out how every operation be handled, typically via methods ofcall or cbi. In this case, call(“action_packages”)will be involved.
example:
entry({"admin", "system", "packages"}, call("action_packages"), _("Software"), 10)
handle packages of file
typical implementation
Refer to action_flashops in system.lua(Controller), filehandler of http need to be set to inform http that how to handle the packages,and “restore” of form value need to be handle in this function.
So insert the following code inaction_packages:
local upload_cmd = "tar -xzC/ >/dev/null 2>&1"
local fp
-- I don't known why this function doesn't take any effect indeed here,
-- so set Request.filehandler directly in http.lua
luci.http.setfilehandler(
function(meta, chunk, eof)
if not fp then
if meta and meta.name == "ipk" then
fp = io.popen(upload_cmd, "w")
end
end
if chunk then
fp:write(chunk)
end
if eof then
fp:close()
end
end
)
if luci.http.formvalue("restore") then
local upload = luci.http.formvalue("ipk")
if upload and #upload > 0 then
install["my.ipk"], out, err = ipkg.install("/my.ipk")
stdout[#stdout+1] = out
stderr[#stderr+1] = err
changes = true
os.execute("rm / my.ipk")
end
end
problem solution
actually, I failed to restore the uploading file by the way introduced in the previous chapter, refer to the comment(yellow color). Anyway, I found another way to fulfill the target, which is a little clumsy – insert the following code into Request.__init__ of http.lua:
local io = require "io"
local fp = nil
local restore_cmd = "tar -xzC/ >/dev/null 2>&1"
local image_tmp = "/tmp/firmware.img"
self.filehandler = function(meta, chunk, eof)
if not fp then
if meta and meta.name == "image" then
fp = io.open(image_tmp, "w")
else
fp = io.popen(restore_cmd, "w")
end
end
if chunk then
fp:write(chunk)
end
if eof then
fp:close()
end
end
- OpenWrt网页支持升级本地package
- 5-Openwrt package Makefile
- openWrt编译package
- openwrt 编译 gcc 包package
- Openwrt 编译添加模块 Package
- OpenWrt 增加 package软件包--1
- OpenWrt 增加 package软件包--0
- openwrt单独编译package包
- Openwrt升级细节
- openwrt升级命令
- MW4530R升级openwrt
- openwrt升级功能介绍
- openwrt 升级系统方法
- openwrt升级uClibc
- openwrt编译/升级过程
- 给本地openwrt/LEDE软件源添加软件包,更新Package.sig签名文件,解决Signature check failed问题
- 搭建 openwrt 本地源
- openwrt 编译支持sqlite3
- 美国移民后到底有多自由疯狂?通过这几件小事就知道了
- delphi 按回车选中下一个控件
- Android 错误集锦及解决方案
- 给DataGridView 添加鼠标单击事件,并且在contexMenutstrip中显示,获取该行的主键
- GridView修改列标题HeaderText
- OpenWrt网页支持升级本地package
- ${param.id}的使用
- 美国移民后到底有多自由疯狂?通过这几件小事就知道了
- jQuery学习笔记2——温故+知新
- 解决 SharePoint 2013 “此power View 报表无效或不受此版本的Power View 支持。它....”
- MVC实现学生管理系统的一些技巧和注意事项
- Android之断点续传下载
- Zend Framework 1.x+jQuery EasyUI 1.3.4 整合四:控制器与视图
- Machine Learning week 5 programming exercise Neural Network Learning