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