Line data Source code
1 : // SPDX-License-Identifier: LGPL-2.1-or-later
2 3 : import React, { useState } from "react";
3 3 : import { createRoot } from 'react-dom/client';
4 :
5 : import { Button } from "@patternfly/react-core/dist/esm/components/Button/index.js";
6 : import { Form, FormGroup } from "@patternfly/react-core/dist/esm/components/Form/index.js";
7 : import { TextInput } from "@patternfly/react-core/dist/esm/components/TextInput/index.js";
8 : import { Page } from "@patternfly/react-core/dist/esm/components/Page/index.js";
9 :
10 3 : import cockpit from "cockpit";
11 : import { WithDialogs, useDialogs } from "dialogs.jsx";
12 : import { connect_host } from "cockpit-connect-ssh";
13 :
14 : import 'page.scss';
15 :
16 3 : const RemotePage = () => {
17 3 : const dialogs = useDialogs();
18 3 : const [host, setHost] = useState("127.0.0.1");
19 3 : const [user, setUser] = useState("");
20 3 : const [command, setCommand] = useState("hostname");
21 3 : const [output, setOutput] = useState("");
22 3 : const [error, setError] = useState("");
23 :
24 3 : const on_go = async () => {
25 3 : setOutput("");
26 3 : setError("");
27 3 : try {
28 3 : await connect_host(dialogs, host, user);
29 3 : const out = await cockpit.script(command, [], { host, user });
30 3 : setOutput(out.trim());
31 1 : } catch (ex) {
32 1 : setError(JSON.stringify(ex));
33 1 : }
34 3 : };
35 :
36 3 : return (
37 3 : <Page className="pf-m-no-sidebar">
38 3 : <Form isHorizontal>
39 3 : <FormGroup fieldId="host" label="Host" isRequired>
40 3 : <TextInput id="host" value={host} onChange={(_ev, value) => setHost(value)} isRequired />
41 3 : </FormGroup>
42 3 : <FormGroup fieldId="user" label="User">
43 2 : <TextInput id="user" value={user} onChange={(_ev, value) => setUser(value)} isRequired />
44 3 : </FormGroup>
45 3 : <FormGroup fieldId="command" label="Command" isRequired>
46 2 : <TextInput id="command" value={command} onChange={(_ev, value) => setCommand(value)} isRequired />
47 3 : </FormGroup>
48 3 : <Button onClick={on_go}>Go</Button>
49 3 : </Form>
50 :
51 3 : <label htmlFor="output" className="control-label">Output:</label>
52 3 : <pre id="output">{output}</pre>
53 3 : <label htmlFor="error" className="control-label">Error:</label>
54 3 : <span id="error">{error}</span>
55 3 : </Page>
56 : );
57 3 : };
58 :
59 3 : document.addEventListener("DOMContentLoaded", () => {
60 3 : cockpit.translate();
61 3 : const app = document.getElementById("app");
62 3 : cockpit.assert(app);
63 3 : createRoot(app).render(<WithDialogs><RemotePage /></WithDialogs>);
64 : // signal tests that we are ready
65 3 : cockpit.transport.wait(() => true);
66 3 : });
|