· 7 years ago · Feb 22, 2018, 02:02 AM
1// config :
2
3$HTTP["url"] =~ "\.flv" {
4magnet.attract-physical-path-to = server.docroot + "/secure-flv.lua"
5}
6
7
8
9// secure-flv.lua :
10
11if (lighty.env["uri.query"]) then
12 -- split the query-string
13 get = {}
14 for k, v in string.gmatch(lighty.env["uri.query"], "(%w+)=(%w+)") do
15 get[k] = v
16 end
17
18 if (get["check"] !=(md5.sum(os.time() .. "secretkey" .. lighty.env["uri.path"]))) then
19 return 403
20 end
21
22 if (get["start"]) then
23 -- missing: check if start is numeric and positive
24
25 -- send te FLV header + a seek into the file
26 lighty.content = { "FLV\x1\x1\0\0\0\x9\0\0\0\x9",
27 { filename = lighty.env["physical.path"], offset = get["start"] } }
28 lighty.header["Content-Type"] = "video/x-flv"
29
30 return 200
31 end
32else
33 return 403
34end