Projekt

Obecné

Profil

Stáhnout (8.01 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("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
            this.displayIssuer = ~this.displayIssuer;
101
        },
102
        onCertificateDownload: async function () {
103
            await onCertificateDownload(this.id);
104
        },
105
        onRootDownload: async function () {
106
            await onCertificateRootDownload(this.id);
107
        },
108
        onChainDownload: async function () {
109
            await onCertificateChainDownload(this.id);
110
        },
111
        onPublicKeyDownload: async function () {
112
            await onPublicKeyDownload(this.id);
113
        },
114
        onPrivateKeyDownload: async function () {
115
            await onPrivateKeyDownload(this.id);
116
        },
117
        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
        onRevoke: async function () {
128
            document.body.scrollTop = 0;
129
            document.documentElement.scrollTop = 0;
130
            try {
131
                const response = await axios.patch(API_URL + "certificates/" + this.id, {
132
                    status: "revoked",
133
                    reason: this.revocationReason
134
                });
135
                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
        },
144
        onDelete: async function () {
145
            document.body.scrollTop = 0;
146
            document.documentElement.scrollTop = 0;
147
            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
        }
158
    },
159
    mounted: async function () {
160
        // 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
                var loadedDetails = false;
169
                // query certificate details
170
                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
                        certificateDetailsApp.loading = false;
180
                        certificateDetailsApp.error = true;
181
                    }
182
                } catch (error) {
183
                    console.error(error);
184
                    certificateDetailsApp.loading = false;
185
                    certificateDetailsApp.error = true;
186
                }
187
            } 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
        } else {
194
            console.error("URL does not contain 'id' parameter")
195
            certificateDetailsApp.loading = false;
196
            certificateDetailsApp.error = true;
197
        }
198

    
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
    }
221
});
222

    
223

    
(5-5/11)