Ver Fonte

Add getIPs()

Pascal Peridont há 18 anos atrás
pai
commit
6da8ff59a0
1 ficheiros alterados com 19 adições e 3 exclusões
  1. 19 3
      std/mtwin/web/Request.hx

+ 19 - 3
std/mtwin/web/Request.hx

@@ -106,19 +106,35 @@ class Request {
 		return Web.getClientHeader("Referer");
 	}
 
-	static var REG_IP = ~/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/;
+	static var REG_IP = ~/^\s*([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/;
 	public function getIP() : String{
 		var ip = Web.getClientIP();
 		var xf = Web.getClientHeader("X-Forwarded-For");
 		if( xf != null && REG_IP.match( xf ) ){
 			var fip = REG_IP.matched(1);
-			if( !~/^(127\.0\.0\.1|192\.168\..*|172\.16\..*|10\..*|224\..*|240\..*)$/.match(fip) ){
+			if( !~/^(127\.0\.0\.1|192\.168\..*|172\.16\..*|10\..*|224\..*|240\..*)$/.match(fip) )
 				ip = fip;
-			}
 		}
 		return ip;
 	}
 
+	public function getIPs() : List<String> {
+		var ret = new List();
+		ret.add(Web.getClientIP());
+		var xf = Web.getClientHeader("X-Forwarded-For");
+		if( xf != null ){
+			var a = xf.split(",");
+			for( ip in a ){
+				if( REG_IP.match( ip ) ){
+					var fip = REG_IP.matched(1);
+					if( !~/^(127\.0\.0\.1|192\.168\..*|172\.16\..*|10\..*|224\..*|240\..*)$/.match(fip) )
+						ret.add(fip);
+				}
+			}
+		}
+		return ret;
+	}
+
 	public function exists( key ) {
 		return params.exists( key );
 	}