]> git.proxmox.com Git - mirror_novnc.git/commitdiff
Add View Only mode setting.
authorJoel Martin <github@martintribe.org>
Thu, 1 Dec 2011 15:05:16 +0000 (09:05 -0600)
committerJoel Martin <github@martintribe.org>
Thu, 1 Dec 2011 15:05:16 +0000 (09:05 -0600)
Resolve issue: https://github.com/kanaka/noVNC/pull/101

Based on proposal from @mightpenguin:
Matthew Balman <emperor@mightypenguin.org>

If view_only option is set then do not send mouse and keyboard events.
This is not a secure/enforced way to make a client view only. To
enforce view only at the server, most VNC servers support setting
a view only password.

include/rfb.js
include/ui.js
vnc.html
vnc_auto.html

index b7aa3f62c8a06069fbcd2fbdc631ec9316965271..9dceea72ec1e9b129eb7aa83da1b4df5399e7dd9 100644 (file)
@@ -131,6 +131,7 @@ Util.conf_defaults(conf, that, defaults, [
     ['true_color',         'rw', 'bool', true,  'Request true color pixel data'],
     ['local_cursor',       'rw', 'bool', false, 'Request locally rendered cursor'],
     ['shared',             'rw', 'bool', true,  'Request shared mode'],
+    ['view_only',          'rw', 'bool', false, 'Disable client mouse/keyboard'],
 
     ['connectTimeout',     'rw', 'int', def_con_timeout, 'Time (s) to wait for connection'],
     ['disconnectTimeout',  'rw', 'int', 3,    'Time (s) to wait for disconnection'],
@@ -565,6 +566,9 @@ checkEvents = function() {
 
 keyPress = function(keysym, down) {
     var arr;
+
+    if (conf.view_only) { return; } // View only, skip keyboard events
+
     arr = keyEvent(keysym, down);
     arr = arr.concat(fbUpdateRequests());
     ws.send(arr);
@@ -586,9 +590,12 @@ mouseButton = function(x, y, down, bmask) {
             return;
         } else {
             viewportDragging = false;
+            ws.send(fbUpdateRequests()); // Force immediate redraw
         }
     }
 
+    if (conf.view_only) { return; } // View only, skip mouse events
+
     mouse_arr = mouse_arr.concat(
             pointerEvent(display.absX(x), display.absY(y)) );
     flushClient();
@@ -611,6 +618,8 @@ mouseMove = function(x, y) {
         return;
     }
 
+    if (conf.view_only) { return; } // View only, skip mouse events
+
     mouse_arr = mouse_arr.concat(
             pointerEvent(display.absX(x), display.absY(y)) );
 };
@@ -1556,7 +1565,7 @@ that.sendPassword = function(passwd) {
 };
 
 that.sendCtrlAltDel = function() {
-    if (rfb_state !== "normal") { return false; }
+    if (rfb_state !== "normal" || conf.view_only) { return false; }
     Util.Info("Sending Ctrl-Alt-Del");
     var arr = [];
     arr = arr.concat(keyEvent(0xFFE3, 1)); // Control
@@ -1572,7 +1581,7 @@ that.sendCtrlAltDel = function() {
 // Send a key press. If 'down' is not specified then send a down key
 // followed by an up key.
 that.sendKey = function(code, down) {
-    if (rfb_state !== "normal") { return false; }
+    if (rfb_state !== "normal" || conf.view_only) { return false; }
     var arr = [];
     if (typeof down !== 'undefined') {
         Util.Info("Sending key code (" + (down ? "down" : "up") + "): " + code);
index 74a0005c828b6fb7d0625192540711b31018d403..21779e1a16e6d340c255e7b50424f0fed99361ce 100644 (file)
@@ -52,6 +52,7 @@ load: function() {
     UI.initSetting('true_color', true);
     UI.initSetting('cursor', false);
     UI.initSetting('shared', true);
+    UI.initSetting('view_only', false);
     UI.initSetting('connectTimeout', 2);
     UI.initSetting('path', '');
 
@@ -252,6 +253,7 @@ toggleSettingsPanel: function() {
         }
         UI.updateSetting('clip');
         UI.updateSetting('shared');
+        UI.updateSetting('view_only');
         UI.updateSetting('connectTimeout');
         UI.updateSetting('path');
         UI.updateSetting('stylesheet');
@@ -292,6 +294,7 @@ settingsApply: function() {
     }
     UI.saveSetting('clip');
     UI.saveSetting('shared');
+    UI.saveSetting('view_only');
     UI.saveSetting('connectTimeout');
     UI.saveSetting('path');
     UI.saveSetting('stylesheet');
@@ -404,6 +407,7 @@ updateVisualState: function() {
         $D('noVNC_cursor').disabled = true;
     }
     $D('noVNC_shared').disabled = connected;
+    $D('noVNC_view_only').disabled = connected;
     $D('noVNC_connectTimeout').disabled = connected;
     $D('noVNC_path').disabled = connected;
 
@@ -464,6 +468,7 @@ connect: function() {
     UI.rfb.set_true_color(UI.getSetting('true_color'));
     UI.rfb.set_local_cursor(UI.getSetting('cursor'));
     UI.rfb.set_shared(UI.getSetting('shared'));
+    UI.rfb.set_view_only(UI.getSetting('view_only'));
     UI.rfb.set_connectTimeout(UI.getSetting('connectTimeout'));
 
     UI.rfb.connect(host, port, password, path);
index 281b4d3b50f4b4029ce180cdc5d8742287c54ffc..104d079130457d8073e33922d414d588bcc450ae 100644 (file)
--- a/vnc.html
+++ b/vnc.html
                     <li><input id="noVNC_encrypt" type="checkbox"> Encrypt</li>
                     <li><input id="noVNC_true_color" type="checkbox" checked> True Color</li>
                     <li><input id="noVNC_cursor" type="checkbox"> Local Cursor</li>
-                    <li><input id="noVNC_clip" type="checkbox"> Clip to window</li>
+                    <li><input id="noVNC_clip" type="checkbox"> Clip to Window</li>
                     <li><input id="noVNC_shared" type="checkbox"> Shared Mode</li>
+                    <li><input id="noVNC_view_only" type="checkbox"> View Only</li>
                     <li><input id="noVNC_connectTimeout" type="input"> Connect Timeout (s)</li>
                     <li><input id="noVNC_path" type="input"> Path</li>
                     <hr>
index a500b797cb1b81650e1274d3c965cd95a0117b20..86a0ce7f94fdd093ed115e315592fcebef0297b5 100644 (file)
                            'true_color':   WebUtil.getQueryVar('true_color', true),
                            'local_cursor': WebUtil.getQueryVar('cursor', true),
                            'shared':       WebUtil.getQueryVar('shared', true),
+                           'view_only':    WebUtil.getQueryVar('view_only', false),
                            'updateState':  updateState,
                            'onPasswordRequired':  passwordRequired});
             rfb.connect(host, port, password, path);