Date + tidy + langs (#2325)
This commit is contained in:
parent
e45c9a1c03
commit
3ae759edd4
|
@ -1032,6 +1032,7 @@ sub tree {
|
||||||
{
|
{
|
||||||
title => 'CrowdSecPlugin',
|
title => 'CrowdSecPlugin',
|
||||||
help => 'crowdsec.html',
|
help => 'crowdsec.html',
|
||||||
|
form => 'simpleInputContainer',
|
||||||
nodes => [
|
nodes => [
|
||||||
'crowdsec', 'crowdsecAction',
|
'crowdsec', 'crowdsecAction',
|
||||||
'crowdsecUrl', 'crowdsecKey',
|
'crowdsecUrl', 'crowdsecKey',
|
||||||
|
@ -1040,6 +1041,7 @@ sub tree {
|
||||||
{
|
{
|
||||||
title => 'newLocationWarnings',
|
title => 'newLocationWarnings',
|
||||||
help => 'newLocationWarning.html',
|
help => 'newLocationWarning.html',
|
||||||
|
form => 'simpleInputContainer',
|
||||||
nodes => [
|
nodes => [
|
||||||
'newLocationWarning',
|
'newLocationWarning',
|
||||||
'newLocationWarningMailAttribute',
|
'newLocationWarningMailAttribute',
|
||||||
|
|
|
@ -568,6 +568,7 @@
|
||||||
"newGrantRule":"قاعدة منح جديدة",
|
"newGrantRule":"قاعدة منح جديدة",
|
||||||
"newHost":"خادم جديد",
|
"newHost":"خادم جديد",
|
||||||
"newLocationWarning":"Activation",
|
"newLocationWarning":"Activation",
|
||||||
|
"newLocationWarnings":"New location warning",
|
||||||
"newLocationWarningMailAttribute":"Session mail attribute",
|
"newLocationWarningMailAttribute":"Session mail attribute",
|
||||||
"newLocationWarningMailBody":"Warning mail content",
|
"newLocationWarningMailBody":"Warning mail content",
|
||||||
"newLocationWarningMailSubject":"Warning mail subject",
|
"newLocationWarningMailSubject":"Warning mail subject",
|
||||||
|
|
|
@ -568,6 +568,7 @@
|
||||||
"newGrantRule":"New grant rule",
|
"newGrantRule":"New grant rule",
|
||||||
"newHost":"New host",
|
"newHost":"New host",
|
||||||
"newLocationWarning":"Activation",
|
"newLocationWarning":"Activation",
|
||||||
|
"newLocationWarnings":"New location warning",
|
||||||
"newLocationWarningMailAttribute":"Session mail attribute",
|
"newLocationWarningMailAttribute":"Session mail attribute",
|
||||||
"newLocationWarningMailBody":"Warning mail content",
|
"newLocationWarningMailBody":"Warning mail content",
|
||||||
"newLocationWarningMailSubject":"Warning mail subject",
|
"newLocationWarningMailSubject":"Warning mail subject",
|
||||||
|
|
|
@ -568,6 +568,7 @@
|
||||||
"newGrantRule":"New grant rule",
|
"newGrantRule":"New grant rule",
|
||||||
"newHost":"New host",
|
"newHost":"New host",
|
||||||
"newLocationWarning":"Activation",
|
"newLocationWarning":"Activation",
|
||||||
|
"newLocationWarnings":"New location warning",
|
||||||
"newLocationWarningMailAttribute":"Session mail attribute",
|
"newLocationWarningMailAttribute":"Session mail attribute",
|
||||||
"newLocationWarningMailBody":"Warning mail content",
|
"newLocationWarningMailBody":"Warning mail content",
|
||||||
"newLocationWarningMailSubject":"Warning mail subject",
|
"newLocationWarningMailSubject":"Warning mail subject",
|
||||||
|
|
|
@ -568,6 +568,7 @@
|
||||||
"newGrantRule":"Nueva regla de admisión",
|
"newGrantRule":"Nueva regla de admisión",
|
||||||
"newHost":"Nuevo host",
|
"newHost":"Nuevo host",
|
||||||
"newLocationWarning":"Activation",
|
"newLocationWarning":"Activation",
|
||||||
|
"newLocationWarnings":"New location warning",
|
||||||
"newLocationWarningMailAttribute":"Session mail attribute",
|
"newLocationWarningMailAttribute":"Session mail attribute",
|
||||||
"newLocationWarningMailBody":"Warning mail content",
|
"newLocationWarningMailBody":"Warning mail content",
|
||||||
"newLocationWarningMailSubject":"Warning mail subject",
|
"newLocationWarningMailSubject":"Warning mail subject",
|
||||||
|
|
|
@ -568,6 +568,7 @@
|
||||||
"newGrantRule":"Nouvelle règle d'accès",
|
"newGrantRule":"Nouvelle règle d'accès",
|
||||||
"newHost":"Nouvel hôte",
|
"newHost":"Nouvel hôte",
|
||||||
"newLocationWarning":"Activation",
|
"newLocationWarning":"Activation",
|
||||||
|
"newLocationWarnings":"Avertissement de nouvelle connexion",
|
||||||
"newLocationWarningMailAttribute":"Attribut utilisateur contenant le mail ",
|
"newLocationWarningMailAttribute":"Attribut utilisateur contenant le mail ",
|
||||||
"newLocationWarningMailBody":"Contenu du mail d'avertissement",
|
"newLocationWarningMailBody":"Contenu du mail d'avertissement",
|
||||||
"newLocationWarningMailSubject":"Sujet du mail d'avertissement",
|
"newLocationWarningMailSubject":"Sujet du mail d'avertissement",
|
||||||
|
|
|
@ -568,6 +568,7 @@
|
||||||
"newGrantRule":"Nuova regola di autorizzazione",
|
"newGrantRule":"Nuova regola di autorizzazione",
|
||||||
"newHost":"Nuovo host",
|
"newHost":"Nuovo host",
|
||||||
"newLocationWarning":"Activation",
|
"newLocationWarning":"Activation",
|
||||||
|
"newLocationWarnings":"New location warning",
|
||||||
"newLocationWarningMailAttribute":"Session mail attribute",
|
"newLocationWarningMailAttribute":"Session mail attribute",
|
||||||
"newLocationWarningMailBody":"Warning mail content",
|
"newLocationWarningMailBody":"Warning mail content",
|
||||||
"newLocationWarningMailSubject":"Warning mail subject",
|
"newLocationWarningMailSubject":"Warning mail subject",
|
||||||
|
|
|
@ -568,6 +568,7 @@
|
||||||
"newGrantRule":"Nowa reguła przyznawania",
|
"newGrantRule":"Nowa reguła przyznawania",
|
||||||
"newHost":"Nowy host",
|
"newHost":"Nowy host",
|
||||||
"newLocationWarning":"Activation",
|
"newLocationWarning":"Activation",
|
||||||
|
"newLocationWarnings":"New location warning",
|
||||||
"newLocationWarningMailAttribute":"Session mail attribute",
|
"newLocationWarningMailAttribute":"Session mail attribute",
|
||||||
"newLocationWarningMailBody":"Warning mail content",
|
"newLocationWarningMailBody":"Warning mail content",
|
||||||
"newLocationWarningMailSubject":"Warning mail subject",
|
"newLocationWarningMailSubject":"Warning mail subject",
|
||||||
|
|
|
@ -568,6 +568,7 @@
|
||||||
"newGrantRule":"Yeni imtiyaz kuralı",
|
"newGrantRule":"Yeni imtiyaz kuralı",
|
||||||
"newHost":"Yeni konak",
|
"newHost":"Yeni konak",
|
||||||
"newLocationWarning":"Activation",
|
"newLocationWarning":"Activation",
|
||||||
|
"newLocationWarnings":"New location warning",
|
||||||
"newLocationWarningMailAttribute":"Session mail attribute",
|
"newLocationWarningMailAttribute":"Session mail attribute",
|
||||||
"newLocationWarningMailBody":"Warning mail content",
|
"newLocationWarningMailBody":"Warning mail content",
|
||||||
"newLocationWarningMailSubject":"Warning mail subject",
|
"newLocationWarningMailSubject":"Warning mail subject",
|
||||||
|
|
|
@ -568,6 +568,7 @@
|
||||||
"newGrantRule":"Quy tắc cấp mới",
|
"newGrantRule":"Quy tắc cấp mới",
|
||||||
"newHost":"Máy chủ mới",
|
"newHost":"Máy chủ mới",
|
||||||
"newLocationWarning":"Activation",
|
"newLocationWarning":"Activation",
|
||||||
|
"newLocationWarnings":"New location warning",
|
||||||
"newLocationWarningMailAttribute":"Session mail attribute",
|
"newLocationWarningMailAttribute":"Session mail attribute",
|
||||||
"newLocationWarningMailBody":"Warning mail content",
|
"newLocationWarningMailBody":"Warning mail content",
|
||||||
"newLocationWarningMailSubject":"Warning mail subject",
|
"newLocationWarningMailSubject":"Warning mail subject",
|
||||||
|
|
|
@ -568,6 +568,7 @@
|
||||||
"newGrantRule":"New grant rule",
|
"newGrantRule":"New grant rule",
|
||||||
"newHost":"New host",
|
"newHost":"New host",
|
||||||
"newLocationWarning":"Activation",
|
"newLocationWarning":"Activation",
|
||||||
|
"newLocationWarnings":"New location warning",
|
||||||
"newLocationWarningMailAttribute":"Session mail attribute",
|
"newLocationWarningMailAttribute":"Session mail attribute",
|
||||||
"newLocationWarningMailBody":"Warning mail content",
|
"newLocationWarningMailBody":"Warning mail content",
|
||||||
"newLocationWarningMailSubject":"Warning mail subject",
|
"newLocationWarningMailSubject":"Warning mail subject",
|
||||||
|
|
|
@ -568,6 +568,7 @@
|
||||||
"newGrantRule":"新授權規則",
|
"newGrantRule":"新授權規則",
|
||||||
"newHost":"新主機",
|
"newHost":"新主機",
|
||||||
"newLocationWarning":"Activation",
|
"newLocationWarning":"Activation",
|
||||||
|
"newLocationWarnings":"New location warning",
|
||||||
"newLocationWarningMailAttribute":"Session mail attribute",
|
"newLocationWarningMailAttribute":"Session mail attribute",
|
||||||
"newLocationWarningMailBody":"Warning mail content",
|
"newLocationWarningMailBody":"Warning mail content",
|
||||||
"newLocationWarningMailSubject":"Warning mail subject",
|
"newLocationWarningMailSubject":"Warning mail subject",
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -2,10 +2,8 @@ package Lemonldap::NG::Portal::Plugins::NewLocationWarning;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use Mouse;
|
use Mouse;
|
||||||
use Lemonldap::NG::Portal::Main::Constants qw(
|
use POSIX qw(strftime);
|
||||||
PE_OK
|
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK);
|
||||||
PE_ERROR
|
|
||||||
);
|
|
||||||
|
|
||||||
our $VERSION = '2.0.13';
|
our $VERSION = '2.0.13';
|
||||||
|
|
||||||
|
@ -20,56 +18,63 @@ use constant endAuth => 'check';
|
||||||
sub init {
|
sub init {
|
||||||
my ($self) = @_;
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub check {
|
sub check {
|
||||||
my ( $self, $req ) = @_;
|
my ( $self, $req ) = @_;
|
||||||
use Data::Dumper;
|
|
||||||
my $successLogin = $req->sessionInfo->{_loginHistory}->{successLogin};
|
my $successLogin = $req->sessionInfo->{_loginHistory}->{successLogin};
|
||||||
my $failedLogin = $req->sessionInfo->{_loginHistory}->{failedLogin};
|
my $failedLogin = $req->sessionInfo->{_loginHistory}->{failedLogin};
|
||||||
my $ipSource = $req->env->{ipAddr};
|
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;
|
return scalar @IPs ? $self->_sendMail($req) : PE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub _sendMail {
|
sub _sendMail {
|
||||||
my ( $self, $req ) = @_;
|
my ( $self, $req ) = @_;
|
||||||
my $epoch = time();
|
my $date = strftime( '%F %X', localtime );
|
||||||
my $ipSource = $req->env->{ipAddr};
|
my $ipSource = $req->env->{ipAddr};
|
||||||
my $host = $req->env->{HTTP_HOST};
|
my $host = $req->env->{HTTP_HOST};
|
||||||
$self->logger->debug( "******************************* $host");
|
|
||||||
|
|
||||||
my $mail =
|
my $mail =
|
||||||
$req->sessionInfo->{ $self->conf->{newLocationWarningMailAttribute}
|
$req->sessionInfo->{ $self->conf->{newLocationWarningMailAttribute}
|
||||||
|| 'mail' };
|
|| 'mail' };
|
||||||
$self->logger->debug("+++++++++++++++++++++++ $mail");
|
|
||||||
|
|
||||||
# Build mail content
|
# Build mail content
|
||||||
my $tr = $self->translate($req);
|
my $tr = $self->translate($req);
|
||||||
my $subject = $self->conf->{newLocationWarningMailSubject};
|
my $subject = $self->conf->{newLocationWarningMailSubject};
|
||||||
unless ($subject) {
|
unless ($subject) {
|
||||||
|
$self->logger->debug('Use default warning subject');
|
||||||
$subject = 'newLocationWarningMailSubject';
|
$subject = 'newLocationWarningMailSubject';
|
||||||
$tr->( \$subject );
|
$tr->( \$subject );
|
||||||
}
|
}
|
||||||
my $body;
|
my ( $body, $html );
|
||||||
my $html;
|
|
||||||
if ( $self->conf->{newLocationWarningMailBody} ) {
|
if ( $self->conf->{newLocationWarningMailBody} ) {
|
||||||
|
|
||||||
# We use a specific text message, no html
|
# We use a specific text message, no html
|
||||||
|
$self->logger->debug('Use specific warning body message');
|
||||||
$body = $self->conf->{newLocationWarningMailBody};
|
$body = $self->conf->{newLocationWarningMailBody};
|
||||||
|
|
||||||
# Replace variables in body
|
# Replace variables in body
|
||||||
$body =~ s/\$newLocationIP/$ipSource/ge;
|
$body =~ s/\$newLocationIP/$ipSource/ge;
|
||||||
$body =~ s/\$newLocationTime/$epoch/ge;
|
$body =~ s/\$newLocationDate/$date/ge;
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
|
@ -80,30 +85,19 @@ sub _sendMail {
|
||||||
filter => $tr,
|
filter => $tr,
|
||||||
params => {
|
params => {
|
||||||
session_ipAddr => $ipSource,
|
session_ipAddr => $ipSource,
|
||||||
newLocationTime => $epoch,
|
date => $date,
|
||||||
host => $host,
|
host => $host,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
$html = 1;
|
$html = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->logger->info( "Warning, user "
|
$self->logger->warn("User $mail is signing in from a new location");
|
||||||
. $req->data->{mailAddress}
|
|
||||||
. " is loggin in from a new location" );
|
|
||||||
|
|
||||||
# Send mail
|
# Send mail
|
||||||
unless (
|
$self->logger->debug('Unable to send new location warning mail')
|
||||||
$self->send_mail(
|
unless ( $self->send_mail( $mail, $subject, $body, $html ) );
|
||||||
$mail, $subject, $body, $html
|
|
||||||
)
|
|
||||||
)
|
|
||||||
{
|
|
||||||
$self->logger->debug('Unable to send new location warning mail');
|
|
||||||
|
|
||||||
# Don't return an error here to avoid enumeration
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return PE_OK;
|
return PE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user