summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel Xavier Penha Neto <mxp@pinhaotec.com>2015-10-01 17:26:44 -0300
committerSolly Ross <sross@redhat.com>2016-01-06 15:56:28 -0500
commitc55f05f61936ac978a8b94cf8d5f8011a217c822 (patch)
tree8eea9d5af47be7ba3b017e0482000bd4241f2f5a
parent28646d978fc5e0bcfdedabf25ddbc9e81ee6746c (diff)
downloadnovnc-c55f05f61936ac978a8b94cf8d5f8011a217c822.tar.gz
Pass token into the path variable
If a token is already present in the path, the new variable is ignored. In order to properly manipulate the path, a new method, `WebUtil.injectParamIfMissing` was introduced. Fixes #536 [@directxman12: fix up path manipulation logic]
-rw-r--r--include/ui.js9
-rw-r--r--include/webutil.js24
-rw-r--r--vnc.html1
-rw-r--r--vnc_auto.html10
4 files changed, 41 insertions, 3 deletions
diff --git a/include/ui.js b/include/ui.js
index 38fbe4b..1a7f803 100644
--- a/include/ui.js
+++ b/include/ui.js
@@ -96,6 +96,7 @@ var UI;
UI.initSetting('view_only', false);
UI.initSetting('path', 'websockify');
UI.initSetting('repeaterID', '');
+ UI.initSetting('token', '');
var autoconnect = WebUtil.getConfigVar('autoconnect', false);
if (autoconnect === 'true' || autoconnect == '1') {
@@ -519,6 +520,7 @@ var UI;
UI.connSettingsOpen = false;
UI.saveSetting('host');
UI.saveSetting('port');
+ UI.saveSetting('token');
//UI.saveSetting('password');
} else {
$D('noVNC_controls').style.display = "block";
@@ -810,7 +812,14 @@ var UI;
var host = $D('noVNC_host').value;
var port = $D('noVNC_port').value;
var password = $D('noVNC_password').value;
+ var token = $D('noVNC_token').value;
var path = $D('noVNC_path').value;
+
+ //if token is in path then ignore the new token variable
+ if (token) {
+ path = WebUtil.injectParamIfMissing(path, "token", token);
+ }
+
if ((!host) || (!port)) {
throw new Error("Must set host and port");
}
diff --git a/include/webutil.js b/include/webutil.js
index f10aa0d..4289aa6 100644
--- a/include/webutil.js
+++ b/include/webutil.js
@@ -260,3 +260,27 @@ WebUtil.selectStylesheet = function (sheet) {
}
return sheet;
};
+
+WebUtil.injectParamIfMissing = function (path, param, value) {
+ // force pretend that we're dealing with a relative path
+ // (assume that we wanted an extra if we pass one in)
+ path = "/" + path;
+
+ var elem = document.createElement('a');
+ elem.href = path;
+
+ var param_eq = encodeURIComponent(param) + "=";
+ var query;
+ if (elem.search) {
+ query = elem.search.slice(1).split('&');
+ } else {
+ query = [];
+ }
+
+ if (!query.some(function (v) { return v.startsWith(param_eq); })) {
+ query.push(param_eq + encodeURIComponent(value));
+ elem.search = "?" + query.join("&");
+ }
+
+ return elem.pathname.slice(1) + elem.search + elem.hash;
+};
diff --git a/vnc.html b/vnc.html
index e2250f5..f64c750 100644
--- a/vnc.html
+++ b/vnc.html
@@ -199,6 +199,7 @@
<li><label><strong>Host: </strong><input id="noVNC_host" /></label></li>
<li><label><strong>Port: </strong><input id="noVNC_port" /></label></li>
<li><label><strong>Password: </strong><input id="noVNC_password" type="password" /></label></li>
+ <li><label><strong>Token: </strong><input id="noVNC_token"/></label></li>
<li><input id="noVNC_connect_button" type="button" value="Connect"></li>
</ul>
</div>
diff --git a/vnc_auto.html b/vnc_auto.html
index 0480322..7317471 100644
--- a/vnc_auto.html
+++ b/vnc_auto.html
@@ -202,16 +202,20 @@
}
}
+ password = WebUtil.getConfigVar('password', '');
+ path = WebUtil.getConfigVar('path', 'websockify');
+
// If a token variable is passed in, set the parameter in a cookie.
// This is used by nova-novncproxy.
token = WebUtil.getConfigVar('token', null);
if (token) {
+
+ // if token is already present in the path we should use it
+ path = WebUtil.injectParamIfMissing(path, "token", token);
+
WebUtil.createCookie('token', token, 1)
}
- password = WebUtil.getConfigVar('password', '');
- path = WebUtil.getConfigVar('path', 'websockify');
-
if ((!host) || (!port)) {
updateState(null, 'fatal', null, 'Must specify host and port in URL');
return;