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 || {}
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)
@ -10,7 +10,7 @@ local function getAPIURL(endpoint)
endpoint = string.gsub(endpoint, ":steamID64", LocalPlayer():SteamID64())
end
return url .. endpoint
return method .. "://" .. gmInte.config.apiFQDN .. "/" .. apiVersion .. endpoint
end
local function showableBody(endpoint)

View File

@ -25,3 +25,16 @@ function gmInte.logHint(msg, debug)
if (debug && !gmInte.config.debug) then return end
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