| 1 | package Lemonldap::NG::Manager::Viewer; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 25 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 25 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 25 | ▶ | use Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 25 | ▶ | use Lemonldap::NG::Common::Conf::Constants; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 25 | ▶ | use Lemonldap::NG::Common::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 25 | ▶ | use URI::URL; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 25 | extends 'Lemonldap::NG::Manager::Conf'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 26 | ▶ | has diffRule => ( is => 'rw', default => sub { 0 } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 26 | ▶ | has brwRule => ( is => 'rw', default => sub { 0 } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 25 | our $VERSION = '2.22.0'; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | ############################# | ||||||||||||||||||||||||||||
| 18 | # I. INITIALIZATION METHODS # | ||||||||||||||||||||||||||||
| 19 | ############################# | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 25 | ▶ | use constant defaultRoute => 'viewer.html'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 25 | ▶ | use constant icon => 'eye-open'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 25 | has ua => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 26 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=9 SCAR=23.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 27 | 26 | my ( $self, $conf ) = @_; | |||||||||||||||||||||||||||
| 28 | 26 | $self->ua( Lemonldap::NG::Common::UserAgent->new($conf) ); | |||||||||||||||||||||||||||
| 29 | 26 | my $hd = "Lemonldap::NG::Handler::PSGI::Main"; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # Parse Diff activation rule | ||||||||||||||||||||||||||||
| 32 | 26 | ▶ | $conf->{viewerAllowDiff} //= 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$conf->{"viewerAllowDiff"} //= 0
MC/DC0%0/1
$conf->{"viewerAllowDiff"} //= 0
$conf->{"viewerAllowDiff"}
Truth table50%1/2
A
A= $conf->{"viewerAllowDiff"}
| |||||||||||||||||||||||||||||
| 33 | $self->logger->debug( | ||||||||||||||||||||||||||||
| 34 | 26 | "Diff activation rule -> " . ( $conf->{viewerAllowDiff} ) ); | |||||||||||||||||||||||||||
| 35 | 26 | my $rule = $hd->buildSub( $hd->substitute( $conf->{viewerAllowDiff} ) ); | |||||||||||||||||||||||||||
| 36 | 26 | ▶ | unless ($rule) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | $self->logger->error( | ||||||||||||||||||||||||||||
| 38 | 0 | "Bad Diff activation rule -> " . $hd->tsv->{jail}->error ); | |||||||||||||||||||||||||||
| 39 | 0 | return 0; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | 26 | $self->diffRule($rule); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # Parse Browser activation rule | ||||||||||||||||||||||||||||
| 44 | 26 | ▶ | $conf->{viewerAllowBrowser} //= 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$conf->{"viewerAllowBrowser"} //= 0
MC/DC0%0/1
$conf->{"viewerAllowBrowser"} //= 0
$conf->{"viewerAllowBrowser"}
Truth table50%1/2
A
A= $conf->{"viewerAllowBrowser"}
| |||||||||||||||||||||||||||||
| 45 | $self->logger->debug( | ||||||||||||||||||||||||||||
| 46 | 26 | "Browser activation rule -> " . ( $conf->{viewerAllowBrowser} ) ); | |||||||||||||||||||||||||||
| 47 | 26 | $rule = $hd->buildSub( $hd->substitute( $conf->{viewerAllowBrowser} ) ); | |||||||||||||||||||||||||||
| 48 | 26 | ▶ | unless ($rule) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | $self->logger->error( | ||||||||||||||||||||||||||||
| 50 | 0 | "Bad Browser activation rule -> " . $hd->tsv->{jail}->error ); | |||||||||||||||||||||||||||
| 51 | 0 | return 0; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 26 | $self->brwRule($rule); | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 26 | ▶ | my $hiddenKeys = $conf->{viewerHiddenKeys} || ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$conf->{'viewerHiddenKeys'} || ''
MC/DC0%0/1
$conf->{'viewerHiddenKeys'} || ''
$conf->{'viewerHiddenKeys'}
Truth table50%1/2
A
A= $conf->{'viewerHiddenKeys'}
| |||||||||||||||||||||||||||||
| 56 | 26 | my @enabledKeys = (); | |||||||||||||||||||||||||||
| 57 | 26 | my @keys = qw(virtualHosts samlIDPMetaDataNodes samlSPMetaDataNodes | |||||||||||||||||||||||||||
| 58 | applicationList oidcOPMetaDataNodes oidcRPMetaDataNodes | ||||||||||||||||||||||||||||
| 59 | casSrvMetaDataNodes casAppMetaDataNodes sfExtra | ||||||||||||||||||||||||||||
| 60 | authChoiceModules grantSessionRules combModules | ||||||||||||||||||||||||||||
| 61 | openIdIDPList keyNodes); | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 26 | foreach (@keys) { | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | # Ignore hidden ConfTree Primary Keys | ||||||||||||||||||||||||||||
| 66 | 364 | ▶ | push @enabledKeys, $_ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | unless ( $hiddenKeys =~ /\b$_\b/ ); | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # Forbid hidden keys | ||||||||||||||||||||||||||||
| 71 | 26 | foreach ( split /[,\s]+/, $hiddenKeys ) { | |||||||||||||||||||||||||||
| 72 | 102 | $self->addRoute( | |||||||||||||||||||||||||||
| 73 | view => { ':cfgNum' => { $_ => 'rejectKey' } }, | ||||||||||||||||||||||||||||
| 74 | ['GET'] | ||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # HTML templates | ||||||||||||||||||||||||||||
| 79 | 26 | $self->addRoute( 'viewer.html', undef, ['GET'] ) | |||||||||||||||||||||||||||
| 80 | ->addRoute( 'viewDiff.html', undef, ['GET'] ) | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | # READ | ||||||||||||||||||||||||||||
| 83 | # Special keys | ||||||||||||||||||||||||||||
| 84 | ->addRoute( | ||||||||||||||||||||||||||||
| 85 | view => { | ||||||||||||||||||||||||||||
| 86 | ':cfgNum' => \@enabledKeys | ||||||||||||||||||||||||||||
| 87 | }, | ||||||||||||||||||||||||||||
| 88 | ['GET'] | ||||||||||||||||||||||||||||
| 89 | ) | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # Difference between confs | ||||||||||||||||||||||||||||
| 92 | ->addRoute( | ||||||||||||||||||||||||||||
| 93 | view => { diff => { ':conf1' => { ':conf2' => 'viewDiff' } } } ) | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | # Other keys | ||||||||||||||||||||||||||||
| 96 | ->addRoute( view => { ':cfgNum' => { '*' => 'viewKey' } }, ['GET'] ); | ||||||||||||||||||||||||||||
| 97 | 26 | return 1; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 20 | ▶ | sub getConfByNum { | ||||||||||||||||||||||||||
|
Subroutine
getConfByNum: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 101 | 20 | my ( $self, $cfgNum, @args ) = @_; | |||||||||||||||||||||||||||
| 102 | 20 | $self->SUPER::getConfByNum( $cfgNum, @args ); | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 2 | ▶ | sub viewDiff { | ||||||||||||||||||||||||||
|
Subroutine
viewDiff: called CC=10 SCAR=23.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 106 | 2 | my ( $self, $req, @path ) = @_; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | # Check Diff activation rule | ||||||||||||||||||||||||||||
| 109 | 2 | ▶ | unless ( $self->diffRule->( $req, $req->{userData} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 1 | ▶ | my $user = $req->{userData}->{_whatToTrace} || 'anonymous'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$req->{'userData'}{'_whatToTrace'} || 'anonymous'
MC/DC0%0/1
$req->{'userData'}{'_whatToTrace'} || 'anonymous'
$req->{'userData'}{'_whatToTrace'}
Truth table50%1/2
A
A= $req->{'userData'}{'_whatToTrace'}
| |||||||||||||||||||||||||||||
| 111 | 1 | $self->auditLog( | |||||||||||||||||||||||||||
| 112 | $req, | ||||||||||||||||||||||||||||
| 113 | code => "CONF_COMPARISON_REFUSED", | ||||||||||||||||||||||||||||
| 114 | message => ("$user is not authorized to compare configurations"), | ||||||||||||||||||||||||||||
| 115 | user => $user, | ||||||||||||||||||||||||||||
| 116 | ); | ||||||||||||||||||||||||||||
| 117 | 1 | return $self->sendJSONresponse( $req, { 'value' => '_Hidden_' } ); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 1 | ▶ | return $self->sendError( $req, 'to many arguments in path info', 400 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | if (@path); | ||||||||||||||||||||||||||||
| 122 | 1 | my @cfgNum = | |||||||||||||||||||||||||||
| 123 | ( scalar( $req->param('conf1') ), scalar( $req->param('conf2') ) ); | ||||||||||||||||||||||||||||
| 124 | 1 | my @conf; | |||||||||||||||||||||||||||
| 125 | 1 | $self->logger->debug(" Loading confs"); | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | # Load the 2 configurations | ||||||||||||||||||||||||||||
| 128 | 1 | ▶ | for ( my $i = 0 ; $i < 2 ; $i++ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 2 | ▶ | if ( %{ $self->currentConf } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
%{$self->currentConf;} and $cfgNum[$i] == $self->currentConf->{"cfgNum"}
MC/DC50%1/2
%{$self->currentConf;} and $cfgNum[$i] == $self->currentConf->{"cfgNum"}
%{$self->currentConf;}
$cfgNum[$i] == $self->currentConf->{"cfgNum"}
Truth table66%2/3
A and B
A= %{$self->currentConf;}B= $cfgNum[$i] == $self->currentConf->{"cfgNum"}
| |||||||||||||||||||||||||||||
| 130 | and $cfgNum[$i] == $self->currentConf->{cfgNum} ) | ||||||||||||||||||||||||||||
| 131 | { | ||||||||||||||||||||||||||||
| 132 | 1 | $conf[$i] = $self->currentConf; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | else { | ||||||||||||||||||||||||||||
| 135 | 1 | $conf[$i] = $self->confAcc->getConf( | |||||||||||||||||||||||||||
| 136 | { cfgNum => $cfgNum[$i], raw => 1, noCache => 1 } ); | ||||||||||||||||||||||||||||
| 137 | 1 | ▶ | return $self->sendError( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | $req, | ||||||||||||||||||||||||||||
| 139 | "Configuration $cfgNum[$i] not available $Lemonldap::NG::Common::Conf::msg", | ||||||||||||||||||||||||||||
| 140 | 400 | ||||||||||||||||||||||||||||
| 141 | ) unless ( $conf[$i] ); | ||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | 1 | require Lemonldap::NG::Manager::Conf::Diff; | |||||||||||||||||||||||||||
| 145 | 1 | my @res = | |||||||||||||||||||||||||||
| 146 | $self->Lemonldap::NG::Manager::Conf::Diff::diff( $conf[0], $conf[1] ); | ||||||||||||||||||||||||||||
| 147 | 1 | ▶ | my $hiddenKeys = $self->{viewerHiddenKeys} || ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'viewerHiddenKeys'} || ''
MC/DC0%0/1
$self->{'viewerHiddenKeys'} || ''
$self->{'viewerHiddenKeys'}
Truth table50%1/2
A
A= $self->{'viewerHiddenKeys'}
| |||||||||||||||||||||||||||||
| 148 | 1 | $self->logger->debug("Deleting hidden Conf keys..."); | |||||||||||||||||||||||||||
| 149 | 1 | foreach ( split /\s+/, $hiddenKeys ) { | |||||||||||||||||||||||||||
| 150 | 0 | $self->logger->debug("-> Delete $_"); | |||||||||||||||||||||||||||
| 151 | 0 | delete $res[0]->{$_}; | |||||||||||||||||||||||||||
| 152 | 0 | delete $res[1]->{$_}; | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | 1 | return $self->sendJSONresponse( $req, [@res] ); | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 7 | ▶ | sub rejectKey { | ||||||||||||||||||||||||||
|
Subroutine
rejectKey: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 158 | 7 | my ( $self, $req, @args ) = @_; | |||||||||||||||||||||||||||
| 159 | 7 | return $self->sendJSONresponse( $req, { 'value' => '_Hidden_' } ); | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 9 | ▶ | sub viewKey { | ||||||||||||||||||||||||||
|
Subroutine
viewKey: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 163 | 9 | my ( $self, $req, @args ) = @_; | |||||||||||||||||||||||||||
| 164 | 9 | $self->logger->debug("Viewer requested URI -> $req->{env}->{REQUEST_URI}"); | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | # Check Browser activation rule | ||||||||||||||||||||||||||||
| 167 | 9 | ▶ | if ( $self->brwRule->( $req, $req->{userData} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | 4 | $self->logger->debug(" No restriction"); | |||||||||||||||||||||||||||
| 169 | 4 | $self->SUPER::getKey( $req, @args ); | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | else { | ||||||||||||||||||||||||||||
| 172 | # Compare the routed path (and not REQUEST_URI, which also contains | ||||||||||||||||||||||||||||
| 173 | # the query string: it could satisfy the whitelist from there) | ||||||||||||||||||||||||||||
| 174 | 5 | ▶ | if ( $req->path =~ m%^/view/(?:latest|\d+/\w+)$% ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | 1 | $self->logger->debug(" $req->{env}->{REQUEST_URI} -> URI allowed"); | |||||||||||||||||||||||||||
| 176 | 1 | $self->SUPER::getKey( $req, @args ); | |||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | else { | ||||||||||||||||||||||||||||
| 179 | 4 | $self->logger->debug( | |||||||||||||||||||||||||||
| 180 | " $req->{env}->{REQUEST_URI} -> URI FORBIDDEN"); | ||||||||||||||||||||||||||||
| 181 | 4 | ▶ | my $user = $req->{userData}->{_whatToTrace} || 'anonymous'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$req->{'userData'}{'_whatToTrace'} || 'anonymous'
MC/DC0%0/1
$req->{'userData'}{'_whatToTrace'} || 'anonymous'
$req->{'userData'}{'_whatToTrace'}
Truth table50%1/2
A
A= $req->{'userData'}{'_whatToTrace'}
| |||||||||||||||||||||||||||||
| 182 | 4 | $self->auditLog( | |||||||||||||||||||||||||||
| 183 | $req, | ||||||||||||||||||||||||||||
| 184 | code => "CONF_BROWSING_REFUSED", | ||||||||||||||||||||||||||||
| 185 | message => ("$user is not authorized to browse configurations"), | ||||||||||||||||||||||||||||
| 186 | user => $user, | ||||||||||||||||||||||||||||
| 187 | ); | ||||||||||||||||||||||||||||
| 188 | 4 | $self->rejectKey( $req, @args ); | |||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 25 | 1; | |||||||||||||||||||||||||||