kanaka/noVNC — Issue #97: Add "View Only" option (patch included)
Author: mightypenguin
Created: 2011-10-19 21:24:55+00:00
State: open

Especially using vnc_auto.html it would be nice to restrict users to view only access sometimes.
Patches below, sorry if this is somewhat messy.

From f3861500e43b44bad22ccc3c2e4df89fae500cc7 Mon Sep 17 00:00:00 2001
From: Matthew Balman
Date: Wed, 19 Oct 2011 16:11:27 -0500
Subject: [PATCH 1/2] Added 'view_only' config option to vnc_auto.htm and
plumbing.

---
include/rfb.js | 13 ++++++++++---
include/ui.js | 1 +
vnc_auto.html | 1 +
3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/include/rfb.js b/include/rfb.js
index b7aa3f6..f58cc43 100644
--- a/include/rfb.js
+++ b/include/rfb.js
@@ -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'],
@@ -207,11 +208,17 @@ function constructor() {
Util.Error("Display exception: " + exc);
updateState('fatal', "No working Display");
}
- keyboard = new Keyboard({'target': conf.focusContainer,
+ if(!conf.view_only) {
+ keyboard = new Keyboard({'target': conf.focusContainer,
'onKeyPress': keyPress});
- mouse = new Mouse({'target': conf.target,
+ mouse = new Mouse({'target': conf.target,
'onMouseButton': mouseButton,
'onMouseMove': mouseMove});
+ }
+ else {
+ keyboard = new Keyboard({'target': conf.focusContainer});
+ mouse = new Mouse({'target': conf.target});
+ }

rmode = display.get_render_mode();

@@ -1556,7 +1563,7 @@ that.sendPassword = function(passwd) {
};

that.sendCtrlAltDel = function() {
- if (rfb_state !== "normal") { return false; }
+ if (rfb_state !== "normal" || conf.view_only==true) { return false; }
Util.Info("Sending Ctrl-Alt-Del");
var arr = [];
arr = arr.concat(keyEvent(0xFFE3, 1)); // Control
diff --git a/include/ui.js b/include/ui.js
index 74a0005..3738cba 100644
--- a/include/ui.js
+++ b/include/ui.js
@@ -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', '');

diff --git a/vnc_auto.html b/vnc_auto.html
index a500b79..ad6ea66 100644
--- a/vnc_auto.html
+++ b/vnc_auto.html
@@ -105,6 +105,7 @@
'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);
--
1.7.6.4

And this patch:

From 26a4d28fb5277f2f1b7910984407eb5922d0f01b Mon Sep 17 00:00:00 2001
From: Matthew Balman
Date: Wed, 19 Oct 2011 16:18:57 -0500
Subject: [PATCH 2/2] Added 'view_only' config option to vnc.htm DOESNOTWORK.

---
include/ui.js | 3 +++
vnc.html | 1 +
2 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/include/ui.js b/include/ui.js
index 3738cba..c63fd62 100644
--- a/include/ui.js
+++ b/include/ui.js
@@ -253,6 +253,7 @@ toggleSettingsPanel: function() {
}
UI.updateSetting('clip');
UI.updateSetting('shared');
+	UI.updateSetting('view_only');
UI.updateSetting('connectTimeout');
UI.updateSetting('path');
UI.updateSetting('stylesheet');
@@ -293,6 +294,7 @@ settingsApply: function() {
}
UI.saveSetting('clip');
UI.saveSetting('shared');
+ UI.saveSetting('view_only');
UI.saveSetting('connectTimeout');
UI.saveSetting('path');
UI.saveSetting('stylesheet');
@@ -405,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;

diff --git a/vnc.html b/vnc.html
index 281b4d3..a7bf247 100644
--- a/vnc.html
+++ b/vnc.html
@@ -120,6 +120,7 @@

Local Cursor

Clip to window

Shared Mode

+
View Only

Connect Timeout (s)

Path

--
1.7.6.4