Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

feat(cli): print a paste-ready command under every device

Rahmane5286205e569
diff --git a/bin/mso.test.ts b/bin/mso.test.ts
index 286d5877..65a6a455 100644
--- a/bin/mso.test.ts
+++ b/bin/mso.test.ts
@@ -110,6 +110,39 @@ describe("bin/mso", () => {
expect(JSON.parse(fs.readFileSync(store, "utf8")).approved).toEqual({});
});
+ it("prints a paste-ready command under every device, quoted safely", () => {
+ const fs = require("node:fs") as typeof import("node:fs");
+ const os = require("node:os") as typeof import("node:os");
+ const store = path.join(fs.mkdtempSync(path.join(os.tmpdir(), "mso-dev-")), "devices.json");
+ const pendingId = "c".repeat(32);
+ const approvedId = "d".repeat(32);
+ // A label with a quote AND a space is the case that breaks naive `"${label}"`
+ // interpolation — the pasted line would split into several arguments.
+ const nasty = 'Chrome "work" laptop';
+ fs.writeFileSync(
+ store,
+ JSON.stringify({
+ approved: { [approvedId]: { label: "phone" } },
+ pending: { [pendingId]: { label: nasty, ip: "10.0.0.1", attempts: 1 } },
+ }),
+ );
+ const withStore = (...args: string[]) =>
+ execFileSync(CLI, args, {
+ encoding: "utf8",
+ env: { ...process.env, MSO_ENV: "/dev/null", OS_DEVICE_STORE: store },
+ });
+
+ const list = withStore("device", "list");
+ expect(list).toContain(`mso device approve ${pendingId} ${JSON.stringify(nasty)}`);
+ expect(list).toContain(`mso device revoke ${approvedId}`);
+ // The bare id stays on its own line — way (1) still works.
+ expect(list).toMatch(new RegExp(`^ {2}${pendingId} `, "m"));
+
+ expect(withStore("device", "pending")).toContain(
+ `mso device approve ${pendingId} ${JSON.stringify(nasty)}`,
+ );
+ });
+
it("accepts -y as confirmation and reports what is left after a single revoke", () => {
const fs = require("node:fs") as typeof import("node:fs");
const os = require("node:os") as typeof import("node:os");
diff --git a/scripts/approve-device.js b/scripts/approve-device.js
index 3cf56500..45a5fd22 100644
--- a/scripts/approve-device.js
+++ b/scripts/approve-device.js
@@ -33,28 +33,42 @@ function write(store) {
}
const ts = (t) => (t ? new Date(t).toISOString() : "—");
+// Two ways to act on a device: copy the bare id (compose your own command), or
+// copy the whole line below it and paste it. JSON.stringify does the quoting, so
+// a label containing a quote or a space still pastes as ONE argument.
+const approveCmd = (id, label) => ` mso device approve ${id} ${JSON.stringify(label || "my device")}`;
+const revokeCmd = (id) => ` mso device revoke ${id}`;
+
+const listApproved = (ap) => {
+ if (!ap.length) return void console.log(" (none)");
+ for (const [id, d] of ap) {
+ console.log(` ${id} "${d.label}" approved=${ts(d.approvedAt)} lastSeen=${ts(d.lastSeen)}`);
+ console.log(revokeCmd(id));
+ }
+};
+const listPending = (pd) => {
+ if (!pd.length) return void console.log(" (none)");
+ for (const [id, d] of pd) {
+ console.log(` ${id} "${d.label}" ip=${d.ip} attempts=${d.attempts} last=${ts(d.lastSeen)}`);
+ console.log(approveCmd(id, d.label));
+ }
+};
+
const args = process.argv.slice(2);
if (args[0] === "--list") {
const s = read();
console.log(`store: ${STORE}\n\nAPPROVED:`);
- const ap = Object.entries(s.approved);
- if (!ap.length) console.log(" (none)");
- for (const [id, d] of ap) console.log(` ${id} "${d.label}" approved=${ts(d.approvedAt)} lastSeen=${ts(d.lastSeen)}`);
+ listApproved(Object.entries(s.approved));
console.log("\nPENDING (typed correct password, awaiting approval):");
- const pd = Object.entries(s.pending);
- if (!pd.length) console.log(" (none)");
- for (const [id, d] of pd) console.log(` ${id} "${d.label}" ip=${d.ip} attempts=${d.attempts} last=${ts(d.lastSeen)}`);
+ listPending(Object.entries(s.pending));
process.exit(0);
}
if (args[0] === "--pending") {
const s = read();
- const pd = Object.entries(s.pending);
console.log(`store: ${STORE}\n\nPENDING (typed correct password, awaiting approval):`);
- if (!pd.length) console.log(" (none)");
- for (const [id, d] of pd) console.log(` ${id} "${d.label}" ip=${d.ip} attempts=${d.attempts} last=${ts(d.lastSeen)}`);
- if (pd.length) console.log(`\napprove: mso device approve ${pd[0][0]} "a label"`);
+ listPending(Object.entries(s.pending));
process.exit(0);
}