Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to add upload / download and webcam functions to OpenWrt luci

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the knowledge of "how to add upload, download and webcam functions to OpenWrt luci". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

It took a few days to get an upload, download and webcam function for OpenWrt. Not familiar with lua and luci, it takes a little too much time. This package is a pure luci application and can be installed on any platform, and the webcam depends on mjpg-streamer. The effect picture is as follows:

The main source codes are as follows:

Controller/updownload.lua file:

-- [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}) end

Model/cbi/updownload.lua file:

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-

View/cbi/other_dvalue.htm file:

View/cbi/other_upload.htm file:

View/cbi/other_download.htm file:

View/webcam.htm file:

In order for the added package to be recognized in the openwrt source code make menuconfig, you need to add the following statement to. / feeds/luci/contrib/package/luci/Makefile:

(eval $(call application,other,luci my other application))

Download address of the package: luci-app-other_0.12.ipk

Download address of complete source code: luci-other_src.tar.gz

This is the end of the introduction of "how to add upload, download and webcam functions to OpenWrt luci". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report