Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions frontend/src/buttons/ServiceConnectButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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.
Expand Down Expand Up @@ -125,7 +130,12 @@ export const ServiceConnectButton: React.FC = () => {
) : named ? (
<Box sx={{ width: '100%' }}>
{local ? (
<LocalSubnetConnect local={local} service={service} connection={connection} />
<LocalSubnetConnect
local={local}
service={service}
connection={connection}
byCertificate={byCertificate}
/>
) : (
<BrowserGatewayConnect
name={reach.name!}
Expand All @@ -135,7 +145,7 @@ export const ServiceConnectButton: React.FC = () => {
port: service.port || 22,
title: service.name,
service: service.id,
console: isConsoleService(service),
byCertificate,
}
: undefined
}
Expand Down Expand Up @@ -167,10 +177,10 @@ export const ServiceConnectButton: React.FC = () => {
{portLink}
</Gutters>
)}
{/* 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 && (
<Gutters size="md" top={null} bottom={null}>
<ConsoleTerminalOption device={device} service={service} />
<AppTerminalOption device={device} service={service} serving={serving} />
</Gutters>
)}
{/* The service's other ports here that this machine's daemon lists: the machine's, opened by someone else. */}
Expand Down
16 changes: 13 additions & 3 deletions frontend/src/components/AppCatalogRow.tsx
Original file line number Diff line number Diff line change
@@ -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: <domain> and Yours for the account's own, Runs as root or Restricted, its description, its platforms and
Verified: <domain> 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 = {
Expand All @@ -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
Expand All @@ -30,6 +33,8 @@ export const AppCatalogRow: React.FC<AppCatalogRowProps> = ({
verifiedDomain,
own,
root,
capabilities,
protocol,
description,
platforms,
aside,
Expand All @@ -41,7 +46,7 @@ export const AppCatalogRow: React.FC<AppCatalogRowProps> = ({
const body = (
<>
<ListItemIcon sx={{ alignSelf: 'flex-start', marginTop: 0.5 }}>
<Icon name={firstPartyApp(id)?.icon ?? 'cube'} size="md" fixedWidth />
<Icon name={appIcon(protocol)} size="md" fixedWidth />
</ListItemIcon>
<ListItemText
primary={
Expand All @@ -61,6 +66,11 @@ export const AppCatalogRow: React.FC<AppCatalogRowProps> = ({
? t('apps.runsAsRootFull', 'Runs as root: full control of the device')
: t('apps.restricted', 'Restricted')}
</Typography>
{!!capabilities?.length && (
<Typography variant="caption" color="textSecondary" data-catalog-capabilities>
{capabilitiesLine(t, capabilities)}
</Typography>
)}
</Box>
}
secondaryTypographyProps={{ component: 'div' }}
Expand Down
86 changes: 78 additions & 8 deletions frontend/src/components/AppRootConsent.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,41 @@
import React, { useState } from 'react'
import React, { useEffect, 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 { graphQLCatalogApp } from '../services/graphQLAppCatalog'
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.

The capabilities named are the release's the yes is given to (release), not the version the device runs: a release
may ask more than the one before it, and graphql takes the yes as covering what that release asks. They are read
from its catalogue entry (useReleaseAsks); until they are, the yes waits. */
export const RootConsent: React.FC<{
app?: { name: string; publisher: string } // open while there is one
app?: { id?: string; 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).
version?: string | null
// The release the yes is given to, where it is not version: a pin, the release enabling gives. None: the app's own.
release?: string | null
accountId?: string // whose catalogue names the release: the device's account
onConfirm: () => void
onDeny: () => void
}> = ({ app, product, action, version, onConfirm, onDeny }) => {
}> = ({ app, product, action, version, release, accountId, onConfirm, onDeny }) => {
const { t } = useTranslation()
const words = { app: app?.name, publisher: app?.publisher, version }
const asks = useReleaseAsks(app, release ?? version, accountId)
return (
<Confirm
open={!!app}
disabled={asks === undefined}
color="error"
title={
product
Expand Down Expand Up @@ -61,6 +74,7 @@ export const RootConsent: React.FC<{
words
)}
</Typography>
<AppCapabilities capabilities={asks} />
<Typography variant="body2">
{product
? t(
Expand All @@ -74,16 +88,68 @@ export const RootConsent: React.FC<{
)
}

/* What the release a consent is for asks of remote.it (its capabilities): its catalogue entry's for that release; the
app's own where no release is named, or where the catalogue does not answer for it (an API without one, an error, a
release it does not list — graphql still refuses a yes that does not cover what the release asks). undefined while
it is read. */
export function useReleaseAsks(
app: { id?: string; capabilities?: string[] } | undefined,
release: string | null | undefined,
accountId?: string
): string[] | undefined {
const [read, setRead] = useState<{ key: string; asks: string[] | null }>()
const key = app?.id && release ? `${accountId ?? ''}/${app.id}/${release}` : ''
useEffect(() => {
if (!key || !app?.id || !release) return
let current = true
graphQLCatalogApp(app.id, { accountId, releases: 100 }).then(answer => {
if (!current) return
const entry = typeof answer === 'object' && answer ? answer.releases.find(r => r.version === release) : undefined
setRead({ key, asks: entry ? entry.capabilities : null })
})
return () => {
current = false
}
}, [key])
if (!app) return undefined
if (!key) return app.capabilities ?? []
if (read?.key !== key) return undefined
return read.asks ?? app.capabilities ?? []
}

// 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 (
<Box sx={{ marginBottom: 1 }} data-app-capabilities>
<Typography variant="body2">{title ?? t('apps.capabilitiesAlso', 'It also asks of remote.it:')}</Typography>
{capabilities.map(capability => (
<Typography
key={capability}
variant="body2"
component="div"
sx={{ paddingLeft: 2 }}
data-app-capability={capability}
>
· {capabilityWords(t, capability)}
</Typography>
))}
</Box>
)
}

/* 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,
in its words, goes to onRefused; a change made, to onChanged. */
export function useAppSwitch(
{ turn, setRelease }: Pick<DeviceApps, 'turn'> & Partial<Pick<DeviceApps, 'setRelease'>>,
onRefused?: (reason: string) => void,
onChanged?: (app: DeviceApp) => void
onChanged?: (app: DeviceApp) => void,
accountId?: string // the device's account, whose catalogue names the release consented to
) {
const { t } = useTranslation()
const [asking, setAsking] = useState<DeviceApp>()
Expand All @@ -102,11 +168,15 @@ export function useAppSwitch(
// An enabled app held back for a release that runs as root: the yes moves it there.
const waiting = (app?: DeviceApp) => !!app?.enabled && (!!app.awaitingRoot || app.heldBack?.reason === 'consent')
const updating = waiting(asking) ? asking?.awaitingRoot || asking?.latest || '' : null
// The release the yes goes to: the one waiting for it, else the one enabling gives — its pin, else its channel's.
const target = updating || asking?.pinned || asking?.latest || asking?.release || asking?.version || null

const consent = (
<RootConsent
app={asking}
version={updating}
release={target}
accountId={accountId}
action={updating !== null ? t('deviceApps.rootUpdateAction', 'Consent and update') : undefined}
onConfirm={() => {
const app = asking
Expand Down
Loading
Loading