* users for admin/subscriber realms are now banned if failed to login X amount of times (UI/API). * rework Redis connection and it's now a Catalyst plugin NGCP::Redis accessed by $c->redis_get_connection({database => 19}), the connection per database, per worker process is established only once and then reused (with auto built-in reconnect support). * remove Utils::Redis.pm as it does not have any code/logic anymore. * ban values are taken from $config->{security}{login} as - ban_enable: 1 - ban_expire_time: 3600 ban expire time in seconds - max_attempts: 5 * if max_attempts set to 0, the ban functionality is disabled as it requires to be at least 1 to work. * upon successful login or ban, the failed attempts counter is removed * the failed attempts counter is also removed automatically with the expire time equals "ban_expire_time" or otherwise 3600 seconds. * user bans are logged into panel.log * banned user receives exactly the same return page/codes as per invalid logic. Change-Id: I05cc68c623ee289488fc64f1af50527004dcaae1mr12.5
parent
d9f283cbc8
commit
60fa23cb68
@ -0,0 +1,31 @@
|
|||||||
|
package Catalyst::Plugin::NGCP::Redis;
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use MRO::Compat;
|
||||||
|
use Redis;
|
||||||
|
|
||||||
|
my $conn = {};
|
||||||
|
|
||||||
|
sub redis_get_connection {
|
||||||
|
my ($c, $params) = @_;
|
||||||
|
|
||||||
|
my $db = $params->{database} // return;
|
||||||
|
my $redis;
|
||||||
|
$redis = $conn->{$db} // do {
|
||||||
|
$redis = Redis->new(
|
||||||
|
server => $c->config->{redis}->{central_url},
|
||||||
|
reconnect => 10, every => 500000, # 500ms
|
||||||
|
cnx_timeout => 3,
|
||||||
|
);
|
||||||
|
unless ($redis) {
|
||||||
|
$c->log->error("Failed to connect to central redis url " . $c->config->{redis}->{central_url});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$redis->select($params->{database});
|
||||||
|
$conn->{$db} = $redis;
|
||||||
|
};
|
||||||
|
|
||||||
|
return $redis;
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
@ -1,23 +0,0 @@
|
|||||||
package NGCP::Panel::Utils::Redis;
|
|
||||||
|
|
||||||
use warnings;
|
|
||||||
use strict;
|
|
||||||
|
|
||||||
use Redis;
|
|
||||||
|
|
||||||
sub get_redis_connection {
|
|
||||||
my ($c, $params) = @_;
|
|
||||||
my $redis = Redis->new(
|
|
||||||
server => $c->config->{redis}->{central_url},
|
|
||||||
reconnect => 10, every => 500000, # 500ms
|
|
||||||
cnx_timeout => 3,
|
|
||||||
);
|
|
||||||
unless ($redis) {
|
|
||||||
$c->log->error("Failed to connect to central redis url " . $c->config->{redis}->{central_url});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$redis->select($params->{database});
|
|
||||||
return $redis;
|
|
||||||
}
|
|
||||||
|
|
||||||
1;
|
|
Loading…
Reference in new issue