Projekt

Obecné

Profil

Stáhnout (5.93 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
        revocationReason: "unspecified",
12
        issuedCertificates: [],
13
        certificate: {
14
            subject: {
15
                C: "",
16
                ST: "",
17
                L: "",
18
                CN: "",
19
                O: "",
20
                OU: "",
21
                emailAddress: "",
22
            },
23
            notBefore: "",
24
            notAfter: "",
25
            usage: {
26
                CA: false,
27
                authentication: false,
28
                digitalSignature: false,
29
                SSL: false,
30
            },
31
            CA: null,
32
        },
33
        errorMessage: "",
34
        successMessage: "",
35
    },
36
    computed: {
37
        startDate: function () {
38
            return this.certificate.notBefore.substr(0, 16);
39
        },
40
        endDate: function () {
41
            return this.certificate.notAfter.substr(0, 16);
42
        },
43
        issuerURL: function () {
44
            return "/static/certificate.html?id=" + this.certificate.CA;
45
        },
46
        crlEndpoint: function () {
47
            return "/api/crl/" + this.certificate.CA;
48
        },
49
        ocspEndpoint: function () {
50
            return "/api/ocsp/" + this.certificate.CA;
51
        }
52
    },
53
    watch: {},
54
    methods: {
55
        onCertificateDownload: async function () {
56
            await onCertificateDownload(this.id);
57
        },
58
        onRootDownload: async function () {
59
            await onCertificateRootDownload(this.id);
60
        },
61
        onChainDownload: async function () {
62
            await onCertificateChainDownload(this.id);
63
        },
64
        onPublicKeyDownload: async function () {
65
            await onPublicKeyDownload(this.id);
66
        },
67
        onPrivateKeyDownload: async function () {
68
            await onPrivateKeyDownload(this.id);
69
        },
70
        onRevoke: async function () {
71
            document.body.scrollTop = 0;
72
            document.documentElement.scrollTop = 0;
73
            try {
74
                const response = await axios.patch(API_URL + "certificates/" + this.id, {
75
                    status: "revoked",
76
                    reason: this.revocationReason
77
                });
78
                if (response.data["success"]) {
79
                    certificateDetailsApp.successMessage = "Certificate revocation successful.";
80
                } else {
81
                    certificateDetailsApp.errorMessage = "Certificate cannot be revoked - " + response.data["data"] + "!";
82
                }
83
            } catch (error) {
84
                certificateDetailsApp.errorMessage = "An error occurred while revoking certificate";
85
            }
86
        },
87
        onDelete: async function () {
88
            document.body.scrollTop = 0;
89
            document.documentElement.scrollTop = 0;
90
            try {
91
                const response = await axios.delete(API_URL + "certificates/" + this.id);
92
                if (response.data["success"]) {
93
                    window.location.href = "/static/index.html?success=Certificate+successfully+deleted";
94
                } else {
95
                    certificateDetailsApp.errorMessage = "Certificate cannot be deleted - " + response.data["data"] + "!";
96
                }
97
            } catch (error) {
98
                certificateDetailsApp.errorMessage = "An error occurred while deleting certificate";
99
            }
100
        }
101
    },
102
    mounted: async function () {
103
        // get details of the selected certificate
104
        const params = window.location.search;
105
        if (params !== "") {
106
            // get requested ID
107
            const urlParams = new URLSearchParams(params);
108
            if (urlParams.get("id") != null) {
109
                const id = urlParams.get("id");
110
                this.id = id;
111
                var loadedDetails = false;
112
                // query certificate details
113
                try {
114
                    const response = await axios.get(API_URL + "certificates/" + id + "/details");
115
                    if (response.data["success"]) {
116
                        // display certificate
117
                        certificateDetailsApp.certificate = response.data["data"];
118
                        loadedDetails = true;
119
                    } else {
120
                        // certificate does not exists
121
                        console.error("Required certificate does not exists");
122
                        certificateDetailsApp.loading = false;
123
                        certificateDetailsApp.error = true;
124
                    }
125
                } catch (error) {
126
                    console.error(error);
127
                    certificateDetailsApp.loading = false;
128
                    certificateDetailsApp.error = true;
129
                }
130
            } else {
131
                // id was not provided as a URL parameter
132
                console.error("URL does not contain 'id' parameter")
133
                certificateDetailsApp.loading = false;
134
                certificateDetailsApp.error = true;
135
            }
136
        } else {
137
            console.error("URL does not contain 'id' parameter")
138
            certificateDetailsApp.loading = false;
139
            certificateDetailsApp.error = true;
140
        }
141

    
142
        if (!loadedDetails) return;
143
        try {
144
            const response = await axios.get(API_URL + "certificates", {
145
                params: {
146
                    filtering: {
147
                        issuedby: parseInt(certificateDetailsApp.id)
148
                    }
149
                }
150
            });
151
            if (response.data["success"]) {
152
                response.data["data"].forEach(item => {
153
                    if (item.id != certificateDetailsApp.id) certificateDetailsApp.issuedCertificates.push(item)
154
                })
155
            } else {
156
                certificateDetailsApp.issuedCertificates = [];
157
            }
158
        } catch (error) {
159
            console.log(error);
160
        }
161
        this.loading = false;
162
        this.error = false;
163
    }
164
});
165

    
166

    
(5-5/11)