Date + tidy + langs (#2325)

This commit is contained in:
Alexandre KARIM 2021-08-11 16:26:05 +02:00
parent e45c9a1c03
commit 3ae759edd4
14 changed files with 47 additions and 40 deletions

View File

@ -1032,6 +1032,7 @@ sub tree {
{
title => 'CrowdSecPlugin',
help => 'crowdsec.html',
form => 'simpleInputContainer',
nodes => [
'crowdsec', 'crowdsecAction',
'crowdsecUrl', 'crowdsecKey',
@ -1040,6 +1041,7 @@ sub tree {
{
title => 'newLocationWarnings',
help => 'newLocationWarning.html',
form => 'simpleInputContainer',
nodes => [
'newLocationWarning',
'newLocationWarningMailAttribute',

View File

@ -568,6 +568,7 @@
"newGrantRule":"قاعدة منح جديدة",
"newHost":"خادم جديد",
"newLocationWarning":"Activation",
"newLocationWarnings":"New location warning",
"newLocationWarningMailAttribute":"Session mail attribute",
"newLocationWarningMailBody":"Warning mail content",
"newLocationWarningMailSubject":"Warning mail subject",

View File

@ -568,6 +568,7 @@
"newGrantRule":"New grant rule",
"newHost":"New host",
"newLocationWarning":"Activation",
"newLocationWarnings":"New location warning",
"newLocationWarningMailAttribute":"Session mail attribute",
"newLocationWarningMailBody":"Warning mail content",
"newLocationWarningMailSubject":"Warning mail subject",

View File

@ -568,6 +568,7 @@
"newGrantRule":"New grant rule",
"newHost":"New host",
"newLocationWarning":"Activation",
"newLocationWarnings":"New location warning",
"newLocationWarningMailAttribute":"Session mail attribute",
"newLocationWarningMailBody":"Warning mail content",
"newLocationWarningMailSubject":"Warning mail subject",

View File

@ -568,6 +568,7 @@
"newGrantRule":"Nueva regla de admisión",
"newHost":"Nuevo host",
"newLocationWarning":"Activation",
"newLocationWarnings":"New location warning",
"newLocationWarningMailAttribute":"Session mail attribute",
"newLocationWarningMailBody":"Warning mail content",
"newLocationWarningMailSubject":"Warning mail subject",

View File

@ -568,6 +568,7 @@
"newGrantRule":"Nouvelle règle d'accès",
"newHost":"Nouvel hôte",
"newLocationWarning":"Activation",
"newLocationWarnings":"Avertissement de nouvelle connexion",
"newLocationWarningMailAttribute":"Attribut utilisateur contenant le mail ",
"newLocationWarningMailBody":"Contenu du mail d'avertissement",
"newLocationWarningMailSubject":"Sujet du mail d'avertissement",

View File

@ -568,6 +568,7 @@
"newGrantRule":"Nuova regola di autorizzazione",
"newHost":"Nuovo host",
"newLocationWarning":"Activation",
"newLocationWarnings":"New location warning",
"newLocationWarningMailAttribute":"Session mail attribute",
"newLocationWarningMailBody":"Warning mail content",
"newLocationWarningMailSubject":"Warning mail subject",

View File

@ -568,6 +568,7 @@
"newGrantRule":"Nowa reguła przyznawania",
"newHost":"Nowy host",
"newLocationWarning":"Activation",
"newLocationWarnings":"New location warning",
"newLocationWarningMailAttribute":"Session mail attribute",
"newLocationWarningMailBody":"Warning mail content",
"newLocationWarningMailSubject":"Warning mail subject",

View File

@ -568,6 +568,7 @@
"newGrantRule":"Yeni imtiyaz kuralı",
"newHost":"Yeni konak",
"newLocationWarning":"Activation",
"newLocationWarnings":"New location warning",
"newLocationWarningMailAttribute":"Session mail attribute",
"newLocationWarningMailBody":"Warning mail content",
"newLocationWarningMailSubject":"Warning mail subject",

View File

@ -568,6 +568,7 @@
"newGrantRule":"Quy tắc cấp mới",
"newHost":"Máy chủ mới",
"newLocationWarning":"Activation",
"newLocationWarnings":"New location warning",
"newLocationWarningMailAttribute":"Session mail attribute",
"newLocationWarningMailBody":"Warning mail content",
"newLocationWarningMailSubject":"Warning mail subject",

View File

@ -568,6 +568,7 @@
"newGrantRule":"New grant rule",
"newHost":"New host",
"newLocationWarning":"Activation",
"newLocationWarnings":"New location warning",
"newLocationWarningMailAttribute":"Session mail attribute",
"newLocationWarningMailBody":"Warning mail content",
"newLocationWarningMailSubject":"Warning mail subject",

View File

@ -568,6 +568,7 @@
"newGrantRule":"新授權規則",
"newHost":"新主機",
"newLocationWarning":"Activation",
"newLocationWarnings":"New location warning",
"newLocationWarningMailAttribute":"Session mail attribute",
"newLocationWarningMailBody":"Warning mail content",
"newLocationWarningMailSubject":"Warning mail subject",

File diff suppressed because one or more lines are too long

View File

@ -2,10 +2,8 @@ package Lemonldap::NG::Portal::Plugins::NewLocationWarning;
use strict;
use Mouse;
use Lemonldap::NG::Portal::Main::Constants qw(
PE_OK
PE_ERROR
);
use POSIX qw(strftime);
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK);
our $VERSION = '2.0.13';
@ -20,56 +18,63 @@ use constant endAuth => 'check';
sub init {
my ($self) = @_;
if ( $self->conf->{disablePersistentStorage} ) {
$self->logger->error(
'"NewLocationWarning" plugin enabled WITHOUT persistent session storage"'
);
return 0;
}
unless ( $self->conf->{loginHistoryEnabled} ) {
$self->logger->error(
'"NewLocationWarning" plugin enabled WITHOUT "History" plugin');
return 0;
}
return 1;
}
sub check {
my ( $self, $req ) = @_;
use Data::Dumper;
my $successLogin = $req->sessionInfo->{_loginHistory}->{successLogin};
my $failedLogin = $req->sessionInfo->{_loginHistory}->{failedLogin};
my $ipSource = $req->env->{ipAddr};
my @IPsS =
map { $_->{ipAddr} eq $ipSource ? $_->{ipAddr} : () } @$successLogin;
my @IPsF =
map { $_->{ipAddr} eq $ipSource ? $_->{ipAddr} : () } @$failedLogin;
my @IPs = ( @IPsS, @IPsF );
$self->logger->debug( '**************** ' . Dumper( \@IPs ) );
my @successIPs =
map { $_->{ipAddr} eq $ipSource ? $_->{ipAddr} : () } @$successLogin;
my @failedIPs =
map { $_->{ipAddr} eq $ipSource ? $_->{ipAddr} : () } @$failedLogin;
my @IPs = ( @successIPs, @failedIPs );
return scalar @IPs ? $self->_sendMail($req) : PE_OK;
}
sub _sendMail {
my ( $self, $req ) = @_;
my $epoch = time();
my $ipSource = $req->env->{ipAddr};
my $host = $req->env->{HTTP_HOST};
$self->logger->debug( "******************************* $host");
my $date = strftime( '%F %X', localtime );
my $ipSource = $req->env->{ipAddr};
my $host = $req->env->{HTTP_HOST};
my $mail =
$req->sessionInfo->{ $self->conf->{newLocationWarningMailAttribute}
|| 'mail' };
$self->logger->debug("+++++++++++++++++++++++ $mail");
# Build mail content
# Build mail content
my $tr = $self->translate($req);
my $subject = $self->conf->{newLocationWarningMailSubject};
unless ($subject) {
$self->logger->debug('Use default warning subject');
$subject = 'newLocationWarningMailSubject';
$tr->( \$subject );
}
my $body;
my $html;
my ( $body, $html );
if ( $self->conf->{newLocationWarningMailBody} ) {
# We use a specific text message, no html
$self->logger->debug('Use specific warning body message');
$body = $self->conf->{newLocationWarningMailBody};
# Replace variables in body
$body =~ s/\$newLocationIP/$ipSource/ge;
$body =~ s/\$newLocationTime/$epoch/ge;
$body =~ s/\$newLocationDate/$date/ge;
}
else {
@ -80,30 +85,19 @@ sub _sendMail {
filter => $tr,
params => {
session_ipAddr => $ipSource,
newLocationTime => $epoch,
host => $host,
date => $date,
host => $host,
},
);
$html = 1;
}
$self->logger->info( "Warning, user "
. $req->data->{mailAddress}
. " is loggin in from a new location" );
$self->logger->warn("User $mail is signing in from a new location");
# Send mail
unless (
$self->send_mail(
$mail, $subject, $body, $html
)
)
{
$self->logger->debug('Unable to send new location warning mail');
$self->logger->debug('Unable to send new location warning mail')
unless ( $self->send_mail( $mail, $subject, $body, $html ) );
# Don't return an error here to avoid enumeration
}
return PE_OK;
}