From fc9240fbac568a0d70d45d6add3123ee228f68b7 Mon Sep 17 00:00:00 2001 From: Toby Chui Date: Sun, 28 Apr 2024 11:27:00 +0800 Subject: [PATCH] Fixed #131 - Added LAN detection in geoip resolver - Updated UI for LAN/loopback request origin rendering --- src/mod/geodb/geodb.go | 5 +++++ src/mod/netutils/ipmatch.go | 4 ++++ src/web/components/stats.html | 5 ++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/mod/geodb/geodb.go b/src/mod/geodb/geodb.go index a25757a..8aed52d 100644 --- a/src/mod/geodb/geodb.go +++ b/src/mod/geodb/geodb.go @@ -83,6 +83,11 @@ func (s *Store) GetRequesterCountryISOCode(r *http.Request) string { if ipAddr == "" { return "" } + + if netutils.IsPrivateIP(ipAddr) { + return "LAN" + } + countryCode, err := s.ResolveCountryCodeFromIP(ipAddr) if err != nil { return "" diff --git a/src/mod/netutils/ipmatch.go b/src/mod/netutils/ipmatch.go index 2abd779..42608c5 100644 --- a/src/mod/netutils/ipmatch.go +++ b/src/mod/netutils/ipmatch.go @@ -93,6 +93,10 @@ func MatchIpCIDR(ip string, cidr string) bool { // Check if a ip is private IP range func IsPrivateIP(ipStr string) bool { + if ipStr == "127.0.0.1" || ipStr == "::1" { + //local loopback + return true + } ip := net.ParseIP(ipStr) if ip == nil { return false diff --git a/src/web/components/stats.html b/src/web/components/stats.html index ba7f43f..4f650b0 100644 --- a/src/web/components/stats.html +++ b/src/web/components/stats.html @@ -765,8 +765,11 @@ let data = Object.values(visitorData); Object.keys(visitorData).forEach(function(cc){ + console.log(cc); if (cc == ""){ - labels.push("Local / Unknown") + labels.push("Unknown") + }else if (cc == "lan"){ + labels.push(`LAN / Loopback`); }else{ labels.push(`${getCountryName(cc)} [${cc.toUpperCase()}]` ); }