Commit ab4054b6 authored by Christophe Maudoux's avatar Christophe Maudoux 🐛

WIP - Inherits Conf.pm (#1661)

parent 3729b707
......@@ -119,10 +119,6 @@
"namespace" : "lemonldap-ng-sessions"
},
"locationRules" : {
"auth.example.com" : {
"(?#checkUser)/checkuser" : "$uid eq \"dwho\"",
"default" : "deny"
},
"manager.__DNSDOMAIN__" : {
"(?#Configuration)^/(manager\\.html|conf/)" : "$uid eq \"dwho\"",
"(?#Notifications)/notifications" : "$uid eq \"dwho\" or $uid eq \"rtyler\"",
......
......@@ -296,6 +296,7 @@ sub defaultValues {
'useRedirectOnError' => 1,
'useSafeJail' => 1,
'utotp2fActivation' => 0,
'viewerAllowDiff' => 1,
'viewerHiddenPK' => 'virtualHosts',
'webIDAuthnLevel' => 1,
'webIDExportedVars' => {},
......
......@@ -133,7 +133,7 @@ sub init {
}
sub tplParams {
return ( VERSION => $VERSION, );
return ( VERSION => $VERSION, ALLOWDIFF => 0 );
}
sub javascript {
......
......@@ -3558,6 +3558,10 @@ qr/^(?:(?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-
],
'type' => 'select'
},
'viewerAllowDiff' => {
'default' => 1,
'type' => 'bool'
},
'viewerHiddenPK' => {
'default' => 'virtualHosts',
'type' => 'text'
......
......@@ -922,6 +922,11 @@ sub attributes {
documentation => 'ConfTree hidden primary keys',
flags => 'm',
},
viewerAllowDiff => {
type => 'bool',
default => 1,
documentation => 'Allow configuration comparator',
},
# Notification
oldNotifFormat => {
......
......@@ -17,7 +17,7 @@ use URI::URL;
use feature 'state';
extends 'Lemonldap::NG::Common::Conf::RESTServer';
extends 'Lemonldap::NG::Manager::Conf';
our $VERSION = '2.0.3';
......@@ -52,18 +52,6 @@ sub addRoutes {
# READ
# Special keys
# ->addRoute(
# view => {
# ':cfgNum' => [
# qw(virtualHosts samlIDPMetaDataNodes samlSPMetaDataNodes
# applicationList oidcOPMetaDataNodes oidcRPMetaDataNodes
# casSrvMetaDataNodes casAppMetaDataNodes
# authChoiceModules grantSessionRules combModules
# openIdIDPList)
# ]
# },
# ['GET']
# )
->addRoute(
view => {
':cfgNum' => \@enabledPK
......@@ -72,102 +60,22 @@ sub addRoutes {
)
# Other keys
->addRoute( view => { ':cfgNum' => { '*' => 'getKey' } }, ['GET'] )
# Difference between confs
->addRoute( diff => { ':conf1' => { ':conf2' => 'diff' } } )
->addRoute( 'diff.html', undef, ['GET'] );
->addRoute( view => { ':cfgNum' => { '*' => 'getKey' } }, ['GET'] );
}
##@method public PSGI-JSON-response prx()
# Load file using posted URL and return its content
#
#@return PSGI JSON response
sub prx {
my ( $self, $req, @others ) = @_;
return $self->sendError( $req, 'There is no subkey for "prx"', 400 )
if (@others);
my $query = $req->jsonBodyToObj;
return $self->sendError( $req, 'Missing parameter', 400 )
unless ( $query->{url} );
return $self->sendError( $req, 'Bad parameter', 400 )
unless ( $query->{url} =~ m#^(?:f|ht)tps?://\w# );
$self->ua->timeout(10);
my $response = $self->ua->get( $query->{url} );
unless ( $response->code == 200 ) {
return $self->sendError( $req,
$response->code . " (" . $response->message . ")", 400 );
}
unless ( $response->header('Content-Type') =~
m#^(?:application/json|(?:application|text)/.*xml).*$# )
{
return $self->sendError( $req,
'Content refused for security reason (neither XML or JSON)', 400 );
}
return $self->sendJSONresponse( $req, { content => $response->content } );
$self->SUPER::prx( $req, @others );
}
######################
# IV. Upload methods #
######################
# - getConfByNum: override SUPER method to be able to use Zero
sub getConfByNum {
my ( $self, $cfgNum, @args ) = @_;
unless ( %{ $self->currentConf }
and $cfgNum == $self->currentConf->{cfgNum} )
{
my $tmp;
if ( $cfgNum == 0 ) {
require Lemonldap::NG::Manager::Conf::Zero;
$tmp = Lemonldap::NG::Manager::Conf::Zero::zeroConf();
$self->currentConf($tmp);
}
else {
$tmp = $self->SUPER::getConfByNum( $cfgNum, @args );
return undef unless ( defined $tmp );
}
}
return $cfgNum;
$self->SUPER::getConfByNum( $cfgNum, @args );
}
sub diff {
my ( $self, $req, @path ) = @_;
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;
return $self->sendJSONresponse(
$req,
[
$self->Lemonldap::NG::Manager::Conf::Diff::diff(
$conf[0], $conf[1]
)
]
);
$self->SUPER::diff( $req, @path );
}
1;
<div class="panel panel-default">
<div class="panel-heading">
<TMPL_IF NAME="ALLOWDIFF">
<h3 class="panel-title">
<span ng-if="!currentCfg.next" trspan="currentConfiguration"></span>
<span ng-if="currentCfg.next" trspan="loadedConfiguration"></span>
<i ng-if="currentCfg.prev">(<a trspan="diffWithPrevious" target="_blank" href="{{scriptname}}/diff.html#!/{{currentCfg.cfgNum}}" role="link"></a>)</i>
</h3>
</TMPL_IF>
</div>
<table class="table table-striped">
<tr>
......
......@@ -22,17 +22,15 @@
<div class="navbar-collapse" ng-class="{'collapse':!showM}" id="formmenu">
<ul class="nav navbar-nav">
<li><a class="link" ng-click="home()"><i class="glyphicon glyphicon-home"></i></a></li>
<!--
<li>
<a id="save" class="link" ng-click="save()" tabIndex="-1">
<i class="glyphicon glyphicon-cloud-upload"></i>
{{translate('save')}}
</a>
</li>
<li >
<input id="forcesave" type="checkbox" ng-model="forceSave" uib-tooltip="{{translate('forceSave')}}" tooltip-placement="right" ng-show="confirmNeeded||currentCfg.next" role="checkbox" aria-label="Force save">
</li>
-->
<TMPL_IF NAME="ALLOWDIFF">
<li uib-dropdown>
<a id="navmenu" name="menu" uib-dropdown-toggle data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><i class="glyphicon glyphicon-cog"></i> {{translate('browse')}} <span class="caret"></span></a>
<ul uib-dropdown-menu aria-labelled-by="navmenu">
......@@ -41,6 +39,9 @@
<li><a class="link" ng-click="getCfg('latest')" title="Latest configuration"><i class="glyphicon glyphicon-refresh"></i> {{translate('latest')}}</a></li>
</ul>
</li>
</TMPL_IF>
<li><a class="link hidden-xs" ng-click="setShowHelp()"><i class="glyphicon" ng-class="{'glyphicon-eye-close': showH,'glyphicon-eye-open': !showH}" ></i> {{ translate((showH ? 'hideHelp' : 'showHelp')) }}</a></li>
<!--
<li ng-repeat="button in menu()" ng-include="'menubutton.html'"></li>
......@@ -52,6 +53,12 @@
<li ng-repeat="menulink in menulinks"><a href="{{menulink.target}}" role="row"><i ng-if="menulink.icon" class="glyphicon glyphicon-{{menulink.icon}}"></i> {{translate(menulink.title)}}</a></li>
<li ng-include="'languages.html'"></li>
</ul>
</li>
<li>
<i class="glyphicon glyphicon-lock"></i>
<u>{{translate('You are on Read-Only mode')}}</u>
</li>
</ul>
</div>
......
......@@ -47,6 +47,8 @@ my @notManagedAttributes = (
# Loggers
'log4perlConfFile', 'userSyslogFacility', 'logger', 'sentryDsn',
'syslogFacility', 'userLogger', 'logLevel',
# Viewer
'viewerHiddenPK', 'viewerAllowDiff',
# Other ini-only prms
'configStorage', 'status', 'localStorageOptions', 'localStorage',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment