32. IP アドレス制限の実装
32
function authenticate_remote_addr(allows)
local bit = require("bit")
local remote_addr = ngx.var.binary_remote_addr
local x0, x1, x2, x3 = string.byte(remote_addr, 1, 4)
local ip
ip = x0 * 16777216
ip = x1 * 65536 + ip
ip = x2 * 256 + ip
ip = x3 + ip
for i, allow in ipairs(allows) do
if bit.band(ip, allow[2]) == bit.tobit(allow[1]) then
return true
end
end
return false
end
33. IP アドレス制限の実装
33
function authenticate_remote_addr(allows)
local bit = require("bit")
local remote_addr = ngx.var.binary_remote_addr
local x0, x1, x2, x3 = string.byte(remote_addr, 1, 4)
local ip
ip = x0 * 16777216
ip = x1 * 65536 + ip
ip = x2 * 256 + ip
ip = x3 + ip
for i, allow in ipairs(allows) do
if bit.band(ip, allow[2]) == bit.tobit(allow[1]) then
return true
end
end
return false
end
nginx の内部変数からクライア
ント IP アドレスを取得する
34. IP アドレス制限の実装
34
function authenticate_remote_addr(allows)
local bit = require("bit")
local remote_addr = ngx.var.binary_remote_addr
local x0, x1, x2, x3 = string.byte(remote_addr, 1, 4)
local ip
ip = x0 * 16777216
ip = x1 * 65536 + ip
ip = x2 * 256 + ip
ip = x3 + ip
for i, allow in ipairs(allows) do
if bit.band(ip, allow[2]) == bit.tobit(allow[1]) then
return true
end
end
return false
end
データベースファイルから読み込んだ
許可リストと比較してアクセス可否を
判定