Replace master branch with local files
This commit is contained in:
commit
875a53f499
60 changed files with 21637 additions and 0 deletions
67
openresty/lua/auth.lua
Normal file
67
openresty/lua/auth.lua
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
local redis_helper = require "redis_helper"
|
||||
local cjson = require "cjson"
|
||||
|
||||
-- Read POST body for OME webhook
|
||||
ngx.req.read_body()
|
||||
local body = ngx.req.get_body_data()
|
||||
|
||||
if not body then
|
||||
ngx.status = ngx.HTTP_BAD_REQUEST
|
||||
ngx.say(cjson.encode({allowed = false, reason = "No body provided"}))
|
||||
return ngx.exit(ngx.HTTP_BAD_REQUEST)
|
||||
end
|
||||
|
||||
-- Parse JSON body
|
||||
local ok, data = pcall(cjson.decode, body)
|
||||
if not ok then
|
||||
ngx.status = ngx.HTTP_BAD_REQUEST
|
||||
ngx.say(cjson.encode({allowed = false, reason = "Invalid JSON"}))
|
||||
return ngx.exit(ngx.HTTP_BAD_REQUEST)
|
||||
end
|
||||
|
||||
-- Extract stream key from the request
|
||||
local stream_key = nil
|
||||
|
||||
-- Check different possible locations for the stream key
|
||||
if data.request and data.request.url then
|
||||
-- Extract from URL path or query string
|
||||
stream_key = data.request.url:match("/app/([^/?]+)")
|
||||
if not stream_key and data.request.params then
|
||||
stream_key = data.request.params.key or data.request.params.streamid
|
||||
end
|
||||
elseif data.stream and data.stream.name then
|
||||
stream_key = data.stream.name
|
||||
end
|
||||
|
||||
-- Handle SRT streamid format (app/KEY)
|
||||
if stream_key then
|
||||
local extracted = stream_key:match("app/(.+)")
|
||||
if extracted then
|
||||
stream_key = extracted
|
||||
end
|
||||
end
|
||||
|
||||
if not stream_key then
|
||||
ngx.status = ngx.HTTP_OK
|
||||
ngx.say(cjson.encode({allowed = false, reason = "No stream key provided"}))
|
||||
return ngx.exit(ngx.HTTP_OK)
|
||||
end
|
||||
|
||||
-- Validate key
|
||||
local valid = redis_helper.validate_stream_key(stream_key)
|
||||
|
||||
-- OME webhook expects specific response format
|
||||
local response = {
|
||||
allowed = valid,
|
||||
stream = {
|
||||
name = stream_key
|
||||
}
|
||||
}
|
||||
|
||||
if not valid then
|
||||
response.reason = "Invalid stream key"
|
||||
end
|
||||
|
||||
ngx.status = ngx.HTTP_OK
|
||||
ngx.header.content_type = "application/json"
|
||||
ngx.say(cjson.encode(response))
|
||||
Loading…
Add table
Add a link
Reference in a new issue