Projekt

Obecné

Profil

Stáhnout (7.51 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
        certificate: {
16
            subject: {
17
                C: "",
18
                ST: "",
19
                L: "",
20
                CN: "",
21
                O: "",
22
                OU: "",
23
                emailAddress: "",
24
            },
25
            notBefore: "",
26
            notAfter: "",
27
            usage: {
28
                CA: false,
29
                authentication: false,
30
                digitalSignature: false,
31
                SSL: false,
32
            },
33
            CA: null,
34
            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
        },
57
        errorMessage: "",
58
        successMessage: "",
59
    },
60
    computed: {
61
        startDate: function () {
62
            return this.certificate.notBefore.substr(0, 16);
63
        },
64
        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
        }
76
    },
77
    watch: {},
78
    methods: {
79
        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
            this.displayIssuer = ~this.displayIssuer;
99
        },
100
        onCertificateDownload: async function () {
101
            await onCertificateDownload(this.id);
102
        },
103
        onRootDownload: async function () {
104
            await onCertificateRootDownload(this.id);
105
        },
106
        onChainDownload: async function () {
107
            await onCertificateChainDownload(this.id);
108
        },
109
        onPublicKeyDownload: async function () {
110
            await onPublicKeyDownload(this.id);
111
        },
112
        onPrivateKeyDownload: async function () {
113
            await onPrivateKeyDownload(this.id);
114
        },
115
        onRevoke: async function () {
116
            document.body.scrollTop = 0;
117
            document.documentElement.scrollTop = 0;
118
            try {
119
                const response = await axios.patch(API_URL + "certificates/" + this.id, {
120
                    status: "revoked",
121
                    reason: this.revocationReason
122
                });
123
                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
        },
132
        onDelete: async function () {
133
            document.body.scrollTop = 0;
134
            document.documentElement.scrollTop = 0;
135
            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
        }
146
    },
147
    mounted: async function () {
148
        // 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
                var loadedDetails = false;
157
                // query certificate details
158
                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
                        certificateDetailsApp.loading = false;
168
                        certificateDetailsApp.error = true;
169
                    }
170
                } catch (error) {
171
                    console.error(error);
172
                    certificateDetailsApp.loading = false;
173
                    certificateDetailsApp.error = true;
174
                }
175
            } 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
        } else {
182
            console.error("URL does not contain 'id' parameter")
183
            certificateDetailsApp.loading = false;
184
            certificateDetailsApp.error = true;
185
        }
186

    
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
    }
209
});
210

    
211

    
(5-5/11)