Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
<!-- SPDX-License-Identifier: GPL-3.0-or-later -->
<!-- Copyright (C) 2025 Jibril Sharafi -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="/css/button.css">
<link rel="stylesheet" type="text/css" href="/css/styles.css">
<link rel="stylesheet" type="text/css" href="/css/section.css">
<link rel="stylesheet" type="text/css" href="/css/typography.css">
<link rel="stylesheet" type="text/css" href="/css/forms.css">
<link rel="stylesheet" type="text/css" href="/css/index.css">
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
<title>EnergyMe - Change password</title>
<style>
/* Self-contained on purpose, like wifi-setup.html. Not for want of a network - this
page always runs on an authenticated LAN session - but because a gate with fewer
moving parts is a gate with fewer ways to fail to render, and a gate that cannot
render cannot be passed. */
.setup-box { width: 30rem; }
.stack { display: flex; flex-direction: column; align-items: stretch; gap: .35rem; }
.stack .buttonForm { width: 100%; }
.status-box { padding: .8rem 1rem; border-radius: 10px; margin-bottom: 1rem; display: none; }
.status-box.visible { display: block; }
.status-info { background: #e8f1fb; border: 1px solid #b6d4f2; }
.status-error { background: #fdecea; border: 1px solid #f5c2bd; }
.status-ok { background: #e9f7ef; border: 1px solid #b7e1c6; }
.muted { color: #808080; font-size: .85rem; }
.row-gap { margin-bottom: .85rem; }
.spinner { display: inline-block; width: .8rem; height: .8rem; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }
input[type="password"] { width: 100%; box-sizing: border-box; margin-bottom: .5rem; }
@media screen and (max-width: 768px) {
.setup-box { width: 95%; }
}
</style>
</head>
<body>
<div class="header">EnergyMe</div>
<div class="subheader" id="productSubheader">Home</div>
<div id="gate" class="section-box setup-box" style="display:none;">
<h2>Choose a password</h2>
<p>This meter is still using the password it shipped with. That password is printed in
the manual and published in the source code, so anyone on this network can currently
change your settings and install firmware on it.</p>
<p class="row-gap">Until you set your own password, the meter will not serve anything else.</p>
<div id="status" class="status-box"></div>
<div class="stack">
<input type="password" id="newPassword" placeholder="New password (min. 8 characters)" autocomplete="new-password">
<input type="password" id="confirmPassword" placeholder="Confirm new password" autocomplete="new-password">
<button class="buttonForm" id="submitButton">Set password</button>
</div>
<p class="muted" style="margin-top:.85rem;">Your browser will ask you to sign in again
with the new password. The username stays <strong>admin</strong>.</p>
<!-- The way out for someone who reached this page over the meter's own access point
because it lost its network. "/" serves this gate in that state, so without the
link they would have nowhere to go but a password form that does not fix their
problem. The WiFi routes stay reachable from the AP for the same reason.
Hidden by default and revealed only when the device says the request came in over
its access point: on the LAN that link redirects straight back to this page, so
showing it there is a dead end. -->
<p class="muted" id="wifiEscape" style="display:none;">Reached this over the meter's own WiFi because it lost your network?
<a href="/wifi-setup.html">Reconnect it first</a>.</p>
</div>
<script>
(function () {
'use strict';
// The published default. Hard-coding it leaks nothing: it is a #define in a public
// repository, printed in the manual, and identical on every shipped device.
//
// Sending it as currentPassword is sound rather than a shortcut. This page is only
// served when the device's flag says the stored password IS the default, and the
// user necessarily supplied it at the digest prompt to get here. The one divergence
// - NVS unreadable, so the flag is conservatively true while the real password is
// something else - makes the endpoint fail on its own read before the comparison is
// reached, so a "current password" field would not have helped.
var DEFAULT_PASSWORD = 'energyme';
var MIN_LENGTH = 8;
var gate = document.getElementById('gate');
var statusBox = document.getElementById('status');
var newPassword = document.getElementById('newPassword');
var confirmPassword = document.getElementById('confirmPassword');
var submitButton = document.getElementById('submitButton');
var wifiEscape = document.getElementById('wifiEscape');
function setStatus(message, kind) {
statusBox.textContent = message;
statusBox.className = 'status-box visible status-' + kind;
}
function clearStatus() {
statusBox.className = 'status-box';
}
function busy(isBusy, label) {
submitButton.disabled = isBusy;
submitButton.innerHTML = isBusy ? '<span class="spinner"></span> ' + label : 'Set password';
}
function submit() {
var next = newPassword.value;
var confirm = confirmPassword.value;
clearStatus();
if (next.length < MIN_LENGTH) {
setStatus('The password must be at least ' + MIN_LENGTH + ' characters long.', 'error');
return;
}
if (next !== confirm) {
setStatus('The two passwords do not match.', 'error');
return;
}
if (next === DEFAULT_PASSWORD) {
setStatus('That is the default password. Choose a different one.', 'error');
return;
}
busy(true, 'Saving');
setStatus('Saving the new password...', 'info');
fetch('/api/v1/auth/change-password', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ currentPassword: DEFAULT_PASSWORD, newPassword: next })
}).then(function (response) {
return response.json().catch(function () { return {}; }).then(function (body) {
if (!response.ok) throw new Error(body.error || ('Request failed: ' + response.status));
return body;
});
}).then(function () {
busy(false);
setStatus('Password changed. Your browser will now ask you to sign in again as "admin" with the new password.', 'ok');
newPassword.value = '';
confirmPassword.value = '';
// The digest credentials the browser cached went stale the moment the device
// reloaded its hash, so the next request re-prompts. Give the user a moment
// to read why before that happens.
setTimeout(function () { window.location.href = '/'; }, 2500);
}).catch(function (error) {
busy(false);
setStatus(error.message, 'error');
});
}
submitButton.addEventListener('click', submit);
confirmPassword.addEventListener('keydown', function (event) {
if (event.key === 'Enter') submit();
});
// Entry state comes from the device, not from the URL - the same probe-first pattern
// wifi-setup.html uses. If the password was changed in another tab, this page has no
// reason to exist.
fetch('/api/v1/auth/status').then(function (response) {
return response.json();
}).then(function (data) {
if (data && data.productName) document.getElementById('productSubheader').textContent = data.productName;
if (data && data.usingDefaultPassword === false) {
window.location.href = '/';
return;
}
if (data && data.apOrigin) wifiEscape.style.display = '';
gate.style.display = '';
newPassword.focus();
}).catch(function () {
// Could not ask. Show the gate anyway - the device is the one enforcing this, and
// a page that hides itself on a failed probe would be a page that hides the only
// way out.
gate.style.display = '';
});
})();
</script>
</body>
</html>
f4329a85eThis file is pinned to the selected release. Download the original to open it in your design tool.