Revize d72b12cf
Přidáno uživatelem Jan Pašek před téměř 4 roky(ů)
static/js/certificate.js | ||
---|---|---|
1 |
Vue.use(VueLoading);
|
|
2 |
Vue.component('loading', VueLoading)
|
|
1 |
Vue.use(VueLoading); |
|
2 |
Vue.component('loading', VueLoading) |
|
3 | 3 |
|
4 | 4 |
|
5 |
var certificateDetailsApp = new Vue({ |
|
6 |
el: "#certificate-detailed-view-content", |
|
7 |
data: { |
|
8 |
loading: true, |
|
9 |
error: false, |
|
10 |
id: null, |
|
11 |
revocationReason: "unspecified", |
|
12 |
issuedCertificates: [], |
|
13 |
certificate: { |
|
14 |
subject: { |
|
15 |
C: "", |
|
16 |
ST: "", |
|
17 |
L: "", |
|
18 |
CN: "", |
|
19 |
O: "", |
|
20 |
OU: "", |
|
21 |
emailAddress: "", |
|
22 |
}, |
|
23 |
notBefore: "", |
|
24 |
notAfter: "", |
|
25 |
usage: { |
|
26 |
CA: false, |
|
27 |
authentication: false, |
|
28 |
digitalSignature: false, |
|
29 |
SSL: false, |
|
30 |
}, |
|
31 |
CA: null, |
|
5 |
var certificateDetailsApp = new Vue({ |
|
6 |
el: "#certificate-detailed-view-content", |
|
7 |
data: { |
|
8 |
loading: true, |
|
9 |
error: false, |
|
10 |
id: null, |
|
11 |
revocationReason: "unspecified", |
|
12 |
issuedCertificates: [], |
|
13 |
certificate: { |
|
14 |
subject: { |
|
15 |
C: "", |
|
16 |
ST: "", |
|
17 |
L: "", |
|
18 |
CN: "", |
|
19 |
O: "", |
|
20 |
OU: "", |
|
21 |
emailAddress: "", |
|
32 | 22 |
}, |
33 |
errorMessage: "", |
|
34 |
successMessage: "", |
|
35 |
}, |
|
36 |
computed: { |
|
37 |
startDate: function () { |
|
38 |
return this.certificate.notBefore.substr(0, 16); |
|
39 |
}, |
|
40 |
endDate: function () { |
|
41 |
return this.certificate.notAfter.substr(0, 16); |
|
42 |
}, |
|
43 |
issuerURL: function () { |
|
44 |
return "/static/certificate.html?id=" + this.certificate.CA; |
|
45 |
}, |
|
46 |
crlEndpoint: function () { |
|
47 |
return "/api/crl/" + this.certificate.CA; |
|
23 |
notBefore: "", |
|
24 |
notAfter: "", |
|
25 |
usage: { |
|
26 |
CA: false, |
|
27 |
authentication: false, |
|
28 |
digitalSignature: false, |
|
29 |
SSL: false, |
|
48 | 30 |
}, |
49 |
ocspEndpoint: function () { |
|
50 |
return "/api/ocsp/" + this.certificate.CA; |
|
51 |
} |
|
31 |
CA: null, |
|
52 | 32 |
}, |
53 |
watch: { |
|
54 |
|
|
33 |
errorMessage: "", |
|
34 |
successMessage: "", |
|
35 |
}, |
|
36 |
computed: { |
|
37 |
startDate: function () { |
|
38 |
return this.certificate.notBefore.substr(0, 16); |
|
55 | 39 |
}, |
56 |
methods: { |
|
57 |
onCertificateDownload: function () { |
|
58 |
onCertificateDownload(this.id); |
|
59 |
}, |
|
60 |
onRootDownload: function () { |
|
61 |
onCertificateRootDownload(this.id); |
|
62 |
}, |
|
63 |
onChainDownload: function () { |
|
64 |
onCertificateChainDownload(this.id); |
|
65 |
}, |
|
66 |
onPublicKeyDownload: function () { |
|
67 |
onPublicKeyDownload(this.id); |
|
68 |
}, |
|
69 |
onPrivateKeyDownload: function () { |
|
70 |
onPrivateKeyDownload(this.id); |
|
71 |
}, |
|
72 |
onRevoke: function () { |
|
73 |
document.body.scrollTop = 0; |
|
74 |
document.documentElement.scrollTop = 0; |
|
75 |
axios.patch(API_URL + "certificates/"+this.id, { |
|
76 |
status: "revoked", |
|
77 |
reason: this.revocationReason |
|
78 |
}) |
|
79 |
.then(function (response) { |
|
80 |
if(response.data["success"]) { |
|
81 |
certificateDetailsApp.successMessage = "Certificate revocation successful."; |
|
82 |
} |
|
83 |
else { |
|
84 |
certificateDetailsApp.errorMessage = "Certificate cannot be revoked - "+response.data["data"]+"!"; |
|
85 |
} |
|
86 |
}) |
|
87 |
.catch(function (error) { |
|
88 |
certificateDetailsApp.errorMessage = "An error occurred while revoking certificate"; |
|
89 |
}); |
|
90 |
}, |
|
91 |
onDelete: function () { |
|
92 |
document.body.scrollTop = 0; |
|
93 |
document.documentElement.scrollTop = 0; |
|
94 |
axios.delete(API_URL + "certificates/" + this.id) |
|
95 |
.then(function (response) { |
|
96 |
if(response.data["success"]){ |
|
97 |
window.location.href = "/static/index.html?success=Certificate+successfully+deleted"; |
|
98 |
} |
|
99 |
else { |
|
100 |
certificateDetailsApp.errorMessage = "Certificate cannot be deleted - "+response.data["data"]+"!"; |
|
101 |
} |
|
102 |
}) |
|
103 |
.catch(function (error) { |
|
104 |
certificateDetailsApp.errorMessage = "An error occurred while deleting certificate"; |
|
105 |
}); |
|
106 |
} |
|
40 |
endDate: function () { |
|
41 |
return this.certificate.notAfter.substr(0, 16); |
|
42 |
}, |
|
43 |
issuerURL: function () { |
|
44 |
return "/static/certificate.html?id=" + this.certificate.CA; |
|
45 |
}, |
|
46 |
crlEndpoint: function () { |
|
47 |
return "/api/crl/" + this.certificate.CA; |
|
48 |
}, |
|
49 |
ocspEndpoint: function () { |
|
50 |
return "/api/ocsp/" + this.certificate.CA; |
|
107 | 51 |
} |
108 |
}); |
|
109 |
|
|
110 |
// get details of the selected certificate |
|
111 |
const params = window.location.search; |
|
112 |
if (params !== "") { |
|
113 |
// get requested ID |
|
114 |
const urlParams = new URLSearchParams(params); |
|
115 |
if (urlParams.get("id") != null) { |
|
116 |
const id = urlParams.get("id"); |
|
117 |
certificateDetailsApp.id = id; |
|
118 |
// query certificate details |
|
119 |
axios.get(API_URL + "certificates/"+id+"/details") |
|
52 |
}, |
|
53 |
watch: {}, |
|
54 |
methods: { |
|
55 |
onCertificateDownload: function () { |
|
56 |
onCertificateDownload(this.id); |
|
57 |
}, |
|
58 |
onRootDownload: function () { |
|
59 |
onCertificateRootDownload(this.id); |
|
60 |
}, |
|
61 |
onChainDownload: function () { |
|
62 |
onCertificateChainDownload(this.id); |
|
63 |
}, |
|
64 |
onPublicKeyDownload: function () { |
|
65 |
onPublicKeyDownload(this.id); |
|
66 |
}, |
|
67 |
onPrivateKeyDownload: function () { |
|
68 |
onPrivateKeyDownload(this.id); |
|
69 |
}, |
|
70 |
onRevoke: function () { |
|
71 |
document.body.scrollTop = 0; |
|
72 |
document.documentElement.scrollTop = 0; |
|
73 |
axios.patch(API_URL + "certificates/" + this.id, { |
|
74 |
status: "revoked", |
|
75 |
reason: this.revocationReason |
|
76 |
}) |
|
120 | 77 |
.then(function (response) { |
121 | 78 |
if (response.data["success"]) { |
122 |
// display certificate |
|
123 |
certificateDetailsApp.certificate = response.data["data"]; |
|
124 |
loadIssuedCertificates(); |
|
125 |
certificateDetailsApp.loading = false; |
|
126 |
certificateDetailsApp.error = false; |
|
79 |
certificateDetailsApp.successMessage = "Certificate revocation successful."; |
|
80 |
} else { |
|
81 |
certificateDetailsApp.errorMessage = "Certificate cannot be revoked - " + response.data["data"] + "!"; |
|
127 | 82 |
} |
128 |
else { |
|
129 |
// certificate does not exists |
|
130 |
console.error("Required certificate does not exists"); |
|
131 |
certificateDetailsApp.loading = false; |
|
132 |
certificateDetailsApp.error = true; |
|
83 |
}) |
|
84 |
.catch(function (error) { |
|
85 |
certificateDetailsApp.errorMessage = "An error occurred while revoking certificate"; |
|
86 |
}); |
|
87 |
}, |
|
88 |
onDelete: function () { |
|
89 |
document.body.scrollTop = 0; |
|
90 |
document.documentElement.scrollTop = 0; |
|
91 |
axios.delete(API_URL + "certificates/" + this.id) |
|
92 |
.then(function (response) { |
|
93 |
if (response.data["success"]) { |
|
94 |
window.location.href = "/static/index.html?success=Certificate+successfully+deleted"; |
|
95 |
} else { |
|
96 |
certificateDetailsApp.errorMessage = "Certificate cannot be deleted - " + response.data["data"] + "!"; |
|
133 | 97 |
} |
134 | 98 |
}) |
135 | 99 |
.catch(function (error) { |
136 |
// server error |
|
137 |
console.error(error); |
|
138 |
certificateDetailsApp.loading = false; |
|
139 |
certificateDetailsApp.error = true; |
|
100 |
certificateDetailsApp.errorMessage = "An error occurred while deleting certificate"; |
|
140 | 101 |
}); |
102 |
}, |
|
103 |
loadIssuedCertificates: function () { |
|
104 |
|
|
105 |
} |
|
106 |
}, |
|
107 |
mounted: function () { |
|
108 |
// get details of the selected certificate |
|
109 |
const params = window.location.search; |
|
110 |
if (params !== "") { |
|
111 |
// get requested ID |
|
112 |
const urlParams = new URLSearchParams(params); |
|
113 |
if (urlParams.get("id") != null) { |
|
114 |
const id = urlParams.get("id"); |
|
115 |
this.id = id; |
|
116 |
// query certificate details |
|
117 |
axios.get(API_URL + "certificates/" + id + "/details") |
|
118 |
.then(function (response) { |
|
119 |
if (response.data["success"]) { |
|
120 |
// display certificate |
|
121 |
certificateDetailsApp.certificate = response.data["data"]; |
|
122 |
axios.get(API_URL + "certificates", { |
|
123 |
params: { |
|
124 |
filtering: { |
|
125 |
issuedby: parseInt(certificateDetailsApp.id) |
|
126 |
} |
|
127 |
} |
|
128 |
}) |
|
129 |
.then(function (response) { |
|
130 |
if (response.data["success"]) { |
|
131 |
response.data["data"].forEach(item => { |
|
132 |
if (item.id != certificateDetailsApp.id) certificateDetailsApp.issuedCertificates.push(item) |
|
133 |
}) |
|
134 |
} else { |
|
135 |
certificateDetailsApp.issuedCertificates = []; |
|
136 |
} |
|
137 |
}) |
|
138 |
.catch(function (error) { |
|
139 |
console.log(error); |
|
140 |
}); |
|
141 |
certificateDetailsApp.loading = false; |
|
142 |
certificateDetailsApp.error = false; |
|
143 |
} else { |
|
144 |
// certificate does not exists |
|
145 |
console.error("Required certificate does not exists"); |
|
146 |
certificateDetailsApp.loading = false; |
|
147 |
certificateDetailsApp.error = true; |
|
148 |
} |
|
149 |
}) |
|
150 |
.catch(function (error) { |
|
151 |
// server error |
|
152 |
console.error(error); |
|
153 |
certificateDetailsApp.loading = false; |
|
154 |
certificateDetailsApp.error = true; |
|
155 |
}); |
|
156 |
} else { |
|
157 |
// id was not provided as a URL parameter |
|
158 |
console.error("URL does not contain 'id' parameter") |
|
159 |
certificateDetailsApp.loading = false; |
|
160 |
certificateDetailsApp.error = true; |
|
161 |
} |
|
141 | 162 |
} else { |
142 |
// id was not provided as a URL parameter |
|
143 | 163 |
console.error("URL does not contain 'id' parameter") |
144 | 164 |
certificateDetailsApp.loading = false; |
145 | 165 |
certificateDetailsApp.error = true; |
146 | 166 |
} |
147 |
} else { |
|
148 |
console.error("URL does not contain 'id' parameter") |
|
149 |
certificateDetailsApp.loading = false; |
|
150 |
certificateDetailsApp.error = true; |
|
151 | 167 |
} |
168 |
}); |
|
169 |
|
|
152 | 170 |
|
153 |
function loadIssuedCertificates() { |
|
154 |
axios.get(API_URL+"certificates", { |
|
155 |
params: { |
|
156 |
filtering: { |
|
157 |
issuedby: parseInt(certificateDetailsApp.id) |
|
158 |
} |
|
159 |
} |
|
160 |
}) |
|
161 |
.then(function (response) { |
|
162 |
if (response.data["success"]) { |
|
163 |
response.data["data"].forEach(item => {if(item.id != certificateDetailsApp.id) certificateDetailsApp.issuedCertificates.push(item)}) |
|
164 |
} |
|
165 |
else |
|
166 |
{ |
|
167 |
certificateDetailsApp.issuedCertificates = []; |
|
168 |
} |
|
169 |
}) |
|
170 |
.catch(function (error) { |
|
171 |
console.log(error); |
|
172 |
}); |
|
173 |
} |
Také k dispozici: Unified diff
Re #8583 - certificate.js moved initialization code to mounted