1
|
Vue.use(VueLoading);
|
2
|
Vue.component('loading', VueLoading)
|
3
|
|
4
|
// certificate listing app VUE instance
|
5
|
var certificateListingApp = new Vue({
|
6
|
el: "#certificateListingPage",
|
7
|
data: {
|
8
|
certificatesPerPage: 20,
|
9
|
hasNextPage: false,
|
10
|
hasPreviousPage: false,
|
11
|
currentPage: 1,
|
12
|
displayFilters: false,
|
13
|
loading: true,
|
14
|
// list of all certificates to be displayed in the list
|
15
|
certificates: [],
|
16
|
successMessage: '',
|
17
|
filtering: {
|
18
|
type: {
|
19
|
RootCA: false,
|
20
|
IntermediateCA: false,
|
21
|
EndCertificate: false,
|
22
|
},
|
23
|
usage: {
|
24
|
CA: false,
|
25
|
authentication: false,
|
26
|
digitalSignature: false,
|
27
|
SSL: false,
|
28
|
},
|
29
|
CN: "",
|
30
|
}
|
31
|
},
|
32
|
methods: {
|
33
|
onNextPage: async function () {
|
34
|
this.currentPage++;
|
35
|
await this.loadPage(this.currentPage, this.certificatesPerPage);
|
36
|
},
|
37
|
reloadData: async function() {
|
38
|
await this.loadPage(this.currentPage, this.certificatesPerPage);
|
39
|
},
|
40
|
onPreviousPage: async function () {
|
41
|
this.currentPage--;
|
42
|
await this.loadPage(this.currentPage, this.certificatesPerPage);
|
43
|
},
|
44
|
loadPage: async function (page, perPage) {
|
45
|
// download a list of all available certificates and display them in the table
|
46
|
this.errorMessage = "";
|
47
|
try {
|
48
|
var params = {
|
49
|
page: page - 1,
|
50
|
per_page: perPage
|
51
|
};
|
52
|
var filtering = this.getFilterParameter();
|
53
|
if (filtering != null) params.filtering = filtering;
|
54
|
const response = await axios.get(API_URL + "certificates", {
|
55
|
params: params
|
56
|
});
|
57
|
if (response.data["success"]) {
|
58
|
this.certificates = [];
|
59
|
response.data["data"].forEach(item => certificateListingApp.certificates.push(item));
|
60
|
this.hasPreviousPage = page > 1;
|
61
|
this.hasNextPage = await this.checkIfNextPage(page, this.certificatesPerPage);
|
62
|
}
|
63
|
else {
|
64
|
this.errorMessage = "Error occurred while loading certificate page.";
|
65
|
console.error(response.data["data"]);
|
66
|
}
|
67
|
} catch (error) {
|
68
|
this.errorMessage = "Error occurred while loading certificate page.";
|
69
|
console.log(error);
|
70
|
}
|
71
|
},
|
72
|
getFilterParameter: function () {
|
73
|
var type = [];
|
74
|
if (this.filtering.type.EndCertificate) type.push("end");
|
75
|
if (this.filtering.type.RootCA) type.push("root");
|
76
|
if (this.filtering.type.IntermediateCA) type.push("inter");
|
77
|
|
78
|
var usage = [];
|
79
|
if (this.filtering.usage.CA) usage.push("CA");
|
80
|
if (this.filtering.usage.SSL) usage.push("SSL");
|
81
|
if (this.filtering.usage.digitalSignature) usage.push("digitalSignature");
|
82
|
if (this.filtering.usage.authentication) usage.push("authentication");
|
83
|
|
84
|
var filtering = {};
|
85
|
if (usage.length > 0) filtering.usage = usage;
|
86
|
if (type.length > 0) filtering.type = type;
|
87
|
|
88
|
if (this.filtering.CN.length > 0) filtering.CN = this.filtering.CN;
|
89
|
|
90
|
if (this.filtering.hasOwnProperty("type") ||
|
91
|
this.filtering.hasOwnProperty("usage") ||
|
92
|
this.filtering.hasOwnProperty("CN"))
|
93
|
return filtering;
|
94
|
else
|
95
|
return null;
|
96
|
},
|
97
|
toggleFilters: function (){
|
98
|
this.displayFilters = ~this.displayFilters;
|
99
|
},
|
100
|
clearFilters: async function () {
|
101
|
this.filtering = {
|
102
|
type: {
|
103
|
RootCA: false,
|
104
|
IntermediateCA: false,
|
105
|
EndCertificate: false,
|
106
|
},
|
107
|
usage: {
|
108
|
CA: false,
|
109
|
authentication: false,
|
110
|
digitalSignature: false,
|
111
|
SSL: false,
|
112
|
},
|
113
|
CN: "",
|
114
|
}
|
115
|
await this.reloadData();
|
116
|
},
|
117
|
checkIfNextPage: async function(page, perPage) {
|
118
|
try {
|
119
|
const response = await axios.get(API_URL + "certificates", {
|
120
|
params: {
|
121
|
page: page,
|
122
|
per_page: perPage
|
123
|
}
|
124
|
});
|
125
|
if (response.data["success"]) {
|
126
|
return response.data["data"].length > 0;
|
127
|
}
|
128
|
this.errorMessage = "Error occurred while loading certificate page.";
|
129
|
return false;
|
130
|
} catch (error) {
|
131
|
this.errorMessage = "Error occurred while loading certificate page.";
|
132
|
console.error(error);
|
133
|
return false;
|
134
|
}
|
135
|
}
|
136
|
},
|
137
|
mounted: async function () {
|
138
|
const params = window.location.search;
|
139
|
if (params !== "") {
|
140
|
const urlParams = new URLSearchParams(params);
|
141
|
if (urlParams.get("success") != null) this.successMessage = urlParams.get("success");
|
142
|
|
143
|
// the following code is necessary to dismiss the alert when the page is reloaded
|
144
|
const nextURL = '/static/index.html';
|
145
|
const nextTitle = 'X.509 Certificate Management';
|
146
|
const nextState = {additionalInformation: 'Updated the URL with JS'};
|
147
|
|
148
|
// This will create a new entry in the browser's history, without reloading
|
149
|
window.history.pushState(nextState, nextTitle, nextURL);
|
150
|
|
151
|
// This will replace the current entry in the browser's history, without reloading
|
152
|
window.history.replaceState(nextState, nextTitle, nextURL);
|
153
|
}
|
154
|
|
155
|
// download a list of all available certificates and display them in the table
|
156
|
await this.loadPage(1, this.certificatesPerPage);
|
157
|
this.loading = false;
|
158
|
}
|
159
|
});
|