|
3 | 3 | <title>guacamole-lite test</title> |
4 | 4 |
|
5 | 5 | <style> |
6 | | - html,body { height:100%; margin:0 } |
7 | | - #display { width:100%; height:100%; cursor:default } |
8 | | - .guac-hide-cursor { cursor:url('dot.gif'), default } |
| 6 | + html, body { height: 100%; margin: 0; display: flex; flex-direction: column; } |
| 7 | + #display { flex-grow: 1; width: 100%; cursor: default; } |
| 8 | + .guac-hide-cursor { cursor: url('dot.gif'), default; } |
| 9 | + #connection-form { padding: 10px; border-bottom: 1px solid #ccc; display: flex; gap: 15px; align-items: center; } |
| 10 | + #remote-host-details { display: none; gap: 10px; } |
| 11 | + #remote-host-details.visible { display: flex; } |
| 12 | + label { margin-right: 5px; } |
| 13 | + input, select, button { padding: 5px; } |
9 | 14 | </style> |
10 | 15 |
|
| 16 | +<!-- Connection Form --> |
| 17 | +<div id="connection-form"> |
| 18 | + <label for="connect-target">Connect to:</label> |
| 19 | + <select id="connect-target"> |
| 20 | + <option value="test-host" selected>Test Host (Linux Desktop)</option> |
| 21 | + <option value="remote-host">Remote Host</option> |
| 22 | + </select> |
| 23 | + |
| 24 | + <label for="protocol">Protocol:</label> |
| 25 | + <select id="protocol"> |
| 26 | + <option value="rdp" selected>RDP</option> |
| 27 | + <option value="vnc">VNC</option> |
| 28 | + </select> |
| 29 | + |
| 30 | + <div id="remote-host-details"> |
| 31 | + <label for="remote-hostname">Host:</label> |
| 32 | + <input type="text" id="remote-hostname" placeholder="hostname or IP"> |
| 33 | + <label for="remote-username">Username:</label> |
| 34 | + <input type="text" id="remote-username"> |
| 35 | + <label for="remote-password">Password:</label> |
| 36 | + <input type="password" id="remote-password"> |
| 37 | + </div> |
| 38 | + |
| 39 | + <button id="connect-button">Connect</button> |
| 40 | +</div> |
| 41 | + |
11 | 42 | <!-- official guacamole-common-js bundle copied by the Dockerfile --> |
12 | 43 | <script src="js/all.min.js"></script> |
13 | 44 |
|
|
21 | 52 | <script src="js/guacamole-init.js"></script> |
22 | 53 |
|
23 | 54 | <script> |
24 | | - (async () => { |
| 55 | + const connectTargetSelect = document.getElementById('connect-target'); |
| 56 | + const remoteHostDetailsDiv = document.getElementById('remote-host-details'); |
| 57 | + const connectButton = document.getElementById('connect-button'); |
| 58 | + const protocolSelect = document.getElementById('protocol'); |
| 59 | + const remoteHostnameInput = document.getElementById('remote-hostname'); |
| 60 | + const remoteUsernameInput = document.getElementById('remote-username'); |
| 61 | + const remotePasswordInput = document.getElementById('remote-password'); |
| 62 | + |
| 63 | + connectTargetSelect.addEventListener('change', () => { |
| 64 | + if (connectTargetSelect.value === 'remote-host') { |
| 65 | + remoteHostDetailsDiv.classList.add('visible'); |
| 66 | + } else { |
| 67 | + remoteHostDetailsDiv.classList.remove('visible'); |
| 68 | + } |
| 69 | + }); |
| 70 | + |
| 71 | + connectButton.addEventListener('click', async () => { |
| 72 | + const target = connectTargetSelect.value; |
| 73 | + const protocol = protocolSelect.value; |
| 74 | + let connectionSettings; |
| 75 | + |
| 76 | + if (target === 'test-host') { |
| 77 | + connectionSettings = { |
| 78 | + hostname: "desktop-linux", // Service name in docker-compose |
| 79 | + username: "testuser", |
| 80 | + password: "Passw0rd!", |
| 81 | + security: "any", |
| 82 | + "ignore-cert": true, |
| 83 | + "enable-drive": protocol === 'rdp', // Drive redirection only for RDP |
| 84 | + "drive-path": protocol === 'rdp' ? "/tmp/guac-drive" : undefined, |
| 85 | + "create-drive-path": protocol === 'rdp', |
| 86 | + "enable-printing": protocol === 'rdp', // Printing only for RDP |
| 87 | + "audio": protocol === 'rdp' ? ["audio/L16;rate=44100"] : undefined // Audio only for RDP |
| 88 | + }; |
| 89 | + // Adjust port based on protocol for test-host |
| 90 | + if (protocol === 'vnc') { |
| 91 | + connectionSettings.port = 5900; // Default VNC port |
| 92 | + } |
| 93 | + // RDP port is handled by default (3389) unless specified |
| 94 | + } else { // remote-host |
| 95 | + connectionSettings = { |
| 96 | + hostname: remoteHostnameInput.value, |
| 97 | + username: remoteUsernameInput.value, |
| 98 | + password: remotePasswordInput.value, |
| 99 | + // Add common settings or let Guacamole use defaults |
| 100 | + "ignore-cert": protocol === 'rdp' ? true : undefined, // Common for RDP self-signed certs |
| 101 | + }; |
| 102 | + // Add port setting if needed, Guacamole uses defaults (3389 for RDP, 5900 for VNC) |
| 103 | + } |
| 104 | + |
25 | 105 | const tokenObj = { |
26 | 106 | connection: { |
27 | | - type: "rdp", |
28 | | - settings: { |
29 | | - "hostname": "desktop-linux", |
30 | | - "username": "testuser", |
31 | | - "password": "Passw0rd!", |
32 | | - "security": "any", |
33 | | - "ignore-cert": true, |
34 | | - "enable-drive": true, |
35 | | - "drive-path": "/tmp/guac-drive", |
36 | | - "create-drive-path": true, |
37 | | - "enable-printing": true, |
38 | | - "audio": ["audio/L16;rate=44100"] |
39 | | - } |
| 107 | + type: protocol, |
| 108 | + settings: connectionSettings |
40 | 109 | } |
41 | 110 | }; |
42 | 111 |
|
43 | | - const token = await generateGuacamoleToken(tokenObj); |
44 | | - await initGuacamole(token); |
45 | | - })(); |
| 112 | + try { |
| 113 | + // Clear previous display if any |
| 114 | + const displayDiv = document.getElementById('display'); |
| 115 | + while (displayDiv.firstChild) { |
| 116 | + displayDiv.removeChild(displayDiv.firstChild); |
| 117 | + } |
| 118 | + |
| 119 | + console.log("Generating token for:", tokenObj); |
| 120 | + const token = await generateGuacamoleToken(tokenObj); |
| 121 | + console.log("Token generated, initializing Guacamole..."); |
| 122 | + await initGuacamole(token, protocol); // Pass protocol to initGuacamole |
| 123 | + console.log("Guacamole initialization called."); |
| 124 | + } catch (error) { |
| 125 | + console.error("Failed to connect:", error); |
| 126 | + alert("Connection failed: " + error.message); |
| 127 | + } |
| 128 | + }); |
46 | 129 | </script> |
0 commit comments