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