2018-03-14 20:52:25 +01:00
|
|
|
// Generated by CoffeeScript 1.12.7
|
2016-03-14 23:22:09 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
LemonLDAP::NG Manager client
|
|
|
|
|
|
|
|
This is the main app file. Other are:
|
|
|
|
- struct.json and js/confTree.js that contains the full tree
|
|
|
|
- translate.json that contains the keywords translation
|
|
|
|
|
|
|
|
This file contains:
|
|
|
|
- the AngularJS controller
|
2015-05-14 08:44:38 +02:00
|
|
|
*/
|
2016-03-14 23:22:09 +01:00
|
|
|
|
2015-05-14 08:44:38 +02:00
|
|
|
(function() {
|
2016-03-14 23:22:09 +01:00
|
|
|
var llapp;
|
|
|
|
|
|
|
|
llapp = angular.module('llngManager', ['ui.tree', 'ui.bootstrap', 'llApp', 'ngCookies']);
|
2015-05-14 08:44:38 +02:00
|
|
|
|
|
|
|
|
2016-03-14 23:22:09 +01:00
|
|
|
/*
|
|
|
|
Main AngularJS controller
|
2015-05-14 08:44:38 +02:00
|
|
|
*/
|
|
|
|
|
2016-03-14 23:22:09 +01:00
|
|
|
llapp.controller('TreeCtrl', [
|
|
|
|
'$scope', '$http', '$location', '$q', '$uibModal', '$translator', '$cookies', '$htmlParams', function($scope, $http, $location, $q, $uibModal, $translator, $cookies, $htmlParams) {
|
2018-03-14 20:52:25 +01:00
|
|
|
var _checkSaveResponse, _download, _getAll, _stoggle, c, id, pathEvent, readError, setDefault, setHelp;
|
2016-03-14 23:22:09 +01:00
|
|
|
$scope.links = window.links;
|
|
|
|
$scope.menu = $htmlParams.menu;
|
|
|
|
$scope.menulinks = window.menulinks;
|
|
|
|
$scope.staticPrefix = window.staticPrefix;
|
|
|
|
$scope.formPrefix = window.formPrefix;
|
|
|
|
$scope.availableLanguages = window.availableLanguages;
|
|
|
|
$scope.waiting = true;
|
|
|
|
$scope.showM = false;
|
|
|
|
$scope.showT = false;
|
|
|
|
$scope.form = 'home';
|
|
|
|
$scope.currentCfg = {};
|
|
|
|
$scope.confPrefix = window.confPrefix;
|
|
|
|
$scope.message = {};
|
|
|
|
$scope.result = '';
|
|
|
|
$scope.translateTitle = function(node) {
|
|
|
|
return $translator.translateField(node, 'title');
|
|
|
|
};
|
|
|
|
$scope.translateP = $translator.translateP;
|
|
|
|
$scope.translate = $translator.translate;
|
|
|
|
$scope.helpUrl = 'start.html#configuration';
|
|
|
|
$scope.setShowHelp = function(val) {
|
|
|
|
var d;
|
|
|
|
if (val == null) {
|
|
|
|
val = !$scope.showH;
|
|
|
|
}
|
|
|
|
$scope.showH = val;
|
|
|
|
d = new Date(Date.now());
|
|
|
|
d.setFullYear(d.getFullYear() + 1);
|
|
|
|
return $cookies.put('showhelp', (val ? 'true' : 'false'), {
|
|
|
|
"expires": d
|
|
|
|
});
|
|
|
|
};
|
|
|
|
$scope.showH = $cookies.get('showhelp') === 'false' ? false : true;
|
|
|
|
if ($scope.showH == null) {
|
|
|
|
$scope.setShowHelp(true);
|
2015-12-23 20:01:26 +01:00
|
|
|
}
|
2016-03-14 23:22:09 +01:00
|
|
|
readError = function(response) {
|
|
|
|
var e, j;
|
|
|
|
e = response.status;
|
|
|
|
j = response.statusLine;
|
|
|
|
$scope.waiting = false;
|
|
|
|
if (e === 403) {
|
|
|
|
$scope.message = {
|
|
|
|
title: 'forbidden',
|
|
|
|
message: '',
|
|
|
|
items: []
|
|
|
|
};
|
|
|
|
} else if (e === 401) {
|
|
|
|
console.log('Authentication needed');
|
|
|
|
$scope.message = {
|
|
|
|
title: 'authenticationNeeded',
|
|
|
|
message: '__waitOrF5__',
|
|
|
|
items: []
|
|
|
|
};
|
|
|
|
} else if (e === 400) {
|
|
|
|
$scope.message = {
|
|
|
|
title: 'badRequest',
|
|
|
|
message: j,
|
|
|
|
items: []
|
|
|
|
};
|
|
|
|
} else if (e > 0) {
|
|
|
|
$scope.message = {
|
|
|
|
title: 'badRequest',
|
|
|
|
message: j,
|
|
|
|
items: []
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
$scope.message = {
|
|
|
|
title: 'networkProblem',
|
|
|
|
message: '',
|
|
|
|
items: []
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return $scope.showModal('message.html');
|
|
|
|
};
|
|
|
|
$scope.showModal = function(tpl, init) {
|
|
|
|
var d, modalInstance;
|
|
|
|
modalInstance = $uibModal.open({
|
|
|
|
templateUrl: tpl,
|
|
|
|
controller: 'ModalInstanceCtrl',
|
|
|
|
size: 'lg',
|
|
|
|
resolve: {
|
|
|
|
elem: function() {
|
|
|
|
return function(s) {
|
|
|
|
return $scope[s];
|
|
|
|
};
|
|
|
|
},
|
|
|
|
set: function() {
|
|
|
|
return function(f, s) {
|
|
|
|
return $scope[f] = s;
|
|
|
|
};
|
|
|
|
},
|
|
|
|
init: function() {
|
|
|
|
return init;
|
2015-05-14 08:44:38 +02:00
|
|
|
}
|
2016-03-14 23:22:09 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
d = $q.defer();
|
|
|
|
modalInstance.result.then(function(msgok) {
|
|
|
|
$scope.message = {
|
|
|
|
title: '',
|
|
|
|
message: '',
|
|
|
|
items: []
|
|
|
|
};
|
|
|
|
return d.resolve(msgok);
|
|
|
|
}, function(msgnok) {
|
|
|
|
$scope.message = {
|
|
|
|
title: '',
|
|
|
|
message: '',
|
|
|
|
items: []
|
|
|
|
};
|
|
|
|
return d.reject(msgnok);
|
|
|
|
});
|
2016-03-21 18:52:50 +01:00
|
|
|
return d.promise;
|
2016-03-14 23:22:09 +01:00
|
|
|
};
|
|
|
|
$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);
|
2015-05-14 08:44:38 +02:00
|
|
|
}
|
|
|
|
}
|
2016-03-14 23:22:09 +01:00
|
|
|
return $scope.showM = false;
|
|
|
|
};
|
|
|
|
$scope.home = function() {
|
|
|
|
$scope.form = 'home';
|
|
|
|
return $scope.showM = false;
|
|
|
|
};
|
|
|
|
_checkSaveResponse = function(data) {
|
|
|
|
var m;
|
2016-01-18 19:40:44 +01:00
|
|
|
$scope.message = {
|
|
|
|
title: '',
|
|
|
|
message: '',
|
|
|
|
items: []
|
|
|
|
};
|
2016-03-14 23:22:09 +01:00
|
|
|
if (data.message === '__needConfirmation__') {
|
|
|
|
$scope.confirmNeeded = true;
|
|
|
|
}
|
|
|
|
if (data.message) {
|
|
|
|
$scope.message.message = data.message;
|
|
|
|
}
|
|
|
|
if (data.details) {
|
|
|
|
for (m in data.details) {
|
|
|
|
if (m !== '__changes__') {
|
|
|
|
$scope.message.items.push({
|
|
|
|
message: m,
|
|
|
|
items: data.details[m]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$scope.waiting = false;
|
|
|
|
if (data.result === 1) {
|
|
|
|
$location.path('/confs/');
|
|
|
|
$scope.message.title = 'successfullySaved';
|
|
|
|
} else {
|
|
|
|
$scope.message.title = 'saveReport';
|
|
|
|
}
|
|
|
|
return $scope.showModal('message.html');
|
|
|
|
};
|
2017-03-13 17:27:47 +01:00
|
|
|
$scope.downloadConf = function() {
|
|
|
|
return window.open($scope.confPrefix + $scope.currentCfg.cfgNum + '?full=1');
|
2017-01-18 00:17:23 +01:00
|
|
|
};
|
2016-03-14 23:22:09 +01:00
|
|
|
$scope.save = function() {
|
|
|
|
$scope.showModal('save.html').then(function() {
|
|
|
|
$scope.waiting = true;
|
|
|
|
$scope.data.push({
|
|
|
|
id: "cfgLog",
|
|
|
|
title: "cfgLog",
|
|
|
|
data: $scope.result ? $scope.result : ''
|
2015-05-14 08:44:38 +02:00
|
|
|
});
|
2016-03-14 23:22:09 +01:00
|
|
|
return $http.post(window.confPrefix + "?cfgNum=" + $scope.currentCfg.cfgNum + ($scope.forceSave ? "&force=1" : ''), $scope.data).then(function(response) {
|
|
|
|
$scope.data.pop();
|
|
|
|
return _checkSaveResponse(response.data);
|
|
|
|
}, function(response) {
|
|
|
|
readError(response);
|
|
|
|
return $scope.data.pop();
|
|
|
|
});
|
|
|
|
}, function() {
|
|
|
|
return console.log('Saving canceled');
|
|
|
|
});
|
|
|
|
return $scope.showM = false;
|
|
|
|
};
|
|
|
|
$scope.saveRawConf = function($fileContent) {
|
2015-05-14 08:44:38 +02:00
|
|
|
$scope.waiting = true;
|
2016-03-14 23:22:09 +01:00
|
|
|
return $http.post(window.confPrefix + "/raw", $fileContent).then(function(response) {
|
|
|
|
return _checkSaveResponse(response.data);
|
|
|
|
}, readError);
|
|
|
|
};
|
|
|
|
$scope.restore = function() {
|
|
|
|
$scope.currentNode = null;
|
|
|
|
return $scope.form = 'restore';
|
|
|
|
};
|
|
|
|
$scope.cancel = function() {
|
|
|
|
$scope.currentNode.data = null;
|
|
|
|
return $scope.getKey($scope.currentNode);
|
|
|
|
};
|
|
|
|
id = 1;
|
|
|
|
$scope._findContainer = function() {
|
|
|
|
return $scope._findScopeContainer().$modelValue;
|
|
|
|
};
|
|
|
|
$scope._findScopeContainer = function() {
|
|
|
|
var cs;
|
|
|
|
cs = $scope.currentScope;
|
|
|
|
while (!cs.$modelValue.type.match(/Container$/)) {
|
|
|
|
cs = cs.$parentNodeScope;
|
|
|
|
}
|
|
|
|
return cs;
|
|
|
|
};
|
|
|
|
$scope._findScopeByKey = function(k) {
|
|
|
|
var cs;
|
|
|
|
cs = $scope.currentScope;
|
|
|
|
while (!(cs.$modelValue.title === k)) {
|
|
|
|
cs = cs.$parentNodeScope;
|
|
|
|
}
|
|
|
|
return cs;
|
|
|
|
};
|
|
|
|
$scope.newGrantRule = function() {
|
|
|
|
var l, n, node;
|
|
|
|
node = $scope._findContainer();
|
|
|
|
l = node.nodes.length;
|
|
|
|
n = l > 0 ? l - 1 : 0;
|
|
|
|
return node.nodes.splice(n, 0, {
|
|
|
|
id: node.id + "/n" + (id++),
|
|
|
|
title: 'New rule',
|
|
|
|
re: '1',
|
|
|
|
comment: 'New rule',
|
|
|
|
data: 'Message',
|
|
|
|
type: "grant"
|
2015-05-14 08:44:38 +02:00
|
|
|
});
|
2016-03-14 23:22:09 +01:00
|
|
|
};
|
|
|
|
$scope.newRule = function() {
|
|
|
|
var l, n, node;
|
|
|
|
node = $scope._findContainer();
|
|
|
|
l = node.nodes.length;
|
|
|
|
n = l > 0 ? l - 1 : 0;
|
|
|
|
return node.nodes.splice(n, 0, {
|
|
|
|
id: node.id + "/n" + (id++),
|
|
|
|
title: 'New rule',
|
|
|
|
re: '^/new',
|
|
|
|
comment: 'New rule',
|
|
|
|
data: 'accept',
|
|
|
|
type: "rule"
|
2016-02-29 23:43:43 +01:00
|
|
|
});
|
2016-03-14 23:22:09 +01:00
|
|
|
};
|
|
|
|
$scope.newPost = function() {
|
|
|
|
var node;
|
|
|
|
node = $scope._findContainer();
|
|
|
|
return node.nodes.push({
|
|
|
|
id: node.id + "/n" + (id++),
|
|
|
|
title: "/absolute/path/to/form",
|
|
|
|
data: {},
|
|
|
|
type: "post"
|
|
|
|
});
|
|
|
|
};
|
|
|
|
$scope.newPostVar = function() {
|
|
|
|
if ($scope.currentNode.data.vars == null) {
|
|
|
|
$scope.currentNode.data.vars = [];
|
2015-05-14 08:44:38 +02:00
|
|
|
}
|
2016-03-14 23:22:09 +01:00
|
|
|
return $scope.currentNode.data.vars.push(['var1', '$uid']);
|
|
|
|
};
|
|
|
|
$scope.newAuthChoice = function() {
|
|
|
|
var node;
|
|
|
|
node = $scope._findContainer();
|
|
|
|
node.nodes.push({
|
|
|
|
id: node.id + "/n" + (id++),
|
|
|
|
title: "1_Key",
|
|
|
|
data: ['Null', 'Null', 'Null'],
|
|
|
|
type: "authChoice"
|
|
|
|
});
|
|
|
|
return $scope.execFilters($scope._findScopeByKey('authParams'));
|
|
|
|
};
|
|
|
|
$scope.newHashEntry = function() {
|
|
|
|
var node;
|
|
|
|
node = $scope._findContainer();
|
|
|
|
return node.nodes.push({
|
|
|
|
id: node.id + "/n" + (id++),
|
|
|
|
title: 'new',
|
|
|
|
data: '',
|
|
|
|
type: "keyText"
|
|
|
|
});
|
|
|
|
};
|
|
|
|
$scope.newCat = function() {
|
|
|
|
var cs;
|
|
|
|
cs = $scope.currentScope;
|
|
|
|
if (cs.$modelValue.type === 'menuApp') {
|
|
|
|
cs = cs.$parentNodeScope;
|
2016-01-16 14:08:53 +01:00
|
|
|
}
|
2016-03-14 23:22:09 +01:00
|
|
|
return cs.$modelValue.nodes.push({
|
|
|
|
id: cs.$modelValue.id + "/n" + (id++),
|
|
|
|
title: "New category",
|
|
|
|
type: "menuCat",
|
|
|
|
nodes: []
|
|
|
|
});
|
|
|
|
};
|
|
|
|
$scope.newApp = function() {
|
|
|
|
var cs;
|
|
|
|
cs = $scope.currentScope;
|
|
|
|
if (cs.$modelValue.type === 'menuApp') {
|
|
|
|
cs = cs.$parentNodeScope;
|
2016-01-16 22:28:35 +01:00
|
|
|
}
|
2016-03-14 23:22:09 +01:00
|
|
|
return cs.$modelValue.nodes.push({
|
|
|
|
id: cs.$modelValue.id + "/n" + (id++),
|
|
|
|
title: "New application",
|
|
|
|
type: "menuApp",
|
|
|
|
data: {
|
|
|
|
description: "New app description",
|
|
|
|
uri: "https://test.example.com/",
|
|
|
|
logo: "network.png",
|
|
|
|
display: "auto"
|
|
|
|
}
|
2016-02-18 19:34:04 +01:00
|
|
|
});
|
2016-03-14 23:22:09 +01:00
|
|
|
};
|
2017-02-06 07:42:22 +01:00
|
|
|
$scope.newCmbMod = function() {
|
|
|
|
var node;
|
|
|
|
node = $scope._findContainer();
|
2017-02-06 19:04:07 +01:00
|
|
|
node.nodes.push({
|
2017-02-06 07:42:22 +01:00
|
|
|
id: node.id + "/n" + (id++),
|
|
|
|
title: 'new',
|
|
|
|
type: 'cmbModule',
|
|
|
|
data: {
|
|
|
|
type: 'LDAP',
|
|
|
|
"for": 0,
|
2017-02-06 18:40:17 +01:00
|
|
|
over: []
|
2017-02-06 07:42:22 +01:00
|
|
|
}
|
|
|
|
});
|
2017-02-06 19:04:07 +01:00
|
|
|
return $scope.execFilters($scope._findScopeByKey('authParams'));
|
2017-02-06 07:42:22 +01:00
|
|
|
};
|
|
|
|
$scope.newCmbOver = function() {
|
2017-02-06 18:40:17 +01:00
|
|
|
var d;
|
|
|
|
d = $scope.currentNode.data;
|
|
|
|
if (!d.over) {
|
|
|
|
d.over = [];
|
|
|
|
}
|
|
|
|
return d.over.push(["new" + (id++), '']);
|
2017-02-06 07:42:22 +01:00
|
|
|
};
|
2017-05-17 10:56:29 +02:00
|
|
|
$scope.addHost = function() {
|
|
|
|
var cn;
|
|
|
|
cn = $scope.currentNode;
|
2017-01-18 00:17:23 +01:00
|
|
|
if (!cn.data) {
|
|
|
|
cn.data = [];
|
|
|
|
}
|
|
|
|
return cn.data.push({
|
|
|
|
k: "newHost",
|
|
|
|
h: [
|
|
|
|
{
|
|
|
|
"k": "key",
|
|
|
|
"v": "uid"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
};
|
2016-03-14 23:22:09 +01:00
|
|
|
$scope.addSamlAttribute = function() {
|
|
|
|
var node;
|
|
|
|
node = $scope._findContainer();
|
|
|
|
return node.nodes.push({
|
|
|
|
id: node.id + "/n" + (id++),
|
|
|
|
title: 'new',
|
|
|
|
type: 'samlAttribute',
|
|
|
|
data: [0, 'New', '', '']
|
2016-02-18 19:34:04 +01:00
|
|
|
});
|
2016-03-14 23:22:09 +01:00
|
|
|
};
|
|
|
|
$scope.addVhost = function() {
|
|
|
|
var name;
|
|
|
|
name = $scope.domain ? "." + $scope.domain.data : '.example.com';
|
|
|
|
$scope.message = {
|
|
|
|
title: 'virtualHostName',
|
|
|
|
field: 'hostname'
|
|
|
|
};
|
|
|
|
return $scope.showModal('prompt.html', name).then(function() {
|
2018-03-14 20:52:25 +01:00
|
|
|
var n;
|
2016-03-14 23:22:09 +01:00
|
|
|
n = $scope.result;
|
|
|
|
if (n) {
|
2018-03-14 20:52:25 +01:00
|
|
|
return $scope.addTemplateNode(n, 'virtualHost');
|
2016-03-14 23:22:09 +01:00
|
|
|
}
|
2016-02-18 19:34:04 +01:00
|
|
|
});
|
2016-03-14 23:22:09 +01:00
|
|
|
};
|
|
|
|
$scope.duplicateVhost = function() {
|
|
|
|
var name;
|
|
|
|
name = $scope.domain ? "." + $scope.domain.data : '.example.com';
|
|
|
|
$scope.message = {
|
|
|
|
title: 'virtualHostName',
|
|
|
|
field: 'hostname'
|
|
|
|
};
|
|
|
|
return $scope.showModal('prompt.html', name).then(function() {
|
|
|
|
var n;
|
|
|
|
n = $scope.result;
|
|
|
|
return $scope.duplicateNode(n, 'virtualHost', $scope.currentNode.title);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
$scope.addSamlIDP = function() {
|
|
|
|
return $scope.newTemplateNode('samlIDPMetaDataNode', 'samlPartnerName', 'idp-example');
|
|
|
|
};
|
|
|
|
$scope.addSamlSP = function() {
|
|
|
|
return $scope.newTemplateNode('samlSPMetaDataNode', 'samlPartnerName', 'sp-example');
|
|
|
|
};
|
|
|
|
$scope.addOidcOp = function() {
|
|
|
|
return $scope.newTemplateNode('oidcOPMetaDataNode', 'oidcOPName', 'op-example');
|
|
|
|
};
|
|
|
|
$scope.addOidcRp = function() {
|
|
|
|
return $scope.newTemplateNode('oidcRPMetaDataNode', 'oidcRPName', 'rp-example');
|
|
|
|
};
|
2017-04-12 18:45:49 +02:00
|
|
|
$scope.addCasSrv = function() {
|
|
|
|
return $scope.newTemplateNode('casSrvMetaDataNode', 'casPartnerName', 'srv-example');
|
|
|
|
};
|
|
|
|
$scope.addCasApp = function() {
|
|
|
|
return $scope.newTemplateNode('casAppMetaDataNode', 'casPartnerName', 'app-example');
|
|
|
|
};
|
2016-03-14 23:22:09 +01:00
|
|
|
$scope.newTemplateNode = function(type, title, init) {
|
|
|
|
$scope.message = {
|
|
|
|
title: title,
|
|
|
|
field: 'name'
|
|
|
|
};
|
|
|
|
return $scope.showModal('prompt.html', init).then(function() {
|
|
|
|
var name;
|
|
|
|
name = $scope.result;
|
|
|
|
if (name) {
|
|
|
|
return $scope.addTemplateNode(name, type);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
$scope.addTemplateNode = function(name, type) {
|
|
|
|
var cs, t;
|
|
|
|
cs = $scope.currentScope;
|
|
|
|
while (cs.$modelValue.title !== (type + "s")) {
|
2016-02-18 19:34:04 +01:00
|
|
|
cs = cs.$parentNodeScope;
|
|
|
|
}
|
2016-03-14 23:22:09 +01:00
|
|
|
t = {
|
|
|
|
id: type + "s/new__" + name,
|
|
|
|
title: name,
|
|
|
|
type: type,
|
|
|
|
nodes: templates(type, "new__" + name)
|
|
|
|
};
|
2018-03-14 20:52:25 +01:00
|
|
|
setDefault(t.nodes);
|
2016-02-18 19:34:04 +01:00
|
|
|
cs.$modelValue.nodes.push(t);
|
2016-03-14 23:22:09 +01:00
|
|
|
cs.expand();
|
2016-02-18 19:34:04 +01:00
|
|
|
return t;
|
2016-03-14 23:22:09 +01:00
|
|
|
};
|
2018-03-14 20:52:25 +01:00
|
|
|
setDefault = function(node) {
|
|
|
|
var len, n, o;
|
|
|
|
for (o = 0, len = node.length; o < len; o++) {
|
|
|
|
n = node[o];
|
|
|
|
if (n.cnodes && n["default"]) {
|
|
|
|
delete n.cnodes;
|
|
|
|
n._nodes = n["default"];
|
|
|
|
}
|
|
|
|
if (n._nodes) {
|
|
|
|
setDefault(n._nodes);
|
|
|
|
} else if (n["default"] || n["default"] === 0) {
|
|
|
|
n.data = n["default"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
};
|
2016-03-14 23:22:09 +01:00
|
|
|
_getAll = function(node) {
|
|
|
|
var d, d2;
|
|
|
|
d = $q.defer();
|
|
|
|
d2 = $q.defer();
|
|
|
|
if (node._nodes) {
|
|
|
|
_stoggle(node);
|
|
|
|
d.resolve();
|
|
|
|
} else if (node.cnodes) {
|
|
|
|
_download(node).then(function() {
|
|
|
|
return d.resolve();
|
|
|
|
});
|
|
|
|
} else if (node.nodes || node.data) {
|
|
|
|
d.resolve();
|
|
|
|
} else {
|
|
|
|
$scope.getKey(node).then(function() {
|
|
|
|
return d.resolve();
|
2015-05-14 08:44:38 +02:00
|
|
|
});
|
|
|
|
}
|
2016-03-14 23:22:09 +01:00
|
|
|
d.promise.then(function() {
|
|
|
|
var len, n, o, ref, t;
|
|
|
|
t = [];
|
|
|
|
if (node.nodes) {
|
|
|
|
ref = node.nodes;
|
|
|
|
for (o = 0, len = ref.length; o < len; o++) {
|
|
|
|
n = ref[o];
|
|
|
|
t.push(_getAll(n));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $q.all(t).then(function() {
|
|
|
|
return d2.resolve();
|
2015-05-14 08:44:38 +02:00
|
|
|
});
|
2016-03-14 23:22:09 +01:00
|
|
|
});
|
|
|
|
return d2.promise;
|
|
|
|
};
|
2016-03-22 08:41:04 +01:00
|
|
|
$scope.duplicateNode = function(name, type, idkey) {
|
2016-03-14 23:22:09 +01:00
|
|
|
var cs;
|
|
|
|
cs = $scope.currentScope;
|
|
|
|
return _getAll($scope.currentNode).then(function() {
|
|
|
|
var t;
|
|
|
|
while (cs.$modelValue.title !== (type + "s")) {
|
|
|
|
cs = cs.$parentNodeScope;
|
|
|
|
}
|
|
|
|
t = JSON.parse(JSON.stringify($scope.currentNode).replace(new RegExp(idkey, 'g'), 'new__' + name));
|
|
|
|
t.id = type + "s/new__" + name;
|
|
|
|
t.title = name;
|
|
|
|
cs.$modelValue.nodes.push(t);
|
|
|
|
return t;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
$scope.del = function(a, i) {
|
|
|
|
return a.splice(i, 1);
|
|
|
|
};
|
|
|
|
$scope.deleteEntry = function() {
|
|
|
|
var p;
|
|
|
|
p = $scope.currentScope.$parentNodeScope;
|
|
|
|
$scope.currentScope.remove();
|
|
|
|
return $scope.displayForm(p);
|
|
|
|
};
|
|
|
|
$scope.down = function() {
|
|
|
|
var i, ind, len, n, o, p, ref, tmp;
|
|
|
|
id = $scope.currentNode.id;
|
|
|
|
p = $scope.currentScope.$parentNodeScope.$modelValue;
|
|
|
|
ind = p.nodes.length;
|
|
|
|
ref = p.nodes;
|
|
|
|
for (i = o = 0, len = ref.length; o < len; i = ++o) {
|
|
|
|
n = ref[i];
|
|
|
|
if (n.id === id) {
|
|
|
|
ind = i;
|
|
|
|
}
|
2015-05-14 08:44:38 +02:00
|
|
|
}
|
2016-03-14 23:22:09 +01:00
|
|
|
if (ind < p.nodes.length - 1) {
|
|
|
|
tmp = p.nodes[ind];
|
|
|
|
p.nodes[ind] = p.nodes[ind + 1];
|
|
|
|
p.nodes[ind + 1] = tmp;
|
|
|
|
}
|
|
|
|
return ind;
|
|
|
|
};
|
|
|
|
$scope.up = function() {
|
|
|
|
var i, ind, len, n, o, p, ref, tmp;
|
|
|
|
id = $scope.currentNode.id;
|
|
|
|
p = $scope.currentScope.$parentNodeScope.$modelValue;
|
|
|
|
ind = -1;
|
|
|
|
ref = p.nodes;
|
|
|
|
for (i = o = 0, len = ref.length; o < len; i = ++o) {
|
|
|
|
n = ref[i];
|
|
|
|
if (n.id === id) {
|
|
|
|
ind = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ind > 0) {
|
|
|
|
tmp = p.nodes[ind];
|
|
|
|
p.nodes[ind] = p.nodes[ind - 1];
|
|
|
|
p.nodes[ind - 1] = tmp;
|
|
|
|
}
|
|
|
|
return ind;
|
|
|
|
};
|
|
|
|
$scope.inSelect = function(value) {
|
|
|
|
var len, n, o, ref;
|
|
|
|
ref = $scope.currentNode.select;
|
|
|
|
for (o = 0, len = ref.length; o < len; o++) {
|
|
|
|
n = ref[o];
|
|
|
|
if (n.k === value) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
$scope.changeRuleTitle = function(node) {
|
|
|
|
return node.title = node.comment.length > 0 ? node.comment : node.re;
|
|
|
|
};
|
|
|
|
$scope.filters = {};
|
|
|
|
$scope.execFilters = function(scope) {
|
|
|
|
var filter, func, ref;
|
|
|
|
scope = scope ? scope : $scope;
|
|
|
|
ref = $scope.filters;
|
|
|
|
for (filter in ref) {
|
|
|
|
func = ref[filter];
|
|
|
|
if ($scope.filters.hasOwnProperty(filter)) {
|
2017-04-27 09:51:50 +02:00
|
|
|
return window.filterFunctions[filter](scope, $q, func);
|
2016-03-14 23:22:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
$scope.stoggle = function(scope) {
|
|
|
|
var node;
|
|
|
|
node = scope.$modelValue;
|
|
|
|
_stoggle(node);
|
|
|
|
return scope.toggle();
|
|
|
|
};
|
|
|
|
_stoggle = function(node) {
|
|
|
|
var a, len, len1, len2, n, o, q, r, ref, ref1, ref2;
|
|
|
|
ref = ['nodes', 'nodes_cond'];
|
|
|
|
for (o = 0, len = ref.length; o < len; o++) {
|
|
|
|
n = ref[o];
|
|
|
|
if (node["_" + n]) {
|
|
|
|
node[n] = [];
|
|
|
|
ref1 = node["_" + n];
|
|
|
|
for (q = 0, len1 = ref1.length; q < len1; q++) {
|
|
|
|
a = ref1[q];
|
|
|
|
node[n].push(a);
|
|
|
|
}
|
|
|
|
delete node["_" + n];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (node._nodes_filter) {
|
|
|
|
if (node.nodes) {
|
|
|
|
ref2 = node.nodes;
|
|
|
|
for (r = 0, len2 = ref2.length; r < len2; r++) {
|
|
|
|
n = ref2[r];
|
|
|
|
n.onChange = $scope.execFilters;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$scope.filters[node._nodes_filter] = node;
|
|
|
|
return $scope.execFilters();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
$scope.toggle = function(scope) {
|
|
|
|
return scope.toggle();
|
|
|
|
};
|
|
|
|
$scope.download = function(scope) {
|
|
|
|
var node;
|
|
|
|
node = scope.$modelValue;
|
|
|
|
return _download(node);
|
|
|
|
};
|
|
|
|
_download = function(node) {
|
|
|
|
var d;
|
|
|
|
d = $q.defer();
|
|
|
|
d.notify('Trying to get datas');
|
|
|
|
$scope.waiting = true;
|
|
|
|
$http.get("" + window.confPrefix + $scope.currentCfg.cfgNum + "/" + node.cnodes).then(function(response) {
|
|
|
|
var a, data, len, o;
|
|
|
|
data = response.data;
|
|
|
|
if (!data) {
|
|
|
|
d.reject('Empty response from server');
|
|
|
|
} else if (data.error) {
|
|
|
|
if (data.error.match(/setDefault$/)) {
|
|
|
|
if (node['default']) {
|
|
|
|
node.nodes = node['default'].slice(0);
|
|
|
|
} else {
|
|
|
|
node.nodes = [];
|
|
|
|
}
|
|
|
|
delete node.cnodes;
|
|
|
|
d.resolve('Set data to default value');
|
|
|
|
} else {
|
|
|
|
d.reject("Server return an error: " + data.error);
|
|
|
|
}
|
|
|
|
} else {
|
2015-05-14 08:44:38 +02:00
|
|
|
delete node.cnodes;
|
2016-03-14 23:22:09 +01:00
|
|
|
if (!node.type) {
|
|
|
|
node.type = 'keyTextContainer';
|
|
|
|
}
|
|
|
|
node.nodes = [];
|
|
|
|
for (o = 0, len = data.length; o < len; o++) {
|
|
|
|
a = data[o];
|
|
|
|
if (a.template) {
|
|
|
|
a._nodes = templates(a.template, a.title);
|
|
|
|
}
|
|
|
|
node.nodes.push(a);
|
|
|
|
}
|
|
|
|
d.resolve('OK');
|
|
|
|
}
|
|
|
|
return $scope.waiting = false;
|
|
|
|
}, function(response) {
|
|
|
|
readError(response);
|
|
|
|
return d.reject('');
|
|
|
|
});
|
|
|
|
return d.promise;
|
|
|
|
};
|
|
|
|
$scope.openCnode = function(scope) {
|
|
|
|
return $scope.download(scope).then(function() {
|
|
|
|
return scope.toggle();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
setHelp = function(scope) {
|
|
|
|
while (!scope.$modelValue.help && scope.$parentNodeScope) {
|
|
|
|
scope = scope.$parentNodeScope;
|
|
|
|
}
|
|
|
|
return $scope.helpUrl = scope.$modelValue.help || 'start.html#configuration';
|
|
|
|
};
|
|
|
|
$scope.displayForm = function(scope) {
|
|
|
|
var f, len, n, node, o, ref;
|
|
|
|
node = scope.$modelValue;
|
|
|
|
if (node.cnodes) {
|
|
|
|
$scope.download(scope);
|
|
|
|
}
|
|
|
|
if (node._nodes) {
|
|
|
|
$scope.stoggle(scope);
|
|
|
|
}
|
|
|
|
$scope.currentNode = node;
|
|
|
|
$scope.currentScope = scope;
|
|
|
|
f = node.type ? node.type : 'text';
|
|
|
|
if (node.nodes || node._nodes || node.cnodes) {
|
|
|
|
$scope.form = f !== 'text' ? f : 'mini';
|
2015-05-14 08:44:38 +02:00
|
|
|
} else {
|
2016-03-14 23:22:09 +01:00
|
|
|
$scope.form = f;
|
|
|
|
$scope.getKey(node);
|
|
|
|
}
|
|
|
|
if (node.type && node.type === 'simpleInputContainer') {
|
|
|
|
ref = node.nodes;
|
|
|
|
for (o = 0, len = ref.length; o < len; o++) {
|
|
|
|
n = ref[o];
|
|
|
|
$scope.getKey(n);
|
2015-05-14 08:44:38 +02:00
|
|
|
}
|
|
|
|
}
|
2016-03-14 23:22:09 +01:00
|
|
|
$scope.showT = false;
|
|
|
|
return setHelp(scope);
|
|
|
|
};
|
|
|
|
$scope.keyWritable = function(scope) {
|
|
|
|
var node;
|
|
|
|
node = scope.$modelValue;
|
2017-02-06 18:40:17 +01:00
|
|
|
if (node.type && node.type.match(/^(?:(?:saml(?:(?:ID|S)PMetaDataNod|Attribut)|(?:cmbMod|r)ul|authChoic)e|(?:virtualHos|keyTex)t|menu(?:App|Cat))$/)) {
|
2016-03-14 23:22:09 +01:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
$scope.newRSAKey = function() {
|
|
|
|
return $scope.showModal('password.html').then(function() {
|
|
|
|
var currentNode, password;
|
|
|
|
$scope.waiting = true;
|
|
|
|
currentNode = $scope.currentNode;
|
|
|
|
password = $scope.result;
|
|
|
|
return $http.post(window.confPrefix + "/newRSAKey", {
|
|
|
|
"password": password
|
|
|
|
}).then(function(response) {
|
|
|
|
currentNode.data[0].data = response.data["private"];
|
|
|
|
currentNode.data[1].data = password;
|
|
|
|
currentNode.data[2].data = response.data["public"];
|
|
|
|
return $scope.waiting = false;
|
|
|
|
}, readError);
|
|
|
|
}, function() {
|
|
|
|
return console.log('New key cancelled');
|
2015-05-14 08:44:38 +02:00
|
|
|
});
|
2016-03-14 23:22:09 +01:00
|
|
|
};
|
|
|
|
$scope.newRSAKeyNoPassword = function() {
|
|
|
|
var currentNode;
|
2015-05-14 08:44:38 +02:00
|
|
|
$scope.waiting = true;
|
2016-03-14 23:22:09 +01:00
|
|
|
currentNode = $scope.currentNode;
|
|
|
|
return $http.post(window.confPrefix + "/newRSAKey", {
|
|
|
|
"password": ''
|
2016-02-29 23:43:43 +01:00
|
|
|
}).then(function(response) {
|
2016-03-14 23:22:09 +01:00
|
|
|
currentNode.data[0].data = response.data["private"];
|
|
|
|
currentNode.data[1].data = response.data["public"];
|
|
|
|
return $scope.waiting = false;
|
|
|
|
}, readError);
|
|
|
|
};
|
|
|
|
$scope.getKey = function(node) {
|
|
|
|
var d, i, len, n, o, ref, tmp;
|
|
|
|
d = $q.defer();
|
|
|
|
if (!node.data) {
|
|
|
|
$scope.waiting = true;
|
|
|
|
if (node.get && typeof node.get === 'object') {
|
|
|
|
node.data = [];
|
|
|
|
tmp = [];
|
|
|
|
ref = node.get;
|
|
|
|
for (i = o = 0, len = ref.length; o < len; i = ++o) {
|
|
|
|
n = ref[i];
|
|
|
|
node.data[i] = {
|
|
|
|
title: n,
|
|
|
|
id: n
|
|
|
|
};
|
|
|
|
tmp.push($scope.getKey(node.data[i]));
|
|
|
|
}
|
|
|
|
$q.all(tmp).then(function() {
|
|
|
|
return d.resolve(node.data);
|
|
|
|
}, function(response) {
|
|
|
|
d.reject(response.statusLine);
|
|
|
|
return $scope.waiting = false;
|
2015-05-14 08:44:38 +02:00
|
|
|
});
|
2016-03-14 23:22:09 +01:00
|
|
|
} else {
|
|
|
|
$http.get("" + window.confPrefix + $scope.currentCfg.cfgNum + "/" + (node.get ? node.get : node.title)).then(function(response) {
|
|
|
|
var data;
|
|
|
|
data = response.data;
|
|
|
|
if ((data.value === null || (data.error && data.error.match(/setDefault$/))) && node['default'] !== null) {
|
|
|
|
node.data = node['default'];
|
|
|
|
} else {
|
|
|
|
node.data = data.value;
|
|
|
|
}
|
|
|
|
if (node.type && node.type.match(/^(int|bool|trool)$/)) {
|
|
|
|
node.data = parseInt(node.data);
|
|
|
|
} else if (node.type && node.type.match(/^(saml(Service|Assertion)|blackWhiteList)$/) && !(typeof node.data === 'object')) {
|
|
|
|
node.data = node.data.split(';');
|
|
|
|
}
|
|
|
|
$scope.waiting = false;
|
|
|
|
return d.resolve(node.data);
|
|
|
|
}, function(response) {
|
|
|
|
readError(response);
|
|
|
|
return d.reject(response.status);
|
|
|
|
});
|
|
|
|
}
|
2015-05-14 08:44:38 +02:00
|
|
|
} else {
|
2016-03-14 23:22:09 +01:00
|
|
|
d.resolve(node.data);
|
|
|
|
}
|
|
|
|
return d.promise;
|
|
|
|
};
|
|
|
|
pathEvent = function(event, next, current) {
|
|
|
|
var n;
|
|
|
|
n = next.match(new RegExp('#/confs/(latest|[0-9]+)'));
|
|
|
|
if (n === null) {
|
|
|
|
return $location.path('/confs/latest');
|
|
|
|
} else {
|
|
|
|
console.log("Trying to get cfg number " + n[1]);
|
|
|
|
return $scope.getCfg(n[1]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
$scope.$on('$locationChangeSuccess', pathEvent);
|
|
|
|
$scope.getCfg = function(n) {
|
|
|
|
if ($scope.currentCfg.cfgNum !== n) {
|
|
|
|
return $http.get("" + window.confPrefix + n).then(function(response) {
|
|
|
|
var d;
|
|
|
|
$scope.currentCfg = response.data;
|
|
|
|
d = new Date($scope.currentCfg.cfgDate * 1000);
|
|
|
|
$scope.currentCfg.date = d.toLocaleString();
|
|
|
|
console.log("Metadatas of cfg " + n + " loaded");
|
|
|
|
$location.path("/confs/" + n);
|
|
|
|
return $scope.init();
|
|
|
|
}, function(response) {
|
|
|
|
return readError(response).then(function() {
|
|
|
|
$scope.currentCfg.cfgNum = 0;
|
|
|
|
return $scope.init();
|
|
|
|
});
|
2015-05-14 08:44:38 +02:00
|
|
|
});
|
2016-03-14 23:22:09 +01:00
|
|
|
} else {
|
|
|
|
return $scope.waiting = false;
|
2015-05-14 08:44:38 +02:00
|
|
|
}
|
2016-03-14 23:22:09 +01:00
|
|
|
};
|
|
|
|
$scope.getLanguage = function(lang) {
|
|
|
|
$scope.lang = lang;
|
|
|
|
$scope.form = 'white';
|
|
|
|
$scope.init();
|
|
|
|
return $scope.showM = false;
|
|
|
|
};
|
|
|
|
$scope.init = function() {
|
|
|
|
var tmp;
|
|
|
|
tmp = null;
|
|
|
|
$scope.waiting = true;
|
|
|
|
$scope.data = [];
|
|
|
|
$scope.confirmNeeded = false;
|
|
|
|
$scope.forceSave = false;
|
|
|
|
return $q.all([
|
|
|
|
$translator.init($scope.lang), $http.get(window.staticPrefix + "struct.json").then(function(response) {
|
|
|
|
tmp = response.data;
|
|
|
|
return console.log("Structure loaded");
|
|
|
|
})
|
|
|
|
]).then(function() {
|
|
|
|
console.log("Starting structure binding");
|
|
|
|
$scope.data = tmp;
|
|
|
|
tmp = null;
|
|
|
|
if ($scope.currentCfg.cfgNum !== 0) {
|
|
|
|
setScopeVars($scope);
|
|
|
|
} else {
|
|
|
|
$scope.message = {
|
|
|
|
title: 'emptyConf',
|
|
|
|
message: '__zeroConfExplanations__'
|
|
|
|
};
|
|
|
|
$scope.showModal('message.html');
|
|
|
|
}
|
|
|
|
$scope.form = 'home';
|
2017-02-06 07:42:22 +01:00
|
|
|
return $scope.waiting = false;
|
2016-03-14 23:22:09 +01:00
|
|
|
}, readError);
|
|
|
|
};
|
|
|
|
c = $location.path().match(new RegExp('^/confs/(latest|[0-9]+)'));
|
|
|
|
if (!c) {
|
|
|
|
console.log("Redirecting to /confs/latest");
|
2015-05-14 08:44:38 +02:00
|
|
|
$location.path('/confs/latest');
|
|
|
|
}
|
2016-03-14 23:22:09 +01:00
|
|
|
$scope.replaceContentByUrl = function(node, url) {
|
|
|
|
$scope.waiting = true;
|
|
|
|
return $http.post(window.scriptname + "prx", {
|
|
|
|
url: url
|
|
|
|
}).then(function(response) {
|
|
|
|
node.data = response.data.content;
|
|
|
|
return $scope.waiting = false;
|
|
|
|
}, readError);
|
|
|
|
};
|
|
|
|
$scope.replaceContent = function(node, $fileContent) {
|
|
|
|
return node.data = $fileContent;
|
|
|
|
};
|
2017-01-18 00:17:23 +01:00
|
|
|
$scope.saveAs = function(content, type, filename) {
|
2016-03-14 23:22:09 +01:00
|
|
|
return saveAs(new Blob([content], {
|
|
|
|
"type": type
|
|
|
|
}), filename);
|
|
|
|
};
|
2017-01-18 00:17:23 +01:00
|
|
|
$scope.saveAsPem = function(cs, scope) {
|
|
|
|
return scope.saveAs(cs.data[0].data + "\n" + cs.data[2].data, 'application/x-pem-file', cs.title + ".pem");
|
|
|
|
};
|
|
|
|
return $scope.saveAsText = function(cs, scope) {
|
|
|
|
return scope.saveAs(cs.data, 'text/plain', cs.title + ".txt");
|
|
|
|
};
|
2016-01-04 23:22:20 +01:00
|
|
|
}
|
2016-03-14 23:22:09 +01:00
|
|
|
]);
|
2015-05-14 08:44:38 +02:00
|
|
|
|
2016-03-14 23:22:09 +01:00
|
|
|
}).call(this);
|