Files
resty_functions/scripts/lib/upt.lua
T

44 lines
1.5 KiB
Lua
Raw Normal View History

2022-08-23 01:11:25 +08:00
-- 指定模块引用目录,否则无法加载同目录下的其他文件
--package.path = package.path .. ';/usr/local/opt/openresty/nginx/scripts/?.lua';
package.path = package.path .. ';<SCRIPT_PATH>/?.lua';
2023-05-07 02:49:52 +08:00
local url_parser = require "net.url"
2022-08-23 01:11:25 +08:00
local _M = {}
2023-08-11 16:49:29 +08:00
function _M.host(s)
2023-05-07 02:29:38 +08:00
return (s.."/"):match("://(.-)/")
end
2023-05-07 02:49:52 +08:00
function _M.upt(url)
local uri = url_parser.parse(url)
local hostname = uri.host
local pathname = uri.path
ngx.log(ngx.INFO, 'hostname...' .. hostname .. ' path...' .. pathname)
2023-05-07 02:08:27 +08:00
local secret;
2023-05-07 02:24:32 +08:00
if string.find(hostname, "moicen.com") then
2023-05-07 23:58:40 +08:00
ngx.log(ngx.INFO, 'match moicen.com: ' .. ngx.var.upt_moicen_secret)
2023-05-07 02:08:27 +08:00
secret = ngx.var.upt_moicen_secret
2023-05-20 01:22:55 +08:00
elseif string.find(hostname, "alchemy-studio.cn", 1, true) then
2023-05-08 00:05:10 +08:00
ngx.log(ngx.INFO, 'match alchemy: ' .. ngx.var.upt_alchemy_secret)
2023-05-07 02:08:27 +08:00
secret = ngx.var.upt_alchemy_secret
2023-05-07 02:24:32 +08:00
elseif string.find(hostname, "huiwings.cn") then
2023-05-07 23:58:40 +08:00
ngx.log(ngx.INFO, 'match huiwings.cn: ' .. ngx.var.upt_huiwings_secret)
2023-05-07 02:08:27 +08:00
secret = ngx.var.upt_huiwings_secret
2023-05-07 23:58:40 +08:00
else
ngx.status = 401
ngx.log(ngx.ERR, "Reject URL -> ", hostname)
ngx.exit(ngx.status)
2023-05-07 02:08:27 +08:00
end
2023-05-07 02:24:32 +08:00
ngx.log(ngx.INFO, 'secret...' .. secret)
2022-08-23 01:11:25 +08:00
local duration = ngx.var.upt_duration
local etime = os.time() + duration
2023-05-07 02:49:52 +08:00
local sign = ngx.md5(secret .. '&' .. etime .. '&' .. pathname)
2022-08-23 13:55:38 +08:00
ngx.log(ngx.INFO, 'sign...' .. sign .. ' etime..' .. etime)
2022-08-23 01:11:25 +08:00
local upt = string.sub(sign, 13, 13 + 7) .. etime
2022-12-26 22:46:51 +08:00
ngx.log(ngx.INFO, 'upt...' .. upt)
2022-08-23 01:14:19 +08:00
return (upt)
2022-08-23 01:12:31 +08:00
end
2022-08-23 01:11:25 +08:00
return _M