Projekt

Obecné

Profil

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