// SPDX-License-Identifier: LGPL-2.1-or-later import React, { useState } from "react"; import { createRoot } from 'react-dom/client'; import { Button } from "@patternfly/react-core/dist/esm/components/Button/index.js"; import { Form, FormGroup } from "@patternfly/react-core/dist/esm/components/Form/index.js"; import { TextInput } from "@patternfly/react-core/dist/esm/components/TextInput/index.js"; import { Page } from "@patternfly/react-core/dist/esm/components/Page/index.js"; import cockpit from "cockpit"; import { WithDialogs, useDialogs } from "dialogs.jsx"; import { connect_host } from "cockpit-connect-ssh"; import 'page.scss'; const RemotePage = () => { const dialogs = useDialogs(); const [host, setHost] = useState("127.0.0.1"); const [user, setUser] = useState(""); const [command, setCommand] = useState("hostname"); const [output, setOutput] = useState(""); const [error, setError] = useState(""); const on_go = async () => { setOutput(""); setError(""); try { await connect_host(dialogs, host, user); const out = await cockpit.script(command, [], { host, user }); setOutput(out.trim()); } catch (ex) { setError(JSON.stringify(ex)); } }; return (
setHost(value)} isRequired /> setUser(value)} isRequired /> setCommand(value)} isRequired />
{output}
{error}
); }; document.addEventListener("DOMContentLoaded", () => { cockpit.translate(); const app = document.getElementById("app"); cockpit.assert(app); createRoot(app).render(); // signal tests that we are ready cockpit.transport.wait(() => true); });