Commit b6162f5a authored by Christophe Maudoux's avatar Christophe Maudoux

Hide secret keys in diff.html

parent cc0dc83d
...@@ -40,8 +40,9 @@ useRedirectOnError = 0 ...@@ -40,8 +40,9 @@ useRedirectOnError = 0
enabledModules = conf, sessions, notifications, 2ndFA, viewer enabledModules = conf, sessions, notifications, 2ndFA, viewer
protection = manager protection = manager
viewerHiddenPK = samlIDPMetaDataNodes samlSPMetaDataNodes portalDisplayLogout viewerHiddenPK = samlIDPMetaDataNodes samlSPMetaDataNodes portalDisplayLogout captcha_login_enabled
viewerAllowBrowser = 1 viewerAllowBrowser = 1
viewerAllowDiff = 1
staticPrefix = /static staticPrefix = /static
languages = fr, en, vi, ar, de, it, zh languages = fr, en, vi, ar, de, it, zh
......
...@@ -364,6 +364,7 @@ enabledModules = conf, sessions, notifications, 2ndFA, viewer ...@@ -364,6 +364,7 @@ enabledModules = conf, sessions, notifications, 2ndFA, viewer
; Viewer options - Default values ; Viewer options - Default values
;viewerHiddenPK = samlIDPMetaDataNodes samlSPMetaDataNodes ;viewerHiddenPK = samlIDPMetaDataNodes samlSPMetaDataNodes
;viewerAllowBrowser = 0 ;viewerAllowBrowser = 0
;viewerAllowDiff = 0
;[node-handler] ;[node-handler]
; ;
......
...@@ -24,6 +24,7 @@ extends 'Lemonldap::NG::Common::Conf::AccessLib', ...@@ -24,6 +24,7 @@ extends 'Lemonldap::NG::Common::Conf::AccessLib',
has csp => ( is => 'rw' ); has csp => ( is => 'rw' );
has brw => ( is => 'rw', default => 0 ); has brw => ( is => 'rw', default => 0 );
has dif => ( is => 'rw', default => 0 );
## @method boolean init($args) ## @method boolean init($args)
# Launch initialization method # Launch initialization method
...@@ -88,6 +89,7 @@ sub init { ...@@ -88,6 +89,7 @@ sub init {
"default-src 'self' $portal;frame-ancestors 'none';form-action 'self';" "default-src 'self' $portal;frame-ancestors 'none';form-action 'self';"
); );
$self->brw( $self->{viewerAllowBrowser} || $conf->{viewerAllowBrowser} ); $self->brw( $self->{viewerAllowBrowser} || $conf->{viewerAllowBrowser} );
$self->dif( $self->{viewerAllowDiff} || $conf->{viewerAllowDiff} );
$self->defaultRoute( $working[0]->defaultRoute ); $self->defaultRoute( $working[0]->defaultRoute );
# Find out more glyphicones at https://www.w3schools.com/icons/bootstrap_icons_glyphicons.asp # Find out more glyphicones at https://www.w3schools.com/icons/bootstrap_icons_glyphicons.asp
...@@ -135,7 +137,7 @@ sub init { ...@@ -135,7 +137,7 @@ sub init {
sub tplParams { sub tplParams {
my ($self) = @_; my ($self) = @_;
return ( VERSION => $VERSION, ALLOWBROWSER => $self->brw ); return ( VERSION => $VERSION, ALLOWBROWSER => $self->brw, ALLOWDIFF => $self->dif );
} }
sub javascript { sub javascript {
......
...@@ -3566,6 +3566,10 @@ qr/^(?:(?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a- ...@@ -3566,6 +3566,10 @@ qr/^(?:(?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-
'default' => 0, 'default' => 0,
'type' => 'bool' 'type' => 'bool'
}, },
'viewerAllowDiff' => {
'default' => 0,
'type' => 'bool'
},
'viewerHiddenPK' => { 'viewerHiddenPK' => {
'default' => 'samlIDPMetaDataNodes samlSPMetaDataNodes', 'default' => 'samlIDPMetaDataNodes samlSPMetaDataNodes',
'type' => 'text' 'type' => 'text'
......
...@@ -927,6 +927,11 @@ sub attributes { ...@@ -927,6 +927,11 @@ sub attributes {
default => 0, default => 0,
documentation => 'Allow configuration browser', documentation => 'Allow configuration browser',
}, },
viewerAllowDiff => {
type => 'bool',
default => 0,
documentation => 'Allow configuration diff',
},
# Notification # Notification
oldNotifFormat => { oldNotifFormat => {
......
...@@ -70,8 +70,9 @@ sub addRoutes { ...@@ -70,8 +70,9 @@ sub addRoutes {
$self->addRoute( view => { ':cfgNum' => { '*' => 'getKey' } }, ['GET'] ) $self->addRoute( view => { ':cfgNum' => { '*' => 'getKey' } }, ['GET'] )
# Difference between confs # Difference between confs
->addRoute( diff => { ':conf1' => { ':conf2' => 'diff' } } ) ->addRoute(
->addRoute( 'diff.html', undef, ['GET'] ); view => { diff => { ':conf1' => { ':conf2' => 'viewDiff' } } } )
->addRoute( 'viewDiff.html', undef, ['GET'] );
} }
sub getConfByNum { sub getConfByNum {
...@@ -79,9 +80,44 @@ sub getConfByNum { ...@@ -79,9 +80,44 @@ sub getConfByNum {
$self->SUPER::getConfByNum( $cfgNum, @args ); $self->SUPER::getConfByNum( $cfgNum, @args );
} }
sub diff { sub viewDiff {
my ( $self, $req, @path ) = @_; my ( $self, $req, @path ) = @_;
$self->SUPER::diff( $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;
my @res =
$self->Lemonldap::NG::Manager::Conf::Diff::diff( $conf[0], $conf[1] );
my $hiddenKeys = $self->{viewerHiddenPK} || '';
$self->logger->debug("Deleting hidden Conf keys...");
foreach ( split /\s+/, $hiddenKeys ) {
$self->logger->debug("Delete hidden Conf keys");
$self->logger->debug("-> Delete $_");
delete $res[0]->{$_};
delete $res[1]->{$_};
}
return $self->sendJSONresponse( $req, [@res] );
} }
sub rejectKey { sub rejectKey {
......
###
diff.html script
###
llapp = angular.module 'llngConfDiff', ['ui.tree', 'ui.bootstrap', 'llApp', 'ngCookies'] , ($rootScopeProvider) -> $rootScopeProvider.digestTtl(15)
llapp.controller 'DiffCtrl', [ '$scope', '$http', '$q', '$translator', '$location', ($scope, $http, $q, $translator, $location) ->
$scope.links = links
$scope.menulinks = menulinks
$scope.staticPrefix = staticPrefix
$scope.scriptname = scriptname
#$scope.formPrefix = formPrefix
$scope.availableLanguages = availableLanguages
$scope.waiting = true
$scope.showM = false
$scope.cfg = []
$scope.data = {}
$scope.currentNode = null
# Import translations functions
$scope.translateTitle = (node) ->
return $translator.translateField node, 'title'
$scope.translateP = $translator.translateP
$scope.translate = $translator.translate
$scope.toggle = (scope) ->
scope.toggle()
$scope.stoggle = (scope,node) ->
$scope.currentNode = node
scope.toggle()
# Handle menu items
$scope.menuClick = (button) ->
if button.popup
window.open button.popup
else
button.action = button.title unless button.action
switch typeof button.action
when 'function'
button.action $scope.currentNode, $scope
when 'string'
$scope[button.action]()
else
console.log typeof button.action
$scope.showM = false
# Function to change interface language
$scope.getLanguage = (lang) ->
$scope.lang = lang
$scope.init()
$scope.showM = false
# function `getCfg(b,n)`:
# Download configuration metadatas
#
#@param b local conf (0 or 1)
#@param n cfgNumber
getCfg = (b,n) ->
d = $q.defer()
if not $scope.cfg[b]? or $scope.cfg[b] != n
$http.get("#{confPrefix}#{n}").then (response) ->
if response and response.data
$scope.cfg[b] = response.data
date = new Date response.data.cfgDate * 1000
$scope.cfg[b].date = date.toLocaleString()
console.log "Metadatas of cfg #{n} loaded"
d.resolve 'OK'
else
d.reject response
, (response) ->
console.log response
d.reject 'NOK'
else
d.resolve()
return d.promise
# Intialization function
# Simply set $scope.waiting to false during $translator and tree root
# initialization
init = ->
$scope.message = null
$scope.currentNode = null
d = $q.defer()
$http.get("#{scriptname}view/diff/#{$scope.cfg[0].cfgNum}/#{$scope.cfg[1].cfgNum}").then (response) ->
data = []
data = readDiff(response.data[0],response.data[1])
$scope.data = buildTree(data)
$scope.message = ''
$scope.waiting = false
, (response) ->
$scope.message = "#{$scope.translate('error')} : #{response.statusLine}"
readDiff = (c1,c2,tr=true) ->
res = []
for k,v of c1
if tr
tmp =
title: $scope.translate(k)
id: k
else
tmp = title: k
unless k.match /^cfg(?:Num|Log|Author(?:IP)?|Date)$/
if v? and typeof v == 'object'
if v.constructor == 'array'
tmp.oldvalue = v
tmp.newvalue = c2[k]
else if typeof c2[k] == 'object'
tmp.nodes = readDiff c1[k],c2[k], false
else
tmp.oldnodes = toNodes v, 'old'
else
tmp.oldvalue = v
tmp.newvalue = c2[k]
res.push tmp
for k,v of c2
unless (k.match /^cfg(?:Num|Log|Author(?:IP)?|Date)$/) or c1[k]?
if tr
tmp =
title: $scope.translate(k)
id: k
else
tmp = title: k
if v? and typeof v == 'object'
if v.constructor == 'array'
tmp.newvalue = v
else
console.log "Iteration"
tmp.newnodes = toNodes v, 'new'
else
tmp.newvalue = v
res.push tmp
return res
toNodes = (c,s) ->
res = []
for k,v of c
tmp = title:k
if typeof v == 'object'
if v.constructor == 'array'
tmp["#{s}value"] = v
else
tmp["#{s}nodes"] = toNodes c[k], s
else
tmp["#{s}value"] = v
res.push tmp
return res
reverseTree = []
buildTree = (data) ->
return data unless reverseTree?
res = []
for elem in data
offset = res
path = if reverseTree[elem.id]? then reverseTree[elem.id].split '/' else ''
for node in path
if node.length > 0
if offset.length
found = -1
for n,i in offset
if n.id == node
#offset = n.nodes
found = i
if found != -1
offset = offset[found].nodes
else
offset.push
id: node
title: $scope.translate node
nodes: []
offset = offset[offset.length-1].nodes
else
offset.push
id: node
title: $scope.translate node
nodes: []
offset = offset[0].nodes
offset.push elem
return res
$scope.newDiff = ->
$location.path("/#{$scope.cfg[0].cfgNum}/#{$scope.cfg[1].cfgNum}")
pathEvent = (event, next, current) ->
n = next.match(new RegExp('#!?/(latest|[0-9]+)(?:/(latest|[0-9]+))?$'))
if n == null
$location.path '/latest'
else
$scope.waiting = true
$q.all [
$translator.init $scope.lang
$http.get("#{staticPrefix}reverseTree.json").then (response) ->
reverseTree = response.data
console.log "Structure loaded"
getCfg 0, n[1]
getCfg 1, n[2] if n[2]?
]
.then ->
if n[2]?
init()
else
if $scope.cfg[0].prev
$scope.cfg[1] = $scope.cfg[0]
getCfg 0, $scope.cfg[1].prev
.then ->
init()
else
$scope.data = []
$scope.waiting = false
, ->
$scope.message = $scope.translate('error')
$scope.waiting = false
true
$scope.$on '$locationChangeSuccess', pathEvent
]
...@@ -27,7 +27,7 @@ llapp.controller 'TreeCtrl', [ ...@@ -27,7 +27,7 @@ llapp.controller 'TreeCtrl', [
$scope.waiting = true $scope.waiting = true
$scope.showM = false $scope.showM = false
$scope.showT = false $scope.showT = false
$scope.form = 'home' $scope.form = 'homeViewer'
$scope.currentCfg = {} $scope.currentCfg = {}
$scope.viewPrefix = window.viewPrefix $scope.viewPrefix = window.viewPrefix
$scope.message = {} $scope.message = {}
...@@ -133,7 +133,7 @@ llapp.controller 'TreeCtrl', [ ...@@ -133,7 +133,7 @@ llapp.controller 'TreeCtrl', [
# Display main form # Display main form
$scope.home = -> $scope.home = ->
$scope.form = 'home' $scope.form = 'homeViewer'
$scope.showM = false $scope.showM = false
# Download raw conf # Download raw conf
...@@ -438,7 +438,7 @@ llapp.controller 'TreeCtrl', [ ...@@ -438,7 +438,7 @@ llapp.controller 'TreeCtrl', [
title: 'emptyConf' title: 'emptyConf'
message: '__zeroConfExplanations__' message: '__zeroConfExplanations__'
$scope.showModal 'message.html' $scope.showModal 'message.html'
$scope.form = 'home' $scope.form = 'homeViewer'
$scope.waiting = false $scope.waiting = false
, readError , readError
# Colorized link # Colorized link
......
<div class="panel panel-default">
<div class="panel-heading">
<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}}/viewDiff.html#!/{{currentCfg.cfgNum}}" role="link"></a>)</i>
</h3>
</div>
<table class="table table-striped">
<tr>
<th><span trspan="number"></span></th>
<td>
<span id="cfgnum" class="label label-success" comment="{{translateP('__newCfgAvailable__')}}" ng-class="{'label-warning':currentCfg.next}">{{currentCfg.cfgNum}}</span>
</td>
</tr>
<tr ng-if="currentCfg.cfgAuthor">
<th><span trspan="author"></span></th>
<td>{{currentCfg.cfgAuthor}}</td>
</tr>
<tr ng-if="currentCfg.cfgAuthorIP">
<th><span trspan="authorIPAddress"></span></th>
<td>{{currentCfg.cfgAuthorIP}}</td>
</tr>
<tr ng-if="currentCfg.cfgDate">
<th><span trspan="date"></span></th>
<td>{{currentCfg.date}}</td>
</tr>
<tr ng-if="currentCfg.cfgVersion">
<th><span trspan="cfgVersion"></span></th>
<td>{{currentCfg.cfgVersion}}</td>
</tr>
<tr ng-if="currentCfg.cfgLog">
<th><span trspan="cfgLog"></span></th>
<td id="cfglog">{{currentCfg.cfgLog}}</td>
</tr>
</table>
</div>
<script type="text/menu">
[{
"title": "downloadIt",
"action": "downloadConf",
"icon": "export"
},{
"title": "restore",
"icon": "import"
}]
</script>
// Generated by CoffeeScript 1.12.7
/*
diff.html script
*/
(function() {
var llapp;
llapp = angular.module('llngConfDiff', ['ui.tree', 'ui.bootstrap', 'llApp', 'ngCookies'], function($rootScopeProvider) {
return $rootScopeProvider.digestTtl(15);
});
llapp.controller('DiffCtrl', [
'$scope', '$http', '$q', '$translator', '$location', function($scope, $http, $q, $translator, $location) {
var buildTree, getCfg, init, pathEvent, readDiff, reverseTree, toNodes;
$scope.links = links;
$scope.menulinks = menulinks;
$scope.staticPrefix = staticPrefix;
$scope.scriptname = scriptname;
$scope.availableLanguages = availableLanguages;
$scope.waiting = true;
$scope.showM = false;
$scope.cfg = [];
$scope.data = {};
$scope.currentNode = null;
$scope.translateTitle = function(node) {
return $translator.translateField(node, 'title');
};
$scope.translateP = $translator.translateP;
$scope.translate = $translator.translate;
$scope.toggle = function(scope) {
return scope.toggle();
};
$scope.stoggle = function(scope, node) {
$scope.currentNode = node;
return scope.toggle();
};
$scope.menuClick = function(button) {
if (button.popup) {
window.open(button.popup);
} else {
if (!button.action) {
button.action = button.title;
}
switch (typeof button.action) {
case 'function':
button.action($scope.currentNode, $scope);
break;
case 'string':
$scope[button.action]();
break;
default:
console.log(typeof button.action);
}
}
return $scope.showM = false;
};
$scope.getLanguage = function(lang) {
$scope.lang = lang;
$scope.init();
return $scope.showM = false;
};
getCfg = function(b, n) {
var d;
d = $q.defer();
if (($scope.cfg[b] == null) || $scope.cfg[b] !== n) {
$http.get("" + confPrefix + n).then(function(response) {
var date;
if (response && response.data) {
$scope.cfg[b] = response.data;
date = new Date(response.data.cfgDate * 1000);
$scope.cfg[b].date = date.toLocaleString();
console.log("Metadatas of cfg " + n + " loaded");
return d.resolve('OK');
} else {
return d.reject(response);
}
}, function(response) {
console.log(response);
return d.reject('NOK');
});
} else {
d.resolve();
}
return d.promise;
};
init = function() {
var d;
$scope.message = null;
$scope.currentNode = null;
d = $q.defer();
return $http.get(scriptname + "view/diff/" + $scope.cfg[0].cfgNum + "/" + $scope.cfg[1].cfgNum).then(function(response) {
var data;
data = [];
data = readDiff(response.data[0], response.data[1]);
$scope.data = buildTree(data);
$scope.message = '';
return $scope.waiting = false;
}, function(response) {
return $scope.message = ($scope.translate('error')) + " : " + response.statusLine;
});
};
readDiff = function(c1, c2, tr) {
var k, res, tmp, v;
if (tr == null) {
tr = true;
}
res = [];
for (k in c1) {
v = c1[k];
if (tr) {
tmp = {
title: $scope.translate(k),
id: k
};
} else {
tmp = {
title: k
};
}
if (!k.match(/^cfg(?:Num|Log|Author(?:IP)?|Date)$/)) {
if ((v != null) && typeof v === 'object') {
if (v.constructor === 'array') {
tmp.oldvalue = v;
tmp.newvalue = c2[k];
} else if (typeof c2[k] === 'object') {
tmp.nodes = readDiff(c1[k], c2[k], false);
} else {
tmp.oldnodes = toNodes(v, 'old');
}
} else {
tmp.oldvalue = v;
tmp.newvalue = c2[k];
}
res.push(tmp);
}
}
for (k in c2) {
v = c2[k];
if (!((k.match(/^cfg(?:Num|Log|Author(?:IP)?|Date)$/)) || (c1[k] != null))) {
if (tr) {
tmp = {
title: $scope.translate(k),
id: k
};
} else {
tmp = {
title: k
};
}
if ((v != null) && typeof v === 'object') {
if (v.constructor === 'array') {
tmp.newvalue = v;
} else {
console.log("Iteration");
tmp.newnodes = toNodes(v, 'new');
}
} else {
tmp.newvalue = v;
}
res.push(tmp);
}
}
return res;
};
toNodes = function(c, s) {
var k, res, tmp, v;
res = [];
for (k in c) {
v = c[k];
tmp = {
title: k
};
if (typeof v === 'object') {
if (v.constructor === 'array') {
tmp[s + "value"] = v;
} else {
tmp[s + "nodes"] = toNodes(c[k], s);
}
} else {
tmp[s + "value"] = v;
}
res.push(tmp);
}
return res;
};
reverseTree = [];
buildTree = function(data) {
var elem, found, i, j, l, len, len1, len2, m, n, node, offset, path, res;
if (reverseTree == null) {
return data;
}
res = [];
for (j = 0, len = data.length; j < len; j++) {
elem = data[j];
offset = res;
path = reverseTree[elem.id] != null ? reverseTree[elem.id].split('/') : '';
for (l = 0, len1 = path.length; l < len1; l++) {
node = path[l];
if (node.length > 0) {
if (offset.length) {
found = -1;
for (i = m = 0, len2 = offset.length; m < len2; i = ++m) {
n = offset[i];
if (n.id === node) {
found = i;
}
}
if (found !== -1) {
offset = offset[found].nodes;
} else {
offset.push({
id