@rxtx4816/cockpit-plugin-base-react 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rxtx4816/cockpit-plugin-base-react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Shared infrastructure for Cockpit plugins: i18n, dark theme, test setup, config presets, CI/CD workflows, and QEMU VM harness",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "RXTX4816",
|
|
@@ -43,6 +43,9 @@
|
|
|
43
43
|
"./hooks/usePollingFetch": {
|
|
44
44
|
"default": "./src/hooks/usePollingFetch.ts"
|
|
45
45
|
},
|
|
46
|
+
"./hooks/useAdminMode": {
|
|
47
|
+
"default": "./src/hooks/useAdminMode.ts"
|
|
48
|
+
},
|
|
46
49
|
"./components": {
|
|
47
50
|
"default": "./src/components/index.ts"
|
|
48
51
|
},
|
|
@@ -61,6 +64,9 @@
|
|
|
61
64
|
},
|
|
62
65
|
"./vitest.config.base": {
|
|
63
66
|
"default": "./vitest.config.base.js"
|
|
67
|
+
},
|
|
68
|
+
"./lib/logParser": {
|
|
69
|
+
"default": "./src/lib/logParser.tsx"
|
|
64
70
|
}
|
|
65
71
|
},
|
|
66
72
|
"files": [
|
|
@@ -91,17 +97,19 @@
|
|
|
91
97
|
"react-dom": ">=19",
|
|
92
98
|
"react-i18next": ">=17"
|
|
93
99
|
},
|
|
100
|
+
"dependencies": {
|
|
101
|
+
"@typescript-eslint/eslint-plugin": "^8.61.1",
|
|
102
|
+
"@typescript-eslint/parser": "^8.61.1",
|
|
103
|
+
"eslint-plugin-react": "^7.37.5",
|
|
104
|
+
"eslint-plugin-react-hooks": "^7.1.1"
|
|
105
|
+
},
|
|
94
106
|
"devDependencies": {
|
|
95
107
|
"@patternfly/react-core": "^6.5.1",
|
|
96
108
|
"@testing-library/jest-dom": "^6.9.1",
|
|
97
109
|
"@testing-library/react": "^16.3.2",
|
|
98
110
|
"@types/react": "^19.2.17",
|
|
99
111
|
"@types/react-dom": "^19.2.3",
|
|
100
|
-
"@typescript-eslint/eslint-plugin": "^8.61.1",
|
|
101
|
-
"@typescript-eslint/parser": "^8.61.1",
|
|
102
112
|
"eslint": "^9.39.4",
|
|
103
|
-
"eslint-plugin-react": "^7.37.5",
|
|
104
|
-
"eslint-plugin-react-hooks": "^7.1.1",
|
|
105
113
|
"i18next": "^26.3.1",
|
|
106
114
|
"jsdom": "^29.1.1",
|
|
107
115
|
"react": "^19.2.7",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useState, useRef, useEffect, type ReactNode } from "react";
|
|
2
|
-
import { Button,
|
|
2
|
+
import { Button, ToggleGroup, ToggleGroupItem } from "@patternfly/react-core";
|
|
3
|
+
import { Tooltip } from "./Tooltip";
|
|
3
4
|
import { SlidersHIcon } from "@patternfly/react-icons";
|
|
4
5
|
import "./LayoutSelector.css";
|
|
5
6
|
|
package/src/components/index.ts
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useState, useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns whether the current Cockpit session has administrative (superuser) access.
|
|
5
|
+
* - `null` — still determining (show nothing or a neutral state)
|
|
6
|
+
* - `true` — admin access granted
|
|
7
|
+
* - `false` — limited mode; privileged operations will fail
|
|
8
|
+
*/
|
|
9
|
+
export function useAdminMode(): boolean | null {
|
|
10
|
+
const [allowed, setAllowed] = useState<boolean | null>(null);
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
const perm = cockpit.permission({ admin: true });
|
|
14
|
+
setAllowed(perm.allowed);
|
|
15
|
+
const onChange = () => setAllowed(perm.allowed);
|
|
16
|
+
perm.addEventListener("changed", onChange);
|
|
17
|
+
return () => {
|
|
18
|
+
perm.removeEventListener("changed", onChange);
|
|
19
|
+
perm.close();
|
|
20
|
+
};
|
|
21
|
+
}, []);
|
|
22
|
+
|
|
23
|
+
return allowed;
|
|
24
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -10,3 +10,4 @@ export type { ConfirmStep, ConfirmActionState } from "./hooks/useConfirmAction";
|
|
|
10
10
|
export { usePollingFetch } from "./hooks/usePollingFetch";
|
|
11
11
|
export type { PollingFetchResult } from "./hooks/usePollingFetch";
|
|
12
12
|
export { useLayout } from "./hooks/useLayout";
|
|
13
|
+
export { useAdminMode } from "./hooks/useAdminMode";
|
package/src/systemd/api.ts
CHANGED
|
@@ -59,3 +59,32 @@ export async function restartService(unit: string): Promise<void> {
|
|
|
59
59
|
export async function reloadService(unit: string): Promise<void> {
|
|
60
60
|
await cockpit.spawn(["systemctl", "reload", unit], { superuser: "try" });
|
|
61
61
|
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Reads a file from the host filesystem via Cockpit, requesting superuser escalation.
|
|
65
|
+
* @param path - Absolute path to the file.
|
|
66
|
+
*/
|
|
67
|
+
export async function readFile(path: string): Promise<string> {
|
|
68
|
+
return cockpit.file(path, { superuser: "try" }).read();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Writes content to a file on the host filesystem via Cockpit, requesting superuser escalation.
|
|
73
|
+
* @param path - Absolute path to the file.
|
|
74
|
+
* @param content - UTF-8 string content to write.
|
|
75
|
+
*/
|
|
76
|
+
export async function writeFile(path: string, content: string): Promise<void> {
|
|
77
|
+
await cockpit.file(path, { superuser: "try" }).replace(content);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Fetches recent journal entries for a systemd unit via `journalctl`.
|
|
82
|
+
* @param unit - The systemd unit name (e.g. `"caddy.service"`).
|
|
83
|
+
* @param lines - Number of lines to return (default 300).
|
|
84
|
+
*/
|
|
85
|
+
export async function fetchServiceLogs(unit: string, lines = 300): Promise<string> {
|
|
86
|
+
return cockpit.spawn(
|
|
87
|
+
["journalctl", "-u", unit, "-n", String(lines), "--no-pager", "--output=short-iso"],
|
|
88
|
+
{ superuser: "try" },
|
|
89
|
+
);
|
|
90
|
+
}
|
package/src/systemd/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { ServiceStatus } from "./types";
|
|
2
|
-
export { getServiceStatus, startService, stopService, restartService, reloadService } from "./api";
|
|
2
|
+
export { getServiceStatus, startService, stopService, restartService, reloadService, readFile, writeFile, fetchServiceLogs } from "./api";
|
|
3
3
|
export { useServiceStatus } from "./useServiceStatus";
|
|
4
4
|
export { ServiceControl } from "./ServiceControl";
|
|
5
5
|
export type { ServiceControlLabels } from "./ServiceControl";
|