clavarium 0.2.3 → 0.2.4
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 +25 -3
- package/deploy/updater.mjs +5 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/api.mjs +2 -1
- package/server/certificate.mjs +67 -0
- package/server/gitchecks.mjs +30 -0
- package/server/gitkeeper.mjs +17 -2
- package/server/guide.mjs +3 -1
- package/server/main.mjs +6 -3
- package/web/app.js +16 -2
- package/web/index.html +3 -0
package/deploy/clavarium-host
CHANGED
|
@@ -210,6 +210,26 @@ folder_of() {
|
|
|
210
210
|
held "$MNT/resources/$1"
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
+
# A VIEW IN A SERVICE OF ITS OWN (clavarium-view-<name>, transient): bindfs
|
|
214
|
+
# runs there, not in the server's service, so that stopping or updating the
|
|
215
|
+
# server never cuts a view from under the machines (19-10: a stop killed them
|
|
216
|
+
# all, and a view left broken stopped the next start). Asked again at each
|
|
217
|
+
# start of the server; a reboot ends them, the server makes them again.
|
|
218
|
+
# Arguments: the unit, the folder, the view. Waits until the view is mounted.
|
|
219
|
+
view_service() {
|
|
220
|
+
local unit="$1" source="$2" target="$3" i
|
|
221
|
+
if [ "$SAY" = "yes" ]; then printf '%s\n' "systemd-run --unit=$unit --collect bindfs -f -r -o allow_other $source $target"; return 0; fi
|
|
222
|
+
# One left from before (failed, or its mount taken off): out of the way first.
|
|
223
|
+
systemctl stop "$unit.service" >/dev/null 2>&1 || true
|
|
224
|
+
systemctl reset-failed "$unit.service" >/dev/null 2>&1 || true
|
|
225
|
+
systemd-run --quiet --unit="$unit" --collect --description="Clavarium - the read-only view $target" \
|
|
226
|
+
--property=Restart=no bindfs -f -r -o allow_other "$source" "$target" \
|
|
227
|
+
|| refuse "the read-only view could not be started: $target"
|
|
228
|
+
for i in $(seq 1 50); do mountpoint -q "$target" && return 0; sleep 0.2; done
|
|
229
|
+
systemctl stop "$unit.service" >/dev/null 2>&1 || true
|
|
230
|
+
refuse "the read-only view did not come up: $target"
|
|
231
|
+
}
|
|
232
|
+
|
|
213
233
|
# A VIEW WHOSE PROGRAM IS GONE (bindfs killed or crashed) stays mounted, but
|
|
214
234
|
# everything done there fails with "Transport endpoint is not connected": the
|
|
215
235
|
# view cannot be made again, and before 0.2.1 the server died at its start on
|
|
@@ -562,7 +582,8 @@ case "$AREA $VERB" in
|
|
|
562
582
|
held "$MNT/views/$1"
|
|
563
583
|
mountpoint -q "$MNT/views/$1" && exit 0
|
|
564
584
|
fi
|
|
565
|
-
|
|
585
|
+
view_service "clavarium-view-$1" "$MNT/resources/$1" "$MNT/views/$1"
|
|
586
|
+
exit 0 ;;
|
|
566
587
|
"tools make")
|
|
567
588
|
# THE TOOLS FOLDER: what every machine is given to install by itself
|
|
568
589
|
# (an archive and an index, put there by the server), seen in each
|
|
@@ -573,7 +594,7 @@ case "$AREA $VERB" in
|
|
|
573
594
|
# stays as it is.
|
|
574
595
|
[ $# -eq 0 ] || usage
|
|
575
596
|
files="$MNT/toolbox/files"; view="$MNT/toolbox/view"
|
|
576
|
-
if [ "$SAY" = "yes" ]; then printf '%s\n' "install -d -o OWNER -g GROUP -m 0755 $files"
|
|
597
|
+
if [ "$SAY" = "yes" ]; then printf '%s\n' "install -d -o OWNER -g GROUP -m 0755 $files"; view_service clavarium-tools-view "$files" "$view"; exit 0; fi
|
|
577
598
|
kept toolbox
|
|
578
599
|
unstale "$view"
|
|
579
600
|
[ ! -L "$files" ] && [ ! -L "$view" ] || refuse "the tools folder is not what it should be"
|
|
@@ -582,7 +603,8 @@ case "$AREA $VERB" in
|
|
|
582
603
|
[ -e "$view" ] || install -d -o root -g root -m 0755 "$view"
|
|
583
604
|
held "$view"
|
|
584
605
|
mountpoint -q "$view" && exit 0
|
|
585
|
-
|
|
606
|
+
view_service clavarium-tools-view "$files" "$view"
|
|
607
|
+
exit 0 ;;
|
|
586
608
|
"view close")
|
|
587
609
|
[ $# -eq 1 ] || usage; is_name "$1" || refuse "not a folder name: $1"
|
|
588
610
|
kept views
|
package/deploy/updater.mjs
CHANGED
|
@@ -372,6 +372,11 @@ export class Updater {
|
|
|
372
372
|
if (!subject || subject.digest?.sha512 !== toHex(integrity)) throw new Error(`${name}@${version}: its provenance is about another archive`);
|
|
373
373
|
const repository = statement.predicate?.buildDefinition?.externalParameters?.workflow?.repository;
|
|
374
374
|
if (repository !== REPOS[name]) throw new Error(`${name}@${version} was built from ${repository ?? 'an unknown place'}, not ${REPOS[name]}`);
|
|
375
|
+
/* And from the branch its kind of version comes from (publish.yml): a version for everybody
|
|
376
|
+
from main only; one to try from next (or main, as before there was a next). */
|
|
377
|
+
const ref = statement.predicate?.buildDefinition?.externalParameters?.workflow?.ref;
|
|
378
|
+
const branches = version.includes('-') ? ['refs/heads/next', 'refs/heads/main'] : ['refs/heads/main'];
|
|
379
|
+
if (!branches.includes(ref)) throw new Error(`${name}@${version} was built from ${ref ?? 'an unknown branch'}: a version ${version.includes('-') ? 'to try' : 'for everybody'} comes from ${branches.join(' or ')}`);
|
|
375
380
|
}
|
|
376
381
|
|
|
377
382
|
/* THE LINK, switched in one rename. */
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
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.4",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/api.mjs
CHANGED
|
@@ -116,7 +116,7 @@ function readBody(request, max = BODY_MAX) {
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
/* Returns true when the request was an API request (answered here). */
|
|
119
|
-
export async function handleApi(request, response, conversations, headers, resources, originOk = sameOrigin, shortcuts, voice, sharing, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, repair, guide, capacity, updates, instance) {
|
|
119
|
+
export async function handleApi(request, response, conversations, headers, resources, originOk = sameOrigin, shortcuts, voice, sharing, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, repair, guide, capacity, updates, instance, certificate) {
|
|
120
120
|
const { pathname } = new URL(request.url ?? '/', 'http://local');
|
|
121
121
|
if (!pathname.startsWith('/api/')) return false;
|
|
122
122
|
const send = (status, body) => {
|
|
@@ -214,6 +214,7 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
214
214
|
if (pathname === '/api/shelf' && shelf) return send(200, shelf.about()), true;
|
|
215
215
|
/* Settings, Updates (updates.mjs): what runs, what is out, the mode, what happened. */
|
|
216
216
|
if (pathname === '/api/updates' && updates) return send(200, updates.about()), true;
|
|
217
|
+
if (pathname === '/api/certificate' && certificate) return send(200, await certificate.about({ fresh: query.get('fresh') === '1' })), true;
|
|
217
218
|
/* This server's disk and memory (capacity.mjs): everything for Settings; only whether it is high for the list. */
|
|
218
219
|
if (pathname === '/api/server' && capacity) return send(200, await capacity.about()), true;
|
|
219
220
|
if (pathname === '/api/server/brief' && capacity) return send(200, { ...(await capacity.brief()), machines: platform?.machines ?? true }), true;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/* THE CERTIFICATE THIS SITE SERVES, as a browser gets it: asked of the front
|
|
2
|
+
* itself (Caddy, on this machine), by its public name, so that what is said is
|
|
3
|
+
* what a visitor is given -- never a file read on the disk, which this server
|
|
4
|
+
* may not read and which may not be the one served.
|
|
5
|
+
*
|
|
6
|
+
* { domain, issuer, validTo, daysLeft, trusted, why, local }
|
|
7
|
+
* trusted a browser accepts it (a known authority, the right name, in date)
|
|
8
|
+
* local Caddy's own authority: the site answers, with a warning, until
|
|
9
|
+
* Let's Encrypt gives one (sudo clavarium doctor --certificate)
|
|
10
|
+
*
|
|
11
|
+
* Looked at once an hour at most; the owner is told, once a day, when it is
|
|
12
|
+
* not trusted or ends within ALERT_DAYS (its renewal should have happened).
|
|
13
|
+
*/
|
|
14
|
+
import tls from 'node:tls';
|
|
15
|
+
|
|
16
|
+
export const ALERT_DAYS = 10;
|
|
17
|
+
const EVERY_MS = 3600_000;
|
|
18
|
+
const ALERT_EVERY_MS = 24 * 3600_000;
|
|
19
|
+
|
|
20
|
+
/* What the front serves for `domain`, or { none, why }. */
|
|
21
|
+
export function served(domain, { host = '127.0.0.1', port = 443, connect = tls.connect, now = Date.now, timeoutMs = 5000 } = {}) {
|
|
22
|
+
return new Promise((resolve) => {
|
|
23
|
+
let done = false;
|
|
24
|
+
const end = (value) => { if (done) return; done = true; try { socket.destroy(); } catch { /* gone */ } resolve(value); };
|
|
25
|
+
const socket = connect({ host, port, servername: domain, rejectUnauthorized: false, timeout: timeoutMs }, () => {
|
|
26
|
+
const cert = socket.getPeerCertificate();
|
|
27
|
+
if (!cert || !cert.valid_to) { end({ domain, none: true, why: 'no certificate was served' }); return; }
|
|
28
|
+
const validTo = new Date(cert.valid_to);
|
|
29
|
+
const issuer = [cert.issuer?.O, cert.issuer?.CN].filter(Boolean).join(', ') || '?';
|
|
30
|
+
end({
|
|
31
|
+
domain, issuer, validTo: validTo.toISOString(),
|
|
32
|
+
daysLeft: Math.floor((validTo.getTime() - now()) / 86_400_000),
|
|
33
|
+
trusted: socket.authorized === true,
|
|
34
|
+
why: socket.authorized ? '' : String(socket.authorizationError ?? 'not trusted'),
|
|
35
|
+
local: /Caddy Local Authority/i.test(issuer),
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
socket.on('timeout', () => end({ domain, none: true, why: `nothing answered on ${port} in time` }));
|
|
39
|
+
socket.on('error', (error) => end({ domain, none: true, why: error.code === 'ECONNREFUSED' ? `nothing answers on ${port}` : String(error.message ?? error) }));
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export class Certificate {
|
|
44
|
+
#domain; #look; #alerts; #now; #last = null; #at = 0; #alertedAt = 0;
|
|
45
|
+
/* `origin`: the public address (none in local mode: nothing to say). */
|
|
46
|
+
constructor({ origin, alerts, look = (domain) => served(domain), now = Date.now }) {
|
|
47
|
+
this.#domain = origin && origin.startsWith('https:') ? new URL(origin).hostname : null;
|
|
48
|
+
this.#look = look; this.#alerts = alerts; this.#now = now;
|
|
49
|
+
}
|
|
50
|
+
/* For the page: { local: true } in local mode, else what the front serves. */
|
|
51
|
+
async about({ fresh = false } = {}) {
|
|
52
|
+
if (!this.#domain) return { local: true };
|
|
53
|
+
if (fresh || !this.#last || this.#now() - this.#at > EVERY_MS) {
|
|
54
|
+
this.#last = await this.#look(this.#domain).catch((error) => ({ domain: this.#domain, none: true, why: String(error?.message ?? error) }));
|
|
55
|
+
this.#at = this.#now();
|
|
56
|
+
this.#warn(this.#last);
|
|
57
|
+
}
|
|
58
|
+
return this.#last;
|
|
59
|
+
}
|
|
60
|
+
#warn(c) {
|
|
61
|
+
const bad = c.none || !c.trusted || c.daysLeft < ALERT_DAYS;
|
|
62
|
+
if (!bad || !this.#alerts || this.#now() - this.#alertedAt < ALERT_EVERY_MS) return;
|
|
63
|
+
this.#alertedAt = this.#now();
|
|
64
|
+
const body = c.none ? `No certificate: ${c.why}.` : !c.trusted ? `Browsers do not trust it: ${c.why}.` : `It ends in ${c.daysLeft} day(s) and was not renewed.`;
|
|
65
|
+
void this.#alerts.tell({ title: `The certificate of ${c.domain}`, body, url: '/?open=settings&at=updates' })?.catch?.(() => {});
|
|
66
|
+
}
|
|
67
|
+
}
|
package/server/gitchecks.mjs
CHANGED
|
@@ -25,6 +25,8 @@
|
|
|
25
25
|
* Bounded: a time limit (killed after it), and only the end of the output
|
|
26
26
|
* comes back.
|
|
27
27
|
*/
|
|
28
|
+
import { originFolder } from './resources.mjs';
|
|
29
|
+
|
|
28
30
|
export const OUTPUT_MAX = 8000;
|
|
29
31
|
export const SECONDS_MIN = 10;
|
|
30
32
|
export const SECONDS_MAX = 3600;
|
|
@@ -35,6 +37,21 @@ const NOT_THERE = 90; const MOVED = 91; const NOTHING = 95; const TIMED_OUT = 12
|
|
|
35
37
|
|
|
36
38
|
/* Runs in the machine, as `sh -c SCRIPT clavarium-check <repo> <head> <line> <url> <command> <hook>`.
|
|
37
39
|
Everything it is given is an argument: nothing is pasted into the script. */
|
|
40
|
+
/* Run in the machine, as `sh -c FETCH_SCRIPT clavarium-fetch <repository> <its reference>`: a local
|
|
41
|
+
fetch into origin/*, hooks off; prints "<branch> <upstream> <old> <new>" for each branch whose
|
|
42
|
+
upstream moved. Not a repository there (attached only now, not cloned yet): exit 90, nothing done. */
|
|
43
|
+
export const FETCH_SCRIPT = `exec 2>/dev/null
|
|
44
|
+
repo="$1"; origin="$2"
|
|
45
|
+
cd "$repo" && [ -d .git ] && [ -d "$origin" ] || exit 90
|
|
46
|
+
before="$(git for-each-ref --format='%(refname) %(objectname)' refs/remotes/origin)"
|
|
47
|
+
git -c core.hooksPath=/dev/null fetch --quiet --no-tags --no-write-fetch-head "$origin" '+refs/heads/*:refs/remotes/origin/*' || exit 1
|
|
48
|
+
git for-each-ref --format='%(refname:short) %(upstream)' refs/heads | while read -r branch up; do
|
|
49
|
+
case "$up" in refs/remotes/origin/*) : ;; *) continue ;; esac
|
|
50
|
+
old="$(printf '%s\\n' "$before" | awk -v r="$up" '$1 == r { print $2 }')"
|
|
51
|
+
new="$(git rev-parse -q --verify "$up")"
|
|
52
|
+
[ -n "$old" ] && [ -n "$new" ] && [ "$old" != "$new" ] && echo "$branch \${up#refs/remotes/} $old $new"
|
|
53
|
+
done
|
|
54
|
+
exit 0`;
|
|
38
55
|
export const SCRIPT = `exec 2>&1
|
|
39
56
|
repo="$1"; head="$2"; line="$3"; url="$4"; cmd="$5"; hook="$6"
|
|
40
57
|
cd "$repo" 2>/dev/null || { echo "The repository is not at $repo in this machine."; exit ${NOT_THERE}; }
|
|
@@ -92,6 +109,19 @@ export class GitChecks {
|
|
|
92
109
|
return undefined;
|
|
93
110
|
}
|
|
94
111
|
|
|
112
|
+
/* THE AGENT'S OWN COPY BROUGHT UP TO DATE, in its machine, as its user, with no network and no
|
|
113
|
+
key: from the reference this server keeps, shown read-only beside it (/resources/<name>-origin).
|
|
114
|
+
origin/* only: its branches, its files and what it left uncommitted are not touched.
|
|
115
|
+
-> { ok, moved: [{ branch, upstream, from, to }] }: the branches it follows whose upstream moved. */
|
|
116
|
+
async fetchIn(conversation, repository) {
|
|
117
|
+
const r = await this.#vms.exec(conversation, ['timeout', '-k', '10', '120', 'sh', '-c', FETCH_SCRIPT, 'clavarium-fetch', `/resources/${repository}`, `/resources/${originFolder(repository)}`], { timeoutMs: 180_000 })
|
|
118
|
+
.catch(() => ({ code: -1, stdout: '' }));
|
|
119
|
+
if (r.code !== 0) return { ok: false, moved: [] };
|
|
120
|
+
const moved = String(r.stdout ?? '').split('\n').map((l) => l.trim().split(' ')).filter((x) => x.length === 4 && /^[0-9a-f]{40,64}$/.test(x[2]) && /^[0-9a-f]{40,64}$/.test(x[3]))
|
|
121
|
+
.map(([branch, upstream, from, to]) => ({ branch: printable(branch), upstream: printable(upstream), from, to }));
|
|
122
|
+
return { ok: true, moved };
|
|
123
|
+
}
|
|
124
|
+
|
|
95
125
|
/* Does this conversation's machine run, with the repository attached
|
|
96
126
|
for writing? Automatic sending acts for a conversation only then: its
|
|
97
127
|
agent is the one at work in the repository, and its checks run there. */
|
package/server/gitkeeper.mjs
CHANGED
|
@@ -83,7 +83,7 @@ const FINAL = new Set(['diverged', 'remote-moved', 'refused', 'forced', 'no-addr
|
|
|
83
83
|
const VARYING = new Set(['space', 'cap']);
|
|
84
84
|
export const PATTERNS_MAX = 20;
|
|
85
85
|
export const DEFAULTS = Object.freeze({
|
|
86
|
-
refreshMinutes: 5, alert: true,
|
|
86
|
+
refreshMinutes: 5, alert: true, tellMoves: true,
|
|
87
87
|
checkCommand: '', checkSeconds: 600, runHook: true, requireForSend: false, fsck: {},
|
|
88
88
|
});
|
|
89
89
|
/* Automatic sending, for one conversation and one repository. A quiet
|
|
@@ -299,7 +299,7 @@ export class GitKeeper {
|
|
|
299
299
|
if (why) throw new Refusal(400, why);
|
|
300
300
|
next.fsck = { ...body.fsck };
|
|
301
301
|
}
|
|
302
|
-
for (const flag of ['alert', 'runHook', 'requireForSend']) if (body?.[flag] !== undefined) next[flag] = body[flag] === true;
|
|
302
|
+
for (const flag of ['alert', 'runHook', 'requireForSend', 'tellMoves']) if (body?.[flag] !== undefined) next[flag] = body[flag] === true;
|
|
303
303
|
this.#store.put({ ...this.#record(r.name), ...next });
|
|
304
304
|
/* Settings just set start from now: what was decided before is looked at again. */
|
|
305
305
|
this.#held.delete(r.name);
|
|
@@ -714,6 +714,7 @@ export class GitKeeper {
|
|
|
714
714
|
const last = this.#record(r.name).mirror?.at;
|
|
715
715
|
if (s.refreshMinutes > 0 && (!last || now - new Date(last).getTime() >= s.refreshMinutes * 60_000)) {
|
|
716
716
|
await this.#review.refresh(r.name).catch(() => {});
|
|
717
|
+
await this.#fetchInMachines(r.name, s).catch(() => {});
|
|
717
718
|
const upkeep = this.#record(r.name).upkeepAt;
|
|
718
719
|
if (!upkeep || now - new Date(upkeep).getTime() >= UPKEEP_MS) {
|
|
719
720
|
await this.#review.upkeep(r.name).catch(() => {});
|
|
@@ -732,6 +733,20 @@ export class GitKeeper {
|
|
|
732
733
|
await this.#autoSend(r.name, listed, running, held).catch(() => {});
|
|
733
734
|
}
|
|
734
735
|
|
|
736
|
+
/* THE AGENTS' OWN COPIES, after each refresh of the reference: brought up to date in each machine
|
|
737
|
+
that runs with the repository attached for writing (gitchecks.mjs, fetchIn), origin/* only.
|
|
738
|
+
A branch it follows that moved is said to its agent, once per move, unless the owner turned
|
|
739
|
+
that line off (tellMoves). */
|
|
740
|
+
async #fetchInMachines(name, s) {
|
|
741
|
+
for (const c of this.#writers(name)) {
|
|
742
|
+
if (!await this.#runs(c, name)) continue;
|
|
743
|
+
const got = await this.#checks.fetchIn?.(c, name).catch(() => undefined);
|
|
744
|
+
if (!got?.ok || !s.tellMoves || got.moved.length === 0) continue;
|
|
745
|
+
const said = got.moved.slice(0, 3).map((m) => `${plain(m.upstream)} moved (${m.from.slice(0, 7)} -> ${m.to.slice(0, 7)}), your branch ${plain(m.branch)} follows it`).join('; ');
|
|
746
|
+
this.#toAgent(name, `${said}; fetched for you into origin/*, nothing of yours changed`, c);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
|
|
735
750
|
async #staleLocks(name) {
|
|
736
751
|
const runner = this.#review.runner;
|
|
737
752
|
if (!runner || !this.#resources.hasOrigin(name)) return [];
|
package/server/guide.mjs
CHANGED
|
@@ -110,7 +110,9 @@ export function ownText({ name, tool, workKept, resources = [], chat, online, se
|
|
|
110
110
|
if (read.length) out.push(`- Read-only: ${list(read.map(where))}.`);
|
|
111
111
|
for (const r of resources.filter((x) => x.type === 'git' && x.origin)) {
|
|
112
112
|
const repo = `/resources/${plain(r.name, 40)}`; const origin = `/resources/${plain(r.origin, 40)}`;
|
|
113
|
-
|
|
113
|
+
/* Read-write: its origin/* is fetched for it every few minutes (gitkeeper.mjs, fetchInMachines). */
|
|
114
|
+
const auto = r.access === 'write' ? ' Its origin/* is fetched into it by itself every few minutes; to have it at once:' : ' Its branches:';
|
|
115
|
+
out.push(`- ${repo}: its origin, read-only and kept up to date, is ${origin}.${auto} git -C ${repo} fetch ${origin} '+refs/heads/*:refs/remotes/origin/*'`);
|
|
114
116
|
}
|
|
115
117
|
out.push(!chat ? '- Chat with the person: off. Do not use parley.'
|
|
116
118
|
: '- Chat with the person: on. Parley is installed: run parley guide.');
|
package/server/main.mjs
CHANGED
|
@@ -55,6 +55,7 @@ import { Setup } from './setup.mjs';
|
|
|
55
55
|
import { Capacity } from './capacity.mjs';
|
|
56
56
|
import { packageFile, PARLEY } from './parley.mjs';
|
|
57
57
|
import { Updates } from './updates.mjs';
|
|
58
|
+
import { Certificate } from './certificate.mjs';
|
|
58
59
|
import { migrateData } from './dataformat.mjs';
|
|
59
60
|
import { VmWatch } from './vmwatch.mjs';
|
|
60
61
|
|
|
@@ -116,7 +117,7 @@ const withoutTmux = (env) => Object.fromEntries(Object.entries(env).filter(([key
|
|
|
116
117
|
|
|
117
118
|
const REFUSED = 'This Clavarium belongs to someone else: your account is not one of its operators.\n';
|
|
118
119
|
|
|
119
|
-
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() } = {}) {
|
|
120
|
+
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 } = {}) {
|
|
120
121
|
/* Its manifest carries the name of this Clavarium, or the one a device chose (instance.mjs). */
|
|
121
122
|
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));
|
|
122
123
|
const sendFile = async (response, file) => {
|
|
@@ -154,7 +155,7 @@ function serve(port, conversations, resources, { gate = () => 'local', originOk,
|
|
|
154
155
|
response.writeHead(403, { ...HEADERS, 'content-type': 'text/plain; charset=utf-8' }).end(REFUSED);
|
|
155
156
|
return;
|
|
156
157
|
}
|
|
157
|
-
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)) return;
|
|
158
|
+
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)) return;
|
|
158
159
|
if (pathname === '/manifest.webmanifest' && request.method === 'GET') { sendManifest(response, request.url); return; }
|
|
159
160
|
const file = FILES[pathname];
|
|
160
161
|
if (!file || (request.method !== 'GET' && request.method !== 'HEAD')) {
|
|
@@ -387,7 +388,9 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
387
388
|
say: (name, text) => { try { talk.event(name, { kind: 'machine-problem', text, tone: 'warn', topic: 'Machine' }); } catch { /* its chat may be off */ } } });
|
|
388
389
|
all.room = (ask) => capacity.check(ask);
|
|
389
390
|
const stopWatch = capacity.start();
|
|
390
|
-
|
|
391
|
+
/* The certificate the front serves, said in Settings (certificate.mjs). */
|
|
392
|
+
const certificate = new Certificate({ origin: publicOrigin, alerts });
|
|
393
|
+
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, repair: (name) => repairTerminal(name) });
|
|
391
394
|
server.on('close', () => { closing = true; stopVmWatch(); stopShelf(); stopHealth(); stopUpdates(); stopWatch(); clearInterval(mailTimer); clearInterval(answerTimer); clearInterval(wakeTimer); clearInterval(gitTimer); talk.stop(); });
|
|
392
395
|
let closing = false;
|
|
393
396
|
bridge = attachBridge(server, {
|
package/web/app.js
CHANGED
|
@@ -3320,6 +3320,19 @@
|
|
|
3320
3320
|
const when = (iso) => new Date(iso).toLocaleString([], { day: 'numeric', month: 'short', hour: '2-digit', minute: '2-digit' });
|
|
3321
3321
|
function updatesError(text) { $('updates-error').textContent = text ?? ''; $('updates-error').hidden = !text; }
|
|
3322
3322
|
let lastUpdates = null;
|
|
3323
|
+
/* THE CERTIFICATE browsers are given (none in local mode): its end, its issuer; a warning when they would not trust it, or it ends soon. */
|
|
3324
|
+
async function paintCertificate() {
|
|
3325
|
+
const c = await fetch(`${API}/certificate`).then((r) => (r.ok ? r.json() : null)).catch(() => null);
|
|
3326
|
+
const line = $('updates-certificate');
|
|
3327
|
+
if (!c || c.local) { line.hidden = true; return; }
|
|
3328
|
+
const day = (iso) => new Date(iso).toLocaleDateString(undefined, { dateStyle: 'medium' });
|
|
3329
|
+
const bad = c.none || !c.trusted || c.daysLeft < 10;
|
|
3330
|
+
line.className = bad ? 'error' : 'hint';
|
|
3331
|
+
line.textContent = c.none ? `Certificate of ${c.domain}: none is served (${c.why}).`
|
|
3332
|
+
: !c.trusted ? `Certificate of ${c.domain}: browsers do not trust it (${c.why})${c.local ? ', it is the machine\'s own until Let\'s Encrypt gives one: sudo clavarium doctor --certificate' : ''}.`
|
|
3333
|
+
: `Certificate of ${c.domain}: by ${c.issuer}, valid until ${day(c.validTo)} (${c.daysLeft} days); renewed by itself.${c.daysLeft < 10 ? ' It should have been renewed already: sudo clavarium doctor --certificate.' : ''}`;
|
|
3334
|
+
line.hidden = false;
|
|
3335
|
+
}
|
|
3323
3336
|
async function paintUpdates() {
|
|
3324
3337
|
clearTimeout(updatesTimer);
|
|
3325
3338
|
const u = await fetch(`${API}/updates`).then((r) => (r.ok ? r.json() : null)).catch(() => null);
|
|
@@ -3327,6 +3340,7 @@
|
|
|
3327
3340
|
if (!u) { if (updatesBusy && !$('settings').hidden) updatesTimer = setTimeout(() => { void paintUpdates(); }, 3000); return; }
|
|
3328
3341
|
lastUpdates = u;
|
|
3329
3342
|
$('updates-version').textContent = `Clavarium ${u.version ?? ''}`;
|
|
3343
|
+
void paintCertificate();
|
|
3330
3344
|
for (const id of ['updates-check', 'updates-settings', 'updates-back']) $(id).hidden = !u.installed;
|
|
3331
3345
|
if (!u.installed) {
|
|
3332
3346
|
$('updates-state').textContent = 'Not installed with install.sh: no updates here.';
|
|
@@ -3723,7 +3737,7 @@
|
|
|
3723
3737
|
gitRequire = s.requireForSend; gitFsck = s.fsck ?? {}; gitLast = Array.isArray(keep.last) ? keep.last : [];
|
|
3724
3738
|
$('gitview-runhook').checked = s.runHook; $('gitview-checkcommand').value = s.checkCommand; $('gitview-checkseconds').value = String(s.checkSeconds);
|
|
3725
3739
|
$('gitview-require').checked = s.requireForSend; $('gitview-refreshminutes').value = String(s.refreshMinutes);
|
|
3726
|
-
$('gitview-alert').checked = s.alert;
|
|
3740
|
+
$('gitview-alert').checked = s.alert; $('gitview-tellmoves').checked = s.tellMoves !== false;
|
|
3727
3741
|
/* Which conversations send by themselves: set in each one's Access panel. */
|
|
3728
3742
|
const senders = Object.entries(keep.auto ?? {});
|
|
3729
3743
|
$('gitview-auto-where').textContent = `Automatic sending is set for each conversation, under its access to this repository (Write), in the conversation's Access panel. ${senders.length ? `Now: ${senders.map(([c, list]) => `${c} (${list.join(', ')})`).join('; ')}.` : 'Now: none.'}`;
|
|
@@ -4022,7 +4036,7 @@
|
|
|
4022
4036
|
try {
|
|
4023
4037
|
await post(`${API}/git/${gitShown}/keep`, {
|
|
4024
4038
|
runHook: $('gitview-runhook').checked, checkCommand: $('gitview-checkcommand').value, checkSeconds: Number($('gitview-checkseconds').value),
|
|
4025
|
-
requireForSend: $('gitview-require').checked, refreshMinutes: Number($('gitview-refreshminutes').value), alert: $('gitview-alert').checked,
|
|
4039
|
+
requireForSend: $('gitview-require').checked, refreshMinutes: Number($('gitview-refreshminutes').value), alert: $('gitview-alert').checked, tellMoves: $('gitview-tellmoves').checked,
|
|
4026
4040
|
});
|
|
4027
4041
|
$('gitview-keep-said').textContent = 'Saved.';
|
|
4028
4042
|
await paintKeep();
|
package/web/index.html
CHANGED
|
@@ -669,6 +669,8 @@
|
|
|
669
669
|
<div id="updates" tabindex="-1">
|
|
670
670
|
<div class="updates-head"><b id="updates-version"></b><span id="updates-state" role="status"></span><button type="button" id="updates-check">Check now</button></div>
|
|
671
671
|
<p id="updates-news" class="updates-news" hidden></p>
|
|
672
|
+
<!-- What the front serves to a browser (server/certificate.mjs). -->
|
|
673
|
+
<p id="updates-certificate" class="hint" role="status" hidden></p>
|
|
672
674
|
<div class="row" id="updates-offer" hidden><button type="button" id="updates-apply" class="primary"></button><button type="button" id="updates-retry-yes" class="primary" hidden>Try again</button><button type="button" id="updates-retry-no" hidden>Cancel</button><span class="hint" id="updates-retry-note" hidden></span></div>
|
|
673
675
|
<div id="updates-settings" class="updates-grid">
|
|
674
676
|
<label for="updates-mode">Mode</label>
|
|
@@ -829,6 +831,7 @@
|
|
|
829
831
|
<p class="hint">Refreshing and automatic sending happen only while a running machine has this repository attached; "Refresh now" works any time.</p>
|
|
830
832
|
<p class="hint" id="gitview-auto-where">Automatic sending is set for each conversation, under its access to this repository (Write), in the conversation's Access panel.</p>
|
|
831
833
|
<label class="check"><input type="checkbox" id="gitview-alert"> Tell my phone about automatic sendings</label>
|
|
834
|
+
<label class="check"><input type="checkbox" id="gitview-tellmoves"> Tell the agent when a branch it follows moved (its origin/* is fetched for it either way)</label>
|
|
832
835
|
<div class="row"><button type="submit" class="primary">Save</button><span class="hint" id="gitview-keep-said" role="status"></span></div>
|
|
833
836
|
</form>
|
|
834
837
|
<b>What was sent by itself, and what went wrong</b>
|