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';
|
|
|
|
|
|
|
|
|
|
local _M = {}
|
|
|
|
|
|
2023-05-07 02:29:38 +08:00
|
|
|
function host(s)
|
|
|
|
|
return (s.."/"):match("://(.-)/")
|
|
|
|
|
end
|
|
|
|
|
|
2022-08-23 01:12:31 +08:00
|
|
|
function _M.upt(uri)
|
2023-05-07 02:29:38 +08:00
|
|
|
local hostname = host(uri)
|
2023-05-07 02:24:32 +08:00
|
|
|
ngx.log(ngx.INFO, 'hostname...', hostname)
|
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 02:08:27 +08:00
|
|
|
secret = ngx.var.upt_moicen_secret
|
2023-05-07 02:24:32 +08:00
|
|
|
elseif string.find(hostname, "alchemy-studio.cn") then
|
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 02:08:27 +08:00
|
|
|
secret = ngx.var.upt_huiwings_secret
|
|
|
|
|
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
|
|
|
|
|
local sign = ngx.md5(secret .. '&' .. etime .. '&' .. uri)
|
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
|