Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass token into the path variable #537

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions include/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ var UI;
UI.initSetting('view_only', false);
UI.initSetting('path', 'websockify');
UI.initSetting('repeaterID', '');
UI.initSetting('token', '');

var autoconnect = WebUtil.getQueryVar('autoconnect', false);
if (autoconnect === 'true' || autoconnect == '1') {
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -810,7 +812,17 @@ 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.indexOf("token") > -1)){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this cause the token insertion not to trigger if I have
path = "/token", in which case a path of token?token=[foo] is perfectly valid.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to fix this by using the an <a> element in memory, and using that to manipulate the path.

if (path.indexOf("?") > -1)
path += "&token=" + token; //there is a query string already
else
path += "?token=" + token;
}

if ((!host) || (!port)) {
throw new Error("Must set host and port");
}
Expand Down
1 change: 1 addition & 0 deletions vnc.html
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,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>
Expand Down
15 changes: 12 additions & 3 deletions vnc_auto.html
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,25 @@
}
}

password = WebUtil.getQueryVar('password', '');
path = WebUtil.getQueryVar('path', 'websockify');

// If a token variable is passed in, set the parameter in a cookie.
// This is used by nova-novncproxy.
token = WebUtil.getQueryVar('token', null);
if (token) {

//if token is already present in the path we should use it
if (!(path.indexOf("token") > -1)){
if (path.indexOf("?") > -1)
path += "&token=" + token; //there is a query string already
else
path += "?token=" + token;
}

WebUtil.createCookie('token', token, 1)
}

password = WebUtil.getQueryVar('password', '');
path = WebUtil.getQueryVar('path', 'websockify');

if ((!host) || (!port)) {
updateState(null, 'fatal', null, 'Must specify host and port in URL');
return;
Expand Down