diff --git a/frontend/src/buttons/ServiceConnectButton.tsx b/frontend/src/buttons/ServiceConnectButton.tsx index e7571112b..8f96f9be3 100644 --- a/frontend/src/buttons/ServiceConnectButton.tsx +++ b/frontend/src/buttons/ServiceConnectButton.tsx @@ -11,11 +11,12 @@ import { ErrorButton } from '../buttons/ErrorButton' import { DesktopUI } from '../components/DesktopUI' import { Gutters } from '../components/Gutters' import { LocalSubnetConnect } from '../components/LocalSubnetConnect' -import { isConsoleService } from '../helpers/sshHelper' +import { opensTerminal } from '../helpers/sshHelper' import { useLocalSignIn, useSubnetReach } from '../hooks/useLocalSubnetName' import { LocalSignInNotice } from '../components/LocalSignInNotice' import { BrowserGatewayConnect } from '../components/BrowserGatewayConnect' -import { ConsoleTerminalOption } from '../components/ConsoleTerminal' +import { AppTerminalOption } from '../components/AppTerminal' +import { useServiceApp } from '../hooks/useDeviceApps' import { useApplication } from '../hooks/useApplication' import { Link } from '../components/Link' import { LocalPortConnect } from '../components/LocalPortConnect' @@ -35,6 +36,10 @@ export const ServiceConnectButton: React.FC = () => { // (services/browserGateway), the proxy one step away as for a local name. const web = useApplication(service, connection).urlForm const ssh = service?.typeID === 28 + // The app the service belongs to, where it does: one whose service is ssh and that signs people in by certificate + // opens in our web SSH as well, with the person's own account (components/AppTerminal). + const serving = useServiceApp(device, service) + const byCertificate = opensTerminal(serving.app) const gateway = !local && reach.checked && !!reach.name && (!!web || ssh) && !proxy // A local port of this machine (services/localPorts), where it runs our daemon: asked for here, or open already — // then it is what the panel shows, until it is disconnected. @@ -125,7 +130,12 @@ export const ServiceConnectButton: React.FC = () => { ) : named ? ( {local ? ( - + ) : ( { port: service.port || 22, title: service.name, service: service.id, - console: isConsoleService(service), + byCertificate, } : undefined } @@ -167,10 +177,10 @@ export const ServiceConnectButton: React.FC = () => { {portLink} )} - {/* The console: our web SSH, an option beside the ways above. */} - {isConsoleService(service) && ( + {/* An app's ssh service that signs people in by certificate: our web SSH, an option beside the ways above. */} + {byCertificate && ( - + )} {/* The service's other ports here that this machine's daemon lists: the machine's, opened by someone else. */} diff --git a/frontend/src/components/AppCatalogRow.tsx b/frontend/src/components/AppCatalogRow.tsx index 17b10f298..533fdaae3 100644 --- a/frontend/src/components/AppCatalogRow.tsx +++ b/frontend/src/components/AppCatalogRow.tsx @@ -1,11 +1,12 @@ import React from 'react' import { useTranslation } from 'react-i18next' import { Box, ListItem, ListItemButton, ListItemIcon, ListItemText, Typography } from '@mui/material' -import { firstPartyApp } from './firstPartyApps' +import { appIcon, capabilitiesLine } from '../helpers/appsHelper' import { Icon } from './Icon' /* One app in the catalogue (presence-server docs/device-apps-design.md, "The Apps pages"): its name, its publisher with - Verified: and Yours for the account's own, Runs as root or Restricted, its description, its platforms and + Verified: and Yours for the account's own, Runs as root or Restricted and what else it asks of remote.it + (its capabilities, in words), its icon from how its service opens, its description, its platforms and what is said beside them (how many devices have it, or why this device cannot take it). The row opens the app; its action (Add…) sits at its end. */ export type AppCatalogRowProps = { @@ -15,6 +16,8 @@ export type AppCatalogRowProps = { verifiedDomain?: string | null own?: boolean // the account's own publisher root: boolean + capabilities?: string[] + protocol?: string | null // how its service opens: its icon description?: string | null platforms?: string | null // as families aside?: React.ReactNode // beside the platforms: how many devices have it @@ -30,6 +33,8 @@ export const AppCatalogRow: React.FC = ({ verifiedDomain, own, root, + capabilities, + protocol, description, platforms, aside, @@ -41,7 +46,7 @@ export const AppCatalogRow: React.FC = ({ const body = ( <> - + = ({ ? t('apps.runsAsRootFull', 'Runs as root: full control of the device') : t('apps.restricted', 'Restricted')} + {!!capabilities?.length && ( + + {capabilitiesLine(t, capabilities)} + + )} } secondaryTypographyProps={{ component: 'div' }} diff --git a/frontend/src/components/AppRootConsent.tsx b/frontend/src/components/AppRootConsent.tsx index 5933671b9..b7008e151 100644 --- a/frontend/src/components/AppRootConsent.tsx +++ b/frontend/src/components/AppRootConsent.tsx @@ -1,16 +1,19 @@ import React, { useState } from 'react' import { useTranslation } from 'react-i18next' -import { Typography } from '@mui/material' +import { Box, Typography } from '@mui/material' import type { DeviceApp } from '../services/graphQLDeviceApps' import { AppChange, refused } from '../services/deviceAppsShared' import type { DeviceApps } from '../hooks/useDeviceApps' +import { capabilityWords } from '../helpers/appsHelper' import { Confirm } from './Confirm' /* Asking for the person's yes to a root app's full control, in words naming the app, its publisher and that it gets - full control of the device (presence-server docs/device-apps-design.md, "Root, shown and consented to"). For a - product it says the yes covers every device in the product, now and later, as graphql keeps it on the product. */ + full control of the device (presence-server docs/device-apps-design.md, "Root, shown and consented to"), and what + else it asks of remote.it — its capabilities, part of the consent (presence-contract docs/self-contained-apps.md, + "Manifest"). For a product it says the yes covers every device in the product, now and later, as graphql keeps it + on the product. */ export const RootConsent: React.FC<{ - app?: { name: string; publisher: string } // open while there is one + app?: { name: string; publisher: string; capabilities?: string[] } // open while there is one product?: boolean // a product's consent, for every device in it action?: string // the confirm button's words, where they are not turning it on // A release of an app already on that newly runs as root: the consent moves it there (a re-consent). @@ -61,6 +64,7 @@ export const RootConsent: React.FC<{ words )} + {product ? t( @@ -74,8 +78,30 @@ export const RootConsent: React.FC<{ ) } +// What an app asks of remote.it beyond running, a line each: in its consent, and where it is offered. +export const AppCapabilities: React.FC<{ capabilities?: string[]; title?: string }> = ({ capabilities, title }) => { + const { t } = useTranslation() + if (!capabilities?.length) return null + return ( + + {title ?? t('apps.capabilitiesAlso', 'It also asks of remote.it:')} + {capabilities.map(capability => ( + + · {capabilityWords(t, capability)} + + ))} + + ) +} + /* Enabling or disabling an app, from wherever it is offered (the device's Apps section, the app's page on the device, - the console's connect panel). A root app is enabled only once the person says yes (RootConsent); that yes is + an app's service's connect panel). A root app is enabled only once the person says yes (RootConsent); that yes is consentRoot, which graphql refuses a root app without. Disabling, or a restricted app, at once. A release that newly runs as root while the app is enabled (awaitingRoot) is asked for the same way (reconsent): the yes is setDeviceAppRelease's consentRoot alone — Update now —, which moves the device to that release. graphql's refusal, diff --git a/frontend/src/components/AppTerminal.test.tsx b/frontend/src/components/AppTerminal.test.tsx new file mode 100644 index 000000000..ef0ff5d57 --- /dev/null +++ b/frontend/src/components/AppTerminal.test.tsx @@ -0,0 +1,248 @@ +import React, { act } from 'react' +import { createRoot, Root } from 'react-dom/client' +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest' + +const { apps, name, openTerminal, env } = vi.hoisted(() => ({ + apps: { value: {} as any }, + name: { value: 'pi-evan.on.remote.it' as string | undefined }, + openTerminal: vi.fn(), + env: { isNative: false }, +})) +// The device's apps as the API says them; which one a service belongs to is the portal's own rule (appsHelper). +vi.mock('../hooks/useDeviceApps', async () => { + const { isAppService, serviceApp } = await import('../helpers/appsHelper') + return { + useServiceApp: (device?: IDevice, service?: IService) => { + const read = device && isAppService(service) ? apps.value : {} + return { ...read, app: serviceApp(read.apps, service) } + }, + } +}) +vi.mock('../hooks/useLocalSubnetName', () => ({ + useSubnetName: (deviceId?: string) => (deviceId ? name.value : undefined), +})) +vi.mock('../helpers/terminalHelper', () => ({ openTerminal })) +vi.mock('../services/browser', () => ({ default: env, windowOpen: vi.fn() })) +vi.mock('./Confirm', () => ({ + Confirm: ({ open, title, children, onConfirm, onDeny }: any) => + open ? ( + + {title} {children} + + ) +} + +/** A service's row in its device's services: a terminal button while its app runs. */ +export const AppTerminalButton: React.FC<{ device: IDevice; service: IService }> = ({ device, service }) => { + const { t } = useTranslation() + const { app } = useServiceApp(device, service) + const terminal = opensTerminal(app) + const name = useSubnetName(terminal ? device.id : undefined) + const port = service.port + if (!app || !terminal || app.state !== 'running' || !app.serviceId || !name || !port) return null + return ( + { + // The row opens the service's page: the button is not the row. + event.stopPropagation() + open(app, name, port) + }} + /> + ) +} + +/** A service's connect panel, where its app opens a terminal (serving: useServiceApp, read by the panel): Open in web + * SSH while the app runs, whichever way the panel connects it — its name on this machine, the browser's client (where + * the panel's own terminal button is this too) or the proxy; otherwise what the app is doing — and, for those who may + * run code on the device (Manage and Scripting), turning it on, with their yes to its running as root + * (components/AppRootConsent). */ +export const AppTerminalOption: React.FC<{ device?: IDevice; service?: IService; serving: ServiceApp }> = ({ + device, + service, + serving: { app, switching, turn, setRelease }, +}) => { + const { t } = useTranslation() + const terminal = opensTerminal(app) + const name = useSubnetName(terminal ? device?.id : undefined) + const { flip, consent } = useAppSwitch({ turn, setRelease }) + if (!app || !terminal || !name) return null + // Not where its product holds it off: graphql refuses that, naming the product. + const canTurnOn = + !app.locked && !!device?.permissions?.includes('MANAGE') && !!device?.permissions?.includes('SCRIPTING') + + const port = service?.port + if (app.state === 'running' && !switching) { + if (!app.serviceId || !port) return null + return ( + + open(app, name, port)}> + + {label(t)} + + + ) + } + + const status = switching + ? t('deviceApps.switching', 'Waiting for the device…') + : app.state === 'starting' + ? t('appTerminal.starting', '{{app}} is starting: web SSH opens it once it runs', { app: app.name }) + : app.state === 'unavailable' + ? t('deviceApps.unavailable', 'Not available here: {{detail}}', { detail: app.detail }) + : t('appTerminal.disabled', '{{app}} is disabled: enable it to open it in web SSH', { app: app.name }) + + return ( + + {status} + {app.state === 'disabled' && !switching && canTurnOn && ( + <> + {' '} + flip(app, true)}>{t('appTerminal.enable', 'Enable it')} + + )} + {consent} + + ) +} diff --git a/frontend/src/components/BrowserGatewayConnect.tsx b/frontend/src/components/BrowserGatewayConnect.tsx index a30525f8f..0a1e706ea 100644 --- a/frontend/src/components/BrowserGatewayConnect.tsx +++ b/frontend/src/components/BrowserGatewayConnect.tsx @@ -12,9 +12,10 @@ import { Icon } from './Icon' browser's remote.it client — nothing to install, and no connection to start. An SSH service opens a terminal in this app instead (pages/TerminalPage), its session through the same client — from the desktop app, in the web portal (helpers/terminalHelper). The counterpart of LocalSubnetConnect, - which is shown instead when an agent here does reach it. The console's plain ssh command is offered to copy as well: - it works from a machine signed in on its remote.it device app. */ -type Props = { name: string; terminal?: { port: number; title?: string; service?: string; console?: boolean } } + which is shown instead when an agent here does reach it. The plain ssh command of an app's service that signs people + in by certificate (byCertificate) is offered to copy as well: it works from a machine signed in on its remote.it + device app. */ +type Props = { name: string; terminal?: { port: number; title?: string; service?: string; byCertificate?: boolean } } export const BrowserGatewayConnect: React.FC = ({ name, terminal }) => { const { t } = useTranslation() @@ -57,14 +58,14 @@ export const BrowserGatewayConnect: React.FC = ({ name, terminal }) => { {t('browserGatewayConnect.failed', 'Could not open it: try again')} )} - {terminal?.console && ( + {terminal?.byCertificate && ( {sshCommand(name, terminal.port)} —{' '} {t('localSubnetConnect.sshHint', 'Works from a machine signed in on its remote.it device app')} )} - {terminal?.console && } + {terminal?.byCertificate && } - device?.services?.find(service => service.id === app.serviceId)?.port - -const ConsoleHostKey: React.FC = ({ app }) => { - const { t } = useTranslation() - const [hostKey, setHostKey] = useState(null) - const running = app.state === 'running' && app.serviceId - - useEffect(() => { - setHostKey(null) - if (!running || !app.serviceId) return - let current = true - graphQLSshHostKey(app.serviceId).then(key => current && setHostKey(key)) - return () => { - current = false - } - }, [running, app.serviceId]) - - if (!running || !hostKey) return null - return ( - - {t('deviceApps.hostKey', 'Host key {{key}}', { key: hostKey })} - - ) -} - -const ConsoleOpenTerminal: React.FC = ({ device, app }) => { - const { t } = useTranslation() - const name = useSubnetName(device.id) - const port = consolePort(device, app) - if (app.state !== 'running' || !name || !port || !app.serviceId) return null - return ( - - ) -} - -export const CONSOLE_APP: FirstPartyApp = { - icon: 'terminal', - state: (t, app) => - app.state === 'running' - ? t('deviceApps.consoleRunning', 'Running — logins by certificate, nothing listening on the device') - : app.state === 'disabled' - ? t('deviceApps.consoleDisabled', 'Disabled — a terminal on this device, from this app, by certificate') - : undefined, - settings: t => ({ - ai_commands: { - label: t('deviceApps.consoleAiCommands', 'Allow AI commands'), - help: t( - 'deviceApps.consoleAiCommandsHelp', - "AI assistants you authorize may run commands on this device's console through remote.it's MCP server. The device's administrator can turn this off on the machine." - ), - }, - }), - Lines: ConsoleHostKey, - Actions: ConsoleOpenTerminal, -} diff --git a/frontend/src/components/ConsoleTerminal.test.tsx b/frontend/src/components/ConsoleTerminal.test.tsx deleted file mode 100644 index 6708a01b6..000000000 --- a/frontend/src/components/ConsoleTerminal.test.tsx +++ /dev/null @@ -1,186 +0,0 @@ -import React, { act } from 'react' -import { createRoot, Root } from 'react-dom/client' -import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest' - -const { apps, name, openTerminal, env } = vi.hoisted(() => ({ - apps: { value: {} as any }, - name: { value: 'pi-evan.on.remote.it' as string | undefined }, - openTerminal: vi.fn(), - env: { isNative: false }, -})) -vi.mock('../hooks/useDeviceApps', () => ({ useDeviceApps: (deviceId?: string) => (deviceId ? apps.value : {}) })) -vi.mock('../hooks/useLocalSubnetName', () => ({ - useSubnetName: (deviceId?: string) => (deviceId ? name.value : undefined), -})) -vi.mock('../helpers/terminalHelper', () => ({ openTerminal })) -vi.mock('../services/browser', () => ({ default: env, windowOpen: vi.fn() })) -vi.mock('./Confirm', () => ({ - Confirm: ({ open, title, children, onConfirm, onDeny }: any) => - open ? ( - - {title} {children} -