clavarium 0.2.159-next.1 → 0.2.160-beta.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/README.md +4 -0
- package/config/launch/claude-code.sh +36 -19
- package/config/launch/codex.sh +36 -0
- package/config/launch/json-set.mjs +5 -2
- package/config/launch/mcp-relay.mjs +98 -0
- package/config/launch/screen-watch.mjs +99 -0
- package/config/launch/toml-block.mjs +26 -0
- package/config/launch/vibe.sh +39 -0
- package/config/tools.json +57 -0
- package/deploy/clavarium-host +89 -6
- package/deploy/install.sh +7 -1
- package/deploy/maintenance.html +5 -2
- package/deploy/updater.mjs +48 -0
- package/npm-shrinkwrap.json +245 -19
- package/package.json +8 -6
- package/server/accounts.mjs +2 -1
- package/server/api.mjs +114 -10
- package/server/boxes.mjs +808 -35
- package/server/capacity.mjs +3 -1
- package/server/catalog.mjs +48 -0
- package/server/conversations.mjs +41 -5
- package/server/demandes.mjs +140 -0
- package/server/dictation-engines.mjs +91 -0
- package/server/door.mjs +9 -2
- package/server/events.mjs +1 -0
- package/server/features.mjs +366 -0
- package/server/files.mjs +50 -6
- package/server/gitpush.mjs +170 -53
- package/server/guide.mjs +2 -0
- package/server/mailbox.mjs +9 -0
- package/server/main.mjs +100 -17
- package/server/network.mjs +121 -13
- package/server/pocket.mjs +136 -0
- package/server/rooms.mjs +219 -0
- package/server/serverlogs.mjs +38 -5
- package/server/settingswords.mjs +52 -0
- package/server/setup.mjs +1 -1
- package/server/speech.mjs +72 -6
- package/server/spoken.mjs +60 -0
- package/server/suggest.mjs +66 -0
- package/server/talk.mjs +44 -11
- package/server/tethers.mjs +32 -5
- package/server/vm.mjs +2 -0
- package/server/voice.mjs +255 -46
- package/server/wakelearn.mjs +214 -0
- package/web/app.js +2054 -425
- package/web/device.html +2 -0
- package/web/features.js +480 -0
- package/web/index.html +634 -471
- package/web/kit.js +272 -0
- package/web/mail-view.js +386 -0
- package/web/style.css +854 -202
- package/web/voice-core.js +25 -0
- package/web/voice.js +9 -3
package/deploy/clavarium-host
CHANGED
|
@@ -82,11 +82,13 @@ SHELF_MEMORY="1536M"
|
|
|
82
82
|
SHELF_STORE="/var/snap/multipass/common"
|
|
83
83
|
SHELF_INSTANCES="$SHELF_STORE/data/multipassd/vault/instances"
|
|
84
84
|
SHELF_CACHE="$SHELF_STORE/cache"
|
|
85
|
+
# The leases its DHCP server gave its machines: "<expiry> <mac> <ip> <name> <client id>" per line.
|
|
86
|
+
LEASES="$SHELF_STORE/data/multipassd/network/dnsmasq.leases"
|
|
85
87
|
# Moved to another disk (deploy/move-machines.sh, Multipass's own way: its
|
|
86
88
|
# MULTIPASS_STORAGE in a drop-in of its service): <path>/data, <path>/cache.
|
|
87
89
|
# (No drop-in is the usual case: under pipefail a missing file must not stop this program.)
|
|
88
90
|
MOVED_TO="$( { sed -n 's/^Environment=MULTIPASS_STORAGE=\(\/[A-Za-z0-9/._-]*\)$/\1/p' /etc/systemd/system/snap.multipass.multipassd.service.d/override.conf 2>/dev/null || true; } | head -1)"
|
|
89
|
-
if [ -n "$MOVED_TO" ] && [ -d "$MOVED_TO/data" ]; then SHELF_STORE="$MOVED_TO"; SHELF_INSTANCES="$MOVED_TO/data/vault/instances"; SHELF_CACHE="$MOVED_TO/cache"; fi
|
|
91
|
+
if [ -n "$MOVED_TO" ] && [ -d "$MOVED_TO/data" ]; then SHELF_STORE="$MOVED_TO"; SHELF_INSTANCES="$MOVED_TO/data/vault/instances"; SHELF_CACHE="$MOVED_TO/cache"; LEASES="$MOVED_TO/data/network/dnsmasq.leases"; fi
|
|
90
92
|
# Also the floor under a grown disk (grow_room): the server keeps the same
|
|
91
93
|
# (MIN_FREE_MB in server/shelf.mjs, used by server/capacity.mjs).
|
|
92
94
|
SHELF_MIN_FREE_MB="6144"
|
|
@@ -731,6 +733,14 @@ MESHUNIT
|
|
|
731
733
|
[ $# -ge 2 ] || usage
|
|
732
734
|
AREA="$1"; VERB="$2"; shift 2
|
|
733
735
|
|
|
736
|
+
# What changes something is written to the system log, by this program: sudo itself is told not to log
|
|
737
|
+
# the server's account (its probes every few seconds made some 800 lines in ten minutes, 31-10). Reading
|
|
738
|
+
# verbs, and commands run inside a machine (the server's own probes, mostly), are not written.
|
|
739
|
+
case "$AREA $VERB" in
|
|
740
|
+
"vm exec"|"vm ping"|"vm states"|"vm info"|"server logs"|"server room"|"server usage"|"shelf info"|"shelf room"|"shelf list"|"shelf size"|"shelf exec"|"git read"|"work room"|"disks list"|"disks room"|"machines places"|"machines moving"|"machines old"|"net taps"|"net leases"|"wifi status"|"wifi scan"|"path held"|"disk room"|"update check"|"meshcentral status"|"operator "*) : ;;
|
|
741
|
+
*) [ "$SAY" = yes ] || logger -t clavarium-host -- "$AREA $VERB$(printf ' %.80s' "$@" | head -c 400)" 2>/dev/null || true ;;
|
|
742
|
+
esac
|
|
743
|
+
|
|
734
744
|
# The remote screen's path carries a per-instance suffix: resolve it before any of its verbs run.
|
|
735
745
|
[ "$AREA" = meshcentral ] && mesh_resolve_path
|
|
736
746
|
|
|
@@ -962,7 +972,7 @@ case "$AREA $VERB" in
|
|
|
962
972
|
# WHAT THE SERVER'S PROGRAMS SAID, for Settings (This server, Logs): one
|
|
963
973
|
# source, over a span; read-only, bounded. The page masks what looks
|
|
964
974
|
# like a secret before showing it.
|
|
965
|
-
# server logs <clavarium|machines|updates|web|signin|tunnel|system> <1|6|24|168|boot>
|
|
975
|
+
# server logs <clavarium|machines|updates|web|signin|tunnel|system> <10m|1|6|24|168|boot>
|
|
966
976
|
[ $# -eq 2 ] || usage
|
|
967
977
|
case "$1" in
|
|
968
978
|
clavarium) units=(-u clavarium.service -u 'clavarium-view-*' -u clavarium-tools-view.service -u clavarium-move-machines.service) ;;
|
|
@@ -974,9 +984,10 @@ case "$AREA $VERB" in
|
|
|
974
984
|
system) units=(-k) ;;
|
|
975
985
|
*) refuse "not a source of logs: $1" ;;
|
|
976
986
|
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
|
-
|
|
987
|
+
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
|
|
988
|
+
# The newest 20000 lines at most: more is too much to read on a page, and to send.
|
|
989
|
+
if [ "$SAY" = "yes" ]; then echo "journalctl ${units[*]} ${since[*]} -o short-iso --no-pager (the last 20000 lines)"; exit 0; fi
|
|
990
|
+
journalctl "${units[@]}" "${since[@]}" -o short-iso --no-pager -n 20000 2>/dev/null | cut -c1-2000 || true
|
|
980
991
|
exit 0 ;;
|
|
981
992
|
"server restart")
|
|
982
993
|
# THIS SERVER STARTED AGAIN, asked from the page: in two seconds, by
|
|
@@ -985,6 +996,36 @@ case "$AREA $VERB" in
|
|
|
985
996
|
if [ "$SAY" = "yes" ]; then echo "systemd-run --on-active=2 systemctl restart clavarium.service"; exit 0; fi
|
|
986
997
|
systemd-run --quiet --collect --unit="clavarium-restart-$(date +%s)" --on-active=2 /usr/bin/systemctl restart clavarium.service
|
|
987
998
|
exit 0 ;;
|
|
999
|
+
"server reboot")
|
|
1000
|
+
# THE WHOLE SERVER STARTED AGAIN, asked from the page (Settings, This server), after a
|
|
1001
|
+
# confirmation there: in five seconds, by systemd, so that the page is answered first.
|
|
1002
|
+
# Every machine stops with it (cleanly, by the VM manager) and starts again after.
|
|
1003
|
+
[ $# -eq 0 ] || usage
|
|
1004
|
+
if [ "$SAY" = "yes" ]; then echo "systemd-run --on-active=5 systemctl reboot"; exit 0; fi
|
|
1005
|
+
systemd-run --quiet --collect --unit="clavarium-reboot-$(date +%s)" --on-active=5 /usr/bin/systemctl reboot
|
|
1006
|
+
exit 0 ;;
|
|
1007
|
+
"server protect")
|
|
1008
|
+
# WHAT KEEPS THE SERVER IN HAND (04-11), at each start of the server: should memory run out,
|
|
1009
|
+
# the kernel stops a machine first, never this server, its front or ssh. Made so for the next
|
|
1010
|
+
# start of each (a drop-in) and at once for what runs (choom). No argument; done again is the same.
|
|
1011
|
+
[ $# -eq 0 ] || usage
|
|
1012
|
+
if [ "$SAY" = "yes" ]; then echo "OOMScoreAdjust=-900 for clavarium caddy dex oauth2-proxy ssh"; exit 0; fi
|
|
1013
|
+
changed=no
|
|
1014
|
+
for unit in clavarium caddy dex oauth2-proxy ssh; do
|
|
1015
|
+
systemctl cat "$unit.service" >/dev/null 2>&1 || continue
|
|
1016
|
+
dir="/etc/systemd/system/$unit.service.d"; file="$dir/clavarium-oom.conf"
|
|
1017
|
+
want='# Written by clavarium-host (server protect): stopped last should memory run out.
|
|
1018
|
+
[Service]
|
|
1019
|
+
OOMScoreAdjust=-900'
|
|
1020
|
+
if [ "$(cat "$file" 2>/dev/null)" != "$want" ]; then
|
|
1021
|
+
mkdir -p "$dir" && printf '%s\n' "$want" > "$file" && changed=yes
|
|
1022
|
+
fi
|
|
1023
|
+
pid=$(systemctl show -p MainPID --value "$unit.service" 2>/dev/null)
|
|
1024
|
+
[ -n "$pid" ] && [ "$pid" != 0 ] && choom -n -900 -p "$pid" >/dev/null 2>&1 || true
|
|
1025
|
+
done
|
|
1026
|
+
[ "$changed" = no ] || systemctl daemon-reload
|
|
1027
|
+
echo "protected"
|
|
1028
|
+
exit 0 ;;
|
|
988
1029
|
"server room")
|
|
989
1030
|
# WHAT THE SERVER HAS LEFT, for Settings (This server) and for the
|
|
990
1031
|
# reserve that creating, starting, waking or growing a machine must
|
|
@@ -1128,6 +1169,17 @@ case "$AREA $VERB" in
|
|
|
1128
1169
|
if [ -d "$at" ] && [ ! -L "$at" ]; then rmdir "$at" 2>/dev/null || true; fi
|
|
1129
1170
|
if [ -f "$img" ] && [ ! -L "$img" ]; then mv -n "$img" "$MNT/removed/$1-work-$(date -u +%Y%m%dT%H%M%SZ)-$$.img"; fi
|
|
1130
1171
|
exit 0 ;;
|
|
1172
|
+
"work erase")
|
|
1173
|
+
# Deleted for good, or its machine reset, BY ITS OWNER, after a confirmation that names the conversation
|
|
1174
|
+
# (01-11): its work disk is ERASED, not put aside. Only that one file and its mount point.
|
|
1175
|
+
[ $# -eq 1 ] || usage; is_name "$1" || refuse "not a conversation name: $1"
|
|
1176
|
+
img="$MNT/work-disks/$1.img"; at="$MNT/work/$1"
|
|
1177
|
+
if [ "$SAY" = "yes" ]; then printf 'disk %s erased\n' "$img"; exit 0; fi
|
|
1178
|
+
kept work; kept work-disks
|
|
1179
|
+
if mountpoint -q "$at"; then umount "$at" || refuse "the work disk of $1 is in use"; fi
|
|
1180
|
+
if [ -d "$at" ] && [ ! -L "$at" ]; then rmdir "$at" 2>/dev/null || true; fi
|
|
1181
|
+
if [ -f "$img" ] && [ ! -L "$img" ]; then rm -f -- "$img"; fi
|
|
1182
|
+
exit 0 ;;
|
|
1131
1183
|
"view make")
|
|
1132
1184
|
[ $# -eq 1 ] || usage; is_name "$1" || refuse "not a folder name: $1"
|
|
1133
1185
|
folder_of "$1"; kept views
|
|
@@ -1339,14 +1391,38 @@ case "$AREA $VERB" in
|
|
|
1339
1391
|
"net taps")
|
|
1340
1392
|
[ $# -eq 0 ] || usage
|
|
1341
1393
|
run pgrep -a qemu-system ;;
|
|
1394
|
+
"net leases")
|
|
1395
|
+
# Which address the VM manager's DHCP server gave which MAC: one "<mac> <ip>" per
|
|
1396
|
+
# line, each checked; nothing else of that file is printed (the name in it is the
|
|
1397
|
+
# VM's own word, never trusted). Read-only. No file yet: nothing.
|
|
1398
|
+
[ $# -eq 0 ] || usage
|
|
1399
|
+
if [ "$SAY" = "yes" ]; then echo "<mac> <ip> of each lease in $LEASES"; exit 0; fi
|
|
1400
|
+
[ -f "$LEASES" ] || exit 0
|
|
1401
|
+
while read -r _ mac ip _; do
|
|
1402
|
+
if [[ "$mac" =~ ^[0-9a-f]{2}(:[0-9a-f]{2}){5}$ && "$ip" =~ ^[0-9]{1,3}(\.[0-9]{1,3}){3}$ ]]; then printf '%s %s\n' "$mac" "$ip"; fi
|
|
1403
|
+
done < "$LEASES"
|
|
1404
|
+
exit 0 ;;
|
|
1342
1405
|
"net bridge")
|
|
1406
|
+
# The bridge the machines' taps are on: multipass 1.17 names it per zone
|
|
1407
|
+
# (mpqemubrzone1, ...), older ones mpqemubr0 (04-11: the offline rules
|
|
1408
|
+
# were never written, their bridge not found). The first tap's says.
|
|
1343
1409
|
[ $# -eq 0 ] || usage
|
|
1344
|
-
|
|
1410
|
+
if [ "$SAY" = "yes" ]; then echo "ip -4 -o addr show <the bridge of the taps, else $BRIDGE>"; exit 0; fi
|
|
1411
|
+
bridge="$BRIDGE"
|
|
1412
|
+
for t in /sys/class/net/tap-*; do
|
|
1413
|
+
[ -e "$t/master" ] || continue
|
|
1414
|
+
m=$(basename "$(readlink "$t/master")"); [[ "$m" =~ ^mpqemubr[a-z0-9]{1,12}$ ]] && { bridge="$m"; break; }
|
|
1415
|
+
done
|
|
1416
|
+
if [ "$bridge" = "$BRIDGE" ] && ! [ -e "/sys/class/net/$BRIDGE" ]; then
|
|
1417
|
+
for b in /sys/class/net/mpqemubr*; do [ -e "$b" ] && { bridge=$(basename "$b"); break; }; done
|
|
1418
|
+
fi
|
|
1419
|
+
run ip -4 -o addr show "$bridge" ;;
|
|
1345
1420
|
"net apply")
|
|
1346
1421
|
# <ruleset>: the whole table, as text. Each line must be one of the
|
|
1347
1422
|
# shapes the server writes; one unknown line refuses the whole.
|
|
1348
1423
|
[ $# -eq 1 ] || usage
|
|
1349
1424
|
tap='"tap-[0-9a-f]{1,12}"'; addr='[0-9]{1,3}(\.[0-9]{1,3}){3}'
|
|
1425
|
+
mac='[0-9a-f]{2}(:[0-9a-f]{2}){5}'; addrs="\\{ $addr(, $addr)* \\}"
|
|
1350
1426
|
while IFS= read -r line; do
|
|
1351
1427
|
[[ -z "$line"
|
|
1352
1428
|
|| "$line" =~ ^(delete\ )?table\ bridge\ $TABLE(\ \{)?$
|
|
@@ -1354,6 +1430,13 @@ case "$AREA $VERB" in
|
|
|
1354
1430
|
|| "$line" =~ ^\ \ \ \ type\ filter\ hook\ (forward|input)\ priority\ 0\;$
|
|
1355
1431
|
|| "$line" =~ ^\ \ \ \ iifname\ $tap\ (drop|udp\ dport\ 67\ accept|ether\ type\ arp\ accept)$
|
|
1356
1432
|
|| "$line" =~ ^\ \ \ \ iifname\ $tap\ ip\ daddr\ $addr\ (accept|meta\ l4proto\ \{\ tcp,\ udp\ \}\ th\ dport\ 53\ drop)$
|
|
1433
|
+
|| "$line" =~ ^\ \ \ \ iifname\ $tap\ (ether\ saddr|arp\ saddr\ ether)\ !=\ $mac\ drop$
|
|
1434
|
+
|| "$line" =~ ^\ \ \ \ iifname\ $tap\ ether\ type\ !=\ \{\ ip,\ arp\ \}\ drop$
|
|
1435
|
+
|| "$line" =~ ^\ \ \ \ iifname\ $tap\ udp\ dport\ 67\ @th,288,48\ !=\ 0x[0-9a-f]{12}\ drop$
|
|
1436
|
+
|| "$line" =~ ^\ \ \ \ iifname\ $tap\ ip\ saddr\ 0\.0\.0\.0\ ip\ daddr\ 255\.255\.255\.255\ udp\ dport\ 67\ accept$
|
|
1437
|
+
|| "$line" =~ ^\ \ \ \ iifname\ $tap\ ip\ saddr\ !=\ $addr\ drop$
|
|
1438
|
+
|| "$line" =~ ^\ \ \ \ iifname\ $tap\ arp\ saddr\ ip\ !=\ \{\ 0\.0\.0\.0,\ $addr\ \}\ drop$
|
|
1439
|
+
|| "$line" =~ ^\ \ \ \ iifname\ $tap\ (ip\ saddr|arp\ saddr\ ip)\ $addrs\ drop$
|
|
1357
1440
|
|| "$line" =~ ^(\ \ )?\}$ ]] || refuse "a network rule of an unknown shape: $line"
|
|
1358
1441
|
done <<< "$1"
|
|
1359
1442
|
run nft "$1" ;;
|
package/deploy/install.sh
CHANGED
|
@@ -238,7 +238,7 @@ apt-get update -qq
|
|
|
238
238
|
# bindfs: the read-only views. nftables: the network rules. build-essential
|
|
239
239
|
# and python3: one module of the server (the terminal) is compiled here.
|
|
240
240
|
# qrencode: the public keys, shown as QR codes on a screen. openssh-client: the tunnel.
|
|
241
|
-
apt-get install -y -qq bindfs nftables build-essential python3 curl ca-certificates xz-utils sudo snapd openssl git qrencode openssh-client >/dev/null
|
|
241
|
+
apt-get install -y -qq bindfs nftables build-essential python3 curl ca-certificates xz-utils sudo snapd openssl git qrencode openssh-client ffmpeg >/dev/null
|
|
242
242
|
snap list multipass >/dev/null 2>&1 || snap install multipass >/dev/null
|
|
243
243
|
|
|
244
244
|
step "account"
|
|
@@ -319,6 +319,12 @@ printf 'DATA=%s\nMNT=%s\n' "$DATA" "$MNT" > "$ETC/host.conf"; chmod 0644 "$ETC/h
|
|
|
319
319
|
rule="$(mktemp)"
|
|
320
320
|
printf '# Clavarium: the server account may run ONE program as root, and nothing else.\n%s ALL=(root) NOPASSWD: %s\n' "$ACCOUNT" "$HOST_PROGRAM" > "$rule"
|
|
321
321
|
visudo -cf "$rule" >/dev/null || refuse "the sudo rule did not pass its check"
|
|
322
|
+
# Its probes every few seconds kept out of the system log, with what this sudo takes (the updater does the same).
|
|
323
|
+
for quiet in '!syslog, !pam_session' '!pam_session'; do
|
|
324
|
+
cp "$rule" "$rule.q"; printf 'Defaults:%s %s\n' "$ACCOUNT" "$quiet" >> "$rule.q"
|
|
325
|
+
if out="$(visudo -cf "$rule.q" 2>&1)" && ! printf '%s' "$out" | grep -qiE 'unknown setting|syntax error|parse error'; then mv "$rule.q" "$rule"; break; fi
|
|
326
|
+
rm -f "$rule.q"
|
|
327
|
+
done
|
|
322
328
|
install -o root -g root -m 0440 "$rule" /etc/sudoers.d/clavarium; rm -f -- "$rule"
|
|
323
329
|
|
|
324
330
|
step "what the machines are given, on root's chain"
|
package/deploy/maintenance.html
CHANGED
|
@@ -56,17 +56,20 @@ const VERSION = /^\d{1,4}\.\d{1,4}\.\d{1,6}(-[0-9A-Za-z.-]{1,40})?$/;
|
|
|
56
56
|
when the server still announces an update about to stop it. */
|
|
57
57
|
const next = ({ kind, startedAt, now, seenDown, answer }) => {
|
|
58
58
|
const up = !!answer && !answer.down && !answer.update && !(answer.status >= 502 && answer.status <= 504);
|
|
59
|
-
|
|
59
|
+
/* The whole server (reboot): five seconds before it stops, a minute of grace. */
|
|
60
|
+
const grace = kind === 'reboot' ? 4 * RESTART_GRACE_MS : kind === 'restart' ? RESTART_GRACE_MS : 0;
|
|
61
|
+
if (up && !(grace && !seenDown && now - startedAt < grace)) return 'back';
|
|
60
62
|
return now - startedAt > STUCK_MS ? 'stuck' : 'wait';
|
|
61
63
|
};
|
|
62
64
|
|
|
63
|
-
/* WHAT IT SAYS, from its address (?kind=update|back|restart&to=<version>): the edge serves
|
|
65
|
+
/* WHAT IT SAYS, from its address (?kind=update|back|restart|reboot&to=<version>): the edge serves
|
|
64
66
|
it at any address, with none of these: then it cannot know which. */
|
|
65
67
|
const title = (kind, to) => {
|
|
66
68
|
const v = VERSION.test(to ?? '') ? to : '';
|
|
67
69
|
if (kind === 'update') return v ? `Updating Clavarium to ${v}...` : 'Updating Clavarium...';
|
|
68
70
|
if (kind === 'back') return v ? `Going back to Clavarium ${v}...` : 'Going back to the previous Clavarium...';
|
|
69
71
|
if (kind === 'restart') return 'Restarting Clavarium...';
|
|
72
|
+
if (kind === 'reboot') return 'Restarting the server: every machine starts again in a few minutes...';
|
|
70
73
|
return 'Clavarium is being updated or restarted...';
|
|
71
74
|
};
|
|
72
75
|
|
package/deploy/updater.mjs
CHANGED
|
@@ -114,6 +114,52 @@ export async function ensureProxySettings({ file = PROXY_CFG, run = runCommand }
|
|
|
114
114
|
return true;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
/* SUDO, QUIET FOR CLAVARIUM'S ONE PROGRAM, kept by the updater: the server asks the host program every
|
|
118
|
+
few seconds (machine states, memory, repositories), and sudo wrote three lines to the system log for
|
|
119
|
+
each call -- some 800 lines in ten minutes, nothing to read in them (found 31-10). The account may run
|
|
120
|
+
that one program and nothing else; what changes something, the program logs itself (clavarium-host). */
|
|
121
|
+
export const SUDOERS = '/etc/sudoers.d/clavarium';
|
|
122
|
+
/* What sudo is told, tried in this order: the first its version takes without a word wins. Some sudo builds do
|
|
123
|
+
not know « syslog » (found 01-11 on a real server: « unknown setting: 'syslog' » on every call); they keep
|
|
124
|
+
the session lines quiet at least. A line of ours their sudo does not take is replaced. */
|
|
125
|
+
export const QUIET_SETTINGS = ['!syslog, !pam_session', '!pam_session'];
|
|
126
|
+
export const quietLine = (account, setting = QUIET_SETTINGS[0]) => `Defaults:${account} ${setting}`;
|
|
127
|
+
const QUIET_COMMENT = '# Added by the Clavarium updater: its probes every few seconds are not written to the system log.';
|
|
128
|
+
export async function ensureQuietSudo({ file = SUDOERS, run = runCommand } = {}) {
|
|
129
|
+
let text;
|
|
130
|
+
try { text = readFileSync(file, 'utf8'); } catch { return false; }
|
|
131
|
+
const account = text.match(/^([a-z_][a-z0-9_-]*)\s+ALL=\(root\)\s+NOPASSWD:/m)?.[1];
|
|
132
|
+
if (!account) return false;
|
|
133
|
+
const accepted = async (candidate) => {
|
|
134
|
+
rmSync(`${file}.new`, { force: true });
|
|
135
|
+
writeFileSync(`${file}.new`, candidate, { mode: 0o440 });
|
|
136
|
+
const r = await run(['visudo', '-cf', `${file}.new`], { timeoutMs: 30_000 });
|
|
137
|
+
return r.code === 0 && !/unknown setting|syntax error|parse error/i.test(`${r.stdout}\n${r.stderr}`);
|
|
138
|
+
};
|
|
139
|
+
/* The rule as it is, without any line of ours. */
|
|
140
|
+
const base = text.split('\n').filter((l) => l !== QUIET_COMMENT && !l.startsWith(`Defaults:${account} `)).join('\n').replace(/\n*$/, '\n');
|
|
141
|
+
const current = QUIET_SETTINGS.map((q) => quietLine(account, q)).find((l) => text.includes(l));
|
|
142
|
+
try {
|
|
143
|
+
if (current && await accepted(text)) return false; /* ours, and taken as it is */
|
|
144
|
+
for (const setting of QUIET_SETTINGS) {
|
|
145
|
+
const next = `${base}${QUIET_COMMENT}\n${quietLine(account, setting)}\n`;
|
|
146
|
+
if (await accepted(next)) { renameSync(`${file}.new`, file); return true; }
|
|
147
|
+
}
|
|
148
|
+
/* None taken: the rule alone, as install.sh wrote it -- never a file sudo complains about. */
|
|
149
|
+
if (current && await accepted(base)) { renameSync(`${file}.new`, file); return true; }
|
|
150
|
+
return false;
|
|
151
|
+
} finally { rmSync(`${file}.new`, { force: true }); }
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/* FFMPEG, kept by the updater: the voice boxes play a radio, a podcast, a music file through it
|
|
155
|
+
(server/boxes.mjs, listen). Installed by install.sh; added once to a machine installed before. */
|
|
156
|
+
export async function ensureFfmpeg({ run = runCommand, has = () => ['/usr/bin/ffmpeg', '/usr/local/bin/ffmpeg'].some((f) => existsSync(f)) } = {}) {
|
|
157
|
+
if (has()) return false;
|
|
158
|
+
if (process.getuid?.() !== 0) return false;
|
|
159
|
+
await run(['apt-get', 'install', '-y', '-qq', 'ffmpeg'], { timeoutMs: 15 * 60_000, env: { ...process.env, DEBIAN_FRONTEND: 'noninteractive' } });
|
|
160
|
+
return has();
|
|
161
|
+
}
|
|
162
|
+
|
|
117
163
|
/* THE MAINTENANCE PAGE, kept by the updater: while the server is down (an update, a restart) the
|
|
118
164
|
front (Caddy) answers it instead of the sign-in proxy's "Bad Gateway". The sign-in proxy answers
|
|
119
165
|
502 in HTML when the server does not; the server's own errors are JSON and pass as they are. A
|
|
@@ -913,6 +959,8 @@ async function main(argv) {
|
|
|
913
959
|
update that brought it ran the PREVIOUS release's code. Idempotent; never stops the turn. */
|
|
914
960
|
try { const [{ installWatch }, { realSys }] = await Promise.all([import('./doctor.mjs'), import('./online.mjs')]); if (await installWatch(realSys())) console.error('updater: the certificate timer set up'); } catch (error) { console.error(`updater: the certificate timer could not be set up: ${error.message}`); }
|
|
915
961
|
try { if (await u.ensureDropIn()) console.error('updater: the drop-in of the server\'s unit written'); } catch (error) { console.error(`updater: the drop-in could not be written: ${error.message}`); }
|
|
962
|
+
try { if (await ensureFfmpeg()) console.error('updater: ffmpeg installed, for the sounds the voice boxes play'); } catch (error) { console.error(`updater: ffmpeg could not be installed: ${error.message}`); }
|
|
963
|
+
try { if (await ensureQuietSudo()) console.error('updater: sudo no longer logs the host program\'s probes'); } catch (error) { console.error(`updater: sudo could not be made quiet: ${error.message}`); }
|
|
916
964
|
try { if (await ensureProxySettings()) console.error('updater: the sign-in proxy takes one CSRF cookie per sign-in'); } catch (error) { console.error(`updater: the sign-in proxy could not be set: ${error.message}`); }
|
|
917
965
|
try { const c = await ensureGenericClientId({ run: runCommand }); if (c.changed.length) console.error('updater: the sign-in client id was made generic (nothing names the product in the open)'); } catch (error) { console.error(`updater: the sign-in client id could not be made generic: ${error.message}`); }
|
|
918
966
|
try { if (await ensureTunnel({ run: runCommand })) console.error('updater: the tunnel to the relay notices a cut sooner'); } catch (error) { console.error(`updater: the tunnel could not be set: ${error.message}`); }
|