diff --git a/lib/NGCP/Panel/Controller/Security.pm b/lib/NGCP/Panel/Controller/Security.pm index c141994705..858024e93f 100644 --- a/lib/NGCP/Panel/Controller/Security.pm +++ b/lib/NGCP/Panel/Controller/Security.pm @@ -4,6 +4,7 @@ use Sipwise::Base; BEGIN { extends 'Catalyst::Controller'; } use XML::Mini::Document; +use URI::Encode; use NGCP::Panel::Utils::Navigation; use NGCP::Panel::Utils::XMLDispatcher; @@ -104,7 +105,10 @@ EOF push @users, { username => $key, auth_count => $usr->{$key}->{auth_count}, - last_auth => $usr->{$key}->{last_auth}, + last_auth => DateTime->from_epoch( + epoch => $usr->{$key}->{last_auth}, + time_zone => DateTime::TimeZone->new(name => 'local') + ), } if($usr->{$key}->{auth_count} >= $c->config->{security}->{failed_auth_attempts}); } } @@ -118,7 +122,8 @@ EOF sub ip_base :Chained('/') :PathPart('security/ip') :CaptureArgs(1) { my ( $self, $c, $ip ) = @_; - $c->stash->{ip} = $ip; + my $decoder = URI::Encode->new; + $c->stash->{ip} = $decoder->decode($ip); } sub ip_unban :Chained('ip_base') :PathPart('unban') :Args(0) { @@ -139,12 +144,14 @@ EOF $dispatcher->dispatch("loadbalancer", 1, 1, $xml); + $c->flash(messages => [{type => 'success', text => 'IP successfully unbanned'}]); NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for('/security')); } sub user_base :Chained('/') :PathPart('security/user') :CaptureArgs(1) { my ( $self, $c, $user ) = @_; - $c->stash->{user} = $user; + my $decoder = URI::Encode->new; + $c->stash->{user} = $decoder->decode($user); } sub user_unban :Chained('user_base') :PathPart('unban') :Args(0) { @@ -152,19 +159,23 @@ sub user_unban :Chained('user_base') :PathPart('unban') :Args(0) { my $dispatcher = NGCP::Panel::Utils::XMLDispatcher->new; my $user = $c->stash->{user}; - my $xml = <<"EOF"; + my @keys = ($user.'::auth_count', $user.'::last_auth'); + foreach my $key (@keys) { + my $xml = <<"EOF"; htable.delete auth - $user + $key EOF - $dispatcher->dispatch("loadbalancer", 1, 1, $xml); + $dispatcher->dispatch("loadbalancer", 1, 1, $xml); + } + $c->flash(messages => [{type => 'success', text => 'User successfully unbanned'}]); NGCP::Panel::Utils::Navigation::back_or($c, $c->uri_for('/security')); } diff --git a/share/templates/security/list.tt b/share/templates/security/list.tt index 4da5790f0e..76c0c2a496 100644 --- a/share/templates/security/list.tt +++ b/share/templates/security/list.tt @@ -33,12 +33,13 @@ [% FOR ip IN banned_ips -%] + [% enc_ip = ip.ip | uri -%] [% ip.ip %]
+ href="[% c.uri_for_action("/security/ip_unban", [enc_ip]) %]"> Unban
@@ -69,6 +70,7 @@ [% FOR user IN banned_users -%] + [% enc_user = user.username | uri -%] [% user.username %] [% user.auth_count %] @@ -76,7 +78,7 @@
+ href="[% c.uri_for_action("/security/user_unban", [enc_user]) %]"> Unban