add: isPrivateIP and allow http on private IP

This commit is contained in:
Linventif 2024-06-28 18:46:43 +00:00
parent e433a1f343
commit 0ae9631880
2 changed files with 15 additions and 2 deletions

View File

@ -2,7 +2,7 @@ local apiVersion = "v3"
gmInte.http = gmInte.http || {} gmInte.http = gmInte.http || {}
local function getAPIURL(endpoint) local function getAPIURL(endpoint)
local url = "https://" .. gmInte.config.apiFQDN .. "/" .. apiVersion local method = gmInte.isPrivateIP(gmInte.config.apiFQDN) && "http" || "https"
endpoint = string.gsub(endpoint, ":serverID", gmInte.config.id) endpoint = string.gsub(endpoint, ":serverID", gmInte.config.id)
@ -10,7 +10,7 @@ local function getAPIURL(endpoint)
endpoint = string.gsub(endpoint, ":steamID64", LocalPlayer():SteamID64()) endpoint = string.gsub(endpoint, ":steamID64", LocalPlayer():SteamID64())
end end
return url .. endpoint return method .. "://" .. gmInte.config.apiFQDN .. "/" .. apiVersion .. endpoint
end end
local function showableBody(endpoint) local function showableBody(endpoint)

View File

@ -24,4 +24,17 @@ end
function gmInte.logHint(msg, debug) function gmInte.logHint(msg, debug)
if (debug && !gmInte.config.debug) then return end if (debug && !gmInte.config.debug) then return end
print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] [HINT] " .. msg) print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] [HINT] " .. msg)
end
// Is Private IP
function gmInte.isPrivateIP(ip)
// detect localhost
if (ip == "localhost") then return true end
// detect private IP addresses (RFC 1918)
local parts = string.Explode(".", ip)
if (parts[1] == "192" && parts[2] == "168") then return true end
if (parts[1] == "10") then return true end
if (parts[1] == "172" && tonumber(parts[2]) >= 16 && tonumber(parts[2]) <= 31) then return true end
if (parts[1] == "127") then return true end
return false
end end