Projekt

Obecné

Profil

Stáhnout (8.01 KB) Statistiky
| Větev: | Tag: | Revize:
1 d72b12cf Jan Pašek
Vue.use(VueLoading);
2
Vue.component('loading', VueLoading)
3 5885e489 Jan Pašek
4 7a423499 Jan Pašek
5 d72b12cf Jan Pašek
var certificateDetailsApp = new Vue({
6
    el: "#certificate-detailed-view-content",
7
    data: {
8
        loading: true,
9
        error: false,
10
        id: null,
11 e5640707 Jan Pašek
        displayIssuer: false,
12
        issuerLoaded: false,
13 d72b12cf Jan Pašek
        revocationReason: "unspecified",
14
        issuedCertificates: [],
15 76cd3805 Jan Pašek
        identityName: "",
16
        identityPass: "",
17 d72b12cf Jan Pašek
        certificate: {
18
            subject: {
19
                C: "",
20
                ST: "",
21
                L: "",
22
                CN: "",
23
                O: "",
24
                OU: "",
25
                emailAddress: "",
26 7a423499 Jan Pašek
            },
27 d72b12cf Jan Pašek
            notBefore: "",
28
            notAfter: "",
29
            usage: {
30
                CA: false,
31
                authentication: false,
32
                digitalSignature: false,
33
                SSL: false,
34 5f211e7b Jan Pašek
            },
35 d72b12cf Jan Pašek
            CA: null,
36 e5640707 Jan Pašek
            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 7a423499 Jan Pašek
        },
59 d72b12cf Jan Pašek
        errorMessage: "",
60
        successMessage: "",
61
    },
62
    computed: {
63
        startDate: function () {
64
            return this.certificate.notBefore.substr(0, 16);
65 7a423499 Jan Pašek
        },
66 d72b12cf Jan Pašek
        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 7a423499 Jan Pašek
        }
78 d72b12cf Jan Pašek
    },
79
    watch: {},
80
    methods: {
81 e5640707 Jan Pašek
        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("Required certificate does not exists");
93
                        this.showError("Error occurred while loading issuer's details.");
94
                    }
95
                } catch (error) {
96
                    console.error(error);
97
                    this.showError("Error occurred while loading issuer's details.");
98
                }
99
            }
100 aea56581 Jan Pašek
            this.displayIssuer = ~this.displayIssuer;
101 e5640707 Jan Pašek
        },
102 4a772c43 Jan Pašek
        onCertificateDownload: async function () {
103
            await onCertificateDownload(this.id);
104 d72b12cf Jan Pašek
        },
105 4a772c43 Jan Pašek
        onRootDownload: async function () {
106
            await onCertificateRootDownload(this.id);
107 d72b12cf Jan Pašek
        },
108 4a772c43 Jan Pašek
        onChainDownload: async function () {
109
            await onCertificateChainDownload(this.id);
110 d72b12cf Jan Pašek
        },
111 4a772c43 Jan Pašek
        onPublicKeyDownload: async function () {
112
            await onPublicKeyDownload(this.id);
113 d72b12cf Jan Pašek
        },
114 4a772c43 Jan Pašek
        onPrivateKeyDownload: async function () {
115
            await onPrivateKeyDownload(this.id);
116 d72b12cf Jan Pašek
        },
117 76cd3805 Jan Pašek
        onIdentityDownload: async function() {
118
            this.errorMessage = "";
119
            if (this.identityName === "") {
120
                this.errorMessage = "Identity name must not be empty! Please try again.";
121
                document.body.scrollTop = 0;
122
                document.documentElement.scrollTop = 0;
123
                return;
124
            }
125
            await onIdentityDownload(this.id, this.identityName, this.identityPass);
126
        },
127 4a772c43 Jan Pašek
        onRevoke: async function () {
128 d72b12cf Jan Pašek
            document.body.scrollTop = 0;
129
            document.documentElement.scrollTop = 0;
130 4a772c43 Jan Pašek
            try {
131
                const response = await axios.patch(API_URL + "certificates/" + this.id, {
132
                    status: "revoked",
133
                    reason: this.revocationReason
134 d72b12cf Jan Pašek
                });
135 4a772c43 Jan Pašek
                if (response.data["success"]) {
136
                    certificateDetailsApp.successMessage = "Certificate revocation successful.";
137
                } else {
138
                    certificateDetailsApp.errorMessage = "Certificate cannot be revoked - " + response.data["data"] + "!";
139
                }
140
            } catch (error) {
141
                certificateDetailsApp.errorMessage = "An error occurred while revoking certificate";
142
            }
143 d72b12cf Jan Pašek
        },
144 4a772c43 Jan Pašek
        onDelete: async function () {
145 d72b12cf Jan Pašek
            document.body.scrollTop = 0;
146
            document.documentElement.scrollTop = 0;
147 4a772c43 Jan Pašek
            try {
148
                const response = await axios.delete(API_URL + "certificates/" + this.id);
149
                if (response.data["success"]) {
150
                    window.location.href = "/static/index.html?success=Certificate+successfully+deleted";
151
                } else {
152
                    certificateDetailsApp.errorMessage = "Certificate cannot be deleted - " + response.data["data"] + "!";
153
                }
154
            } catch (error) {
155
                certificateDetailsApp.errorMessage = "An error occurred while deleting certificate";
156
            }
157 d72b12cf Jan Pašek
        }
158
    },
159 4a772c43 Jan Pašek
    mounted: async function () {
160 d72b12cf Jan Pašek
        // get details of the selected certificate
161
        const params = window.location.search;
162
        if (params !== "") {
163
            // get requested ID
164
            const urlParams = new URLSearchParams(params);
165
            if (urlParams.get("id") != null) {
166
                const id = urlParams.get("id");
167
                this.id = id;
168 4a772c43 Jan Pašek
                var loadedDetails = false;
169 d72b12cf Jan Pašek
                // query certificate details
170 4a772c43 Jan Pašek
                try {
171
                    const response = await axios.get(API_URL + "certificates/" + id + "/details");
172
                    if (response.data["success"]) {
173
                        // display certificate
174
                        certificateDetailsApp.certificate = response.data["data"];
175
                        loadedDetails = true;
176
                    } else {
177
                        // certificate does not exists
178
                        console.error("Required certificate does not exists");
179 d72b12cf Jan Pašek
                        certificateDetailsApp.loading = false;
180
                        certificateDetailsApp.error = true;
181 4a772c43 Jan Pašek
                    }
182
                } catch (error) {
183
                    console.error(error);
184
                    certificateDetailsApp.loading = false;
185
                    certificateDetailsApp.error = true;
186
                }
187 d72b12cf Jan Pašek
            } else {
188
                // id was not provided as a URL parameter
189
                console.error("URL does not contain 'id' parameter")
190
                certificateDetailsApp.loading = false;
191
                certificateDetailsApp.error = true;
192
            }
193 7a423499 Jan Pašek
        } else {
194 5885e489 Jan Pašek
            console.error("URL does not contain 'id' parameter")
195
            certificateDetailsApp.loading = false;
196
            certificateDetailsApp.error = true;
197 7a423499 Jan Pašek
        }
198 4a772c43 Jan Pašek
199
        if (!loadedDetails) return;
200
        try {
201
            const response = await axios.get(API_URL + "certificates", {
202
                params: {
203
                    filtering: {
204
                        issuedby: parseInt(certificateDetailsApp.id)
205
                    }
206
                }
207
            });
208
            if (response.data["success"]) {
209
                response.data["data"].forEach(item => {
210
                    if (item.id != certificateDetailsApp.id) certificateDetailsApp.issuedCertificates.push(item)
211
                })
212
            } else {
213
                certificateDetailsApp.issuedCertificates = [];
214
            }
215
        } catch (error) {
216
            console.log(error);
217
        }
218
        this.loading = false;
219
        this.error = false;
220 5885e489 Jan Pašek
    }
221 d72b12cf Jan Pašek
});
222