EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
TabRds-old.jsx
Go to the documentation of this file.
1import React from 'react';
2import { apiFetch } from '../../lib/api';
3
4function TabRds({ agentId, agentUuid }) {
5 const [rustdeskInfo, setRustdeskInfo] = React.useState(null);
6 const [loading, setLoading] = React.useState(false);
7 const [error, setError] = React.useState(null);
8
9 React.useEffect(() => {
10 if (agentUuid) {
11 loadRustdeskInfo();
12 }
13 }, [agentUuid]);
14
15 async function loadRustdeskInfo() {
16 setLoading(true);
17 setError(null);
18
19 try {
20 const response = await apiFetch(`/rustdesk/connect/${agentUuid}`);
21
22 if (!response.ok) {
23 throw new Error(`HTTP ${response.status}: ${response.statusText}`);
24 }
25
26 const data = await response.json();
27 console.log('[RDS] Received data:', data);
28
29 if (data.success) {
30 setRustdeskInfo(data);
31 } else if (data.install_required) {
32 setRustdeskInfo({ install_required: true });
33 } else {
34 setError(data.error || 'Failed to load Rustdesk info');
35 }
36 } catch (err) {
37 console.error('[RDS] Failed to load info:', err);
38 setError(err.message);
39 } finally {
40 setLoading(false);
41 }
42 }
43
44 function openRustdesk() {
45 if (!rustdeskInfo || !rustdeskInfo.rustdesk_id) return;
46
47 const { rustdesk_id, server, public_key } = rustdeskInfo;
48
49 // Build complete connection URL with all parameters
50 // Format: rustdesk://<ID>?relay-server=<server>:21117&rendezvous-server=<server>:21116&key=<key>
51 const rustdeskUrl = `rustdesk://${rustdesk_id}?relay-server=${server}:21117&rendezvous-server=${server}:21116&key=${encodeURIComponent(public_key)}`;
52
53 console.log('[RDS] Opening RustDesk with URL:', rustdeskUrl);
54
55 // Attempt to open (may not work on all platforms)
56 const iframe = document.createElement('iframe');
57 iframe.style.display = 'none';
58 iframe.src = rustdeskUrl;
59 document.body.appendChild(iframe);
60
61 setTimeout(() => {
62 document.body.removeChild(iframe);
63 }, 1000);
64
65 // Show manual instructions
66 alert(`RustDesk Connection Info:
67
68ID: ${rustdesk_id}
69Server: ${server}
70Public Key: ${public_key}
71
72⚠️ IMPORTANT - ONE-TIME SETUP REQUIRED:
73Your RustDesk client must be configured to use YOUR custom server.
74Otherwise you'll get "Failed to connect" or wrong server errors.
75
76Quick Setup Options:
77
78OPTION 1 - Automatic Setup (Windows):
79 Download and run: https://everydaytech.au/agent/rustdesk-admin-setup.bat
80 This will configure RustDesk automatically.
81
82OPTION 2 - Manual Setup:
83 1. Open RustDesk application
84 2. Click the menu icon (☰) or go to Settings
85 3. Click "Network" tab
86 4. Click "Unlock Network Settings"
87 5. Set ID Server: ${server}
88 6. Set Relay Server: ${server}
89 7. Set Key: ${public_key}
90 8. Click "Apply" and restart RustDesk
91
92After setup, you can connect by just entering the ID: ${rustdesk_id}
93No password needed for unattended access.`);
94 }
95
96 if (loading) {
97 return (
98 <div className="tab-container">
99 <h2>Remote Desktop (Rustdesk)</h2>
100 <div className="card">Loading...</div>
101 </div>
102 );
103 }
104
105 if (error) {
106 return (
107 <div className="tab-container">
108 <h2>Remote Desktop (Rustdesk)</h2>
109 <div className="card" style={{ color: 'red' }}>
110 Error: {error}<br /><br />
111 <button className="btn" onClick={loadRustdeskInfo}>Retry</button>
112 </div>
113 </div>
114 );
115 }
116
117 if (!rustdeskInfo) {
118 return (
119 <div className="tab-container">
120 <h2>Remote Desktop (Rustdesk)</h2>
121 <div className="card">No connection info available</div>
122 </div>
123 );
124 }
125
126 if (rustdeskInfo.install_required) {
127 return (
128 <div className="tab-container">
129 <h2>Remote Desktop (Rustdesk)</h2>
130 <div className="card">
131 <p><strong>Rustdesk is installing...</strong></p>
132 <p>Rustdesk will automatically install when the agent starts. This may take a few minutes.</p>
133 <p>Please refresh this page in 2-3 minutes.</p>
134 <br />
135 <button className="btn" onClick={loadRustdeskInfo}>Refresh Status</button>
136 </div>
137 </div>
138 );
139 }
140
141 return (
142 <div className="tab-container">
143 <h2>Remote Desktop (Rustdesk)</h2>
144 <div className="card">
145 <h3>Connection Information</h3>
146 <div style={{ marginBottom: '15px' }}>
147 <div style={{ marginBottom: '10px' }}>
148 <strong>Rustdesk ID:</strong>
149 <code style={{
150 marginLeft: '10px',
151 padding: '4px 8px',
152 background: '#f5f5f5',
153 borderRadius: '4px',
154 fontSize: '14px',
155 userSelect: 'all'
156 }}>
157 {rustdeskInfo.rustdesk_id}
158 </code>
159 </div>
160 <div style={{ marginBottom: '10px' }}>
161 <strong>Server:</strong>
162 <code style={{
163 marginLeft: '10px',
164 padding: '4px 8px',
165 background: '#f5f5f5',
166 borderRadius: '4px',
167 fontSize: '14px',
168 userSelect: 'all'
169 }}>
170 {rustdeskInfo.server}
171 </code>
172 </div>
173 <div style={{ marginBottom: '10px' }}>
174 <strong>Public Key:</strong>
175 <code style={{
176 marginLeft: '10px',
177 padding: '4px 8px',
178 background: '#f5f5f5',
179 borderRadius: '4px',
180 fontSize: '12px',
181 userSelect: 'all',
182 wordBreak: 'break-all'
183 }}>
184 {rustdeskInfo.public_key}
185 </code>
186 </div>
187 <div style={{ marginBottom: '10px' }}>
188 <strong>Hostname:</strong> {rustdeskInfo.hostname}
189 </div>
190 </div>
191
192 <div style={{
193 marginBottom: '20px',
194 padding: '12px',
195 background: '#fff3cd',
196 border: '1px solid #ffc107',
197 borderRadius: '4px'
198 }}>
199 <strong>⚠️ ONE-TIME SETUP REQUIRED</strong><br />
200 Your computer must be configured to use YOUR custom RustDesk server.<br />
201 <strong>Download and run:</strong> <a href="/agent/rustdesk-admin-setup.bat" download style={{fontWeight: 'bold'}}>rustdesk-admin-setup.bat</a><br />
202 <em style={{fontSize: '0.9em', color: '#856404'}}>This only needs to be done once per support computer.</em>
203 </div>
204
205 <button className="btn" onClick={openRustdesk} style={{ marginBottom: '20px' }}>
206 🖥️ Connect via Rustdesk
207 </button>
208
209 <div style={{
210 marginTop: '20px',
211 padding: '15px',
212 background: '#f9f9f9',
213 borderRadius: '4px',
214 fontSize: '0.9em'
215 }}>
216 <p style={{ marginTop: 0 }}><strong>⚠️ First Time Setup (Required):</strong></p>
217 <ol style={{ marginBottom: 0, paddingLeft: '20px' }}>
218 <li>Open RustDesk application on your computer</li>
219 <li>Click the <strong>menu icon (☰)</strong> at the top</li>
220 <li>Select <strong>"Settings"</strong></li>
221 <li>Click <strong>"Network"</strong> tab</li>
222 <li>Click <strong>"Unlock Network Settings"</strong> button</li>
223 <li>In <strong>ID Server</strong> field, enter: <code style={{background: '#fff', padding: '2px 6px'}}>{rustdeskInfo.server}</code></li>
224 <li>In <strong>Relay Server</strong> field, enter: <code style={{background: '#fff', padding: '2px 6px'}}>{rustdeskInfo.server}</code></li>
225 <li>In <strong>Key</strong> field, paste: <code style={{background: '#fff', padding: '2px 6px', fontSize: '11px'}}>{rustdeskInfo.public_key}</code></li>
226 <li>Click <strong>"Apply"</strong> or <strong>"OK"</strong></li>
227 <li>Close and restart RustDesk</li>
228 <li>After restart, enter this ID: <code style={{background: '#fff', padding: '2px 6px'}}>{rustdeskInfo.rustdesk_id}</code></li>
229 <li>Click <strong>"Connect"</strong></li>
230 </ol>
231 <p style={{ marginTop: '15px', marginBottom: 0, color: '#d9534f' }}>
232 <strong>⚠️ On Linux:</strong> You may need to reboot your computer after installing RustDesk for the protocol handler to work.
233 </p>
234 <p style={{ marginTop: '10px', marginBottom: 0 }}>
235 <strong>Don't have RustDesk?</strong>
236 <a href="https://rustdesk.com/download" target="_blank" rel="noopener" style={{ marginLeft: '5px' }}>
237 Download here
238 </a>
239 </p>
240 </div>
241 </div>
242 </div>
243 );
244}
245
246export default TabRds;