23 lines
871 B
Lua
23 lines
871 B
Lua
local session, err, exists = require "resty.session".open()
|
|
if exists and session:get("authenticated") then
|
|
local account = session:get("account")
|
|
ngx.log(ngx.INFO, session:get("account"), " 访问")
|
|
local accounts = require("lua/accounts")
|
|
local credentials = accounts.credentials()
|
|
local password = ""
|
|
if credentials then
|
|
password = credentials[account]
|
|
end
|
|
local auth_value = ngx.encode_base64(account .. ':' .. password)
|
|
ngx.req.set_header("Authorization", "Basic " .. auth_value)
|
|
else
|
|
local server = ""
|
|
if ngx.var.server_port == "80" then
|
|
server = ngx.var.host
|
|
else
|
|
server = ngx.var.host .. ":" .. ngx.var.server_port
|
|
end
|
|
local target_url = ngx.var.scheme .. "://" .. server .. ngx.var.request_uri
|
|
ngx.redirect('https://amass.fun/LoginPage?next=' .. ngx.escape_uri(target_url))
|
|
end
|