Projekt

Obecné

Profil

Stáhnout (9.05 KB) Statistiky
| Větev: | Tag: | Revize:
1
Vue.use(VueLoading);
2
Vue.component('loading', VueLoading)
3

    
4

    
5
var certificateDetailsApp = new Vue({
6
    el: "#certificate-detailed-view-content",
7
    data: {
8
        loading: true,
9
        error: false,
10
        id: null,
11
        displayIssuer: false,
12
        issuerLoaded: false,
13
        revocationReason: "unspecified",
14
        issuedCertificates: [],
15
        identityName: "",
16
        identityPass: "",
17
        certificate: {
18
            subject: {
19
                C: "",
20
                ST: "",
21
                L: "",
22
                CN: "",
23
                O: "",
24
                OU: "",
25
                emailAddress: "",
26
            },
27
            notBefore: "",
28
            notAfter: "",
29
            usage: {
30
                CA: false,
31
                authentication: false,
32
                digitalSignature: false,
33
                SSL: false,
34
            },
35
            CA: null,
36
            status: "",
37
        },
38
        issuer: {
39
            subject: {
40
                C: "",
41
                ST: "",
42
                L: "",
43
                CN: "",
44
                O: "",
45
                OU: "",
46
                emailAddress: "",
47
            },
48
            notBefore: "",
49
            notAfter: "",
50
            usage: {
51
                CA: false,
52
                authentication: false,
53
                digitalSignature: false,
54
                SSL: false,
55
            },
56
            CA: null,
57
            status: "",
58
        },
59
        errorMessage: "",
60
        successMessage: "",
61
    },
62
    computed: {
63
        startDate: function () {
64
            return this.certificate.notBefore.substr(0, 16);
65
        },
66
        endDate: function () {
67
            return this.certificate.notAfter.substr(0, 16);
68
        },
69
        issuerURL: function () {
70
            return "/static/certificate.html?id=" + this.certificate.CA;
71
        },
72
        crlEndpoint: function () {
73
            return "/api/crl/" + this.certificate.CA;
74
        },
75
        ocspEndpoint: function () {
76
            return "/api/ocsp/" + this.certificate.CA;
77
        }
78
    },
79
    watch: {},
80
    methods: {
81
        onShowIssuer: async function() {
82
            if (!this.issuerLoaded) {
83
                // query certificate details
84
                try {
85
                    const response = await axios.get(API_URL + "certificates/" + this.certificate.CA + "/details");
86
                    if (response.data["success"]) {
87
                        // display certificate
88
                        certificateDetailsApp.issuer = response.data["data"];
89
                        this.issuerLoaded = true;
90
                    } else {
91
                        // certificate does not exists
92
                        console.error(response.data["data"]);
93
                        this.errorMessage = "Error occurred while loading issuer's details.";
94
                    }
95
                } catch (error) {
96
                    console.error(error);
97
                    this.errorMessage = "Error occurred while loading issuer's details.";
98
                }
99
            }
100
            this.displayIssuer = ~this.displayIssuer;
101
        },
102
        onCertificateDownload: async function () {
103
            try {
104
                await onCertificateDownload(this.id);
105
            }
106
            catch (err) {
107
                this.errorMessage = err.message;
108
            }
109
        },
110
        onRootDownload: async function () {
111
            try {
112
                await onCertificateRootDownload(this.id);
113
            }
114
            catch (err) {
115
                this.errorMessage = err.message;
116
            }
117
        },
118
        onChainDownload: async function () {
119
            try {
120
                await onCertificateChainDownload(this.id);
121
            }
122
            catch (err) {
123
                this.errorMessage = err.message;
124
            }
125
        },
126
        onPublicKeyDownload: async function () {
127
            try {
128
                await onPublicKeyDownload(this.id);
129
            }
130
            catch (err) {
131
                this.errorMessage = err.message;
132
            }
133
        },
134
        onPrivateKeyDownload: async function () {
135
            try {
136
                await onPrivateKeyDownload(this.id);
137
            }
138
            catch (err) {
139
                this.errorMessage = err.message;
140
            }
141
        },
142
        onIdentityDownload: async function() {
143
            try {
144
                this.errorMessage = "";
145
                if (this.identityName === "") {
146
                    this.errorMessage = "Identity name must not be empty! Please try again.";
147
                    document.body.scrollTop = 0;
148
                    document.documentElement.scrollTop = 0;
149
                    return;
150
                }
151
                await onIdentityDownload(this.id, this.identityName, this.identityPass);
152
            } catch (err) {
153
                this.errorMessage = err.message;
154
            }
155
        },
156
        onRevoke: async function () {
157
            document.body.scrollTop = 0;
158
            document.documentElement.scrollTop = 0;
159
            try {
160
                const response = await axios.patch(API_URL + "certificates/" + this.id, {
161
                    status: "revoked",
162
                    reason: this.revocationReason
163
                });
164
                if (response.data["success"]) {
165
                    this.certificate.status="revoked";
166
                    certificateDetailsApp.successMessage = "Certificate revocation successful.";
167
                } else {
168
                    console.error(response.data["data"]);
169
                    certificateDetailsApp.errorMessage = "Certificate cannot be revoked - " + response.data["data"] + "!";
170
                }
171
            } catch (error) {
172
                console.error(error);
173
                certificateDetailsApp.errorMessage = "An error occurred while revoking certificate";
174
            }
175
        },
176
        onDelete: async function () {
177
            document.body.scrollTop = 0;
178
            document.documentElement.scrollTop = 0;
179
            try {
180
                const response = await axios.delete(API_URL + "certificates/" + this.id);
181
                if (response.data["success"]) {
182
                    window.location.href = "/static/index.html?success=Certificate+successfully+deleted";
183
                } else {
184
                    console.error(response.data["data"]);
185
                    certificateDetailsApp.errorMessage = "Certificate cannot be deleted - " + response.data["data"] + "!";
186
                }
187
            } catch (error) {
188
                console.error(error);
189
                certificateDetailsApp.errorMessage = "An error occurred while deleting certificate";
190
            }
191
        }
192
    },
193
    mounted: async function () {
194
        // get details of the selected certificate
195
        const params = window.location.search;
196
        if (params !== "") {
197
            // get requested ID
198
            const urlParams = new URLSearchParams(params);
199
            if (urlParams.get("id") != null) {
200
                const id = urlParams.get("id");
201
                this.id = id;
202
                var loadedDetails = false;
203
                // query certificate details
204
                try {
205
                    const response = await axios.get(API_URL + "certificates/" + id + "/details");
206
                    if (response.data["success"]) {
207
                        // display certificate
208
                        certificateDetailsApp.certificate = response.data["data"];
209
                        loadedDetails = true;
210
                    } else {
211
                        // certificate does not exists
212
                        console.error("Required certificate does not exists");
213
                        console.error(response.data["data"])
214
                        certificateDetailsApp.loading = false;
215
                        certificateDetailsApp.error = true;
216
                    }
217
                } catch (error) {
218
                    console.error(error);
219
                    certificateDetailsApp.loading = false;
220
                    certificateDetailsApp.error = true;
221
                }
222
            } else {
223
                // id was not provided as a URL parameter
224
                console.error("URL does not contain 'id' parameter")
225
                certificateDetailsApp.loading = false;
226
                certificateDetailsApp.error = true;
227
            }
228
        } else {
229
            console.error("URL does not contain 'id' parameter")
230
            certificateDetailsApp.loading = false;
231
            certificateDetailsApp.error = true;
232
        }
233

    
234
        if (!loadedDetails) return;
235
        try {
236
            const response = await axios.get(API_URL + "certificates", {
237
                params: {
238
                    filtering: {
239
                        issuedby: parseInt(certificateDetailsApp.id)
240
                    }
241
                }
242
            });
243
            if (response.data["success"]) {
244
                response.data["data"].forEach(item => {
245
                    if (item.id != certificateDetailsApp.id) certificateDetailsApp.issuedCertificates.push(item)
246
                })
247
            } else {
248
                certificateDetailsApp.issuedCertificates = [];
249
            }
250
        } catch (error) {
251
            console.error(error);
252
        }
253
        this.loading = false;
254
        this.error = false;
255
    }
256
});
257

    
258

    
(7-7/13)