Skip to content

Commit 73c6d5f

Browse files
committed
Loca captcha on softlimit
1 parent 0c6bcad commit 73c6d5f

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

cgi-bin/page.fcgi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ Readonly my $MAX_REQUESTS => 100; # Default max requests allowed
6868
Readonly my $TIME_WINDOW => '60s'; # Time window for the maximum requests
6969

7070
my $info = CGI::Info->new();
71-
my $config;
7271
my @suffixlist = ('.pl', '.fcgi');
7372
my $script_name = basename($info->script_name(), @suffixlist);
7473
my $tmpdir = $info->tmpdir();
@@ -110,6 +109,7 @@ if($@) {
110109
}
111110
use VWF::Data::vwf_log;
112111

112+
my $config;
113113
my $database_dir = "$script_dir/../data";
114114
Database::Abstraction::init({
115115
cache => CHI->new(driver => 'Memory', datastore => {}),
@@ -288,6 +288,7 @@ sub doit
288288
# config file to read
289289
$config ||= VWF::Config->new({
290290
logger => $logger,
291+
info => $info,
291292
debug => $params{'debug'},
292293
lingua => CGI::Lingua->new({ supported => [ 'en-gb' ], info => $info, logger => $logger }) # Use a temporary CGI::Lingua
293294
});
@@ -420,8 +421,11 @@ sub doit
420421

421422
if ($recaptcha_config && $recaptcha_config->{enabled}) {
422423
$logger->info("Soft rate limit exceeded for $client_ip ($request_count requests) - CAPTCHA challenge issued");
423-
$info->status(429);
424424

425+
unless(VWF::Display::captcha->can('new')) {
426+
require VWF::Display::captcha;
427+
VWF::Display::captcha->import();
428+
}
425429
my $display = VWF::Display::captcha->new({
426430
cachedir => $cachedir,
427431
info => $info,

lib/VWF/Display/captcha.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ sub html {
3030
my $request_count = $args{'request_count'} || 0;
3131

3232
if ($self->{'logger'}) {
33-
$self->{'logger'}->debug("Displaying CAPTCHA page for " . ($is_hard_block ? "hard block" : "soft limit"));
33+
$self->{'logger'}->debug('Displaying CAPTCHA page for ' . ($is_hard_block ? 'hard block' : 'soft limit'));
3434
}
3535

3636
return $self->SUPER::html({

templates/default/web/VWF/Display/captcha.tmpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,13 @@
130130
.hard-block {
131131
background: #fee;
132132
border-left-color: #dc3545;
133-
}
133+
}
134134

135-
.hard-block-icon {
136-
color: #dc3545;
137-
}
135+
.hard-block-icon {
136+
color: #dc3545;
137+
}
138138

139-
@media (max-width: 480px) {
139+
@media (max-width: 480px) {
140140
.captcha-container {
141141
padding: 30px 20px;
142142
}

0 commit comments

Comments
 (0)