mirror of
https://github.com/gmod-integration/lua.git
synced 2025-03-15 22:07:34 +00:00
add: isPrivateIP and allow http on private IP
This commit is contained in:
parent
e433a1f343
commit
0ae9631880
|
@ -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)
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue
Block a user