Skip to content

Commit e1ab82e

Browse files
committed
Code cleaning and CS fixes.
1 parent e9e484c commit e1ab82e

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

config.inc.php.dist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ $rcmail_config['recaptcha_log_failure'] = 'Error: Verification failed for %u. [%
4040
$rcmail_config['recaptcha_log_unknown'] = 'Error: Unknown log type.';
4141

4242
// Block IPv6 clients based on prefix length
43-
$rcmail_config['rcguard_ipv6_prefix'] = 64;
43+
// Use an integer between 16 and 128, 0 to disable
44+
$rcmail_config['rcguard_ipv6_prefix'] = 0;

rcguard.php

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -279,24 +279,21 @@ private function get_client_ip()
279279
$prefix = rcmail::get_instance()->config->get('rcguard_ipv6_prefix', 128);
280280
$client_ip = rcube_utils::remote_addr();
281281

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);
298291
}
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+
}
300297

301298
// fall back: return unaltered client IP
302299
return $client_ip;

0 commit comments

Comments
 (0)