summaryrefslogtreecommitdiffstats
path: root/_includes/cig_password.html
blob: 5223e35cd7dc6d07903f43e2d6a88c93ebcd8d9e (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
<div>
    <form id="cig-password" novalidate>
        <div class="form-floating mb-3">
            <input type="text" class="form-control" placeholder="Serial Number" name="serial" id="serial" required pattern="[0-9A-Za-z]{4}[0-9A-Fa-f]{8}">
            <label for="serial" class="form-label">GPON S/N in format GPONabc12345</label>
            <div class="invalid-feedback">
                Please provide a valid GPON S/N.
            </div>
        </div>
        <div class="mb-3">
            <input type="submit" class="btn btn-primary" value="Generate!" id="submit">
            <label for="submit" class="form-label">Warning: this script is hosted on a third-party server.</label>
        </div>
        <div class="form-floating mb-3">
            <input readonly type="text" class="form-control" placeholder="Serial Number" name="username" id="username" value="{{include.username}}">
            <label for="username" class="form-label">Username</label>
        </div>
        <div class="form-floating mb-3">
            <input readonly class="form-control" type="text" id="result" placeholder="Result">
            <label for="result" class="form-label">Password</label>
        </div>
    </form>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.2.0/crypto-js.min.js"></script>
    <script type="text/javascript" src="/assets/js/cigpassword.js"></script>
    <script>
        var cigPassword = document.getElementById('cig-password');
        cigPassword.addEventListener('submit', (event) => {
            event.preventDefault();
            if (!cigPassword.checkValidity()) {
                event.preventDefault();
            } else {
                const data = new FormData(cigPassword);
                document.getElementById('result').value = cigpassword_gpon(data.get("serial"), data.get("username"));
            }
            [...cigPassword.elements].map(e => e.parentNode).forEach(e => e.classList.toggle('was-validated', true));
        });
    </script>
</div>