lua-cs-bouncer-mcaptcha/lib/plugins/crowdsec/utils.lua

57 lines
1.3 KiB
Lua
Raw Normal View History

2022-01-26 18:41:57 +01:00
local M = {}
M.HTTP_CODE = {}
M.HTTP_CODE["200"] = ngx.HTTP_OK
M.HTTP_CODE["202"] = ngx.HTTP_ACCEPTED
M.HTTP_CODE["204"] = ngx.HTTP_NO_CONTENT
M.HTTP_CODE["301"] = ngx.HTTP_MOVED_PERMANENTLY
M.HTTP_CODE["302"] = ngx.HTTP_MOVED_TEMPORARILY
M.HTTP_CODE["400"] = ngx.HTTP_BAD_REQUEST
M.HTTP_CODE["401"] = ngx.HTTP_UNAUTHORIZED
M.HTTP_CODE["401"] = ngx.HTTP_UNAUTHORIZED
M.HTTP_CODE["403"] = ngx.HTTP_FORBIDDEN
M.HTTP_CODE["404"] = ngx.HTTP_NOT_FOUND
M.HTTP_CODE["405"] = ngx.HTTP_NOT_ALLOWED
M.HTTP_CODE["406"] = ngx.HTTP_NOT_ACCEPTABLE
2022-01-26 18:41:57 +01:00
M.HTTP_CODE["500"] = ngx.HTTP_INTERNAL_SERVER_ERROR
2022-01-30 17:07:51 +01:00
function M.read_file(path)
local file = io.open(path, "r") -- r read mode and b binary mode
if not file then return nil end
io.input(file)
local content = io.read("*a")
2022-01-30 17:07:51 +01:00
io.close(file)
return content
end
2022-01-27 18:57:05 +01:00
2022-01-30 17:07:51 +01:00
function M.file_exist(path)
2022-02-08 16:49:41 +01:00
if path == nil then
return nil
2022-02-08 16:42:27 +01:00
end
2022-01-30 17:07:51 +01:00
local f = io.open(path, "r")
if f ~= nil then
io.close(f)
return true
else
return false
end
end
2022-01-27 18:57:05 +01:00
2022-01-28 11:03:15 +01:00
function M.starts_with(str, start)
return str:sub(1, #start) == start
end
function M.ends_with(str, ending)
return ending == "" or str:sub(-#ending) == ending
end
2022-01-28 17:08:08 +01:00
function M.table_len(table)
local count = 0
for k, v in pairs(table) do
count = count + 1
end
return count
end
2022-01-27 18:57:05 +01:00
2022-01-26 18:41:57 +01:00
return M