Projekt

Obecné

Profil

Stáhnout (6.39 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

    
55
        },
56
        methods: {
57
            onCertificateDownload: function () {
58
                onCertificateDownload(this.id);
59
            },
60
            onRootDownload: function () {
61
                onCertificateRootDownload(this.id);
62
            },
63
            onChainDownload: function () {
64
                onCertificateChainDownload(this.id);
65
            },
66
            onPublicKeyDownload: function () {
67
                onPublicKeyDownload(this.id);
68
            },
69
            onPrivateKeyDownload: function () {
70
                onPrivateKeyDownload(this.id);
71
            },
72
            onRevoke: function () {
73
                document.body.scrollTop = 0;
74
                document.documentElement.scrollTop = 0;
75
                axios.patch(API_URL + "certificates/"+this.id, {
76
                    status: "revoked",
77
                    reason: this.revocationReason
78
                })
79
                    .then(function (response) {
80
                        if(response.data["success"]) {
81
                            certificateDetailsApp.successMessage = "Certificate revocation successful.";
82
                        }
83
                        else {
84
                            certificateDetailsApp.errorMessage = "Certificate cannot be revoked - "+response.data["data"]+"!";
85
                        }
86
                    })
87
                    .catch(function (error) {
88
                        certificateDetailsApp.errorMessage = "An error occurred while revoking certificate";
89
                    });
90
            },
91
            onDelete: function () {
92
                document.body.scrollTop = 0;
93
                document.documentElement.scrollTop = 0;
94
                axios.delete(API_URL + "certificates/" + this.id)
95
                    .then(function (response) {
96
                        if(response.data["success"]){
97
                            window.location.href = "/static/index.html?success=Certificate+successfully+deleted";
98
                        }
99
                        else {
100
                            certificateDetailsApp.errorMessage = "Certificate cannot be deleted - "+response.data["data"]+"!";
101
                        }
102
                    })
103
                    .catch(function (error) {
104
                        certificateDetailsApp.errorMessage = "An error occurred while deleting certificate";
105
                    });
106
            }
107
        }
108
    });
109

    
110
    // get details of the selected certificate
111
    const params = window.location.search;
112
    if (params !== "") {
113
        // get requested ID
114
        const urlParams = new URLSearchParams(params);
115
        if (urlParams.get("id") != null) {
116
            const id = urlParams.get("id");
117
            certificateDetailsApp.id = id;
118
            // query certificate details
119
            axios.get(API_URL + "certificates/"+id+"/details")
120
                .then(function (response) {
121
                    if (response.data["success"]) {
122
                        // display certificate
123
                        certificateDetailsApp.certificate = response.data["data"];
124
                        loadIssuedCertificates();
125
                        certificateDetailsApp.loading = false;
126
                        certificateDetailsApp.error = false;
127
                    }
128
                    else {
129
                        // certificate does not exists
130
                        console.error("Required certificate does not exists");
131
                        certificateDetailsApp.loading = false;
132
                        certificateDetailsApp.error = true;
133
                    }
134
                })
135
                .catch(function (error) {
136
                    // server error
137
                    console.error(error);
138
                    certificateDetailsApp.loading = false;
139
                    certificateDetailsApp.error = true;
140
                });
141
        } else {
142
            // id was not provided as a URL parameter
143
            console.error("URL does not contain 'id' parameter")
144
            certificateDetailsApp.loading = false;
145
            certificateDetailsApp.error = true;
146
        }
147
    } else {
148
        console.error("URL does not contain 'id' parameter")
149
        certificateDetailsApp.loading = false;
150
        certificateDetailsApp.error = true;
151
    }
152

    
153
    function loadIssuedCertificates() {
154
            axios.get(API_URL+"certificates", {
155
            params: {
156
                filtering: {
157
                    issuedby: parseInt(certificateDetailsApp.id)
158
                }
159
            }
160
        })
161
        .then(function (response) {
162
            if (response.data["success"]) {
163
                response.data["data"].forEach(item => {if(item.id != certificateDetailsApp.id) certificateDetailsApp.issuedCertificates.push(item)})
164
            }
165
            else
166
            {
167
                certificateDetailsApp.issuedCertificates = [];
168
            }
169
        })
170
        .catch(function (error) {
171
            console.log(error);
172
        });
173
    }
(5-5/11)