OpenWrt luci怎么添加上传下载及网络摄像头功能
发表于:2025-12-01 作者:千家信息网编辑
千家信息网最后更新 2025年12月01日,本篇内容介绍了"OpenWrt luci怎么添加上传下载及网络摄像头功能"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅
千家信息网最后更新 2025年12月01日OpenWrt luci怎么添加上传下载及网络摄像头功能
本篇内容介绍了"OpenWrt luci怎么添加上传下载及网络摄像头功能"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
花了几天时间给OpenWrt弄了个上传下载及网络摄像头功能。对lua及luci不熟,时间花的有点多。此软件包是纯luci应用,可以安装在任意平台,网络摄像头要依赖mjpg-streamer。效果图如下:

主要源码如下:
controller/updownload.lua文件:
--[[Other moduleDescription: File upload / download, web cameraAuthor: yuleniwo xzm2@qq.com QQ:529698939]]--module("luci.controller.other", package.seeall)function index() local page = entry({"admin", "system", "other"}, alias("admin", "system", "other", "updownload"), _("Other"), 89) entry({"admin", "system", "other", "updownload"}, form("updownload"), _("Upload / Download")) if nixio.fs.access("/etc/config/mjpg-streamer") then entry({"admin", "system", "other", "webcam"}, call("Webcam"), _("Web Camera")) end page.i18n = "other" page.dependent = trueendlocal translate = luci.i18n.translatelocal http = luci.httpfunction Webcam() local iframe = '' local html, msg, status local act = http.formvalue("act") if act then if act == "start" then luci.sys.call("/etc/init.d/mjpg-streamer start") elseif act == "stop" then luci.sys.call("/etc/init.d/mjpg-streamer stop") luci.sys.call("sleep 1") end end local v = nixio.fs.glob("/dev/video[0-9]")() if v then if luci.sys.call("pidof mjpg_streamer > /dev/null") == 0 then local uci, user, pwd, ip, port uci = require "luci.model.uci".cursor() user = uci:get("mjpg-streamer", "core", "username") pwd = uci:get("mjpg-streamer", "core", "password") ip = uci:get("network", "lan", "ipaddr") port = uci:get("mjpg-streamer", "core", "port") html = string.format(iframe, user, pwd, ip, port) status = true else status = false msg = translate("Service 'mjpg_streamer' not started.") end else msg = translate("Video device not found.") end luci.template.render("webcam", {html = html, msg = msg, status = status})endmodel/cbi/updownload.lua文件:
local fs = require "luci.fs"local http = luci.httpful = SimpleForm("upload", translate("Upload"), nil)ful.reset = falseful.submit = falsesul = ful:section(SimpleSection, "", translate("Upload file to '/tmp/upload/'"))fu = sul:option(FileUpload, "")fu.template = "cbi/other_upload"um = sul:option(DummyValue, "", nil)um.template = "cbi/other_dvalue"fdl = SimpleForm("download", translate("Download"), nil)fdl.reset = falsefdl.submit = falsesdl = fdl:section(SimpleSection, "", translate("Download file"))fd = sdl:option(FileUpload, "")fd.template = "cbi/other_download"dm = sdl:option(DummyValue, "", nil)dm.template = "cbi/other_dvalue"function Download() local sPath, sFile, fd, block sPath = http.formvalue("dlfile") sFile = nixio.fs.basename(sPath) if luci.fs.isdirectory(sPath) then fd = io.popen('tar -C "%s" -cz .' % {sPath}, "r") sFile = sFile .. ".tar.gz" else fd = nixio.open(sPath, "r") end if not fd then dm.value = translate("Couldn't open file: ") .. sPath return end dm.value = nil http.header('Content-Disposition', 'attachment; filename="%s"' % {sFile}) http.prepare_content("application/octet-stream") while true do block = fd:read(nixio.const.buffersize) if (not block) or (#block ==0) then break else http.write(block) end end fd:close() http.close()endlocal dir, fddir = "/tmp/upload/"nixio.fs.mkdir(dir)http.setfilehandler( function(meta, chunk, eof) if not fd then if not meta then return end fd = nixio.open(dir .. meta.file, "w") if not fd then um.value = translate("Create upload file error.") return end end if chunk and fd then fd:write(chunk) end if eof and fd then fd:close() fd = nil um.value = translate("File saved to") .. ' "/tmp/upload/' .. meta.file .. '"' end end)if luci.http.formvalue("upload") then local f = luci.http.formvalue("ulfile") if #f <= 0 then um.value = translate("No specify upload file.") endelseif luci.http.formvalue("download") then Download()endlocal inits, attr = {}for i, f in ipairs(fs.glob("/tmp/upload/*")) do attr = fs.stat(f) if attr then inits[i] = {} inits[i].name = fs.basename(f) inits[i].mtime = os.date("%Y-%m-%d %H:%M:%S", attr.mtime) inits[i].modestr = attr.modestr inits[i].size = tostring(attr.size) inits[i].remove = 0 inits[i].install = false endendform = SimpleForm("filelist", translate("Upload file list"), nil)form.reset = falseform.submit = falsetb = form:section(Table, inits)nm = tb:option(DummyValue, "name", translate("File name"))mt = tb:option(DummyValue, "mtime", translate("Modify time"))ms = tb:option(DummyValue, "modestr", translate("Mode string"))sz = tb:option(DummyValue, "size", translate("Size"))btnrm = tb:option(Button, "remove", translate("Remove"))btnrm.render = function(self, section, scope) self.inputstyle = "remove" Button.render(self, section, scope)endbtnrm.write = function(self, section) local v = luci.fs.unlink("/tmp/upload/" .. luci.fs.basename(inits[section].name)) if v then table.remove(inits, section) end return vendfunction IsIpkFile(name) name = name or "" local ext = string.lower(string.sub(name, -4, -1)) return ext == ".ipk"endbtnis = tb:option(Button, "install", translate("Install"))btnis.template = "cbi/other_button"btnis.render = function(self, section, scope) if not inits[section] then return false end if IsIpkFile(inits[section].name) then scope.display = "" else scope.display = "none" end self.inputstyle = "apply" Button.render(self, section, scope)endbtnis.write = function(self, section) local r = luci.sys.exec(string.format('opkg --force-depends install "/tmp/upload/%s"', inits[section].name)) form.description = string.format('%s', r)endreturn ful, fdl, formview/cbi/other_button.htm文件:
<%+cbi/valueheader%> <% if self:cfgvalue(section) ~= false then %> " type="submit"<%= attr("name", cbid) .. attr("id", cbid) .. attr("value", self.inputtitle or self.title)%> /> <% else %> - <% end %><%+cbi/valuefooter%>view/cbi/other_dvalue.htm文件:
<%+cbi/valueheader%><% local val = self:cfgvalue(section) or self.default or "" write(pcdata(val))%><%+cbi/valuefooter%>view/cbi/other_upload.htm文件:
<%+cbi/valueheader%> <%+cbi/valuefooter%>
view/cbi/other_download.htm文件:
<%+cbi/valueheader%> <%+cbi/valuefooter%>
view/webcam.htm文件:
<%+header%><% end %>><%=msg%>
<% if html then write(html) end %>
<%+footer%>为了使添加的软件包能在openwrt源码make menuconfig时识别出来,需要在./feeds/luci/contrib/package/luci/Makefile增加如下语句:
$(eval $(call application,other,luci my other application))
软件包下载地址:luci-app-other_0.12.ipk
完整源码下载地址:luci-other_src.tar.gz
"OpenWrt luci怎么添加上传下载及网络摄像头功能"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!
文件
摄像头
网络
摄像
上传下载
功能
源码
软件
软件包
内容
地址
更多
知识
实用
学有所成
接下来
困境
天时
实际
平台
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
浪潮软件开发工程师面试
互联网科技加工厂
服务器报警400是什么意思
龙岩游戏软件开发
蓝牙设备怎么连接终端数据库
蝙蝠服务器
软件开发和应用技术就业前景
sql数据库只显示一个字段
asp连接数据库出错
网络安全教育内容设计
两个内网服务器怎么互相登录
组装电脑服务器cpu是干嘛的
什么是数据库安全定义
车载网络技术ppt模板
成都银行网络安全中标结果
把电脑设置时间服务器
平顶山软件开发销售价格
中国信息网络技术突破
江苏软件开发企业招聘信息
蛟龙服务器哪个
中华医典数据库免费
常熟职业滨江技术学校数据库
plus数据库连接
迷你军团服务器开放时间
网络安全简介70字
网络安全复习
参观军营网络安全活动心得体会
护童网络安全课看后感
潍坊平台软件开发解决方案
阜阳安卓软件开发定制公司