feat(hosts): manage servers and encrypted SSH credentials in UI (#7)
This commit is contained in:
+19
-56
@@ -24,6 +24,8 @@ import type {
|
||||
StartRunRequest,
|
||||
Step,
|
||||
} from "@shellbook/core";
|
||||
import { HostKeyConfirmation } from "./HostKeyConfirmation";
|
||||
import { HostsPage } from "./HostsPage";
|
||||
import { HttpError } from "./api";
|
||||
import type { Api } from "./api";
|
||||
import { emptySession, eventReducer, stepKey } from "./events";
|
||||
@@ -46,6 +48,7 @@ function steps(blocks: Block[]): Step[] {
|
||||
);
|
||||
}
|
||||
export function App({ api }: { api: Api }) {
|
||||
const [hostsPage, setHostsPage] = useState(false);
|
||||
const [auth, setAuth] = useState<"loading" | "login" | "ready">("loading");
|
||||
const [password, setPassword] = useState("");
|
||||
const [list, setList] = useState<NotebookSummary[]>([]);
|
||||
@@ -119,6 +122,10 @@ export function App({ api }: { api: Api }) {
|
||||
})
|
||||
.catch((e) => setError(String(e)));
|
||||
const close = api.events((event: ServerEvent) => {
|
||||
if ((event.type === "file.changed" || event.type === "file.deleted") && event.path === "hosts.yaml") {
|
||||
void api.hosts().then(result => setHosts(result.hosts)).catch(e => setError(String(e)));
|
||||
window.dispatchEvent(new Event("shellbook:hosts-changed")); return;
|
||||
}
|
||||
const open = current.current;
|
||||
if (event.type === "file.changed" && event.path === open.doc?.path) {
|
||||
if (open.dirty) setConflict(true);
|
||||
@@ -324,6 +331,7 @@ export function App({ api }: { api: Api }) {
|
||||
<h1>
|
||||
ShellBook<span>RUNBOOKS</span>
|
||||
</h1>
|
||||
<button onClick={() => setHostsPage(!hostsPage)}>{hostsPage ? "Back to notebooks" : "Servers & SSH"}</button>
|
||||
<nav aria-label="Notebooks">
|
||||
{list.map((item) => (
|
||||
<button
|
||||
@@ -347,6 +355,7 @@ export function App({ api }: { api: Api }) {
|
||||
</small>
|
||||
</aside>
|
||||
<main>
|
||||
{hostsPage ? <HostsPage onChange={() => { void api.hosts().then(result => setHosts(result.hosts)).catch(e => setError(String(e))); }} /> : <>
|
||||
<div className="toolbar">
|
||||
<span>{doc?.notebook.title ?? "Loading workspace…"}</span>
|
||||
<button onClick={() => setEdit(!edit)}>
|
||||
@@ -468,6 +477,7 @@ export function App({ api }: { api: Api }) {
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</>}
|
||||
</main>
|
||||
{terminalOpened && (
|
||||
<Suspense fallback={<p>Loading terminal...</p>}>
|
||||
@@ -499,62 +509,15 @@ export function App({ api }: { api: Api }) {
|
||||
</section>
|
||||
</div>
|
||||
)}
|
||||
{keyPrompt?.hostKey && (
|
||||
<div className="modal-backdrop">
|
||||
<section
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="hostkey-title"
|
||||
>
|
||||
<h2 id="hostkey-title">
|
||||
{keyPrompt.hostKey.changed
|
||||
? "⚠ HOST KEY CHANGED"
|
||||
: "Unknown SSH host key"}
|
||||
</h2>
|
||||
{keyPrompt.hostKey.changed && (
|
||||
<p className="error">
|
||||
STOP: a different key is already trusted. This may indicate a
|
||||
man-in-the-middle attack. Verify the fingerprint independently
|
||||
before accepting.
|
||||
</p>
|
||||
)}
|
||||
<p>
|
||||
Verify the key for <strong>{keyPrompt.hostKey.host}</strong>{" "}
|
||||
through a trusted channel.
|
||||
</p>
|
||||
<code>{keyPrompt.hostKey.fingerprint}</code>
|
||||
<div className="actions">
|
||||
<button
|
||||
onClick={() =>
|
||||
dispatch({
|
||||
type: "run.error",
|
||||
runId: keyPrompt.runId,
|
||||
message: "Host key rejected",
|
||||
})
|
||||
}
|
||||
>
|
||||
Reject
|
||||
</button>
|
||||
<button
|
||||
onClick={() => {
|
||||
const request = requests.current.get(keyPrompt.runId)!;
|
||||
dispatch({
|
||||
type: "run.error",
|
||||
runId: keyPrompt.runId,
|
||||
message: "Retrying with accepted host key",
|
||||
});
|
||||
void start({
|
||||
...request,
|
||||
acceptHostKey: keyPrompt.hostKey!.fingerprint,
|
||||
});
|
||||
}}
|
||||
>
|
||||
Trust this fingerprint and retry
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
)}
|
||||
{keyPrompt?.hostKey && <HostKeyConfirmation
|
||||
{...keyPrompt.hostKey}
|
||||
onReject={() => dispatch({ type: "run.error", runId: keyPrompt.runId, message: "Host key rejected" })}
|
||||
onTrust={() => {
|
||||
const request = requests.current.get(keyPrompt.runId)!;
|
||||
dispatch({ type: "run.error", runId: keyPrompt.runId, message: "Retrying with accepted host key" });
|
||||
void start({ ...request, acceptHostKey: keyPrompt.hostKey!.fingerprint });
|
||||
}}
|
||||
/>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user