remote API - basic send of bad IPs

This commit is contained in:
bunkerity
2021-10-07 12:00:20 +02:00
parent fb799765a4
commit fdc02be051
10 changed files with 37 additions and 29 deletions

View File

@@ -83,30 +83,23 @@ if use_remote_api then
-- Save version
local f = io.open("/opt/bunkerized-nginx/VERSION", "r")
ngx.shared.remote_api:set("version", f:read("*all"), 0)
ngx.shared.remote_api:set("version", f:read("*all"):gsub("[\r\n]", ""), 0)
f:close()
-- Save and ask a machine ID if needed
local f = io.open("/etc/nginx/machine.id", "rw")
-- Save machine ID
local f = io.open("/etc/nginx/machine.id", "r")
if f == nil then
id = nil
id = "empty"
logger.log(ngx.ERR, "REMOTE API", "USE_REMOTE_API is set to yes but machine ID is not generated - communication with {{ REMOTE_API_SERVER }} won't work")
else
id = f:read("*all")
id = f:read("*all"):gsub("[\r\n]", "")
logger.log(ngx.ERR, "REMOTE API", "*NOT AN ERROR* Machine ID = " .. id)
f:close()
end
f:close()
-- Test the machine ID
if id ~= nil then
local res, pong = remoteapi.ping()
if not res or pong ~= "pong" then
logger.log(ngx.ERR, "REMOTE API", "Ping failed, the remote server may be down or your machine ID is invalid")
else
logger.log(ngx.ERR, "REMOTE API", "*NOT AN ERROR* Ping successful")
end
end
ngx.shared.remote_api:set("id", id, 0)
-- TODO : ping (blocking socket)
-- TODO : load database
end
}