Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- channels = {
- -- promo channel for auth_request redirect
- ["promo"] = "...",
- -- channel list
- }
- access_list_file = "/etc/astra/access_list.txt"
- access_redirect = "/promo"
- function ip_to_number(ip)
- ip = split(ip, "%.")
- if #ip ~= 4 then return 0 end
- for k,v in ipairs(ip) do
- ip[k] = tonumber(v)
- if not ip[k] then return 0 end
- end
- return (ip[1] * 0x1000000) + (ip[2] * 0x10000) + (ip[3] * 0x100) + (ip[4])
- end
- function mask_to_number(mask)
- local a = 0xFFFFFFFF
- local m = 32 - tonumber(mask)
- if m > 0 then
- a = bit32.rshift(a, m)
- a = bit32.lshift(a, m)
- end
- return a
- end
- function ip_check(ip)
- ip = ip_to_number(ip)
- for _,v in ipairs(access_list) do
- if v[1] == bit32.band(ip, v[2]) then return true end
- end
- return false
- end
- function load_access_list()
- local r = {}
- local f = io.open(access_list_file, "r")
- for ip in f:lines() do
- local b = ip:find("/")
- if b then
- local a = ip_to_number(ip:sub(1, b - 1))
- local m = mask_to_number(ip:sub(b + 1))
- a = bit32.band(a, m)
- table.insert(r, { a, m })
- else
- local a = ip_to_number(ip)
- local m = mask_to_number(32)
- table.insert(r, { a, m })
- end
- end
- f:close()
- return r
- end
- access_list = load_access_list()
- function auth_request(client_id, request, auth_callback)
- if not request then
- return nil
- end
- if request.path == access_redirect then
- auth_callback(true)
- return nil
- end
- if ip_check(request.addr) then
- auth_callback(true)
- else
- auth_callback(access_redirect)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment