TT#47268 Fix getting banned items

Change-Id: I751b3c9e2cf32bef0b3c9c9fd77b6fbdbb83ea8b
changes/18/25318/2
Irina Peshinskaya 7 years ago
parent 667522fafc
commit 8ee1e8e08b

@ -17,7 +17,7 @@ sub allowed_methods {
sub delete_item {
my($self, $c, $item, $old_resource, $resource, $form) = @_;
my $ip = $item;
my $ip = $item->{ip};
NGCP::Panel::Utils::Security::ip_unban($c, $ip);
return 1;
}

@ -17,7 +17,7 @@ sub allowed_methods {
sub delete_item {
my($self, $c, $item, $old_resource, $resource, $form) = @_;
my $user = $item;
my $user = $item->{username};
NGCP::Panel::Utils::Security::user_unban($c, $user);
return 1;
}

@ -30,7 +30,8 @@ sub valid_id {
}
sub item_by_id{
my ($self, $c, $id) = @_;
return $id;
my $list = NGCP::Panel::Utils::Security::list_banned_ips($c, id => $id );
return ref $list eq 'ARRAY' ? $list->[0] : undef ;
}
1;
# vim: set tabstop=4 expandtab:

@ -31,7 +31,8 @@ sub valid_id {
sub item_by_id{
my ($self, $c, $id) = @_;
return $id;
my $list = NGCP::Panel::Utils::Security::list_banned_users($c, id => $id );
return ref $list eq 'ARRAY' ? $list->[0] : undef ;
}

@ -7,7 +7,7 @@ use NGCP::Panel::Utils::XMLDispatcher;
use NGCP::Panel::Utils::DateTime;
sub list_banned_ips {
my ( $c ) = @_;
my ( $c, %params ) = @_;
my $xml_parser = XML::LibXML->new();
my $ip_xml = <<'EOF';
@ -23,13 +23,18 @@ EOF
my $ip_res = NGCP::Panel::Utils::XMLDispatcher::dispatch($c, "loadbalancer", 1, 1, $ip_xml);
my @ips = ();
for my $host (grep {$$_[1]} @$ip_res) {
XML_RESULTS_LOOP: for my $host (grep {$$_[1]} @$ip_res) {
my $xmlDoc = $xml_parser->parse_string($host->[2]);
foreach my $node ($xmlDoc->findnodes('//member')) {
my $name = $node->findvalue('./name');
my $value = $node->findvalue('./value/string');
if ($name eq 'name') {
push @ips, { ip => $value };
if (!defined $params{id} || $params{id} eq $value) {
push @ips, { ip => $value, id => $value, };
if (defined $params{id}) {
last XML_RESULTS_LOOP;
}
}
}
}
}
@ -74,7 +79,8 @@ EOF
}
}
my $config_failed_auth_attempts = $c->config->{security}->{failed_auth_attempts} // 3;
for my $key (keys %{ $usr }) {
#in case we requested to filter by username, we will use it as the only possible key
for my $key ( ( defined $params{id} && exists $usr->{$params{id}}) ? ( $params{id} ) : (keys %{ $usr }) ) {
my $last_auth = $usr->{$key}->{last_auth} ? NGCP::Panel::Utils::DateTime::epoch_local($usr->{$key}->{last_auth}) : undef;
if ($last_auth) {
$last_auth->set_time_zone($c->session->{user_tz}) if $c->session->{user_tz};
@ -84,6 +90,7 @@ EOF
&& $usr->{$key}->{auth_count} >= $config_failed_auth_attempts ) {
push @users, {
username => $key,
id => $key,
auth_count => $usr->{$key}->{auth_count},
last_auth => $last_auth,
};

Loading…
Cancel
Save