2015-05-14 08:44:38 +02:00
|
|
|
# Manager main component
|
|
|
|
#
|
|
|
|
# This package contains these parts:
|
|
|
|
# - Properties and private methods
|
|
|
|
# - Initialization method (launched by Lemonldap::NG::Common::PSGI)
|
|
|
|
# that declares routes
|
|
|
|
# - Upload methods (launched by Lemonldap::NG::Common::PSGI::Router)
|
|
|
|
#
|
|
|
|
# It inherits from Conf.pm to responds to display methods and from
|
|
|
|
# Sessions.pm to manage sessions
|
2006-12-18 12:32:33 +01:00
|
|
|
package Lemonldap::NG::Manager;
|
|
|
|
|
2015-05-14 08:44:38 +02:00
|
|
|
use 5.10.0;
|
2016-01-07 13:34:34 +01:00
|
|
|
use utf8;
|
2015-05-14 08:44:38 +02:00
|
|
|
use Mouse;
|
2016-04-06 22:09:58 +02:00
|
|
|
use JSON;
|
2015-05-14 08:44:38 +02:00
|
|
|
use Lemonldap::NG::Common::Conf::Constants;
|
|
|
|
use Lemonldap::NG::Common::PSGI::Constants;
|
|
|
|
|
2016-04-06 22:09:58 +02:00
|
|
|
our $VERSION = '2.0.0';
|
|
|
|
|
2017-01-18 00:17:23 +01:00
|
|
|
extends 'Lemonldap::NG::Common::Conf::AccessLib',
|
|
|
|
'Lemonldap::NG::Handler::PSGI::Router';
|
2015-05-14 08:44:38 +02:00
|
|
|
|
2017-03-15 23:27:58 +01:00
|
|
|
has csp => ( is => 'rw' );
|
|
|
|
|
2015-05-14 08:44:38 +02:00
|
|
|
## @method boolean init($args)
|
|
|
|
# Launch initialization method
|
|
|
|
#
|
|
|
|
# @param $args hashref to merge with object
|
|
|
|
# @return 0 in case of error, 1 else
|
|
|
|
sub init {
|
2016-01-02 10:29:05 +01:00
|
|
|
my ( $self, $args ) = @_;
|
2015-05-14 08:44:38 +02:00
|
|
|
$args ||= {};
|
|
|
|
|
2017-01-31 20:11:59 +01:00
|
|
|
if ( my $localconf = $self->confAcc->getLocalConf(MANAGERSECTION) ) {
|
2017-02-21 07:41:50 +01:00
|
|
|
foreach ( keys %$localconf ) {
|
|
|
|
$args->{$_} //= $localconf->{$_};
|
2017-03-03 18:25:03 +01:00
|
|
|
$self->{$_} = $args->{$_} unless (/^(?:l|userL)ogger$/);
|
2017-02-21 07:41:50 +01:00
|
|
|
}
|
2010-01-09 15:48:35 +01:00
|
|
|
}
|
|
|
|
|
2016-01-28 07:43:46 +01:00
|
|
|
# Manager needs to keep new Ajax behaviour
|
|
|
|
$args->{noAjaxHook} = 0;
|
|
|
|
|
2016-02-17 11:12:19 +01:00
|
|
|
return 0
|
|
|
|
unless ( $self->Lemonldap::NG::Handler::PSGI::Router::init($args) );
|
2014-08-19 18:08:11 +02:00
|
|
|
|
2015-05-14 08:44:38 +02:00
|
|
|
# TODO: manage errors
|
|
|
|
unless ( -r $self->{templateDir} ) {
|
2015-05-14 08:45:03 +02:00
|
|
|
$self->error("Unable to read $self->{templateDir}");
|
2015-05-14 08:44:38 +02:00
|
|
|
return 0;
|
2009-12-11 19:17:00 +01:00
|
|
|
}
|
2010-01-28 11:09:02 +01:00
|
|
|
|
2015-05-14 08:44:38 +02:00
|
|
|
$self->{enabledModules} ||= "conf, sessions, notifications";
|
|
|
|
my @links;
|
|
|
|
my @enabledModules =
|
|
|
|
map { push @links, $_; "Lemonldap::NG::Manager::" . ucfirst($_) }
|
|
|
|
split( /[,\s]+/, $self->{enabledModules} );
|
2016-01-25 19:03:46 +01:00
|
|
|
extends 'Lemonldap::NG::Handler::PSGI::Router', @enabledModules;
|
2016-01-14 13:42:07 +01:00
|
|
|
my @working;
|
2017-01-31 20:11:59 +01:00
|
|
|
my $conf = $self->confAcc->getConf;
|
2017-06-05 18:45:55 +02:00
|
|
|
unless ($conf) {
|
|
|
|
require Lemonldap::NG::Manager::Conf::Zero;
|
|
|
|
$conf = Lemonldap::NG::Manager::Conf::Zero::zeroConf();
|
|
|
|
}
|
2016-01-22 17:53:41 +01:00
|
|
|
for ( my $i = 0 ; $i < @enabledModules ; $i++ ) {
|
2016-01-18 22:12:36 +01:00
|
|
|
my $mod = $enabledModules[$i];
|
2015-05-14 08:44:38 +02:00
|
|
|
no strict 'refs';
|
2017-02-15 07:41:50 +01:00
|
|
|
if ( &{"${mod}::addRoutes"}( $self, $conf ) ) {
|
|
|
|
$self->logger->debug("Module $mod enabled");
|
2016-01-14 13:42:07 +01:00
|
|
|
push @working, $mod;
|
|
|
|
}
|
|
|
|
else {
|
2016-01-18 22:12:36 +01:00
|
|
|
$links[$i] = undef;
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->error(
|
|
|
|
"Module $mod can not be enabled: " . $self->error );
|
2016-01-14 13:42:07 +01:00
|
|
|
}
|
2010-03-20 18:14:28 +01:00
|
|
|
}
|
2016-01-14 13:42:07 +01:00
|
|
|
return 0 unless (@working);
|
2017-02-21 06:38:59 +01:00
|
|
|
$self->addRoute( links => 'links', ['GET'] );
|
|
|
|
$self->addRoute( 'psgi.js' => 'sendJs', ['GET'] );
|
2010-03-15 12:21:12 +01:00
|
|
|
|
2017-03-15 23:27:58 +01:00
|
|
|
my $portal = $conf->{portal};
|
2017-03-16 07:30:32 +01:00
|
|
|
$portal =~ s#https?://([^/]*).*#$1#;
|
2017-03-15 23:27:58 +01:00
|
|
|
$self->csp(
|
2017-03-16 07:30:33 +01:00
|
|
|
"default-src 'self';frame-ancestors 'none';form-action 'self';img-src 'self' $portal;style-src 'self' $portal;"
|
2017-03-15 23:27:58 +01:00
|
|
|
);
|
|
|
|
|
2016-01-14 13:42:07 +01:00
|
|
|
$self->defaultRoute( $working[0]->defaultRoute );
|
2010-09-01 17:02:55 +02:00
|
|
|
|
2016-01-05 15:41:14 +01:00
|
|
|
my $linksIcons =
|
|
|
|
{ 'conf' => 'cog', 'sessions' => 'duplicate', 'notifications' => 'bell' };
|
|
|
|
|
2015-05-14 08:44:38 +02:00
|
|
|
$self->links( [] );
|
|
|
|
for ( my $i = 0 ; $i < @links ; $i++ ) {
|
2016-01-18 22:12:36 +01:00
|
|
|
next unless ( defined $links[$i] );
|
2015-05-14 08:44:38 +02:00
|
|
|
push @{ $self->links },
|
2016-01-05 15:41:14 +01:00
|
|
|
{
|
|
|
|
target => $enabledModules[$i]->defaultRoute,
|
|
|
|
title => $links[$i],
|
|
|
|
icon => $linksIcons->{ $links[$i] }
|
|
|
|
};
|
2009-12-11 19:17:00 +01:00
|
|
|
}
|
2016-01-05 15:41:14 +01:00
|
|
|
|
2016-01-05 14:59:42 +01:00
|
|
|
$self->menuLinks( [] );
|
2017-06-05 18:45:55 +02:00
|
|
|
if ( my $portal =
|
|
|
|
$conf->{cfgNum}
|
|
|
|
? Lemonldap::NG::Handler::PSGI::Main->tsv->{portal}->()
|
|
|
|
: $conf->{portal} )
|
|
|
|
{
|
2016-07-03 09:28:08 +02:00
|
|
|
push @{ $self->menuLinks },
|
|
|
|
{
|
|
|
|
target => $portal,
|
|
|
|
title => 'backtoportal',
|
|
|
|
icon => 'home'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
target => "$portal?logout=1",
|
|
|
|
title => 'logout',
|
|
|
|
icon => 'log-out'
|
|
|
|
};
|
|
|
|
}
|
2015-05-14 08:44:38 +02:00
|
|
|
1;
|
2009-12-11 19:17:00 +01:00
|
|
|
}
|
|
|
|
|
2016-04-06 22:09:58 +02:00
|
|
|
sub tplParams {
|
2017-01-18 00:17:23 +01:00
|
|
|
return ( VERSION => $VERSION, );
|
|
|
|
}
|
|
|
|
|
|
|
|
sub javascript {
|
|
|
|
my ($self) = @_;
|
|
|
|
return
|
|
|
|
'var formPrefix=staticPrefix+"forms/";var confPrefix=scriptname+"confs/";'
|
|
|
|
. ( $self->links ? 'var links=' . to_json( $self->links ) . ';' : '' )
|
2017-02-15 07:41:50 +01:00
|
|
|
. (
|
|
|
|
$self->menuLinks
|
2017-01-18 00:17:23 +01:00
|
|
|
? 'var menulinks=' . to_json( $self->menuLinks ) . ';'
|
2017-02-15 07:41:50 +01:00
|
|
|
: ''
|
|
|
|
);
|
2016-04-06 22:09:58 +02:00
|
|
|
}
|
|
|
|
|
2017-03-15 23:27:58 +01:00
|
|
|
sub sendHtml {
|
|
|
|
my ( $self, $req, $template, %args ) = @_;
|
|
|
|
my $res = $self->SUPER::sendHtml( $req, $template, %args );
|
|
|
|
push @{ $res->[1] },
|
|
|
|
'Content-Security-Policy' => $self->csp,
|
|
|
|
'X-Content-Type-Options' => 'nosniff',
|
|
|
|
'X-Frame-Options' => 'DENY',
|
|
|
|
'X-XSS-Protection' => '1; mode=block';
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
2009-12-11 19:17:00 +01:00
|
|
|
1;
|
2009-12-13 16:40:33 +01:00
|
|
|
__END__
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
2010-01-03 09:09:59 +01:00
|
|
|
=encoding utf8
|
|
|
|
|
2009-12-13 16:40:33 +01:00
|
|
|
Lemonldap::NG::Manager - Perl extension for managing Lemonldap::NG Web-SSO
|
|
|
|
system.
|
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
2017-01-05 08:41:29 +01:00
|
|
|
Use any of Plack launcher. Example:
|
|
|
|
|
|
|
|
#!/usr/bin/env plackup
|
2015-05-14 08:44:38 +02:00
|
|
|
|
|
|
|
use Lemonldap::NG::Manager;
|
|
|
|
|
|
|
|
# This must be the last instruction ! See PSGI for more
|
|
|
|
Lemonldap::NG::Manager->run($opts);
|
2009-12-13 16:40:33 +01:00
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
Lemonldap::NG::Manager provides a web interface to manage Lemonldap::NG Web-SSO
|
|
|
|
system.
|
|
|
|
|
2015-12-26 08:30:27 +01:00
|
|
|
The Perl part of Lemonldap::NG::Manager is the REST server. Web interface is
|
|
|
|
written in Javascript, using AngularJS framework and can be found in `site`
|
|
|
|
directory. The REST API is described in REST-API.md file given in source tree.
|
|
|
|
|
|
|
|
Lemonldap::NG Manager uses L<Plack> to be compatible with CGI, FastCGI,... It
|
2016-01-25 19:03:46 +01:00
|
|
|
inherits of L<Lemonldap::NG::Handler::PSGI::Router>
|
2015-12-26 08:30:27 +01:00
|
|
|
|
|
|
|
=head1 ORGANIZATION
|
|
|
|
|
2017-01-05 06:57:16 +01:00
|
|
|
Lemonldap::NG Manager contains 5 parts:
|
2015-12-26 08:30:27 +01:00
|
|
|
|
|
|
|
=over
|
|
|
|
|
2017-01-05 06:57:16 +01:00
|
|
|
=item Configuration management
|
2015-12-26 08:30:27 +01:00
|
|
|
|
2017-01-05 06:57:16 +01:00
|
|
|
=item Session explorer
|
2015-12-26 08:30:27 +01:00
|
|
|
|
2017-01-05 06:57:16 +01:00
|
|
|
=item Notification explorer
|
2015-12-26 08:30:27 +01:00
|
|
|
|
2017-01-05 06:57:16 +01:00
|
|
|
=item Configuration builder (see L<Lemonldap::NG::Manager::Build>
|
2016-01-01 20:56:00 +01:00
|
|
|
|
2017-01-05 06:57:16 +01:00
|
|
|
=item Command line (see L<Lemonldap::NG::Manager::Cli>
|
2015-12-26 08:30:27 +01:00
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
=head2 Generation of static files
|
|
|
|
|
2015-12-26 21:08:31 +01:00
|
|
|
The `scripts/jsongenerator.pl` file uses Lemonldap::NG::Manager::Build::Attributes,
|
|
|
|
Lemonldap::NG::Manager::Build::Tree and Lemonldap::NG::Manager::Build::CTrees to generate
|
2015-12-26 08:30:27 +01:00
|
|
|
|
|
|
|
=over
|
|
|
|
|
2017-02-27 07:08:22 +01:00
|
|
|
=item `site/htdocs/static/struct.json`:
|
2016-01-01 20:56:00 +01:00
|
|
|
|
|
|
|
the main file that contains the tree view;
|
|
|
|
|
2017-02-27 07:08:22 +01:00
|
|
|
=item `site/htdocs/static/js/conftree.js`:
|
2016-01-01 20:56:00 +01:00
|
|
|
|
|
|
|
generates sub tree for virtualhosts and SAML and OpenID-Connect partners;
|
|
|
|
|
2017-01-10 22:43:37 +01:00
|
|
|
=item `Lemonldap::NG::Common::Conf::ReConstants`:
|
2015-12-26 08:30:27 +01:00
|
|
|
|
2016-01-01 20:56:00 +01:00
|
|
|
constants used by all Perl manager components;
|
2015-12-26 08:30:27 +01:00
|
|
|
|
2016-01-01 20:56:00 +01:00
|
|
|
=item `Lemonldap::NG::Common::Conf::DefaultValues`:
|
2015-12-26 08:30:27 +01:00
|
|
|
|
2016-01-01 20:56:00 +01:00
|
|
|
constants used to read configuration.
|
2015-12-26 08:30:27 +01:00
|
|
|
|
|
|
|
=back
|
2015-05-14 08:44:38 +02:00
|
|
|
|
|
|
|
=head1 PARAMETERS
|
|
|
|
|
|
|
|
You can use a hash ref to override any LemonLDAP::NG parameter. Currently, you
|
|
|
|
can specify where your lemonldap-ng.ini file is:
|
|
|
|
|
|
|
|
Lemonldap::NG::Manager->run( { confFile => '/path/to/lemonldap-ng.ini' } );
|
|
|
|
|
2015-12-26 08:30:27 +01:00
|
|
|
=head2 lemonldap-ng.ini parameters
|
|
|
|
|
|
|
|
You can override any configuration parameter in lemonldap-ng.ini, but some are
|
|
|
|
required and can't be set to global configuration (as any Lemonldap::NG module,
|
|
|
|
you can also fix them in $opts hash ref passed as argument to run() or new()).
|
|
|
|
|
|
|
|
[manager]
|
|
|
|
;protection: choose one of none, authenticate, manager as explain in
|
2016-01-25 19:03:46 +01:00
|
|
|
; Lemonldap::NG::Handler::PSGI::Router doc.
|
2015-12-26 08:30:27 +01:00
|
|
|
protection = manager
|
|
|
|
|
|
|
|
;enabledModules: Modules to display. Default to `conf, sessions, notifications`
|
|
|
|
enabledModules = conf, sessions, notifications
|
|
|
|
|
|
|
|
;logLevel: choose one of error, warn, notice, info, debug
|
|
|
|
; See Lemonldap::NG::Common::PSGI doc for more
|
|
|
|
logLevel = notice
|
|
|
|
|
|
|
|
;staticPrefix: set here the URI path to static content
|
|
|
|
; See Lemonldap::NG::Common::PSGI doc for more
|
|
|
|
staticPrefix = static/
|
|
|
|
|
|
|
|
;languages: Available interface languages
|
|
|
|
languages = en, fr
|
|
|
|
|
|
|
|
;templateDir: the path to the directory containing HTML templates
|
|
|
|
; See Lemonldap::NG::Common::PSGI doc for more
|
|
|
|
templateDir = /usr/share/lemonldap-ng/manager/
|
|
|
|
|
2009-12-13 16:40:33 +01:00
|
|
|
=head1 SEE ALSO
|
|
|
|
|
2010-10-26 08:08:16 +02:00
|
|
|
L<http://lemonldap-ng.org/>
|
2009-12-13 16:40:33 +01:00
|
|
|
|
2015-05-14 08:44:38 +02:00
|
|
|
=head1 AUTHORS
|
2009-12-13 16:40:33 +01:00
|
|
|
|
2013-01-31 06:33:10 +01:00
|
|
|
=over
|
|
|
|
|
2017-01-04 21:37:29 +01:00
|
|
|
=item LemonLDAP::NG team L<http://lemonldap-ng.org/team>
|
2013-01-31 06:33:10 +01:00
|
|
|
|
|
|
|
=back
|
2009-12-13 16:40:33 +01:00
|
|
|
|
|
|
|
=head1 BUG REPORT
|
|
|
|
|
|
|
|
Use OW2 system to report bug or ask for features:
|
2010-10-26 08:08:16 +02:00
|
|
|
L<http://jira.ow2.org>
|
2009-12-13 16:40:33 +01:00
|
|
|
|
2017-01-05 06:57:16 +01:00
|
|
|
Note that if you want to post a ticket for a conf upload problem, please
|
|
|
|
see L<Lemonldap::NG::Manager::Conf::Parser> before.
|
|
|
|
|
2009-12-13 16:40:33 +01:00
|
|
|
=head1 DOWNLOAD
|
|
|
|
|
|
|
|
Lemonldap::NG is available at
|
|
|
|
L<http://forge.objectweb.org/project/showfiles.php?group_id=274>
|
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE
|
|
|
|
|
2017-01-04 21:37:29 +01:00
|
|
|
See COPYING file for details.
|
2009-12-13 16:40:33 +01:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify
|
2013-01-31 06:33:10 +01:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see L<http://www.gnu.org/licenses/>.
|
2009-12-13 16:40:33 +01:00
|
|
|
|
|
|
|
=cut
|