2019-03-12 16:33:09 +01:00
|
|
|
package Lemonldap::NG::Manager::Viewer;
|
|
|
|
|
|
|
|
use 5.10.0;
|
|
|
|
use utf8;
|
|
|
|
use Mouse;
|
|
|
|
use Lemonldap::NG::Common::Conf::Constants;
|
|
|
|
use Lemonldap::NG::Common::UserAgent;
|
|
|
|
use URI::URL;
|
|
|
|
|
|
|
|
use feature 'state';
|
|
|
|
|
2019-03-14 16:39:49 +01:00
|
|
|
extends 'Lemonldap::NG::Manager::Conf';
|
2019-03-12 16:33:09 +01:00
|
|
|
|
2019-03-13 22:56:16 +01:00
|
|
|
our $VERSION = '2.0.3';
|
2019-03-12 16:33:09 +01:00
|
|
|
|
|
|
|
#############################
|
|
|
|
# I. INITIALIZATION METHODS #
|
|
|
|
#############################
|
|
|
|
|
|
|
|
use constant defaultRoute => 'viewer.html';
|
|
|
|
|
|
|
|
has ua => ( is => 'rw' );
|
|
|
|
|
|
|
|
sub addRoutes {
|
|
|
|
my ( $self, $conf ) = @_;
|
|
|
|
$self->ua( Lemonldap::NG::Common::UserAgent->new($conf) );
|
|
|
|
|
2019-03-26 22:53:18 +01:00
|
|
|
my $hiddenPK = '';
|
2019-04-01 14:52:23 +02:00
|
|
|
$hiddenPK = $self->{viewerHiddenKeys} || $conf->{viewerHiddenKeys};
|
2019-03-13 22:56:16 +01:00
|
|
|
my @enabledPK = ();
|
|
|
|
my @keys = qw(virtualHosts samlIDPMetaDataNodes samlSPMetaDataNodes
|
|
|
|
applicationList oidcOPMetaDataNodes oidcRPMetaDataNodes
|
|
|
|
casSrvMetaDataNodes casAppMetaDataNodes
|
|
|
|
authChoiceModules grantSessionRules combModules
|
|
|
|
openIdIDPList);
|
|
|
|
|
|
|
|
foreach (@keys) {
|
|
|
|
|
|
|
|
# Ignore hidden ConfTree Primary Keys
|
|
|
|
push @enabledPK, $_
|
2019-03-20 17:38:45 +01:00
|
|
|
unless ( $hiddenPK =~ /\b$_\b/ );
|
2019-03-13 22:56:16 +01:00
|
|
|
}
|
|
|
|
|
2019-03-12 16:33:09 +01:00
|
|
|
# HTML template
|
|
|
|
$self->addRoute( 'viewer.html', undef, ['GET'] )
|
|
|
|
|
|
|
|
# READ
|
|
|
|
# Special keys
|
|
|
|
->addRoute(
|
2019-03-12 22:59:15 +01:00
|
|
|
view => {
|
2019-03-13 22:56:16 +01:00
|
|
|
':cfgNum' => \@enabledPK
|
2019-03-12 16:33:09 +01:00
|
|
|
},
|
|
|
|
['GET']
|
2019-03-19 17:56:23 +01:00
|
|
|
);
|
2019-03-12 16:33:09 +01:00
|
|
|
|
2019-03-20 17:38:45 +01:00
|
|
|
foreach ( split /\s+/, $hiddenPK ) {
|
2019-03-19 17:56:23 +01:00
|
|
|
$self->addRoute(
|
|
|
|
view => { ':cfgNum' => { $_ => 'rejectKey' } },
|
|
|
|
['GET']
|
|
|
|
);
|
|
|
|
}
|
2019-03-26 22:53:18 +01:00
|
|
|
unless ( $self->{viewerAllowBrowser} || $conf->{viewerAllowBrowser} ) {
|
|
|
|
$self->addRoute(
|
|
|
|
view => { ':cfgNum' => 'rejectKey' },
|
|
|
|
['GET']
|
|
|
|
);
|
|
|
|
}
|
2019-03-19 17:56:23 +01:00
|
|
|
|
2019-04-01 16:48:23 +02:00
|
|
|
# Difference between confs
|
2019-04-01 22:55:47 +02:00
|
|
|
if ( $self->{viewerAllowDiff} || $conf->{viewerAllowDiff} ) {
|
2019-04-01 16:48:23 +02:00
|
|
|
$self->addRoute(
|
|
|
|
view => { diff => { ':conf1' => { ':conf2' => 'viewDiff' } } } )
|
|
|
|
->addRoute( 'viewDiff.html', undef, ['GET'] );
|
|
|
|
}
|
2019-03-12 16:33:09 +01:00
|
|
|
|
2019-04-01 16:48:23 +02:00
|
|
|
# Other keys
|
|
|
|
$self->addRoute( view => { ':cfgNum' => { '*' => 'getKey' } }, ['GET'] );
|
2019-03-12 16:33:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub getConfByNum {
|
|
|
|
my ( $self, $cfgNum, @args ) = @_;
|
2019-03-14 16:39:49 +01:00
|
|
|
$self->SUPER::getConfByNum( $cfgNum, @args );
|
2019-03-12 16:33:09 +01:00
|
|
|
}
|
|
|
|
|
2019-04-01 14:42:25 +02:00
|
|
|
sub viewDiff {
|
2019-03-12 16:33:09 +01:00
|
|
|
my ( $self, $req, @path ) = @_;
|
2019-04-01 14:42:25 +02:00
|
|
|
return $self->sendError( $req, 'to many arguments in path info', 400 )
|
|
|
|
if (@path);
|
|
|
|
my @cfgNum =
|
|
|
|
( scalar( $req->param('conf1') ), scalar( $req->param('conf2') ) );
|
|
|
|
my @conf;
|
|
|
|
$self->logger->debug(" Loading confs");
|
|
|
|
|
|
|
|
# Load the 2 configurations
|
|
|
|
for ( my $i = 0 ; $i < 2 ; $i++ ) {
|
|
|
|
if ( %{ $self->currentConf }
|
|
|
|
and $cfgNum[$i] == $self->currentConf->{cfgNum} )
|
|
|
|
{
|
|
|
|
$conf[$i] = $self->currentConf;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$conf[$i] = $self->confAcc->getConf(
|
|
|
|
{ cfgNum => $cfgNum[$i], raw => 1, noCache => 1 } );
|
|
|
|
return $self->sendError(
|
|
|
|
$req,
|
|
|
|
"Configuration $cfgNum[$i] not available $Lemonldap::NG::Common::Conf::msg",
|
|
|
|
400
|
|
|
|
) unless ( $conf[$i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
require Lemonldap::NG::Manager::Conf::Diff;
|
|
|
|
my @res =
|
|
|
|
$self->Lemonldap::NG::Manager::Conf::Diff::diff( $conf[0], $conf[1] );
|
2019-04-01 14:52:23 +02:00
|
|
|
my $hiddenKeys = $self->{viewerHiddenKeys} || '';
|
2019-04-01 14:42:25 +02:00
|
|
|
$self->logger->debug("Deleting hidden Conf keys...");
|
|
|
|
foreach ( split /\s+/, $hiddenKeys ) {
|
|
|
|
$self->logger->debug("-> Delete $_");
|
|
|
|
delete $res[0]->{$_};
|
|
|
|
delete $res[1]->{$_};
|
|
|
|
}
|
|
|
|
return $self->sendJSONresponse( $req, [@res] );
|
2019-03-12 16:33:09 +01:00
|
|
|
}
|
|
|
|
|
2019-03-19 17:56:23 +01:00
|
|
|
sub rejectKey {
|
|
|
|
my ( $self, $req ) = @_;
|
|
|
|
return $self->sendJSONresponse( $req, { 'value' => '_Hidden_' } );
|
|
|
|
}
|
|
|
|
|
2019-03-12 16:33:09 +01:00
|
|
|
1;
|