Skip to content

An open-source, self-hosted system for apps built with web technologies.

Keep shell forwarding client-specific

zohayrslilehc1827c6fb495
diff --git a/scripts/contracts/gateway.ts b/scripts/contracts/gateway.ts
index e17ad9a..f7ecc65 100644
--- a/scripts/contracts/gateway.ts
+++ b/scripts/contracts/gateway.ts
@@ -44,14 +44,6 @@ const process = {
const application = {
system: {
listPrograms() { return [] },
- async *shell(command: string) {
-
- assert.equal(command, "printf hello")
-
- yield { event: "started", pid: 42 }
- yield { event: "output", stream: "stdout", text: "hello" }
- yield { event: "exited", exit: { status: "exited", code: 0, signal: null } }
- },
async forceCreateProgram() { return entry.program },
requireProgram(identity: string) { return identity === forkedEntry.program.identity ? forkedEntry : entry },
programSnapshot(selected: typeof entry) { return { ...programSnapshot, identity: selected.program.identity } },
@@ -93,17 +85,6 @@ try {
assert.deepEqual(system, [{ success: true, result: { data: [], total: 0, truncated: false } }])
- const shell = await exchange(path, {
- target: "shell",
- request: { command: "printf hello", options: {} }
- })
-
- assert.deepEqual(shell, [
- { event: "started", pid: 42 },
- { event: "output", stream: "stdout", text: "hello" },
- { event: "exited", exit: { status: "exited", code: 0, signal: null } }
- ])
-
const ready = await exchange(path, {
target: "system",
request: {
diff --git a/source/client/core/link-manager/auth-manager/auth-manager.ts b/source/client/core/link-manager/auth-manager/auth-manager.ts
index d96a18d..a85ccd0 100644
--- a/source/client/core/link-manager/auth-manager/auth-manager.ts
+++ b/source/client/core/link-manager/auth-manager/auth-manager.ts
@@ -58,6 +58,11 @@ export default class AuthManager extends TheLink {
return await this.$outbound.publishFirst("/storage", operation, values)
}
+ public async uploadsPath() {
+
+ return await this.$outbound.publishFirst("/uploads/path") as string
+ }
+
public async updateAppearance(value: unknown) {
return await this.$outbound.publishFirst("/appearance/update", value)
diff --git a/source/client/view/components/desktop-host/host.ts b/source/client/view/components/desktop-host/host.ts
index 821012b..7a1b5cb 100644
--- a/source/client/view/components/desktop-host/host.ts
+++ b/source/client/view/components/desktop-host/host.ts
@@ -872,14 +872,16 @@ export default function host(authManager: AuthManager, pane: string, desktop: ()
// fact, and the gutter remains private desktop layout state.
if (word === "desktopSurface") return [desktop()]
- // Uploads are one flat public collection. A pane may provide bytes or
- // one opaque file key; it never receives a filesystem path or route.
+ // Uploads are one flat public collection. The all permission exposes
+ // its native entry point as part of the complete System contract.
if (word === "uploads") {
await access.requireAll()
const operation = args[0]
+ if (operation === "path") return [await authManager.uploadsPath()]
+
if (operation === "stat") {
if (!isUploadFile(args[1])) throw new Error("Uploads stat takes one upload file")
diff --git a/source/server/core/link-manager/auth-manager/auth-manager.ts b/source/server/core/link-manager/auth-manager/auth-manager.ts
index 687bda1..9f855fe 100644
--- a/source/server/core/link-manager/auth-manager/auth-manager.ts
+++ b/source/server/core/link-manager/auth-manager/auth-manager.ts
@@ -106,6 +106,12 @@ export default class AuthManager extends TheLink {
throw new Error(`System storage does not know "${operation}"`)
}
+ @Connect("/uploads/path")
+ protected async uploadsPath() {
+
+ return this.uploads.fileManager.path
+ }
+
@Connect("/appearance/update")
protected async changeAppearance(value: unknown) {
diff --git a/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts b/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts
index 57b1de7..01b2541 100644
--- a/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts
+++ b/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts
@@ -17,7 +17,7 @@ import { endpointReference, processReference } from "./endpoint-reference"
import EndpointEvents from "./endpoint-events"
import EndpointServices from "./endpoint-services"
import OutsideQuestions from "./outside-questions"
-import { isServiceKey, type ClientLaunch, type Launch, type Permission, type PermissionChange, type PermissionRequest, type ServerLaunch, type ServiceKey, type ShellOptions, type WindowGeometry, type WindowLayer } from "@phreshos/core"
+import { isServiceKey, type ClientLaunch, type Launch, type Permission, type PermissionChange, type PermissionRequest, type ServerLaunch, type ServiceKey, type WindowGeometry, type WindowLayer } from "@phreshos/core"
import type { ServerRuntime } from "./server-runtime"
import { permissionCatalog } from "@server/core/permissions"
@@ -2231,30 +2231,6 @@ export default class ProcessManager extends TheLink {
const operation = args[0]
- if (operation === "shell") {
-
- if (typeof args[1] !== "string") throw new Error("A shell command must be text")
-
- const command = this.system.shell(args[1], args[2] as ShellOptions ?? {})
-
- cancel = () => {
-
- active = false
- void command.return(undefined)
- }
-
- for await (const event of command) {
-
- if (!active) return
-
- await this.say(server, "host-end", "stream", question, "data", event)
- }
-
- if (active) await this.say(server, "host-end", "stream", question, "answer", succeeded(undefined))
-
- return
- }
-
const program = this.system.holdProgram(args[1])
if (operation === "run") {
diff --git a/source/server/view/gateway/gateway.ts b/source/server/view/gateway/gateway.ts
index d12b666..1af4140 100644
--- a/source/server/view/gateway/gateway.ts
+++ b/source/server/view/gateway/gateway.ts
@@ -2,7 +2,6 @@ import type Application from "@server/core/application"
import localServer from "./local-server"
import apiRequest from "./api-request"
import programRequest from "./program-request"
-import shellRequest from "./shell-request"
import systemRequest from "./system-request"
const maximumRequestSize = 16 * 1024 * 1024
@@ -45,12 +44,6 @@ export default function gateway(application: Application, path: string) {
return
}
- if (envelope.target === "shell") {
-
- shellRequest(application, socket, envelope.request, controller.signal).catch(error => fail(socket, error))
- return
- }
-
if (envelope.target === "api") {
apiRequest(application, envelope.request, controller.signal).then(
@@ -84,7 +77,7 @@ function parseEnvelope(line: string): GatewayEnvelope {
if (Object.keys(envelope).some(key => key !== "target" && key !== "request")) throw new Error("The gateway request contains an unknown field")
- if (envelope.target !== "api" && envelope.target !== "program" && envelope.target !== "shell" && envelope.target !== "system") throw new Error("The Gateway target must be api, program, shell, or system")
+ if (envelope.target !== "api" && envelope.target !== "program" && envelope.target !== "system") throw new Error("The Gateway target must be api, program, or system")
if (!("request" in envelope)) throw new Error("The gateway request is missing")
return { target: envelope.target, request: envelope.request }
@@ -107,6 +100,6 @@ function reason(error: unknown) {
interface GatewayEnvelope {
- target: "api" | "program" | "shell" | "system"
+ target: "api" | "program" | "system"
request: unknown
}
diff --git a/source/server/view/gateway/shell-request.ts b/source/server/view/gateway/shell-request.ts
deleted file mode 100644
index 327d4b3..0000000
--- a/source/server/view/gateway/shell-request.ts
+++ /dev/null
@@ -1,47 +0,0 @@
-import type Application from "@server/core/application"
-import type { ShellOptions } from "@phreshos/core"
-import type { Socket } from "node:net"
-
-/** Stream one owner-local shell command through the System gateway. */
-export default async function shellRequest(application: Application, socket: Socket, value: unknown, signal: AbortSignal) {
-
- if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("The shell request must be an object")
-
- const request = value as Record<string, unknown>
-
- if (Object.keys(request).some(key => key !== "command" && key !== "options")) throw new Error("The shell request contains an unknown field")
- if (typeof request.command !== "string") throw new Error("A shell command must be text")
-
- const options = request.options === undefined ? {} : request.options
-
- if (!options || typeof options !== "object" || Array.isArray(options)) throw new Error("Shell options must be an object")
- if (Object.keys(options).some(key => key !== "cwd" && key !== "env")) throw new Error("Shell options contain an unknown field")
-
- for await (const event of application.system.shell(request.command, { ...(options as ShellOptions), signal })) {
-
- if (!await write(socket, `${JSON.stringify(event)}\n`)) return
- }
-
- if (socket.writable) socket.end()
-}
-
-async function write(socket: Socket, value: string) {
-
- if (!socket.writable) return false
- if (socket.write(value)) return true
-
- await new Promise<void>(resolve => {
-
- const settled = () => {
-
- socket.off("drain", settled)
- socket.off("close", settled)
- resolve()
- }
-
- socket.once("drain", settled)
- socket.once("close", settled)
- })
-
- return socket.writable
-}