clavarium 0.2.169-next.1 → 0.2.173-next.1
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/deploy/clavarium-host +5 -4
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/api.mjs +1 -1
- package/server/boxes.mjs +1 -0
- package/server/serverlogs.mjs +32 -5
- package/web/app.js +38 -4
- package/web/index.html +2 -1
package/deploy/clavarium-host
CHANGED
|
@@ -962,7 +962,7 @@ case "$AREA $VERB" in
|
|
|
962
962
|
# WHAT THE SERVER'S PROGRAMS SAID, for Settings (This server, Logs): one
|
|
963
963
|
# source, over a span; read-only, bounded. The page masks what looks
|
|
964
964
|
# like a secret before showing it.
|
|
965
|
-
# server logs <clavarium|machines|updates|web|signin|tunnel|system> <1|6|24|168|boot>
|
|
965
|
+
# server logs <clavarium|machines|updates|web|signin|tunnel|system> <10m|1|6|24|168|boot>
|
|
966
966
|
[ $# -eq 2 ] || usage
|
|
967
967
|
case "$1" in
|
|
968
968
|
clavarium) units=(-u clavarium.service -u 'clavarium-view-*' -u clavarium-tools-view.service -u clavarium-move-machines.service) ;;
|
|
@@ -974,9 +974,10 @@ case "$AREA $VERB" in
|
|
|
974
974
|
system) units=(-k) ;;
|
|
975
975
|
*) refuse "not a source of logs: $1" ;;
|
|
976
976
|
esac
|
|
977
|
-
case "$2" in 1|6|24|168) since=(--since "-$2h") ;; boot) since=(-b) ;; *) refuse "not a span: $2 (1, 6, 24, 168 hours, or boot)" ;; esac
|
|
978
|
-
|
|
979
|
-
|
|
977
|
+
case "$2" in 10m) since=(--since "-10min") ;; 1|6|24|168) since=(--since "-$2h") ;; boot) since=(-b) ;; *) refuse "not a span: $2 (10m, 1, 6, 24, 168 hours, or boot)" ;; esac
|
|
978
|
+
# The newest 20000 lines at most: more is too much to read on a page, and to send.
|
|
979
|
+
if [ "$SAY" = "yes" ]; then echo "journalctl ${units[*]} ${since[*]} -o short-iso --no-pager (the last 20000 lines)"; exit 0; fi
|
|
980
|
+
journalctl "${units[@]}" "${since[@]}" -o short-iso --no-pager -n 20000 2>/dev/null | cut -c1-2000 || true
|
|
980
981
|
exit 0 ;;
|
|
981
982
|
"server restart")
|
|
982
983
|
# THIS SERVER STARTED AGAIN, asked from the page: in two seconds, by
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.173-next.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "clavarium",
|
|
9
|
-
"version": "0.2.
|
|
9
|
+
"version": "0.2.173-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/api.mjs
CHANGED
|
@@ -310,7 +310,7 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
310
310
|
}));
|
|
311
311
|
return send(200, history.together(query.get('span') ?? '1h', machines, { memoryMb: a?.memory?.totalMb, cores: room?.cpu?.cores, diskMb: a?.disk?.sizeMb })), true;
|
|
312
312
|
}
|
|
313
|
-
if (pathname === '/api/server/logs' && serverLogs)
|
|
313
|
+
if (pathname === '/api/server/logs' && serverLogs) { const r = await serverLogs.start(query.get('source') ?? 'clavarium', query.get('span') ?? '10m'); return send(r.pending ? 202 : 200, r), true; }
|
|
314
314
|
if (pathname === '/api/machines/disks' && machinesMove) return send(200, await machinesMove.disks()), true;
|
|
315
315
|
if (pathname === '/api/machines/places' && machinesMove) return send(200, await machinesMove.places()), true;
|
|
316
316
|
if (pathname === '/api/machines/moving' && machinesMove) return send(200, await machinesMove.moving()), true;
|
package/server/boxes.mjs
CHANGED
|
@@ -214,6 +214,7 @@ export class Boxes {
|
|
|
214
214
|
try { m = JSON.parse(String(data)); } catch { return; }
|
|
215
215
|
if (!m || typeof m !== 'object') return;
|
|
216
216
|
if (m.t === 'ping') { send({ t: 'pong' }); return; }
|
|
217
|
+
if (m.t === 'hello' && typeof m.problem === 'string' && m.problem) this.#log(`voice box ${box.name}: back online after ${Number(m.tries) || '?'} tries; it had: ${m.problem.slice(0, 160)}`);
|
|
217
218
|
if (m.t === 'hello') { link.muted = m.muted === true; link.volume = Number.isFinite(m.volume) ? m.volume : null; this.#change(box.id, { firmware: String(m.firmware ?? '').slice(0, 20) }); seen(); return; }
|
|
218
219
|
if (m.t === 'listen.start') { sentence = []; size = 0; return; }
|
|
219
220
|
if (m.t === 'listen.end' && sentence) {
|
package/server/serverlogs.mjs
CHANGED
|
@@ -11,8 +11,10 @@
|
|
|
11
11
|
import { Refusal } from './conversations.mjs';
|
|
12
12
|
|
|
13
13
|
export const SOURCES = ['clavarium', 'machines', 'updates', 'web', 'signin', 'tunnel', 'system'];
|
|
14
|
-
export const SPANS = ['1', '6', '24', '168', 'boot'];
|
|
15
|
-
|
|
14
|
+
export const SPANS = ['10m', '1', '6', '24', '168', 'boot'];
|
|
15
|
+
/* What a page reads at once: masking and sending more held this server for seconds (found 31-10:
|
|
16
|
+
the front then said "being updated" to every other page meanwhile). The newest are kept. */
|
|
17
|
+
const TEXT_MAX = 4 * 1024 * 1024;
|
|
16
18
|
|
|
17
19
|
const NAMED = /\b(password|passwd|passphrase|secret|token|api[_-]?key|authorization|cookie|bearer|client[_-]?secret)(["']?\s*[=:]\s*|\s+)("[^"]*"|'[^']*'|\S+)/gi;
|
|
18
20
|
const LONG = /[A-Za-z0-9_+/=]{32,}/g;
|
|
@@ -20,12 +22,37 @@ export function mask(text) {
|
|
|
20
22
|
return String(text).replace(NAMED, (all, word, between) => `${word}${between}[masked]`).replace(LONG, '[masked]');
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
/* A read longer than this is answered "still reading": the front cuts a request that waits
|
|
26
|
+
much longer (found 31-10 on a big journal: even 10 minutes took too long there). */
|
|
27
|
+
export const WAIT_MS = 12_000;
|
|
28
|
+
export const KEPT_MS = 120_000;
|
|
29
|
+
|
|
23
30
|
export class ServerLogs {
|
|
24
|
-
#host;
|
|
25
|
-
constructor({ host }) { this.#host = host; }
|
|
31
|
+
#host; #reads = new Map(); #now;
|
|
32
|
+
constructor({ host, now = () => Date.now() }) { this.#host = host; this.#now = now; }
|
|
33
|
+
|
|
34
|
+
/* The same read asked again while it runs is the same read; once done, kept a moment for
|
|
35
|
+
the page that comes back for it. Resolves { pending: true } past `wait`. */
|
|
36
|
+
async start(source, span, wait = WAIT_MS) {
|
|
37
|
+
const key = `${source}:${span}`;
|
|
38
|
+
const now = this.#now();
|
|
39
|
+
for (const [k, r] of this.#reads) if (r.done && now - r.done > KEPT_MS) this.#reads.delete(k);
|
|
40
|
+
let r = this.#reads.get(key);
|
|
41
|
+
if (!r) {
|
|
42
|
+
r = { done: 0 };
|
|
43
|
+
r.promise = this.read(source, span).then((v) => { r.value = v; }, (e) => { r.error = e; }).finally(() => { r.done = this.#now(); });
|
|
44
|
+
this.#reads.set(key, r);
|
|
45
|
+
}
|
|
46
|
+
await Promise.race([r.promise, new Promise((ok) => { setTimeout(ok, wait).unref?.(); })]);
|
|
47
|
+
if (!r.done) return { pending: true, source, span: String(span) };
|
|
48
|
+
this.#reads.delete(key);
|
|
49
|
+
if (r.error) throw r.error;
|
|
50
|
+
return r.value;
|
|
51
|
+
}
|
|
52
|
+
|
|
26
53
|
async read(source, span) {
|
|
27
54
|
if (!SOURCES.includes(source)) throw new Refusal(400, `Not a source of logs: say one of ${SOURCES.join(', ')}.`);
|
|
28
|
-
if (!SPANS.includes(String(span))) throw new Refusal(400, 'Not a span: 1, 6, 24 or 168 hours, or since the server started (boot).');
|
|
55
|
+
if (!SPANS.includes(String(span))) throw new Refusal(400, 'Not a span: 10 minutes (10m), 1, 6, 24 or 168 hours, or since the server started (boot).');
|
|
29
56
|
const r = await this.#host(['server', 'logs', source, String(span)], { timeoutMs: 120_000, maxBytes: TEXT_MAX * 2 });
|
|
30
57
|
if (r.code !== 0) throw new Refusal(502, `The logs could not be read: ${String(r.stderr ?? '').trim().split('\n').pop()?.replace(/^REFUSED: /, '').slice(0, 200) || `exit ${r.code}`}`);
|
|
31
58
|
let text = String(r.stdout ?? '');
|
package/web/app.js
CHANGED
|
@@ -980,9 +980,13 @@
|
|
|
980
980
|
pointManifest(installName());
|
|
981
981
|
|
|
982
982
|
/* ---------- the list ---------- */
|
|
983
|
+
/* THE FRONT'S "NO ANSWER" (503, down): the server was busy a moment, or restarting -- it does
|
|
984
|
+
not know which. Said as busy, never as an update (#220); a read is tried again by itself. */
|
|
985
|
+
const BUSY = 'The server is busy just now: try again in a moment.';
|
|
983
986
|
const post = async (path, body) => {
|
|
984
987
|
const r = await fetch(path, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body ?? {}) });
|
|
985
988
|
const j = await r.json().catch(() => ({}));
|
|
989
|
+
if (!r.ok && r.status === 503 && j.down === true) throw Object.assign(new Error(BUSY), { retry: true });
|
|
986
990
|
if (!r.ok) throw Object.assign(new Error(j.error || 'The request failed.'), { kind: j.kind, retry: j.retry === true });
|
|
987
991
|
return j;
|
|
988
992
|
};
|
|
@@ -3296,7 +3300,30 @@
|
|
|
3296
3300
|
/* Adding to a type category of live links (a calendar, an address book, an
|
|
3297
3301
|
access) is connecting an account: they all open the connect-account form. */
|
|
3298
3302
|
const addForm = (k) => (['agenda', 'contacts', 'acces'].includes(k) ? 'connexion' : k);
|
|
3299
|
-
|
|
3303
|
+
/* Its answer, or { state: 'error', message }: the server's own words, or busy (asked again first). */
|
|
3304
|
+
const readOrSay = async (path) => {
|
|
3305
|
+
for (let i = 0; i < 3; i++) {
|
|
3306
|
+
try {
|
|
3307
|
+
const r = await fetch(`${API}${path}`);
|
|
3308
|
+
const j = await r.json().catch(() => ({}));
|
|
3309
|
+
if (r.ok) return j;
|
|
3310
|
+
if (!(r.status === 503 && j.down === true)) return { state: 'error', message: j.error || 'It could not be read.' };
|
|
3311
|
+
} catch { return { state: 'error', message: 'It could not be read.' }; }
|
|
3312
|
+
await new Promise((ok) => setTimeout(ok, 1500 * (i + 1)));
|
|
3313
|
+
}
|
|
3314
|
+
return { state: 'error', message: BUSY };
|
|
3315
|
+
};
|
|
3316
|
+
const getJson = async (path, fallback) => {
|
|
3317
|
+
for (let i = 0; i < 3; i++) {
|
|
3318
|
+
try {
|
|
3319
|
+
const r = await fetch(`${API}${path}`);
|
|
3320
|
+
if (r.ok) return await r.json();
|
|
3321
|
+
if (r.status !== 503) return fallback;
|
|
3322
|
+
} catch { return fallback; }
|
|
3323
|
+
await new Promise((ok) => setTimeout(ok, 1500 * (i + 1))); /* busy a moment: asked again */
|
|
3324
|
+
}
|
|
3325
|
+
return fallback;
|
|
3326
|
+
};
|
|
3300
3327
|
const el = (tag, cls, text) => { const e = document.createElement(tag); if (cls) e.className = cls; if (text !== undefined) e.textContent = text; return e; };
|
|
3301
3328
|
/* A commit: its line, and the rest of its message under it, opened by a click. */
|
|
3302
3329
|
function commitRow(c) {
|
|
@@ -3728,7 +3755,7 @@
|
|
|
3728
3755
|
const query = new URLSearchParams();
|
|
3729
3756
|
if (r.branch) query.set('branch', r.branch);
|
|
3730
3757
|
if (r.target) query.set('target', r.target);
|
|
3731
|
-
const [out, keep] = await Promise.all([
|
|
3758
|
+
const [out, keep] = await Promise.all([readOrSay(`/git/${r.name}/outgoing${query.size ? `?${query}` : ''}`), r.keep ? r.keep : getJson(`/git/${r.name}/keep`, null)]);
|
|
3732
3759
|
r.out = out; r.keep = keep; r.branch = out.branch ?? r.branch; r.target = out.target ?? r.target; r.check = null;
|
|
3733
3760
|
/* What the server knows of this very commit and target: a check still running is followed again; the last
|
|
3734
3761
|
one that ran is shown with its age (left and come back, even the next day: nothing run again for nothing). */
|
|
@@ -6048,8 +6075,15 @@
|
|
|
6048
6075
|
const source = $('logs-source').value; const span = $('logs-span').value;
|
|
6049
6076
|
$('logs-said').textContent = 'Reading...'; $('logs-show').disabled = true;
|
|
6050
6077
|
try {
|
|
6051
|
-
|
|
6052
|
-
|
|
6078
|
+
/* A big journal takes a while: the server says "still reading" (202), and is asked again. */
|
|
6079
|
+
let r; let body = {};
|
|
6080
|
+
for (let i = 0; i < 30; i++) {
|
|
6081
|
+
r = await fetch(`${API}/server/logs?source=${encodeURIComponent(source)}&span=${encodeURIComponent(span)}`);
|
|
6082
|
+
body = await r.json().catch(() => ({}));
|
|
6083
|
+
if (r.status === 202 || (r.status === 503 && body.down === true)) { $('logs-said').textContent = `Reading... (a big journal: ${(i + 1) * 12} s)`; continue; }
|
|
6084
|
+
break;
|
|
6085
|
+
}
|
|
6086
|
+
if (r.status === 202) throw new Error('The logs take too long to read: try a shorter span.');
|
|
6053
6087
|
if (!r.ok) throw new Error(body.error ?? `The logs could not be read (${r.status}).`);
|
|
6054
6088
|
logsShown = body;
|
|
6055
6089
|
$('logs-text').textContent = body.text || '';
|
package/web/index.html
CHANGED
|
@@ -965,9 +965,10 @@
|
|
|
965
965
|
<option value="tunnel">Tunnel</option>
|
|
966
966
|
</select></label>
|
|
967
967
|
<label>Over <select id="logs-span" class="pill">
|
|
968
|
+
<option value="10m" selected>the last 10 minutes</option>
|
|
968
969
|
<option value="1">the last hour</option>
|
|
969
970
|
<option value="6">the last 6 hours</option>
|
|
970
|
-
<option value="24"
|
|
971
|
+
<option value="24">the last 24 hours</option>
|
|
971
972
|
<option value="168">the last 7 days</option>
|
|
972
973
|
<option value="boot">since the server started</option>
|
|
973
974
|
</select></label>
|