Add portal status plugin (#595)
This commit is contained in:
parent
863c458702
commit
6b2dbd6482
|
@ -185,6 +185,7 @@ sub defaultValues {
|
|||
'portalPingInterval' => 60000,
|
||||
'portalRequireOldPassword' => 1,
|
||||
'portalSkin' => 'bootstrap',
|
||||
'portalStatus' => 0,
|
||||
'portalUserAttr' => '_user',
|
||||
'proxyAuthnLevel' => 2,
|
||||
'proxyUseSoap' => 0,
|
||||
|
|
|
@ -1948,6 +1948,10 @@ qr/^(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0-
|
|||
'test' => qr/^\w+$/,
|
||||
'type' => 'keyTextContainer'
|
||||
},
|
||||
'portalStatus' => {
|
||||
'default' => 0,
|
||||
'type' => 'bool'
|
||||
},
|
||||
'portalUserAttr' => {
|
||||
'default' => '_user',
|
||||
'type' => 'text'
|
||||
|
|
|
@ -304,9 +304,15 @@ sub attributes {
|
|||
default => 'http://auth.example.com/',
|
||||
documentation => 'Portal URL',
|
||||
},
|
||||
portalStatus => {
|
||||
type => 'bool',
|
||||
default => 0,
|
||||
documentation => 'Enable portal status',
|
||||
},
|
||||
portalUserAttr => {
|
||||
type => 'text',
|
||||
default => '_user',
|
||||
help => 'monitoring.html',
|
||||
documentation =>
|
||||
'Session parameter to display connected user in portal',
|
||||
},
|
||||
|
|
|
@ -511,6 +511,7 @@ sub tree {
|
|||
help => 'start.html#advanced_features',
|
||||
nodes => [
|
||||
'customFunctions',
|
||||
'portalStatus',
|
||||
{
|
||||
title => 'portalServers',
|
||||
form => 'simpleInputContainer',
|
||||
|
|
|
@ -512,6 +512,7 @@
|
|||
"portalSkin": "Default Skin",
|
||||
"portalSkinBackground": "Skin background",
|
||||
"portalSkinRules": "Skin display rules",
|
||||
"portalStatus": "Publish portal status",
|
||||
"portalUserAttr": "User attribute",
|
||||
"post": "Form replay",
|
||||
"postedVars": "Variables to post",
|
||||
|
|
|
@ -512,6 +512,7 @@
|
|||
"portalSkin": "Thème visuel par défaut",
|
||||
"portalSkinBackground": "Image de fond",
|
||||
"portalSkinRules": "Règles d'affichage du thème visuel",
|
||||
"portalStatus": "Publie le statut du portail",
|
||||
"portalUserAttr": "Attribut de l'utilisateur",
|
||||
"post": "Rejeu de formulaires",
|
||||
"postedVars": "Variables à poster",
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -2,13 +2,7 @@
|
|||
bower.json
|
||||
Changes
|
||||
eg/index.fcgi
|
||||
example/cas.pl
|
||||
example/cdc.pl
|
||||
example/index.pl
|
||||
example/index_simple.pl
|
||||
example/index_skin.pl
|
||||
example/mail.pl
|
||||
example/PortalStatus.pl
|
||||
example/soapconfigtest.pl
|
||||
example/soaperrortest.pl
|
||||
example/soaptest.pl
|
||||
|
@ -86,6 +80,7 @@ lib/Lemonldap/NG/Portal/Plugins/Notifications.pm
|
|||
lib/Lemonldap/NG/Portal/Plugins/Register.pm
|
||||
lib/Lemonldap/NG/Portal/Plugins/RESTServer.pm
|
||||
lib/Lemonldap/NG/Portal/Plugins/SOAPServer.pm
|
||||
lib/Lemonldap/NG/Portal/Plugins/Status.pm
|
||||
lib/Lemonldap/NG/Portal/Register/AD.pm
|
||||
lib/Lemonldap/NG/Portal/Register/Demo.pm
|
||||
lib/Lemonldap/NG/Portal/Register/LDAP.pm
|
||||
|
@ -358,6 +353,7 @@ t/34-Auth-Proxy-and-SOAP-Server.t
|
|||
t/40-Notifications-DBI.t
|
||||
t/41-Register-Demo.t
|
||||
t/50-IssuerGet.t
|
||||
t/60-status.t
|
||||
t/90-translations.t
|
||||
t/99-pod.t
|
||||
t/lmConf-1.js
|
||||
|
|
|
@ -1,108 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use CGI;
|
||||
use strict;
|
||||
|
||||
# Status page for Lemonldap::NG::Portal
|
||||
#
|
||||
# This CGI displays some information about Lemonldap::NG sessions
|
||||
#
|
||||
|
||||
BEGIN {
|
||||
|
||||
sub Apache::Session::get_sessions_count {
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub Apache::Session::MySQL::get_sessions_count {
|
||||
my $class = shift;
|
||||
my $args = shift;
|
||||
my $dbh =
|
||||
DBI->connect( $args->{DataSource}, $args->{UserName},
|
||||
$args->{Password} )
|
||||
or die("$!$@");
|
||||
my $table = $args->{TableName} || 'sessions';
|
||||
my $sth = $dbh->prepare("SELECT count(*) from $table");
|
||||
$sth->execute;
|
||||
return ( $sth->fetchrow_array )[0];
|
||||
}
|
||||
|
||||
*Apache::Session::Postgres::get_sessions_count =
|
||||
\&Apache::Session::MySQL::get_sessions_count;
|
||||
*Apache::Session::Oracle::get_sessions_count =
|
||||
\&Apache::Session::MySQL::get_sessions_count;
|
||||
*Apache::Session::Sybase::get_sessions_count =
|
||||
\&Apache::Session::MySQL::get_sessions_count;
|
||||
*Apache::Session::Informix::get_sessions_count =
|
||||
\&Apache::Session::MySQL::get_sessions_count;
|
||||
|
||||
sub Apache::Session::File::get_sessions_count {
|
||||
my $class = shift;
|
||||
my $args = shift;
|
||||
$args->{Directory} ||= '__SESSIONDIR__';
|
||||
unless ( opendir DIR, $args->{Directory} ) {
|
||||
die "Cannot open directory $args->{Directory}\n";
|
||||
}
|
||||
my @t =
|
||||
grep { -f "$args->{Directory}/$_" and /^[A-Za-z0-9@\-]+$/ }
|
||||
readdir(DIR);
|
||||
closedir DIR;
|
||||
return $#t + 1;
|
||||
}
|
||||
|
||||
sub Apache::Session::DB_File::get_sessions_count {
|
||||
my $class = shift;
|
||||
my $args = shift;
|
||||
|
||||
if ( !tied %{ $class->{dbm} } ) {
|
||||
my $rv = tie %{ $class->{dbm} }, 'DB_File', $args->{FileName};
|
||||
|
||||
if ( !$rv ) {
|
||||
die "Could not open dbm file $args->{FileName}: $!";
|
||||
}
|
||||
}
|
||||
my @t = keys( %{ $class->{dbm} } );
|
||||
return $#t + 1;
|
||||
}
|
||||
}
|
||||
|
||||
use Lemonldap::NG::Common::Conf;
|
||||
use Lemonldap::NG::Common::Conf::Constants;
|
||||
use strict;
|
||||
use DBI;
|
||||
|
||||
my $cgi = CGI->new();
|
||||
|
||||
print $cgi->header(
|
||||
-charset => 'ascii',
|
||||
-type => 'text/plain',
|
||||
);
|
||||
|
||||
print "LEMONLDAP::NG::PORTAL STATUS\n\nConfiguration : ";
|
||||
|
||||
my $lmconf = Lemonldap::NG::Common::Conf->new();
|
||||
|
||||
unless ($lmconf) {
|
||||
print "unable to create conf object\n";
|
||||
}
|
||||
else {
|
||||
my $conf = $lmconf->getConf;
|
||||
unless ($conf) {
|
||||
write "unable to get configuration ($!)\n";
|
||||
}
|
||||
else {
|
||||
print "OK\nApache::Session module : ";
|
||||
my $tmp = $conf->{globalStorage};
|
||||
eval "use $tmp";
|
||||
if ($@) {
|
||||
print "unable to load $tmp ($@)\n";
|
||||
}
|
||||
else {
|
||||
my $t = $tmp->get_sessions_count( $conf->{globalStorageOptions} );
|
||||
print "OK\nActive sessions : $t\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
@ -44,6 +44,9 @@ sub enabledPlugins {
|
|||
if ( $self->conf->{soapSessionServer}
|
||||
or $self->conf->{soapConfigServer} );
|
||||
|
||||
# Check if portal status is enabled
|
||||
push @res, '::Plugins::Status' if($self->conf->{portalStatus});
|
||||
|
||||
# Add REST (check is done by it)
|
||||
push @res, '::Plugins::RESTServer';
|
||||
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
# Status plugin
|
||||
#
|
||||
# this plugin adds /portalStatus entrypoint which display session count
|
||||
# by category
|
||||
|
||||
package Lemonldap::NG::Portal::Plugins::Status;
|
||||
|
||||
use strict;
|
||||
use Mouse;
|
||||
use MIME::Base64;
|
||||
|
||||
our $VERSION = '2.0.0';
|
||||
|
||||
extends 'Lemonldap::NG::Portal::Main::Plugin';
|
||||
|
||||
# INITIALIZATION
|
||||
|
||||
sub init {
|
||||
my ($self) = @_;
|
||||
$self->addUnauthRoute( portalStatus => 'status', ['GET'] );
|
||||
$self->addAuthRoute( portalStatus => 'status', ['GET'] );
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub status {
|
||||
my ( $self, $req ) = @_;
|
||||
my $res = {};
|
||||
foreach my $type (qw(global persistent cas saml oidc)) {
|
||||
if ( $self->conf->{"${type}Storage"} ) {
|
||||
my %modOpts = (
|
||||
%{ $self->conf->{"${type}StorageOptions"} },
|
||||
backend => $self->conf->{"${type}Storage"}
|
||||
);
|
||||
my $sessions = Lemonldap::NG::Common::Apache::Session->searchOn(
|
||||
\%modOpts,
|
||||
_session_kind => 'SSO',
|
||||
'_session_id'
|
||||
);
|
||||
if (%$sessions) {
|
||||
my @s = keys %$sessions;
|
||||
$res->{$type} = @s;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $self->p->sendJSONresponse($req,$res);
|
||||
}
|
||||
|
||||
1;
|
Loading…
Reference in New Issue
Block a user