Browse Source

Added LAN / loopback detection in statistic

Toby Chui 10 months ago
parent
commit
11fad9451a
4 changed files with 16 additions and 2 deletions
  1. 5 0
      mod/geodb/geodb.go
  2. 4 0
      mod/netutils/ipmatch.go
  3. 4 1
      web/components/stats.html
  4. 3 1
      web/components/utils.html

+ 5 - 0
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 ""

+ 4 - 0
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

+ 4 - 1
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()}]` );
             }

+ 3 - 1
web/components/utils.html

@@ -345,7 +345,8 @@
             form.find('input[name="hostname"]').parent().removeClass('error');
         }
 
-        // validate domain
+        // validate domain, now allow empty string (for smtp that dont use domain as input)
+        /*
         const domain = form.find('input[name="domain"]').val().trim();
         if (!domainRegex.test(domain)) {
             form.find('input[name="domain"]').parent().addClass('error');
@@ -353,6 +354,7 @@
         } else {
             form.find('input[name="domain"]').parent().removeClass('error');
         }
+        */
 
         // validate username
         const username = form.find('input[name="username"]').val().trim();