honeypot/assets/js/pages/login.js
vlw 0234ef984b refactor: release 2.0.0 (#1)
Baby steps that implements everything from the original [unfinished] version of this project from a bit over 2 years ago. We'll see what fun stuff we can add over time!

Reviewed-on: https://codeberg.org/vlw/honeypot/pulls/1
Co-authored-by: vlw <victor@vlw.se>
Co-committed-by: vlw <victor@vlw.se>
2025-09-23 20:09:41 +02:00

57 lines
No EOL
1.8 KiB
JavaScript

// Simulate a fake login page
{
const WHITELIST_USERNAMES = [
"user",
"root",
"admin",
"mydlink"
];
const WHITELIST_PASSWORDS = [
"root",
"admin",
"12345",
"mydlink",
"password",
"123456789"
];
const INPUT_NAME_USERNAME = "username";
const INPUT_NAME_PASSWORD = "password";
document.querySelector("form button").addEventListener("click", (event) => {
event.preventDefault();
VV.shell.setAttribute("vv-loading", true);
const form = new FormData(event.target.closest("form"));
// Invalid fake username or password derp
if (
!WHITELIST_USERNAMES.includes(form.get(INPUT_NAME_USERNAME))
|| !WHITELIST_PASSWORDS.includes(form.get(INPUT_NAME_PASSWORD))
) {
// Show "incorrect credentials" dialog after global Vegvisir delay
setTimeout(() => {
VV.shell.setAttribute("vv-loading", false);
document.querySelector("dialog").showModal();
}, VV.delay);
return;
}
new VV().navigate("/dashboard");
});
}
// Only start logging if the user does something with the input fields
{
const abortInitialInputChange = new AbortController();
const startLogging = () =>{
abortInitialInputChange.abort();
new globalThis.Logger().start();
};
document.querySelector("button").addEventListener("click", () => startLogging(), { signal: abortInitialInputChange.signal });
document.querySelectorAll("input").forEach(element => element.addEventListener("click", () => startLogging(), { signal: abortInitialInputChange.signal }));
document.querySelectorAll("input").forEach(element => element.addEventListener("keydown", () => startLogging(), { signal: abortInitialInputChange.signal }));
document.querySelectorAll("input").forEach(element => element.addEventListener("change", () => startLogging(), { signal: abortInitialInputChange.signal }));
}