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]
This commit is contained in:
parent
28646d978f
commit
c55f05f619
|
@ -96,6 +96,7 @@ var UI;
|
||||||
UI.initSetting('view_only', false);
|
UI.initSetting('view_only', false);
|
||||||
UI.initSetting('path', 'websockify');
|
UI.initSetting('path', 'websockify');
|
||||||
UI.initSetting('repeaterID', '');
|
UI.initSetting('repeaterID', '');
|
||||||
|
UI.initSetting('token', '');
|
||||||
|
|
||||||
var autoconnect = WebUtil.getConfigVar('autoconnect', false);
|
var autoconnect = WebUtil.getConfigVar('autoconnect', false);
|
||||||
if (autoconnect === 'true' || autoconnect == '1') {
|
if (autoconnect === 'true' || autoconnect == '1') {
|
||||||
|
@ -519,6 +520,7 @@ var UI;
|
||||||
UI.connSettingsOpen = false;
|
UI.connSettingsOpen = false;
|
||||||
UI.saveSetting('host');
|
UI.saveSetting('host');
|
||||||
UI.saveSetting('port');
|
UI.saveSetting('port');
|
||||||
|
UI.saveSetting('token');
|
||||||
//UI.saveSetting('password');
|
//UI.saveSetting('password');
|
||||||
} else {
|
} else {
|
||||||
$D('noVNC_controls').style.display = "block";
|
$D('noVNC_controls').style.display = "block";
|
||||||
|
@ -810,7 +812,14 @@ var UI;
|
||||||
var host = $D('noVNC_host').value;
|
var host = $D('noVNC_host').value;
|
||||||
var port = $D('noVNC_port').value;
|
var port = $D('noVNC_port').value;
|
||||||
var password = $D('noVNC_password').value;
|
var password = $D('noVNC_password').value;
|
||||||
|
var token = $D('noVNC_token').value;
|
||||||
var path = $D('noVNC_path').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)) {
|
if ((!host) || (!port)) {
|
||||||
throw new Error("Must set host and port");
|
throw new Error("Must set host and port");
|
||||||
}
|
}
|
||||||
|
|
|
@ -260,3 +260,27 @@ WebUtil.selectStylesheet = function (sheet) {
|
||||||
}
|
}
|
||||||
return 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;
|
||||||
|
};
|
||||||
|
|
1
vnc.html
1
vnc.html
|
@ -199,6 +199,7 @@
|
||||||
<li><label><strong>Host: </strong><input id="noVNC_host" /></label></li>
|
<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>Port: </strong><input id="noVNC_port" /></label></li>
|
||||||
<li><label><strong>Password: </strong><input id="noVNC_password" type="password" /></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>
|
<li><input id="noVNC_connect_button" type="button" value="Connect"></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -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.
|
// If a token variable is passed in, set the parameter in a cookie.
|
||||||
// This is used by nova-novncproxy.
|
// This is used by nova-novncproxy.
|
||||||
token = WebUtil.getConfigVar('token', null);
|
token = WebUtil.getConfigVar('token', null);
|
||||||
if (token) {
|
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)
|
WebUtil.createCookie('token', token, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
password = WebUtil.getConfigVar('password', '');
|
|
||||||
path = WebUtil.getConfigVar('path', 'websockify');
|
|
||||||
|
|
||||||
if ((!host) || (!port)) {
|
if ((!host) || (!port)) {
|
||||||
updateState(null, 'fatal', null, 'Must specify host and port in URL');
|
updateState(null, 'fatal', null, 'Must specify host and port in URL');
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue