EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
TabScriptRunner.jsx
Go to the documentation of this file.
1import React from "react";
2import { apiFetch } from "../../lib/api";
3import MeshCentralEmbed, { VIEWMODE } from "../../components/MeshCentralEmbed";
4
5export default function TabScriptRunner({ agentId, agentUuid, agent }) {
6 const [useMeshCentral, setUseMeshCentral] = React.useState(true);
7 const [meshInfo, setMeshInfo] = React.useState(null);
8 const [meshLoading, setMeshLoading] = React.useState(false);
9
10 // Check if MeshCentral is available
11 React.useEffect(() => {
12 if (!agentId && !agentUuid) return;
13
14 setMeshLoading(true);
15 apiFetch(`/agent/${agentUuid || agentId}/meshcentral-url`)
16 .then((res) => res.ok ? res.json() : null)
17 .then((data) => {
18 if (data?.meshcentralNodeId) {
19 setMeshInfo(data);
20 setUseMeshCentral(true);
21 } else {
22 setUseMeshCentral(false);
23 }
24 })
25 .catch(() => setUseMeshCentral(false))
26 .finally(() => setMeshLoading(false));
27 }, [agentId, agentUuid]);
28
29 if (meshLoading) {
30 return (
31 <div className="tab-container">
32 <h2>Script Runner</h2>
33 <div className="card">Loading...</div>
34 </div>
35 );
36 }
37
38 return (
39 <div className="tab-container">
40 <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '16px' }}>
41 <h2 style={{ margin: 0 }}>Script Runner</h2>
42 {meshInfo?.available && (
43 <button
44 className="btn-sm"
45 onClick={() => setUseMeshCentral(!useMeshCentral)}
46 style={{ display: 'flex', alignItems: 'center', gap: '4px' }}
47 >
48 <span className="material-symbols-outlined" style={{ fontSize: '18px' }}>
49 {useMeshCentral ? 'code' : 'desktop_windows'}
50 </span>
51 {useMeshCentral ? 'Switch to Legacy' : 'Switch to MeshCentral'}
52 </button>
53 )}
54 </div>
55
56 {/* MeshCentral Console View */}
57 {useMeshCentral && meshInfo?.available && (
58 <div className="card" style={{ padding: '16px' }}>
59 <MeshCentralEmbed
60 agentUuid={agent?.uuid || agentUuid}
61 viewMode={VIEWMODE.CONSOLE}
62 title="Console / Script Runner (MeshCentral)"
63 />
64 </div>
65 )}
66
67 {/* Legacy Placeholder */}
68 {(!useMeshCentral || !meshInfo?.available) && (
69 <div className="card" style={{ padding: '40px 20px', textAlign: 'center', color: '#888' }}>
70 <span className="material-symbols-outlined" style={{ fontSize: '48px', opacity: 0.3 }}>
71 terminal
72 </span>
73 <p style={{ marginTop: '16px', fontSize: '16px' }}>
74 Legacy script runner not yet implemented
75 </p>
76 <p style={{ fontSize: '14px', opacity: 0.7 }}>
77 {meshInfo?.available ? 'Switch to MeshCentral for console and script execution' : 'MeshCentral connection required for script execution'}
78 </p>
79 </div>
80 )}
81 </div>
82 );
83}