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