clavarium 0.2.18 → 0.2.19-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/server/main.mjs CHANGED
@@ -13,6 +13,7 @@
13
13
  * no VM: one tool on this machine, at /?c=<name>. For development.
14
14
  */
15
15
  import { readFileSync } from 'node:fs';
16
+ import { createHash } from 'node:crypto';
16
17
  import { createServer } from 'node:http';
17
18
  import { readFile } from 'node:fs/promises';
18
19
  import { fileURLToPath } from 'node:url';
@@ -59,6 +60,7 @@ import { Certificate } from './certificate.mjs';
59
60
  import { Operators } from './operators.mjs';
60
61
  import { HealthReact } from './healthreact.mjs';
61
62
  import { MachinesMove } from './machinesmove.mjs';
63
+ import { Wifi } from './wifi.mjs';
62
64
  import { ServerLogs } from './serverlogs.mjs';
63
65
  import { History, STEP_MS as HISTORY_STEP_MS } from './history.mjs';
64
66
  import { Events } from './events.mjs';
@@ -67,6 +69,7 @@ import { migrateData } from './dataformat.mjs';
67
69
  import { VmWatch } from './vmwatch.mjs';
68
70
 
69
71
  const ROOT = fileURLToPath(new URL('..', import.meta.url));
72
+ const MAINTENANCE = 'deploy/maintenance.html';
70
73
  export const FILES = {
71
74
  '/': ['web/index.html', 'text/html; charset=utf-8'],
72
75
  '/app.js': ['web/app.js', 'text/javascript; charset=utf-8'],
@@ -81,6 +84,8 @@ export const FILES = {
81
84
  '/icons.js': ['web/icons.js', 'text/javascript; charset=utf-8'],
82
85
  '/links.js': ['web/links.js', 'text/javascript; charset=utf-8'],
83
86
  '/gitgraph.js': ['web/gitgraph.js', 'text/javascript; charset=utf-8'],
87
+ /* The page shown while an update stops this server (app.js goes to it); the front serves the same file while it is down. */
88
+ '/maintenance.html': [MAINTENANCE, 'text/html; charset=utf-8'],
84
89
  /* The review's diff, drawn by diff2html (vendored, pinned: web/vendor/diff2html/LICENSE). */
85
90
  '/vendor/diff2html.js': ['web/vendor/diff2html/diff2html-ui-slim.min.js', 'text/javascript; charset=utf-8'],
86
91
  '/vendor/diff2html.css': ['web/vendor/diff2html/diff2html.min.css', 'text/css; charset=utf-8'],
@@ -113,6 +118,13 @@ const HEADERS = {
113
118
  'referrer-policy': 'no-referrer',
114
119
  'cache-control': 'no-store',
115
120
  };
121
+ /* The maintenance page is ONE file, its script in it: the front (Caddy) serves it alone while this
122
+ server is down. Here its script is allowed by its hash, and nothing else inline. */
123
+ export const MAINTENANCE_HEADERS = (() => {
124
+ const script = /<script>([\s\S]*?)<\/script>/.exec(readFileSync(ROOT + MAINTENANCE, 'utf8'))?.[1] ?? '';
125
+ const hash = createHash('sha256').update(script).digest('base64');
126
+ return { ...HEADERS, 'content-security-policy': HEADERS['content-security-policy'].replace("default-src 'self';", `default-src 'self'; script-src 'sha256-${hash}';`) };
127
+ })();
116
128
 
117
129
  export function option(argv, name, fallback) {
118
130
  const i = argv.indexOf(`--${name}`);
@@ -124,16 +136,21 @@ const withoutTmux = (env) => Object.fromEntries(Object.entries(env).filter(([key
124
136
 
125
137
  const REFUSED = 'This Clavarium belongs to someone else: your account is not one of its operators.\n';
126
138
 
127
- function serve(port, conversations, resources, { gate = () => 'local', originOk, shortcuts, voice, sharing, door, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, guide, repair, capacity, updates, instance = new Instance(), certificate, team, reacting, machinesMove, serverLogs, history, events, bundles } = {}) {
139
+ function serve(port, conversations, resources, { gate = () => 'local', originOk, shortcuts, voice, sharing, door, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, guide, repair, capacity, updates, instance = new Instance(), certificate, team, reacting, machinesMove, serverLogs, history, events, bundles, wifi } = {}) {
128
140
  /* Its manifest carries the name of this Clavarium, or the one a device chose (instance.mjs). */
129
141
  const sendManifest = (response, url) => response.writeHead(200, { ...HEADERS, 'content-type': 'application/manifest+json' }).end(instance.manifest(new URL(url ?? '/', 'http://local').searchParams.get('name') ?? undefined));
130
142
  const sendFile = async (response, file) => {
131
143
  /* Several files are one, in their order. */
132
144
  const body = Array.isArray(file[0]) ? Buffer.concat((await Promise.all(file[0].map((f) => readFile(f.startsWith('/') ? f : ROOT + f)))).flatMap((b) => [b, Buffer.from('\n;\n')])) : await readFile(file[0].startsWith('/') ? file[0] : ROOT + file[0]);
133
- response.writeHead(200, { ...HEADERS, 'content-type': file[1] }).end(body);
145
+ response.writeHead(200, { ...(file[0] === MAINTENANCE ? MAINTENANCE_HEADERS : HEADERS), 'content-type': file[1] }).end(body);
134
146
  };
135
147
  const server = createServer(async (request, response) => {
136
148
  const { pathname } = new URL(request.url ?? '/', 'http://local');
149
+ /* An update about to stop this server (updates.mjs, notice): said on every answer, so that
150
+ every page hears it at its next question, whatever it asks. */
151
+ try { const notice = updates?.notice(); if (notice) response.setHeader('x-clavarium-update', notice); } catch { /* never in the way of an answer */ }
152
+ /* The version that answers, to the page's own questions: a page loaded before an update starts again (app.js). */
153
+ if (platform?.version && (pathname.startsWith('/api/') || pathname.startsWith('/c/api/'))) response.setHeader('x-clavarium-version', platform.version);
137
154
  /* The device door first, and apart: it never consults the gate. */
138
155
  /* An address that wakes a tool, called from outside by what its owner
139
156
  runs elsewhere: the address is the right. Nothing else is looked at,
@@ -162,7 +179,7 @@ function serve(port, conversations, resources, { gate = () => 'local', originOk,
162
179
  response.writeHead(403, { ...HEADERS, 'content-type': 'text/plain; charset=utf-8' }).end(REFUSED);
163
180
  return;
164
181
  }
165
- if (conversations && await handleApi(request, response, conversations, HEADERS, resources, originOk, shortcuts, voice, sharing, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, repair, guide, capacity, updates, instance, certificate, team, reacting, machinesMove, serverLogs, history, events, bundles)) return;
182
+ if (conversations && await handleApi(request, response, conversations, HEADERS, resources, originOk, shortcuts, voice, sharing, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, repair, guide, capacity, updates, instance, certificate, team, reacting, machinesMove, serverLogs, history, events, bundles, wifi)) return;
166
183
  if (pathname === '/manifest.webmanifest' && request.method === 'GET') { sendManifest(response, request.url); return; }
167
184
  const file = FILES[pathname];
168
185
  if (!file || (request.method !== 'GET' && request.method !== 'HEAD')) {
@@ -431,12 +448,14 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
431
448
  const machinesMove = new MachinesMove({ host: asHost, usedMb: () => capacity.machinesUsedMb() });
432
449
  /* What the server's programs said, and this server started again, from Settings (serverlogs.mjs). */
433
450
  const serverLogs = new ServerLogs({ host: asHost });
451
+ /* This server's Wi-Fi, from Settings (wifi.mjs): how a switch ended, said in What happened. */
452
+ const wifi = new Wifi({ host: asHost, said: (text) => events.add({ kind: 'server', text }) });
434
453
  if (team) {
435
454
  team.useAlerts(alerts);
436
455
  void team.refresh().catch((error) => console.error(`operators: ${error.message}`));
437
456
  const watching = setInterval(() => { void team.watch().catch(() => {}); }, 60_000); watching.unref?.();
438
457
  }
439
- const { server, listening } = serve(port, all, folders, { gate, originOk, shortcuts, voice, sharing, door, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, guide, capacity, updates, instance, certificate, team, reacting, machinesMove, serverLogs, history, events, bundles: new Bundles({ dir: `${dataDir}/imports`, folder: (name) => folders.folder(name) }), repair: (name) => repairTerminal(name) });
458
+ const { server, listening } = serve(port, all, folders, { gate, originOk, shortcuts, voice, sharing, door, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, guide, capacity, updates, instance, certificate, team, reacting, machinesMove, serverLogs, history, events, wifi, bundles: new Bundles({ dir: `${dataDir}/imports`, folder: (name) => folders.folder(name) }), repair: (name) => repairTerminal(name) });
440
459
  server.on('close', () => { closing = true; clearInterval(historyTimer); history.save(); stopVmWatch(); stopShelf(); stopHealth(); stopUpdates(); stopWatch(); clearInterval(mailTimer); clearInterval(answerTimer); clearInterval(wakeTimer); clearInterval(gitTimer); talk.stop(); });
441
460
  let closing = false;
442
461
  bridge = attachBridge(server, {
package/server/talk.mjs CHANGED
@@ -349,13 +349,16 @@ export class Talk {
349
349
  if (!this.of(name).on) throw new Refusal(409, 'Talking through the app is not turned on for this conversation.');
350
350
  const given = files === undefined || files === null ? [] : files;
351
351
  if (!Array.isArray(given) || given.length > FILES_MAX) throw new Refusal(400, `A message has ${FILES_MAX} files at most.`);
352
- /* Only files put here by `attach`: their paths are this server's, and each is there. */
353
- const attached = given.map((path) => {
352
+ /* Only files put here by `attach`: their paths are this server's, and each is there. Each is
353
+ its path, or { path, note }: what the person wrote about that file alone (Parley bounds it). */
354
+ const attached = given.map((item) => {
355
+ const path = item && typeof item === 'object' && !Array.isArray(item) ? item.path : item;
354
356
  const m = typeof path === 'string' ? ATTACHED.exec(path) : null;
355
357
  const file = m ? join(this.#dir(name), FILES, m[1], m[2]) : undefined;
356
358
  const info = file ? lstatSync(file, { throwIfNoEntry: false }) : undefined;
357
359
  if (!info?.isFile()) throw new Refusal(400, 'A file of this message was not attached here first.');
358
- return { path, name: m[2], size: info.size };
360
+ const note = item && typeof item === 'object' && typeof item.note === 'string' ? item.note : '';
361
+ return { path, name: m[2], size: info.size, ...(note ? { note } : {}) };
359
362
  });
360
363
  try { this.#parley(name).say(text ?? '', answers, attached, { via: via === 'voice' ? 'voice' : undefined }); } catch (error) { if (error instanceof RangeError) throw new Refusal(400, error.message); throw error; }
361
364
  const told = await this.#wake(name);
@@ -11,6 +11,10 @@
11
11
  *
12
12
  * A failed update is told to the owner once: an alert on the devices that
13
13
  * asked for alerts (alerts.mjs), and the line in Settings.
14
+ *
15
+ * An update about to stop this server is told to every page (notice): a
16
+ * header on each answer, read by app.js, which gives way to the maintenance
17
+ * page (deploy/maintenance.html) until the new server answers.
14
18
  */
15
19
  import { readFileSync, existsSync } from 'node:fs';
16
20
  import { spawnSync } from 'node:child_process';
@@ -29,6 +33,12 @@ const HISTORY_SHOWN = 8;
29
33
  /* The updater's timer (install.sh): every 15 minutes, up to 3 more at random; the registry asked at most every 6 hours in mode "ask". */
30
34
  export const LOOK_EVERY_MS = 15 * 60_000;
31
35
  export const ASK_EVERY_MS = 6 * 3600_000;
36
+ /* The updater's steps from which this server is about to stop (deploy/updater.mjs, #switchAndCheck). */
37
+ export const STOPPING = ['Switching', 'Restarting'];
38
+ /* A step older than this was not followed by a restart (an updater killed): no page is held by it. */
39
+ export const NOTICE_STALE_MS = 10 * 60_000;
40
+ /* state.json read for the notice at most this often: it is asked on every answer. */
41
+ const NOTICE_READ_MS = 1000;
32
42
 
33
43
  /* WHEN IT WILL HAPPEN, for Settings: the updater's next look, and when an update may be installed. All times in
34
44
  milliseconds; the window is in this server's own time, as the updater reads it. */
@@ -60,11 +70,11 @@ const firstLine = (text) => String(text ?? '').trim().split('\n').filter(Boolean
60
70
  const RELAY_STATES = ['none', 'no-key', 'current', 'brought', 'refused', 'failed'];
61
71
 
62
72
  export class Updates {
63
- #host; #state; #conf; #version; #store; #alerts; #timer; #lastLook; #lastLookCache = { at: 0, value: null };
73
+ #host; #state; #conf; #version; #store; #alerts; #timer; #lastLook; #lastLookCache = { at: 0, value: null }; #clock; #noticeCache = { at: -Infinity, value: '' };
64
74
 
65
75
  /* `host(argv)`: the host program. `store`: what was told already. */
66
- constructor({ host, version, stateFile = STATE_FILE, confFile = CONF_FILE, store, alerts, lastLook = timerLastRun }) {
67
- this.#lastLook = lastLook;
76
+ constructor({ host, version, stateFile = STATE_FILE, confFile = CONF_FILE, store, alerts, lastLook = timerLastRun, clock = () => Date.now() }) {
77
+ this.#lastLook = lastLook; this.#clock = clock;
68
78
  this.#host = host; this.#version = version; this.#state = stateFile; this.#conf = confFile; this.#store = store; this.#alerts = alerts;
69
79
  }
70
80
 
@@ -103,6 +113,21 @@ export class Updates {
103
113
  };
104
114
  }
105
115
 
116
+ /* AN UPDATE ABOUT TO STOP THIS SERVER: 'update <version>', 'back <version>', or ''. Said only
117
+ from the step where the updater switches and restarts (it waits NOTICE_MS there, so that every
118
+ page hears it), only towards another version than this one (the new server, up while the
119
+ updater still watches it, says nothing), and only for a recent step. */
120
+ notice() {
121
+ const now = this.#clock();
122
+ if (now - this.#noticeCache.at < NOTICE_READ_MS) return this.#noticeCache.value;
123
+ const r = this.installed ? this.#read().running : null;
124
+ const at = Date.parse(r?.at ?? '');
125
+ const value = r && (r.action === 'update' || r.action === 'back') && STOPPING.includes(r.step) && VERSION.test(r.version ?? '') && r.version !== this.#version
126
+ && Number.isFinite(at) && now - at < NOTICE_STALE_MS ? `${r.action} ${r.version}` : '';
127
+ this.#noticeCache = { at: now, value };
128
+ return value;
129
+ }
130
+
106
131
  /* The timer's last run, asked of systemd at most once a minute. */
107
132
  #timer_() {
108
133
  if (Date.now() - this.#lastLookCache.at > 60_000) this.#lastLookCache = { at: Date.now(), value: (() => { try { return this.#lastLook(); } catch { return null; } })() };
@@ -0,0 +1,125 @@
1
+ /* WI-FI, from Settings (This server, Network): the networks THIS SERVER sees,
2
+ * the one it is on, joining another, forgetting one it keeps. All of it is done
3
+ * by the host program as root, through NetworkManager (deploy/clavarium-host,
4
+ * verbs "wifi ...").
5
+ *
6
+ * The server is often reached from afar over that very Wi-Fi. So a join only
7
+ * STARTS a switch, which runs in a unit of its own on the host: if the new
8
+ * network gives no working one within a minute, the host goes back to the one
9
+ * before by itself -- whether or not this server, the page or the request are
10
+ * still there to see it. The outcome is read back from `status()`.
11
+ *
12
+ * status() { available, why, device, using: {ssid, signal} | null, saved: [ssid],
13
+ * last: {state, at, ssid, back, why} | null }
14
+ * why (not available): no-nmcli, not-running, no-device, unmanaged, unreadable
15
+ * last.state: joining, joined, went-back, back-failed, interrupted
16
+ * scan() [{ ssid, signal, security, inUse }], the strongest first
17
+ * security: open, wpa, wpa3 (a password); wep, enterprise, other (not joined here)
18
+ * join(ssid, password) the switch started: { started, ssid, back } (back: the network it
19
+ * goes back to, or null); the password goes to the host on standard input only
20
+ * forget(ssid) a kept network deleted (never the one in use)
21
+ */
22
+ import { Refusal } from './conversations.mjs';
23
+
24
+ const firstLine = (text) => String(text ?? '').trim().split('\n').filter(Boolean).pop()?.replace(/^REFUSED: /, '').slice(0, 200) ?? '';
25
+ /* As the host program takes them: a name of 1 to 32 bytes on one line; a WPA password
26
+ of 8 to 63 plain characters, or none (an open network). Checked here to say it at
27
+ once, and again there, where it matters. */
28
+ export function nameOk(ssid) {
29
+ const bytes = Buffer.byteLength(String(ssid ?? ''), 'utf8');
30
+ return typeof ssid === 'string' && bytes >= 1 && bytes <= 32 && !/[\u0000-\u001f\u007f]/.test(ssid);
31
+ }
32
+ export function passwordWhy(password) {
33
+ if (password === '') return '';
34
+ if (typeof password !== 'string') return 'The password is missing.';
35
+ if (password.length < 8 || password.length > 63) return 'A Wi-Fi password has 8 to 63 characters.';
36
+ if (!/^[\x20-\x7e]+$/.test(password)) return 'A Wi-Fi password is made of plain characters: letters without accents, digits, signs, spaces.';
37
+ if (/^ | $/.test(password)) return 'A password that starts or ends with a space cannot be given here.';
38
+ return '';
39
+ }
40
+ const STATES = ['joining', 'joined', 'went-back', 'back-failed', 'interrupted'];
41
+ /* After a join, the outcome is looked for this often and this long, to be said in What happened. */
42
+ const WATCH_EVERY_MS = 5000;
43
+ const WATCH_FOR_MS = 6 * 60_000;
44
+
45
+ /* "wifi status", line by line: only the lines of the expected shapes. */
46
+ export function readStatus(text) {
47
+ const out = { available: false, why: null, device: null, using: null, saved: [], last: null };
48
+ let nmcli = false;
49
+ for (const line of String(text ?? '').split('\n').slice(0, 300)) {
50
+ const word = line.split(' ', 1)[0]; const rest = line.slice(word.length + 1);
51
+ if (word === 'nmcli') nmcli = rest === 'yes';
52
+ else if (word === 'wifiwhy' && /^[a-z-]{1,20}$/.test(rest)) out.why = rest;
53
+ else if (word === 'device' && /^[A-Za-z0-9._-]{1,15}$/.test(rest)) out.device = rest;
54
+ else if (word === 'using') { const m = /^(\d{1,3}) (.+)$/.exec(rest); if (m) out.using = { signal: Math.min(100, Number(m[1])), ssid: m[2] }; }
55
+ else if (word === 'saved' && rest) out.saved.push(rest);
56
+ else if (word === 'last') { const m = /^([a-z-]+) (\d{1,12})$/.exec(rest); if (m && STATES.includes(m[1])) out.last = { ...(out.last ?? {}), state: m[1], at: new Date(Number(m[2]) * 1000).toISOString() }; }
57
+ else if (['lastssid', 'lastback', 'lastwhy'].includes(word) && line.startsWith(`${word} `)) out.last = { ...(out.last ?? {}), [word.slice(4)]: rest || null };
58
+ }
59
+ out.available = nmcli && !out.why && Boolean(out.device);
60
+ if (!nmcli && !out.why) out.why = 'unreadable';
61
+ if (out.last && !out.last.state) out.last = null;
62
+ return out;
63
+ }
64
+ /* "wifi scan": network <signal> <security> <now|other> <ssid>. */
65
+ export function readScan(text) {
66
+ const out = [];
67
+ for (const line of String(text ?? '').split('\n').slice(0, 200)) {
68
+ const m = /^network (\d{1,3}) ([a-z0-9]{1,12}) (now|other) (.+)$/.exec(line);
69
+ if (m) out.push({ ssid: m[4], signal: Math.min(100, Number(m[1])), security: m[2], inUse: m[3] === 'now' });
70
+ }
71
+ return out;
72
+ }
73
+
74
+ export class Wifi {
75
+ #host; #said; #watching = null; #everyMs; #forMs;
76
+ /* `said(text)`: an outcome, in What happened (events.mjs). */
77
+ constructor({ host, said = () => {}, watchEveryMs = WATCH_EVERY_MS, watchForMs = WATCH_FOR_MS }) {
78
+ this.#host = host; this.#said = said; this.#everyMs = watchEveryMs; this.#forMs = watchForMs;
79
+ }
80
+ async status() {
81
+ const r = await this.#host(['wifi', 'status'], { timeoutMs: 30_000 });
82
+ if (r.code !== 0) return { ...readStatus(''), why: 'unreadable', said: firstLine(r.stderr) || `exit ${r.code}` };
83
+ return readStatus(r.stdout);
84
+ }
85
+ async scan() {
86
+ const r = await this.#host(['wifi', 'scan'], { timeoutMs: 60_000 });
87
+ if (r.code !== 0) throw new Refusal(r.code === 78 ? 409 : 502, `The networks could not be listed: ${firstLine(r.stderr) || `exit ${r.code}`}`);
88
+ return readScan(r.stdout);
89
+ }
90
+ async join(ssid, password) {
91
+ if (!nameOk(ssid)) throw new Refusal(400, 'Not a network name: 1 to 32 bytes, on one line.');
92
+ const why = passwordWhy(password ?? '');
93
+ if (why) throw new Refusal(400, why);
94
+ /* On standard input, never as an argument: arguments are seen by every account of the server. */
95
+ const r = await this.#host(['wifi', 'join'], { input: `${ssid}\n${password ?? ''}\n`, timeoutMs: 60_000 });
96
+ if (r.code !== 0) throw new Refusal(r.code === 78 ? 409 : 502, firstLine(r.stderr) || `exit ${r.code}`);
97
+ const back = /^fallback (.*)$/m.exec(String(r.stdout ?? ''))?.[1] || null;
98
+ this.#watch(ssid);
99
+ return { started: true, ssid, back };
100
+ }
101
+ async forget(ssid) {
102
+ if (!nameOk(ssid)) throw new Refusal(400, 'Not a network name.');
103
+ const r = await this.#host(['wifi', 'forget', ssid], { timeoutMs: 30_000 });
104
+ if (r.code !== 0) throw new Refusal(r.code === 78 ? 409 : 502, firstLine(r.stderr) || `exit ${r.code}`);
105
+ return { forgotten: ssid };
106
+ }
107
+ /* THE OUTCOME, said once in What happened, whoever looks at the page: this server
108
+ keeps running through the switch (only its network comes and goes). */
109
+ #watch(ssid) {
110
+ clearTimeout(this.#watching);
111
+ const until = Date.now() + this.#forMs;
112
+ const look = async () => {
113
+ const s = await this.status().catch(() => null);
114
+ const last = s?.last;
115
+ if (last && last.state !== 'joining' && last.ssid === ssid) {
116
+ this.#watching = null;
117
+ const words = { joined: `Wi-Fi: this server is on "${ssid}" now`, 'went-back': `Wi-Fi: "${ssid}" did not work (${{ password: 'wrong password', 'no-connection': 'no connection', 'no-internet': 'no working network within a minute', stopped: 'stopped' }[last.why] ?? last.why ?? 'no reason given'}): back on ${last.back ? `"${last.back}"` : 'the network before'}`, 'back-failed': `Wi-Fi: "${ssid}" did not work, and "${last.back ?? ''}" did not come back: NetworkManager goes on trying`, interrupted: `Wi-Fi: the switch to "${ssid}" was interrupted` };
118
+ try { this.#said(words[last.state] ?? `Wi-Fi: ${last.state}`); } catch { /* never in the way */ }
119
+ return;
120
+ }
121
+ if (Date.now() < until) { this.#watching = setTimeout(look, this.#everyMs); this.#watching.unref?.(); }
122
+ };
123
+ this.#watching = setTimeout(look, this.#everyMs); this.#watching.unref?.();
124
+ }
125
+ }
package/web/app.js CHANGED
@@ -77,6 +77,24 @@
77
77
  let socket;
78
78
  let wanted = false; /* false while we closed the socket on purpose */
79
79
  let pollTimer;
80
+ /* AN UPDATE OR A RESTART (deploy/maintenance.html): the server says an update is about to stop
81
+ it (server/updates.mjs, notice), or the front says it is down: the page gives way to the
82
+ maintenance page, which comes back here by itself once the server answers again. And a page
83
+ older than the server (it slept through an update) starts again on the new one. True when
84
+ the page is leaving. */
85
+ let serverVersion = '';
86
+ const leaving = (r) => {
87
+ const update = r.headers.get('x-clavarium-update') ?? '';
88
+ if (update || r.headers.get('x-clavarium-down')) {
89
+ const [kind, to] = update ? update.split(' ') : ['', ''];
90
+ location.replace(`${DEVICE ? '/c' : ''}/maintenance.html?${new URLSearchParams({ kind, ...(to ? { to } : {}), back: location.pathname + location.search })}`);
91
+ return true;
92
+ }
93
+ const version = r.headers.get('x-clavarium-version') ?? '';
94
+ if (version && serverVersion && version !== serverVersion) { location.reload(); return true; }
95
+ serverVersion ||= version;
96
+ return false;
97
+ };
80
98
 
81
99
  const say = (label, kind) => { state.textContent = label; state.dataset.state = kind; };
82
100
  const show = (text, action, run, cancel) => {
@@ -828,7 +846,7 @@
828
846
  /* Given its chat and not its terminal: the chat is the whole page, and no terminal is ever opened. */
829
847
  if (noTerminal()) { chatAlone(); return; }
830
848
  /* Asleep because somebody asked: it stays asleep until somebody asks. */
831
- if (c && c.asleep === true && !socket) { say('asleep', 'waiting'); show('Asleep. The tool is frozen as it was.', 'Wake it', connect); return; }
849
+ if (c && c.asleep === true && !socket) { say('asleep', 'waiting'); show(`Asleep. The tool is frozen as it was.${c.sizeAtWake ? ` When it wakes, its machine is restarted with its new size (${laterWords(c.sizeAtWake)}), and the tool takes up its session.` : ''}`, 'Wake it', connect); return; }
832
850
  if (!socket) { terminal.reset(); connect(); }
833
851
  void watchSignIn();
834
852
  }
@@ -1278,6 +1296,7 @@
1278
1296
  if (DEVICE) {
1279
1297
  const mePath = () => `${API}/me?c=${encodeURIComponent(current)}`;
1280
1298
  let r = await fetch(mePath());
1299
+ if (leaving(r)) return;
1281
1300
  if (r.status === 401) {
1282
1301
  /* The session ended: the device signs again, quietly. */
1283
1302
  const door = await window.clavariumDoor();
@@ -1296,6 +1315,7 @@
1296
1315
  conversations = me.name ? [me] : []; current = me.name ?? '';
1297
1316
  } else {
1298
1317
  const r = await fetch(`${API}/conversations`);
1318
+ if (leaving(r)) return;
1299
1319
  if (!r.ok) throw new Error('no api');
1300
1320
  conversations = await r.json();
1301
1321
  await readDevices();
@@ -1795,6 +1815,8 @@
1795
1815
 
1796
1816
  /* ---------- the machine: its health, its size, a restart ---------- */
1797
1817
  const sizeWords = (mb) => (mb >= 1024 ? `${Number.isInteger(mb / 1024) ? mb / 1024 : (mb / 1024).toFixed(1)} GB` : `${mb} MB`);
1818
+ /* The size kept for its wake, in the words the server uses for a size. */
1819
+ function laterWords(w) { return `${w.memoryMb} MB, ${w.cpus} core${w.cpus > 1 ? 's' : ''}, ${w.diskGb} GB`; }
1798
1820
  /* `brief`: over a wait, only what to know -- figures stay in the Machine chapter. */
1799
1821
  function healthLines(list, record, { all = true, brief = false } = {}) {
1800
1822
  list.replaceChildren();
@@ -2015,6 +2037,13 @@
2015
2037
  for (const id of ['machine-memory', 'machine-cpus', 'machine-disk', 'machine-size-apply']) $(id).disabled = Boolean(waiting);
2016
2038
  $('machine-size').toggleAttribute('data-waiting', Boolean(waiting));
2017
2039
  $('machine-size-wait').textContent = waiting; $('machine-size-wait').hidden = !waiting;
2040
+ /* Asleep: chosen now, applied as it wakes -- it is not woken for it. */
2041
+ $('machine-size-hint').textContent = here?.asleep === true
2042
+ ? 'It is asleep: a new size is kept and applied when it wakes. Its machine is then stopped cleanly, set and started again, and the tool takes up its session. A disk can only grow.'
2043
+ : 'Changing them stops the machine cleanly, sets them and starts it again: its work folder, folders and branches stay. A disk can only grow.';
2044
+ $('machine-later-text').textContent = here?.sizeAtWake ? `Will be applied when it wakes: ${laterWords(here.sizeAtWake)}` : '';
2045
+ $('machine-later').hidden = !here?.sizeAtWake;
2046
+ $('machine-size-apply').textContent = here?.asleep === true ? 'Keep for its wake' : 'Apply...';
2018
2047
  /* When its tool starts: its last session, or a new one -- for a tool that can take one up. */
2019
2048
  $('resume-box').hidden = DEVICE || !here?.resumes;
2020
2049
  for (const b of $('resume-on').children) b.setAttribute('aria-pressed', String((b.dataset.on === 'true') === (here?.resume !== false)));
@@ -2036,6 +2065,11 @@
2036
2065
  catch (error) { $('panel-error').textContent = error.message; $('panel-error').hidden = false; }
2037
2066
  });
2038
2067
  }
2068
+ $('machine-later-cancel').addEventListener('click', async () => {
2069
+ $('panel-error').hidden = true;
2070
+ try { await post(`${API}/conversations/${encodeURIComponent(current)}/machine/cancel`, {}); await refresh(); paintMachine(conversations.find((x) => x.name === current)); }
2071
+ catch (error) { $('panel-error').textContent = error.message; $('panel-error').hidden = false; }
2072
+ });
2039
2073
  $('machine-size').addEventListener('submit', (event) => {
2040
2074
  event.preventDefault();
2041
2075
  const name = current;
@@ -2043,9 +2077,18 @@
2043
2077
  if (!here) return;
2044
2078
  const memoryMb = Number($('machine-memory').value); const diskGb = Number($('machine-disk').value); const cpus = Number($('machine-cpus').value) || (here.cpus ?? 1);
2045
2079
  if (memoryMb === here.memoryMb && diskGb === (here.diskGb ?? 8) && cpus === (here.cpus ?? 1)) { $('panel-error').textContent = 'Nothing to change: choose another memory, cores or disk first.'; $('panel-error').hidden = false; return; }
2080
+ const changes = [memoryMb !== here.memoryMb ? `${sizeWords(memoryMb)} of memory (now ${sizeWords(here.memoryMb)})` : '', cpus !== (here.cpus ?? 1) ? `${cpus} core${cpus > 1 ? 's' : ''} (now ${here.cpus ?? 1})` : '', diskGb !== (here.diskGb ?? 8) ? `a disk of ${diskGb} GB (now ${here.diskGb ?? 8} GB; it can never shrink again)` : ''].filter(Boolean).join(' and ');
2081
+ /* Asleep: kept for its wake, from Settings, where it is then said; nothing is stopped or woken now. */
2082
+ if (here.asleep === true) {
2083
+ $('panel-error').hidden = true;
2084
+ void (async () => {
2085
+ try { await post(`${API}/conversations/${encodeURIComponent(name)}/machine`, { memoryMb, diskGb, cpus }); await refresh(); paintMachine(conversations.find((x) => x.name === name)); }
2086
+ catch (error) { $('panel-error').textContent = error.message; $('panel-error').hidden = false; }
2087
+ })();
2088
+ return;
2089
+ }
2046
2090
  leavePanel();
2047
2091
  const resume = socket && state.dataset.state === 'live' ? () => { notice.hidden = true; focusTerminal(); } : enter;
2048
- const changes = [memoryMb !== here.memoryMb ? `${sizeWords(memoryMb)} of memory (now ${sizeWords(here.memoryMb)})` : '', cpus !== (here.cpus ?? 1) ? `${cpus} core${cpus > 1 ? 's' : ''} (now ${here.cpus ?? 1})` : '', diskGb !== (here.diskGb ?? 8) ? `a disk of ${diskGb} GB (now ${here.diskGb ?? 8} GB; it can never shrink again)` : ''].filter(Boolean).join(' and ');
2049
2092
  show(`Give "${name}" ${changes}? ITS MACHINE IS STOPPED CLEANLY, SET, AND STARTED AGAIN: what the tool is doing now is interrupted. Its work folder, its folders and its branches stay.`,
2050
2093
  'Change it', async () => {
2051
2094
  disconnect(); say('restarting', 'connecting'); show('Changing its machine...'); $('notice-spin').hidden = false;
@@ -2242,7 +2285,7 @@
2242
2285
  onView: (v) => { chatView = v; try { localStorage.setItem('clavarium-chat-view', v); } catch { /* as above */ } },
2243
2286
  load: () => fetch(talkPath(name)).then((r) => r.json()).then(machineLines).then((data) => withMachine(data, name)),
2244
2287
  /* `via: 'voice'`: part of it was dictated, said to the tool. */
2245
- send: (text, answers, files, extra) => post(talkPath(name), { text, answers, ...(files ? { files: files.map((f) => f.path) } : {}), ...(extra?.via === 'voice' ? { via: 'voice' } : {}) }),
2288
+ send: (text, answers, files, extra) => post(talkPath(name), { text, answers, ...(files ? { files: files.map((f) => (f.note ? { path: f.path, note: f.note } : f.path)) } : {}), ...(extra?.via === 'voice' ? { via: 'voice' } : {}) }),
2246
2289
  /* A reaction to one of its messages: wherever the chat may be written in. */
2247
2290
  ...(!DEVICE || deviceParts.chat === 'write' ? { react: (to, reaction) => post(talkPath(name, '/react'), { to, reaction }) } : {}),
2248
2291
  /* The buttons of a line of the machine: what this screen may do. */
@@ -3456,6 +3499,7 @@
3456
3499
  $('settings-address').textContent = `Address: ${platform.address ?? 'not declared'}.`;
3457
3500
  $('settings-about').textContent = `Clavarium ${platform.version ?? ''}`;
3458
3501
  void paintInstance();
3502
+ if ($('settings-wifi-top').open) void paintWifi();
3459
3503
  await Promise.all([paintHosts(), paintShelf(), paintServer(), paintUpdates()]);
3460
3504
  }
3461
3505
 
@@ -3887,6 +3931,130 @@
3887
3931
  if (!p.disks.some((d) => !d.system)) rows.append(el('p', 'hint', 'No other disk: plug one in (or add one to this server), then open this again.'));
3888
3932
  }
3889
3933
  $('move-machines-box').addEventListener('toggle', () => { if ($('move-machines-box').open) void paintMoveMachines(); });
3934
+ /* NETWORK: this server's Wi-Fi (server/wifi.mjs). The networks it sees, the one it is on, another
3935
+ joined with its password, one it keeps forgotten. A join only STARTS a switch: the host goes back
3936
+ to the network before by itself when the new one does not work within a minute -- this page may
3937
+ lose the server meanwhile, so it says so before, and reads the outcome when it can again. */
3938
+ const WIFI_OUTSIDE = {
3939
+ 'no-nmcli': 'Wi-Fi is managed outside Clavarium on this server (NetworkManager is not installed here).',
3940
+ 'not-running': 'Wi-Fi is managed outside Clavarium on this server (NetworkManager does not run here).',
3941
+ 'no-device': 'This server has no Wi-Fi device that NetworkManager sees: its network is managed outside Clavarium.',
3942
+ unmanaged: 'Wi-Fi is managed outside Clavarium on this server (its Wi-Fi device is not NetworkManager\'s to drive).',
3943
+ unreadable: 'This server\'s network cannot be read just now.',
3944
+ };
3945
+ const WIFI_WHY = { password: 'the password was not accepted', 'no-connection': 'it could not connect', 'no-internet': 'it gave no working network within a minute', stopped: 'the switch was stopped' };
3946
+ const SECURITY_WORDS = { open: 'open', wpa: 'password', wpa3: 'password (WPA3)', wep: 'old protection (WEP): not joined here', enterprise: 'user and certificate (802.1X): not joined here', other: 'not joined here' };
3947
+ let wifiNow = null; let wifiTimer;
3948
+ /* Four bars, as many lit as the signal is strong; the figure for whoever reads it aloud. */
3949
+ const signalBars = (signal) => {
3950
+ const box = el('span', 'wifi-bars'); box.setAttribute('role', 'img'); box.setAttribute('aria-label', `Signal ${signal}%`); box.title = `Signal ${signal}%`;
3951
+ for (let i = 1; i <= 4; i++) { const bar = el('span', signal >= i * 25 - 12 ? 'on' : ''); bar.style.height = `${i * 25}%`; box.append(bar); }
3952
+ return box;
3953
+ };
3954
+ const lockSign = () => {
3955
+ const ns = 'http://www.w3.org/2000/svg'; const svg = document.createElementNS(ns, 'svg');
3956
+ svg.setAttribute('viewBox', '0 0 24 24'); svg.setAttribute('class', 'wifi-lock'); svg.setAttribute('role', 'img'); svg.setAttribute('aria-label', 'Protected');
3957
+ const body = document.createElementNS(ns, 'rect'); body.setAttribute('x', '5'); body.setAttribute('y', '11'); body.setAttribute('width', '14'); body.setAttribute('height', '10'); body.setAttribute('rx', '2');
3958
+ const arch = document.createElementNS(ns, 'path'); arch.setAttribute('d', 'M8 11V7a4 4 0 0 1 8 0v4');
3959
+ svg.append(body, arch); return svg;
3960
+ };
3961
+ async function paintWifi() {
3962
+ clearTimeout(wifiTimer);
3963
+ const s = await fetch(`${API}/wifi`, { cache: 'no-store' }).then((r) => (r.ok ? r.json() : null)).catch(() => null);
3964
+ if (!s) {
3965
+ /* Lost during a switch, most likely: looked at again until it answers. */
3966
+ $('wifi-now').textContent = 'This server does not answer just now. If it is changing networks, it comes back within a minute or two.';
3967
+ if ($('settings-wifi-top').open && !$('settings').hidden) wifiTimer = setTimeout(() => { void paintWifi(); }, 4000);
3968
+ return;
3969
+ }
3970
+ wifiNow = s;
3971
+ $('wifi-controls').hidden = !s.available;
3972
+ if (!s.available) { $('wifi-now').textContent = WIFI_OUTSIDE[s.why] ?? WIFI_OUTSIDE.unreadable; $('wifi-last').hidden = true; return; }
3973
+ $('wifi-now').replaceChildren();
3974
+ if (s.using) $('wifi-now').append(el('span', '', 'On '), el('b', '', s.using.ssid), el('span', '', ` (Wi-Fi, ${s.device}) `), signalBars(s.using.signal));
3975
+ else $('wifi-now').textContent = `Not on a Wi-Fi network (${s.device}).`;
3976
+ /* The last switch, as the host recorded it. */
3977
+ const last = s.last; const words = !last ? '' : {
3978
+ joining: `Joining "${last.ssid}"... If it does not work within a minute, the server goes back to ${last.back ? `"${last.back}"` : 'the network before'} by itself.`,
3979
+ joined: `"${last.ssid}" worked: this server is on it.`,
3980
+ 'went-back': `"${last.ssid}" did not work (${WIFI_WHY[last.why] ?? last.why ?? 'no reason given'}): the server went back to ${last.back ? `"${last.back}"` : 'the network before'}.`,
3981
+ 'back-failed': `"${last.ssid}" did not work, and ${last.back ? `"${last.back}"` : 'the network before'} did not come back at once: NetworkManager goes on trying by itself.`,
3982
+ interrupted: `The switch to "${last.ssid}" was interrupted (the server restarted?).`,
3983
+ }[last.state] ?? '';
3984
+ $('wifi-last').textContent = words; $('wifi-last').hidden = !words;
3985
+ if (last?.state === 'joining' && $('settings-wifi-top').open && !$('settings').hidden) wifiTimer = setTimeout(() => { void paintWifi(); }, 3000);
3986
+ /* What it keeps: forgotten here (never the one in use). */
3987
+ const saved = $('wifi-saved'); saved.replaceChildren();
3988
+ for (const ssid of s.saved) {
3989
+ const row = el('div', 'folder'); row.append(el('b', '', ssid));
3990
+ if (s.using?.ssid === ssid) row.append(el('small', 'hint', ' in use'));
3991
+ else {
3992
+ const forget = el('button', '', 'Forget...'); forget.type = 'button';
3993
+ forget.addEventListener('click', () => {
3994
+ if (forget.dataset.sure !== 'yes') { forget.dataset.sure = 'yes'; forget.textContent = `Yes: forget "${ssid}" and its password`; return; }
3995
+ forget.disabled = true;
3996
+ void post(`${API}/wifi/forget`, { ssid }).then(() => { $('wifi-said').textContent = `"${ssid}" forgotten.`; void paintWifi(); }).catch((error) => { $('wifi-said').textContent = error.message; forget.disabled = false; });
3997
+ });
3998
+ row.append(forget);
3999
+ }
4000
+ saved.append(row);
4001
+ }
4002
+ $('wifi-saved-box').hidden = !s.saved.length;
4003
+ }
4004
+ $('settings-wifi-top').addEventListener('toggle', () => { if ($('settings-wifi-top').open) void paintWifi(); else clearTimeout(wifiTimer); });
4005
+ $('wifi-scan').addEventListener('click', async () => {
4006
+ $('wifi-scan').disabled = true; $('wifi-said').textContent = 'Looking (a few seconds)...';
4007
+ try {
4008
+ const r = await fetch(`${API}/wifi/scan`, { cache: 'no-store' });
4009
+ const list = await r.json().catch(() => null);
4010
+ if (!r.ok) throw new Error(list?.error ?? 'The networks could not be listed.');
4011
+ const ul = $('wifi-list'); ul.replaceChildren();
4012
+ for (const n of list) {
4013
+ const li = el('li', 'wifi-network'); li.dataset.ssid = n.ssid;
4014
+ const joinable = ['open', 'wpa', 'wpa3'].includes(n.security) && !n.inUse;
4015
+ const pick = el('button', 'as-link', ''); pick.type = 'button'; pick.disabled = !joinable;
4016
+ pick.append(signalBars(n.signal), ...(n.security === 'open' ? [] : [lockSign()]), el('span', 'wifi-name', n.ssid));
4017
+ li.append(pick, el('small', 'hint', n.inUse ? 'in use' : SECURITY_WORDS[n.security] ?? n.security));
4018
+ pick.addEventListener('click', () => { chooseWifi(n); });
4019
+ ul.append(li);
4020
+ }
4021
+ ul.hidden = !list.length;
4022
+ $('wifi-said').textContent = list.length ? '' : 'No network in sight.';
4023
+ } catch (error) { $('wifi-said').textContent = error.message; }
4024
+ $('wifi-scan').disabled = false;
4025
+ });
4026
+ /* One chosen: its password asked (never shown back), and what happens if it does not work said BEFORE. */
4027
+ let wifiChosen = null;
4028
+ function chooseWifi(n) {
4029
+ wifiChosen = n;
4030
+ const open = n.security === 'open';
4031
+ $('wifi-join-what').textContent = open ? `Join "${n.ssid}", an open network?` : `Join "${n.ssid}":`;
4032
+ $('wifi-password-box').hidden = open;
4033
+ $('wifi-password').value = ''; $('wifi-password').required = !open;
4034
+ const back = wifiNow?.using?.ssid;
4035
+ $('wifi-join-back').textContent = back
4036
+ ? `If it does not work within a minute, the server goes back to "${back}" by itself. This page may lose the server meanwhile: it comes back by itself.`
4037
+ : 'If it does not work within a minute, the server leaves it by itself.';
4038
+ $('wifi-join-error').hidden = true; $('wifi-join-go').disabled = false;
4039
+ $('wifi-join').hidden = false;
4040
+ if (!open) $('wifi-password').focus();
4041
+ }
4042
+ $('wifi-join-cancel').addEventListener('click', () => { $('wifi-join').hidden = true; $('wifi-password').value = ''; wifiChosen = null; });
4043
+ $('wifi-join').addEventListener('submit', (event) => {
4044
+ event.preventDefault();
4045
+ if (!wifiChosen) return;
4046
+ const n = wifiChosen; const password = n.security === 'open' ? '' : $('wifi-password').value;
4047
+ if (n.security !== 'open' && (password.length < 8 || password.length > 63)) { $('wifi-join-error').textContent = 'A Wi-Fi password has 8 to 63 characters.'; $('wifi-join-error').hidden = false; return; }
4048
+ $('wifi-join-go').disabled = true;
4049
+ void post(`${API}/wifi/join`, { ssid: n.ssid, password }).then(() => {
4050
+ /* The password leaves the page with the request: not kept in the field. */
4051
+ $('wifi-password').value = ''; $('wifi-join').hidden = true; wifiChosen = null;
4052
+ $('wifi-list').hidden = true;
4053
+ void paintWifi();
4054
+ }).catch((error) => {
4055
+ $('wifi-join-error').textContent = error.message; $('wifi-join-error').hidden = false; $('wifi-join-go').disabled = false;
4056
+ });
4057
+ });
3890
4058
  /* WHAT HAPPENED: newest first, a page at a time; chosen by kind, searched. */
3891
4059
  const EVENT_WORDS = { conversation: 'Conversation', machine: 'Machine', access: 'Access', asset: 'Asset', update: 'Update', server: 'Server', 'sign-in': 'Sign-in' };
3892
4060
  let eventsShown = []; let eventsAsk = 0;
@@ -3961,9 +4129,8 @@
3961
4129
  go.disabled = true;
3962
4130
  void post(`${API}/server/restart`, {}).then(() => {
3963
4131
  $('server-restart-said').textContent = 'Restarting: this page comes back by itself.';
3964
- /* Back once it answers again. */
3965
- const back = async () => { try { if ((await fetch(`${API}/updates`, { cache: 'no-store' })).ok) { location.reload(); return; } } catch { /* not yet */ } setTimeout(back, 2000); };
3966
- setTimeout(back, 5000);
4132
+ /* The maintenance page waits for it (it answers a moment more before it stops), then comes back here. */
4133
+ location.replace(`/maintenance.html?${new URLSearchParams({ kind: 'restart', back: location.pathname + location.search })}`);
3967
4134
  }).catch((error) => { $('server-restart-said').textContent = error.message; go.disabled = false; delete go.dataset.sure; go.textContent = 'Restart this server...'; });
3968
4135
  });
3969
4136
  /* THE CURVES (server/history.mjs): memory, CPU and disk over time, one small chart each, one
package/web/index.html CHANGED
@@ -210,6 +210,8 @@
210
210
  <select id="machine-disk"></select>
211
211
  <p class="hint" id="machine-size-wait" role="status" hidden></p>
212
212
  <p class="hint" id="machine-size-hint">Changing them stops the machine cleanly, sets them and starts it again: its work folder, folders and branches stay. A disk can only grow.</p>
213
+ <!-- CHOSEN WHILE IT SLEEPS: kept, and applied when it wakes (server/conversations.mjs, #wakeResized). -->
214
+ <p class="hint" id="machine-later" role="status" hidden><span id="machine-later-text"></span> · <button type="button" id="machine-later-cancel" class="inline">cancel</button></p>
213
215
  <div class="row"><button type="submit" id="machine-size-apply">Apply...</button></div>
214
216
  </form>
215
217
  <div id="work-box">
@@ -705,6 +707,35 @@
705
707
  (server/updates.mjs; the updater, as root: deploy/updater.mjs). -->
706
708
  </div>
707
709
  </details>
710
+ <!-- NETWORK: this server's Wi-Fi (server/wifi.mjs; done as root by the host program,
711
+ through NetworkManager). A switch goes back by itself when the new network does not work. -->
712
+ <details class="chapter" id="settings-wifi-top" data-chapter="s-network">
713
+ <summary><span class="chapter-title">Network</span><span class="chapter-about">The Wi-Fi this server is on; another one joined.</span></summary>
714
+ <div class="chapter-body">
715
+ <div id="wifi" tabindex="-1">
716
+ <p id="wifi-now" role="status"></p>
717
+ <p id="wifi-last" class="hint" role="status" hidden></p>
718
+ <div id="wifi-controls" hidden>
719
+ <div class="row"><button type="button" id="wifi-scan">Look for networks</button><span class="hint" id="wifi-said" role="status"></span></div>
720
+ <ul id="wifi-list" class="wifi-list" hidden></ul>
721
+ <form id="wifi-join" class="wifi-join" hidden>
722
+ <p id="wifi-join-what"></p>
723
+ <div id="wifi-password-box">
724
+ <label for="wifi-password">Its password</label>
725
+ <input id="wifi-password" type="password" autocomplete="off" spellcheck="false" autocapitalize="off" minlength="8" maxlength="63">
726
+ </div>
727
+ <p class="hint" id="wifi-join-back"></p>
728
+ <div class="row"><button type="submit" class="primary" id="wifi-join-go">Join</button><button type="button" id="wifi-join-cancel">Cancel</button></div>
729
+ <p id="wifi-join-error" class="error" role="alert" hidden></p>
730
+ </form>
731
+ <details id="wifi-saved-box" hidden>
732
+ <summary>Networks this server keeps</summary>
733
+ <div id="wifi-saved"></div>
734
+ </details>
735
+ </div>
736
+ </div>
737
+ </div>
738
+ </details>
708
739
  <details class="chapter" id="settings-updates-top" data-chapter="s-updates">
709
740
  <summary><span class="chapter-title">Updates</span><span class="chapter-about">The version that runs, and how it updates.</span></summary>
710
741
  <div class="chapter-body">