@bom0792/herdgate 0.9.17 → 0.9.18

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.
@@ -72,7 +72,7 @@ async function readJson(path) {
72
72
  export default class Herdgate extends View {
73
73
  init(_props, cx) {
74
74
  this.h = cx.focus_handle();
75
- this.settings = { cloud: "", root: "", name: "", accountToken: "" };
75
+ this.settings = { cloud: "", root: "", name: "", accountToken: "", allowAct: false };
76
76
  this.paired = false;
77
77
  this.cloud = "";
78
78
  this.publisher = { pid: null, running: false };
@@ -109,7 +109,7 @@ export default class Herdgate extends View {
109
109
 
110
110
  async load() {
111
111
  const s = await readJson(SETTINGS);
112
- if (s) this.settings = { cloud: s.cloud ?? "", root: s.root ?? "", name: s.name ?? "", accountToken: s.accountToken ?? "" };
112
+ if (s) this.settings = { cloud: s.cloud ?? "", root: s.root ?? "", name: s.name ?? "", accountToken: s.accountToken ?? "", allowAct: s.allowAct === true };
113
113
  await this.refresh();
114
114
  }
115
115
 
@@ -140,6 +140,21 @@ export default class Herdgate extends View {
140
140
  cx?.notify?.();
141
141
  }
142
142
 
143
+ /** Flip the owner's switch for `act` (control) devices — the only way a paired
144
+ * device gets more than read. Takes effect on the next pair; the publisher
145
+ * re-reads settings on each request. */
146
+ async toggleAct(cx) {
147
+ const cur = await readJson(SETTINGS);
148
+ const s = { cloud: "", root: "", name: "", accountToken: "", ...(cur ?? {}), ...this.settings };
149
+ s.allowAct = s.allowAct !== true;
150
+ await sh('umask 077; printf "%s" "$2" > "$3"', [BASE, JSON.stringify(s, null, 2), SETTINGS]);
151
+ this.settings = s;
152
+ this.message = s.allowAct
153
+ ? "act devices allowed — new pairs can control (existing devices keep their scope)"
154
+ : "act devices blocked — new pairs are read-only";
155
+ cx?.notify?.();
156
+ }
157
+
143
158
  // ---- pairing: mint, show, poll, write the token --------------------------
144
159
 
145
160
  pair(cx) {
@@ -507,6 +522,11 @@ export default class Herdgate extends View {
507
522
  .child(field("hg-root", this.rootInput, "herdgate folder"))
508
523
  .child(field("hg-name", this.nameInput, "this machine's name"))
509
524
  .child(field("hg-token", this.tokenInput, "account token (owner) — used to approve other machines"))
525
+ .child(
526
+ h_flex().justify_between().items_center().gap(6).child(
527
+ div().text_size(10).text_color(t.dim).child("control (act) devices — let paired machines do more than read"),
528
+ ).child(this.button(t, "hg-act", this.settings.allowAct ? "allowed" : "blocked", (c) => this.toggleAct(c))),
529
+ )
510
530
  .child(
511
531
  h_flex().justify_between().items_center().child(
512
532
  div().text_size(9.5).text_color(t.dim).child("stored under the app's herdgate dir, mode 0600"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bom0792/herdgate",
3
- "version": "0.9.17",
3
+ "version": "0.9.18",
4
4
  "description": "Cloud relay hub for herdr-core: every machine dials out, phones and browsers follow (PWA + SSH leg, E2E payloads).",
5
5
  "type": "module",
6
6
  "engines": {
@@ -9,7 +9,7 @@
9
9
  import { spawn } from "node:child_process";
10
10
  import { existsSync, readFileSync, writeFileSync, mkdirSync, rmSync } from "node:fs";
11
11
  import { join, dirname } from "node:path";
12
- import { hostname } from "node:os";
12
+ import { hostname, homedir } from "node:os";
13
13
  import { dirs, readConfig, writeConfig, readState, writeState, herdrSnapshot, summarize } from "./common.mjs";
14
14
  import { createSshBridge } from "./ssh.mjs";
15
15
  import { HostChannel, b64d, b64e, fingerprint, generateKeyPair } from "./e2e.mjs";
@@ -17,6 +17,10 @@ import { HostChannel, b64d, b64e, fingerprint, generateKeyPair } from "./e2e.mjs
17
17
  const D = dirs();
18
18
  const NAME = process.env.HERDGATE_HOST_NAME || hostname();
19
19
  const log = (line) => console.error(`herdgate: ${line}`);
20
+ /** The panel's settings file (app home herdgate dir) — the owner's switches live
21
+ * there. HERDGATE_SETTINGS lets tests point somewhere else. */
22
+ const SETTINGS =
23
+ process.env.HERDGATE_SETTINGS ?? join(homedir(), ".config", "herdr-app", "herdgate", "settings.json");
20
24
 
21
25
  /** The publisher runs as a detached child of `serve`, recording its pid in state. */
22
26
  const pidPath = D.stateDir ? join(D.stateDir, "publisher.pid") : "";
@@ -273,7 +277,10 @@ async function publisherLoop() {
273
277
  wsRef = ws;
274
278
  let helloed = false;
275
279
  ws.onopen = () => {
276
- ws.send(JSON.stringify({ v: 1, t: "hello", roomToken: token, info: { name: NAME, version: "0.1.0", capabilities: ["dev.herdgate.host", "read-only"] } }));
280
+ // Advertise honestly: `act` only when the owner's switch allows it.
281
+ let allowAct = false;
282
+ try { allowAct = (JSON.parse(readFileSync(SETTINGS, "utf8")) ?? {}).allowAct === true; } catch { /* no settings yet */ }
283
+ ws.send(JSON.stringify({ v: 1, t: "hello", roomToken: token, info: { name: NAME, version: "0.1.0", capabilities: ["dev.herdgate.host", allowAct ? "act" : "read-only"] } }));
277
284
  };
278
285
  ws.onmessage = (ev) => {
279
286
  void (async () => {
@@ -329,8 +336,13 @@ async function publisherLoop() {
329
336
  return void replyTo({ op: "error", code: "read-only", message: `dev.herdgate.host has no op ${String(op)}` });
330
337
  }
331
338
  if (m.t === "pair.request") {
332
- // Read-only plugin: `act` is never granted.
333
- ws.send(JSON.stringify({ v: 1, t: "pair.response", requestId: m.requestId, ok: false }));
339
+ // `act` (control) is the owner's call, made ON THIS MACHINE: the settings'
340
+ // allowAct switch. Read fresh — the panel can flip it while we run.
341
+ let allow = false;
342
+ try { allow = (JSON.parse(readFileSync(SETTINGS, "utf8")) ?? {}).allowAct === true; } catch { /* not configured */ }
343
+ const ok = allow && m.scope === "act";
344
+ log(`pair request from ${m.device?.name ?? "?"} for ${m.scope}: ${ok ? "approved (allowAct)" : "denied"}`);
345
+ ws.send(JSON.stringify({ v: 1, t: "pair.response", requestId: m.requestId, ok }));
334
346
  return;
335
347
  }
336
348
  if (m.t === "ping") ws.send(JSON.stringify({ v: 1, t: "pong", n: m.n ?? 0 }));