Introducing new PKI management
This commit is contained in:
parent
5b558bcf00
commit
c118035c33
19 changed files with 857 additions and 53 deletions
|
@ -17,6 +17,10 @@ angular.module("FICApp", ["ngRoute", "ngResource", "ngSanitize"])
|
|||
controller: "SettingsController",
|
||||
templateUrl: "views/settings.html"
|
||||
})
|
||||
.when("/pki", {
|
||||
controller: "PKIController",
|
||||
templateUrl: "views/pki.html"
|
||||
})
|
||||
.when("/exercices", {
|
||||
controller: "AllExercicesListController",
|
||||
templateUrl: "views/exercice-list.html"
|
||||
|
@ -132,6 +136,14 @@ angular.module("FICApp")
|
|||
'update': {method: 'PUT'},
|
||||
})
|
||||
})
|
||||
.factory("Certificate", function($resource) {
|
||||
return $resource("/api/certs/:serial", { serial: '@id' }, {
|
||||
'update': {method: 'PUT'},
|
||||
})
|
||||
})
|
||||
.factory("CACertificate", function($resource) {
|
||||
return $resource("/api/ca/:serial", { serial: '@id' })
|
||||
})
|
||||
.factory("File", function($resource) {
|
||||
return $resource("/api/files/:fileId", { fileId: '@id' })
|
||||
})
|
||||
|
@ -153,6 +165,9 @@ angular.module("FICApp")
|
|||
'update': {method: 'PUT'},
|
||||
})
|
||||
})
|
||||
.factory("TeamCertificate", function($resource) {
|
||||
return $resource("/api/teams/:teamId/certificates", { teamId: '@id' })
|
||||
})
|
||||
.factory("TeamMember", function($resource) {
|
||||
return $resource("/api/teams/:teamId/members", { teamId: '@id' }, {
|
||||
'save': {method: 'PUT'},
|
||||
|
@ -451,6 +466,56 @@ angular.module("FICApp")
|
|||
};
|
||||
})
|
||||
|
||||
.controller("PKIController", function($scope, $rootScope, Certificate, CACertificate, Team, $location, $http) {
|
||||
$scope.teams = Team.query();
|
||||
$scope.certificates = Certificate.query();
|
||||
$scope.ca = CACertificate.get();
|
||||
|
||||
$scope.revoke = function() {
|
||||
var targetserial = $("#revokeModal").data("certificate");
|
||||
if (targetserial) {
|
||||
Certificate.delete({ serial: targetserial }).$promise.then(
|
||||
function() {
|
||||
$('#revokeModal').modal('hide');
|
||||
$scope.certificates = Certificate.query();
|
||||
}, function(response) {
|
||||
$rootScope.newBox('danger', 'An error occurs when trying to associate certificate:', response.data);
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
$scope.associate = function() {
|
||||
var targetserial = $("#associationModal").data("certificate");
|
||||
if (!targetserial) return;
|
||||
Certificate.update({ serial: targetserial }, { id_team: $scope.selectedTeam }).$promise.then(
|
||||
function() {
|
||||
$('#associationModal').modal('hide');
|
||||
$scope.certificates = Certificate.query();
|
||||
$scope.selectedTeam = null;
|
||||
}, function(response) {
|
||||
$rootScope.newBox('danger', 'An error occurs when trying to associate certificate:', response.data);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
$scope.generateCA = function() {
|
||||
$http.post("/api/ca/new").then(function() {
|
||||
$scope.ca = CACertificate.get();
|
||||
}, function(response) {
|
||||
$rootScope.newBox('danger', 'An error occurs when generating CA:', response.data);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.generateCert = function() {
|
||||
$http.post("/api/certs").then(function() {
|
||||
$scope.certificates = Certificate.query();
|
||||
}, function(response) {
|
||||
$rootScope.newBox('danger', 'An error occurs when generating certificate:', response.data);
|
||||
});
|
||||
};
|
||||
})
|
||||
|
||||
.controller("PublicController", function($scope, $rootScope, $routeParams, $location, Scene, Theme, Teams, Exercice) {
|
||||
$scope.screens = [0,1,2,3,4,5,6,7,8,9];
|
||||
$scope.screenid = $routeParams.screenId;
|
||||
|
@ -1068,47 +1133,26 @@ angular.module("FICApp")
|
|||
}
|
||||
}
|
||||
})
|
||||
.controller("TeamController", function($scope, $rootScope, $location, Team, TeamMember, $routeParams, $http) {
|
||||
.controller("TeamController", function($scope, $rootScope, $location, Team, TeamMember, TeamCertificate, $routeParams, $http) {
|
||||
if ($scope.team && $scope.team.id)
|
||||
$routeParams.teamId = $scope.team.id;
|
||||
$scope.team = Team.get({ teamId: $routeParams.teamId });
|
||||
$scope.fields = ["name", "color"];
|
||||
|
||||
$scope.hasCertificate = false;
|
||||
$http({
|
||||
url: "/api/teams/" + Math.floor($routeParams.teamId) + "/certificate.p12",
|
||||
method: "HEAD",
|
||||
transformResponse: null
|
||||
}).then(function(response) {
|
||||
$scope.hasCertificate = true;
|
||||
}, function(response) {
|
||||
$scope.hasCertificate = false;
|
||||
});
|
||||
$scope.certificates = TeamCertificate.query({ teamId: $routeParams.teamId });
|
||||
|
||||
$scope.generateCertificate = function() {
|
||||
$scope.dissociateCertificate = function(certificate) {
|
||||
$http({
|
||||
url: "/api/teams/" + Math.floor($routeParams.teamId) + "/certificate/generate",
|
||||
method: "POST",
|
||||
transformResponse: null
|
||||
url: "/api/certs/" + certificate.id,
|
||||
method: "PUT",
|
||||
data: {
|
||||
id_team: null
|
||||
}
|
||||
}).then(function(response) {
|
||||
$scope.hasCertificate = true;
|
||||
$rootScope.newBox('success', 'Team certificate successfully generated!');
|
||||
$scope.certificates = TeamCertificate.query({ teamId: $routeParams.teamId });
|
||||
$rootScope.newBox('success', 'Certificate successfully dissociated!');
|
||||
}, function(response) {
|
||||
$rootScope.newBox('danger', 'An error occurs when generating certiticate:', response.data);
|
||||
});
|
||||
}
|
||||
$scope.revokeCertificate = function() {
|
||||
if (!confirm("Are you sure you want to revoke this certificate?"))
|
||||
return false;
|
||||
|
||||
$http({
|
||||
url: "/api/teams/" + Math.floor($routeParams.teamId) + "/certificate.p12",
|
||||
method: "DELETE",
|
||||
transformResponse: null
|
||||
}).then(function(response) {
|
||||
$scope.hasCertificate = false;
|
||||
}, function(response) {
|
||||
$rootScope.newBox('danger', 'An error occurs when revoking the certiticate:', response.data);
|
||||
$rootScope.newBox('danger', 'An error occurs when dissociating certiticate:', response.data);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue