]> git.proxmox.com Git - mirror_novnc.git/blob - vnc_auto.html
State machine refactoring.
[mirror_novnc.git] / vnc_auto.html
1 <!--
2 noVNC Example: Automatically connect on page load.
3
4 Connect parameters are provided in query string:
5 http://example.com/?host=HOST&port=PORT&encrypt=1&true_color=1
6 -->
7 <html>
8 <head>
9 <title>VNC Client</title>
10 <link rel="stylesheet" href="include/plain.css">
11 <!--
12 <script type='text/javascript'
13 src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
14 -->
15 <script src="include/vnc.js"></script>
16 </head>
17
18 <body style="margin: 0px;">
19 <div id="VNC_screen">
20 <div id="VNC_status_bar" class="VNC_status_bar" style="margin-top: 0px;">
21 <table border=0 width=100%><tr>
22 <td><div id="VNC_status">Loading</div></td>
23 <td width=10%><div id="VNC_buttons">
24 <input type=button value="Send CtrlAltDel"
25 id="sendCtrlAltDelButton"
26 onclick="sendCtrlAltDel();"></div></td>
27 </tr></table>
28 </div>
29 <canvas id="VNC_canvas" width="640px" height="20px">
30 Canvas not supported.
31 </canvas>
32 </div>
33 </body>
34
35 <script>
36 function setPassword() {
37 RFB.sendPassword($('password_input').value);
38 return false;
39 }
40 function sendCtrlAltDel() {
41 RFB.sendCtrlAltDel();
42 }
43 function updateState(state, msg) {
44 var s, sb, klass, html;
45 s = $('VNC_status');
46 sb = $('VNC_status_bar');
47 cad = $('sendCtrlAltDelButton');
48 switch (state) {
49 case 'failed':
50 case 'fatal':
51 klass = "VNC_status_error";
52 break;
53 case 'normal':
54 klass = "VNC_status_normal";
55 break;
56 case 'disconnected':
57 case 'loaded':
58 klass = "VNC_status_normal";
59 break;
60 case 'password':
61 msg = '<form onsubmit="return setPassword();"';
62 msg += ' style="margin-bottom: 0px">';
63 msg += 'Password Required: ';
64 msg += '<input type=password size=10 id="password_input" class="VNC_status">';
65 msg += '</form>';
66 // Fall through
67 default:
68 klass = "VNC_status_warn";
69 }
70
71 if (state === "normal") { cad.disabled = false; }
72 else { cad.disabled = true; }
73
74 if (typeof(msg) !== 'undefined') {
75 sb.setAttribute("class", klass);
76 s.innerHTML = msg;
77 }
78 }
79
80 window.onload = function () {
81 var host, port, password, encrypt;
82
83 url = document.location.href;
84 host = (url.match(/host=([A-Za-z0-9.\-]*)/) || ['',''])[1];
85 port = (url.match(/port=([0-9]*)/) || ['',''])[1];
86 password = (url.match(/password=([^&#]*)/) || ['',''])[1];
87 encrypt = (url.match(/encrypt=([A-Za-z0-9]*)/) || ['',1])[1];
88 true_color = (url.match(/true_color=([A-Za-z0-9]*)/) || ['',1])[1];
89 if ((!host) || (!port)) {
90 updateState('failed',
91 "Must specify host and port in URL");
92 return;
93 }
94
95 RFB.setUpdateState(updateState);
96 RFB.load();
97 RFB.connect(host, port, password, encrypt, true_color);
98 }
99 </script>
100 </html>
101