File tree Expand file tree Collapse file tree 3 files changed +29
-3
lines changed Expand file tree Collapse file tree 3 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -38,3 +38,6 @@ $rcmail_config['recaptcha_log'] = false;
38
38
$rcmail_config['recaptcha_log_success'] = 'Verification succeeded for %u. [%r]';
39
39
$rcmail_config['recaptcha_log_failure'] = 'Error: Verification failed for %u. [%r]';
40
40
$rcmail_config['recaptcha_log_unknown'] = 'Error: Unknown log type.';
41
+
42
+ // Block IPv6 clients based on prefix length
43
+ $rcmail_config['rcguard_ipv6_prefix'] = 64;
Original file line number Diff line number Diff line change 3
3
$ labels = array ();
4
4
5
5
$ messages = array ();
6
- $ messages ['recaptchafailed ' ] = 'Die Überprüfung des Sicherheitscodes ist fehlgeschlagen! ' ;
7
- $ messages ['recaptchaempty ' ] = 'Bitte geben Sie den Sicherheitscode ein ! ' ;
6
+ $ messages ['recaptchafailed ' ] = 'Die Überprüfung des Captchas ist fehlgeschlagen! ' ;
7
+ $ messages ['recaptchaempty ' ] = 'Bitte füllen Sie das Captcha aus ! ' ;
8
8
9
9
?>
Original file line number Diff line number Diff line change @@ -276,6 +276,29 @@ private function table_name()
276
276
277
277
private function get_client_ip ()
278
278
{
279
- return rcube_utils::remote_addr ();
279
+ $ prefix = rcmail::get_instance ()->config ->get ('rcguard_ipv6_prefix ' , 128 );
280
+ $ client_ip = rcube_utils::remote_addr ();
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 ) );
298
+ }
299
+ }
300
+
301
+ // fall back: return unaltered client IP
302
+ return $ client_ip ;
280
303
}
281
304
}
You can’t perform that action at this time.
0 commit comments