Ask about a reboot in a box over the page

The reboot links on the Overview open the question instead of sending
you to the Advanced page, where the button is out of sight.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 13:26:30 +01:00
co-authored by Claude Sonnet 5.5
parent 81eea34501
commit e3f93698a9
5 changed files with 88 additions and 3 deletions
+81
View File
@@ -0,0 +1,81 @@
// A question in a box over the page, instead of the browser's own.
// <form data-dialog="Reboot now?" data-dialog-ok="Reboot"> asks when it is sent;
// <button data-dialog="Reboot now?" data-dialog-ok="Reboot" data-post="/reboot"> posts there when answered yes
// (with the session's token, which the page names in <meta name="csrf">).
(function () {
function ask(message, ok, yes) {
var box = document.createElement("div");
box.className = "upload-overlay";
box.setAttribute("role", "alertdialog");
box.setAttribute("aria-modal", "true");
var card = document.createElement("div");
card.className = "upload-card";
var text = document.createElement("p");
text.className = "dialog-question";
text.textContent = message;
var row = document.createElement("div");
row.className = "dialog-actions";
var no = document.createElement("button");
no.type = "button";
no.className = "secondary";
no.textContent = "Cancel";
var go = document.createElement("button");
go.type = "button";
go.textContent = ok || "OK";
row.append(no, go);
card.append(text, row);
box.append(card);
var before = document.activeElement;
function close() {
document.removeEventListener("keydown", key, true);
box.remove();
if (before && before.focus) before.focus();
}
function key(e) {
if (e.key === "Escape") { e.preventDefault(); close(); }
}
no.onclick = close;
go.onclick = function () { close(); yes(); };
// A click beside the box cancels, too.
box.onclick = function (e) { if (e.target === box) close(); };
document.addEventListener("keydown", key, true);
document.body.append(box);
// The safe answer has the focus.
no.focus();
}
function post(path) {
var meta = document.querySelector('meta[name="csrf"]');
var form = document.createElement("form");
form.method = "post";
form.action = path;
var field = document.createElement("input");
field.type = "hidden";
field.name = "csrf";
field.value = meta ? meta.content : "";
form.append(field);
document.body.append(form);
form.submit();
}
document.addEventListener("submit", function (e) {
var form = e.target;
if (!form.hasAttribute("data-dialog") || form.dialogAnswered) return;
e.preventDefault();
ask(form.getAttribute("data-dialog"), form.getAttribute("data-dialog-ok"), function () {
form.dialogAnswered = true;
form.submit();
});
});
// The page can be replaced while it is open (live.js), so ask for the element at click time.
document.addEventListener("click", function (e) {
var el = e.target.closest ? e.target.closest("[data-post][data-dialog]") : null;
if (!el) return;
e.preventDefault();
ask(el.getAttribute("data-dialog"), el.getAttribute("data-dialog-ok"), function () {
post(el.getAttribute("data-post"));
});
});
})();
+2
View File
@@ -60,6 +60,8 @@ section { margin: 0 0 1.5rem; }
section.busy, section.pending { padding: .75rem 1rem; border-radius: var(--radius); background: var(--warn); } section.busy, section.pending { padding: .75rem 1rem; border-radius: var(--radius); background: var(--warn); }
.upload-overlay { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, .55); padding: 1rem; } .upload-overlay { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, .55); padding: 1rem; }
.upload-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 32px rgba(0, 0, 0, .35); padding: 1.25rem 1.5rem; width: min(30rem, 100%); } .upload-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 32px rgba(0, 0, 0, .35); padding: 1.25rem 1.5rem; width: min(30rem, 100%); }
.dialog-question { margin: 0; font-size: 1.05rem; }
.dialog-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1.25rem; }
.upload-card.wide { width: min(48rem, 100%); } .upload-card.wide { width: min(48rem, 100%); }
.upload-card pre.log { margin: .75rem 0 0; max-height: min(18rem, 40vh); } .upload-card pre.log { margin: .75rem 0 0; max-height: min(18rem, 40vh); }
.upload-card h2 { margin: 0 0 .75rem; } .upload-card h2 { margin: 0 0 .75rem; }
+1 -1
View File
@@ -54,7 +54,7 @@
<section class="panel"> <section class="panel">
<h2>Reboot</h2> <h2>Reboot</h2>
<p>Restarts the router; routing stops for a minute or two. A new kernel from an update only runs after this.</p> <p>Restarts the router; routing stops for a minute or two. A new kernel from an update only runs after this.</p>
<form method="post" action="/reboot" data-confirm="Reboot the router now?"><input type="hidden" name="csrf" value="{{.CSRF}}"><button>Reboot</button></form> <form method="post" action="/reboot" data-dialog="Reboot the router now? Routing stops for a minute or two." data-dialog-ok="Reboot"><input type="hidden" name="csrf" value="{{.CSRF}}"><button>Reboot</button></form>
</section> </section>
<section class="panel"> <section class="panel">
+2 -2
View File
@@ -33,8 +33,8 @@
<h2>System</h2> <h2>System</h2>
<dl> <dl>
<dt>Uptime</dt><dd>{{age $sys.Uptime}}</dd> <dt>Uptime</dt><dd>{{age $sys.Uptime}}</dd>
{{if $sys.Kernel}}<dt>Kernel</dt><dd>{{$sys.Kernel}}{{if $sys.KernelNext}} <span class="bad">reboot to run {{$sys.KernelNext}}</span> <a href="/advanced">Reboot</a>{{end}}</dd>{{end}} {{if $sys.Kernel}}<dt>Kernel</dt><dd>{{$sys.Kernel}}{{if $sys.KernelNext}} <span class="bad">reboot to run {{$sys.KernelNext}}</span> <button type="button" class="link" data-dialog="Reboot the router now? Routing stops for a minute or two." data-dialog-ok="Reboot" data-post="/reboot">Reboot</button>{{end}}</dd>{{end}}
{{if $sys.BootPending}}<dt>Reboot</dt><dd><span class="bad">a new configuration starts at the next reboot</span> <a href="/advanced">Reboot</a></dd>{{end}} {{if $sys.BootPending}}<dt>Reboot</dt><dd><span class="bad">a new configuration starts at the next reboot</span> <button type="button" class="link" data-dialog="Reboot the router now? Routing stops for a minute or two." data-dialog-ok="Reboot" data-post="/reboot">Reboot</button></dd>{{end}}
<dt>Load</dt><dd>{{$sys.Load}}</dd> <dt>Load</dt><dd>{{$sys.Load}}</dd>
<dt>CPU</dt><dd>{{value $sys.CPU "%"}}</dd> <dt>CPU</dt><dd>{{value $sys.CPU "%"}}</dd>
{{if $sys.MemTotal}}<dt>Memory</dt><dd>{{bytes $sys.MemUsed}} of {{bytes $sys.MemTotal}}</dd>{{end}} {{if $sys.MemTotal}}<dt>Memory</dt><dd>{{bytes $sys.MemUsed}} of {{bytes $sys.MemTotal}}</dd>{{end}}
+2
View File
@@ -3,6 +3,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
{{if .CSRF}}<meta name="csrf" content="{{.CSRF}}">{{end}}
<title>{{.Title}} · router</title> <title>{{.Title}} · router</title>
<link rel="stylesheet" href="/static/style.css"> <link rel="stylesheet" href="/static/style.css">
</head> </head>
@@ -45,5 +46,6 @@
<script src="/static/menu.js"></script> <script src="/static/menu.js"></script>
<script src="/static/live.js"></script> <script src="/static/live.js"></script>
<script src="/static/upload.js"></script> <script src="/static/upload.js"></script>
<script src="/static/dialog.js"></script>
</body> </body>
</html> </html>