aboutsummaryrefslogtreecommitdiff
path: root/src_frontend/Components/Settings/SSLCert.svelte
blob: adb36499ed7bba5417b684f1b0dcf9d93d4f5b63 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<script>
    import { onMount } from "svelte";

    import FloatingButton from "../../ComponentLib/Button/FloatingButton.svelte";
    import ConfirmActionDialog from "../Dialogs/ConfirmActionDialog.svelte";
    import { authorizedSocket } from "../../stores/socketStore.js";

    let isValid = false;
    let CN = "-";
    let validTime = "-";

    authorizedSocket.on("sslcert:info", (status) => {
        isValid = status.isValid;
        CN = status.CN;
        validTime = Math.round((status.certExpire-(new Date()).getTime())/86400000);
    });

    let newCertPromise;
    function generateNewCert() {
        newCertPromise = new Promise((resolve, reject) => {
            authorizedSocket.emit("sslcert:generate_new", () => {
                resolve();
            });
        });
    }

    onMount(async() => {
        authorizedSocket.emit("sslcert:info");
    });
</script>

<style>
    h1 { margin-bottom: 0; }
    p { margin: 0; }
    .small {
        font-weight: 100;
        font-style: italic;
        font-size: 12px;
        color: var(--grey-600);
    }
    .button {
        margin-top: 10px;
    }
</style>

<div>
    <h1>SSL Certificate</h1>
    <p>{isValid ? "VALID" : "INVALID"} <span class="small">(for {validTime} days)</span></p>
    <p><span class="small">CN</span> {CN}</p>

    <ConfirmActionDialog title="Are you sure?" text="Are you sure you want to generate new self signed SSL Certificate?" action={generateNewCert}>
        <svelte:fragment slot="trigger" let:open>
            <div class="button"><FloatingButton on:click={open} bind:loadingPromise={newCertPromise} fullWidth=true>Generate new cerificate</FloatingButton></div>
        </svelte:fragment>
    </ConfirmActionDialog>
    <!-- <div class="button"><Button fullWidth=true round=true>Show details</Button></div> -->
</div>