]> git.proxmox.com Git - mirror_novnc.git/blame - vnc_lite.html
Allow connecting with empty string credentials
[mirror_novnc.git] / vnc_lite.html
CommitLineData
40f281eb 1<!DOCTYPE html>
80c52ba7 2<html lang="en">
e84101b3
3<head>
4
82744aa8 5 <!--
83391ffc 6 noVNC example: lightweight example using minimal UI and features
8c2866df
SM
7
8 This is a self-contained file which doesn't import WebUtil or external CSS.
9
412d9306 10 Copyright (C) 2019 The noVNC Authors
1d728ace 11 noVNC is licensed under the MPL 2.0 (see LICENSE.txt)
d58f8b51 12 This file is licensed under the 2-Clause BSD license (see LICENSE.txt).
d595e656
JM
13
14 Connect parameters are provided in query string:
51f9f009 15 http://example.com/?host=HOST&port=PORT&scale=true
d595e656 16 -->
e84101b3
17 <title>noVNC</title>
18
2aa3b5bc 19 <meta charset="utf-8">
33f5d3bd 20
45c644a6 21 <style>
e0d4e5a1
SM
22
23 body {
24 margin: 0;
de79ae92 25 background-color: dimgrey;
e0d4e5a1
SM
26 height: 100%;
27 display: flex;
28 flex-direction: column;
29 }
30 html {
e0d4e5a1
SM
31 height: 100%;
32 }
33
8613f6f4 34 #top_bar {
de79ae92 35 background-color: #6e84a3;
011e4bff
SM
36 color: white;
37 font: bold 12px Helvetica;
38 padding: 6px 5px 4px 5px;
de79ae92 39 border-bottom: 1px outset;
e0d4e5a1 40 }
8613f6f4 41 #status {
011e4bff 42 text-align: center;
e0d4e5a1 43 }
011e4bff
SM
44 #sendCtrlAltDelButton {
45 position: fixed;
46 top: 0px;
47 right: 0px;
48 border: 1px outset;
49 padding: 5px 5px 4px 5px;
50 cursor: pointer;
e0d4e5a1
SM
51 }
52
1c945f81
SM
53 #screen {
54 flex: 1; /* fill remaining space */
55 overflow: hidden;
56 }
57
e0d4e5a1 58 </style>
e84101b3 59
8c2866df 60 <!-- Promise polyfill for IE11 -->
7569cdc2 61 <script src="vendor/promise.js"></script>
8c2866df 62
14ecdc62 63 <!-- ES2015/ES6 modules polyfill -->
0b51419c 64 <script nomodule src="vendor/browser-es-module-loader/dist/browser-es-module-loader.js"></script>
14ecdc62
FC
65
66 <!-- actual script modules -->
bf826444 67 <script type="module" crossorigin="anonymous">
8c2866df 68 // RFB holds the API to connect and communicate with a VNC server
7569cdc2 69 import RFB from './core/rfb.js';
6f4b1e40 70
25551b6b
SM
71 let rfb;
72 let desktopName;
8db09746 73
26d51e49
SM
74 // When this function is called we have
75 // successfully connected to a server
76 function connectedToServer(e) {
26d51e49
SM
77 status("Connected to " + desktopName);
78 }
79
80 // This function is called when we are disconnected
81 function disconnectedFromServer(e) {
26d51e49
SM
82 if (e.detail.clean) {
83 status("Disconnected");
84 } else {
85 status("Something went wrong, connection is closed");
86 }
3bb12056 87 }
8c2866df
SM
88
89 // When this function is called, the server requires
90 // credentials to authenticate
c756665e 91 function credentialsAreRequired(e) {
5271e300
SM
92 const password = prompt("Password Required:");
93 rfb.sendCredentials({ password: password });
d890e864 94 }
8c2866df 95
26d51e49
SM
96 // When this function is called we have received
97 // a desktop name from the server
98 function updateDesktopName(e) {
99 desktopName = e.detail.name;
100 }
101
8c2866df
SM
102 // Since most operating systems will catch Ctrl+Alt+Del
103 // before they get a chance to be intercepted by the browser,
104 // we provide a way to emulate this key sequence.
63708ff5 105 function sendCtrlAltDel() {
8db09746 106 rfb.sendCtrlAltDel();
a8edf9d8 107 return false;
63708ff5 108 }
26d51e49 109
8c2866df 110 // Show a status text in the top bar
de79ae92 111 function status(text) {
8613f6f4 112 document.getElementById('status').textContent = text;
3bb12056 113 }
91308399 114
6517c498
SM
115 // This function extracts the value of one variable from the
116 // query string. If the variable isn't defined in the URL
117 // it returns the default value instead.
118 function readQueryVariable(name, defaultValue) {
119 // A URL with a query parameter can look like this:
120 // https://www.example.com?myqueryparam=myvalue
121 //
122 // Note that we use location.href instead of location.search
123 // because Firefox < 53 has a bug w.r.t location.search
124 const re = new RegExp('.*[?&]' + name + '=([^&#]*)'),
125 match = document.location.href.match(re);
126 if (typeof defaultValue === 'undefined') { defaultValue = null; }
127
128 if (match) {
129 // We have to decode the URL since want the cleartext value
130 return decodeURIComponent(match[1]);
131 }
132
133 return defaultValue;
134 }
135
e20f0ee9
SM
136 document.getElementById('sendCtrlAltDelButton')
137 .onclick = sendCtrlAltDel;
91308399 138
6517c498 139 // Read parameters specified in the URL query string
7569cdc2 140 // By default, use the host and port of server that served this file
25551b6b
SM
141 const host = readQueryVariable('host', window.location.hostname);
142 let port = readQueryVariable('port', window.location.port);
143 const password = readQueryVariable('password', '');
144 const path = readQueryVariable('path', 'websockify');
c55f05f6 145
8c2866df
SM
146 // | | | | | |
147 // | | | Connect | | |
148 // v v v v v v
0139b256 149
25551b6b 150 status("Connecting");
91308399 151
25551b6b
SM
152 // Build the websocket URL used to connect
153 let url;
154 if (window.location.protocol === "https:") {
155 url = 'wss';
156 } else {
157 url = 'ws';
158 }
159 url += '://' + host;
160 if(port) {
161 url += ':' + port;
162 }
163 url += '/' + path;
164
165 // Creating a new RFB object will start a new connection
1c945f81 166 rfb = new RFB(document.getElementById('screen'), url,
25551b6b
SM
167 { credentials: { password: password } });
168
169 // Add listeners to important events from the RFB module
c756665e
SM
170 rfb.addEventListener("connect", connectedToServer);
171 rfb.addEventListener("disconnect", disconnectedFromServer);
172 rfb.addEventListener("credentialsrequired", credentialsAreRequired);
25551b6b
SM
173 rfb.addEventListener("desktopname", updateDesktopName);
174
175 // Set parameters that can be changed on an active connection
176 rfb.viewOnly = readQueryVariable('view_only', false);
177 rfb.scaleViewport = readQueryVariable('scale', false);
7569cdc2
SR
178 </script>
179</head>
180
178bf8ec 181<body>
8613f6f4
SM
182 <div id="top_bar">
183 <div id="status">Loading</div>
184 <div id="sendCtrlAltDelButton">Send CtrlAltDel</div>
185 </div>
1c945f81
SM
186 <div id="screen">
187 <!-- This is where the remote screen will appear -->
188 </div>
178bf8ec 189</body>
91308399 190</html>