@@ -279,24 +279,21 @@ private function get_client_ip()
279
279
$ prefix = rcmail::get_instance ()->config ->get ('rcguard_ipv6_prefix ' , 128 );
280
280
$ client_ip = rcube_utils::remote_addr ();
281
281
282
- // process only v6 addresses
283
- if (!filter_var ($ client_ip , FILTER_VALIDATE_IP , FILTER_FLAG_IPV6 ) === false ) {
284
-
285
- // process only if prefix is sane
286
- if (is_int ($ prefix ) && $ prefix > 16 && $ prefix < 128 ) {
287
-
288
- // construct subnet mask
289
- $ mask_string = str_repeat ('1 ' , $ prefix ) . str_repeat ('0 ' , 128 -$ prefix );
290
- $ mask_split = str_split ($ mask_string , 16 );
291
- foreach ($ mask_split as &$ item ) {
292
- $ item = base_convert ($ item , 2 , 16 );
293
- }
294
- $ mask_hex = implode (": " , $ mask_split );
295
-
296
- // return network part
297
- return inet_ntop ( inet_pton ($ client_ip ) & inet_pton ($ mask_hex ) );
282
+ // process only if prefix is sane and it's an IPv6 address
283
+ if (is_int ($ prefix ) && $ prefix > 16 && $ prefix < 128 &&
284
+ filter_var ($ client_ip , FILTER_VALIDATE_IP , FILTER_FLAG_IPV6 ) !== false ) {
285
+
286
+ // construct subnet mask
287
+ $ mask_string = str_repeat ('1 ' , $ prefix ) . str_repeat ('0 ' , 128 - $ prefix );
288
+ $ mask_split = str_split ($ mask_string , 16 );
289
+ foreach ($ mask_split as $ item ) {
290
+ $ item = base_convert ($ item , 2 , 16 );
298
291
}
299
- }
292
+ $ mask_hex = implode (": " , $ mask_split );
293
+
294
+ // return network part
295
+ return inet_ntop (inet_pton ($ client_ip ) & inet_pton ($ mask_hex ));
296
+ }
300
297
301
298
// fall back: return unaltered client IP
302
299
return $ client_ip ;
0 commit comments