Remove special password state
We already have a callback mechanism for this, so let's use that.
Adds an optional parameter 'msg' to the callback.
Fixes vnc_auto.html (#646) which was broken after
4e0c36dda7
This commit is contained in:
parent
1c1cc1d0e9
commit
7d714b15f5
33
app/ui.js
33
app/ui.js
|
@ -339,6 +339,7 @@ var UI;
|
||||||
try {
|
try {
|
||||||
UI.rfb = new RFB({'target': document.getElementById('noVNC_canvas'),
|
UI.rfb = new RFB({'target': document.getElementById('noVNC_canvas'),
|
||||||
'onUpdateState': UI.updateState,
|
'onUpdateState': UI.updateState,
|
||||||
|
'onPasswordRequired': UI.passwordRequired,
|
||||||
'onXvpInit': UI.updateXvpButton,
|
'onXvpInit': UI.updateXvpButton,
|
||||||
'onClipboard': UI.clipboardReceive,
|
'onClipboard': UI.clipboardReceive,
|
||||||
'onFBUComplete': UI.initialResize,
|
'onFBUComplete': UI.initialResize,
|
||||||
|
@ -373,15 +374,6 @@ var UI;
|
||||||
case 'loaded':
|
case 'loaded':
|
||||||
UI.showStatus(msg, 'normal');
|
UI.showStatus(msg, 'normal');
|
||||||
break;
|
break;
|
||||||
case 'password':
|
|
||||||
document.getElementById('noVNC_password_dlg')
|
|
||||||
.classList.add('noVNC_open');
|
|
||||||
setTimeout(function () {
|
|
||||||
document.getElementById(('noVNC_password_input').focus());
|
|
||||||
}, 100);
|
|
||||||
|
|
||||||
UI.showStatus(msg, 'warn');
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
UI.showStatus(msg, 'warn');
|
UI.showStatus(msg, 'warn');
|
||||||
break;
|
break;
|
||||||
|
@ -977,6 +969,27 @@ var UI;
|
||||||
// Don't display the connection settings until we're actually disconnected
|
// Don't display the connection settings until we're actually disconnected
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/* ------^-------
|
||||||
|
* /CONNECTION
|
||||||
|
* ==============
|
||||||
|
* PASSWORD
|
||||||
|
* ------v------*/
|
||||||
|
|
||||||
|
passwordRequired: function(rfb, msg) {
|
||||||
|
|
||||||
|
document.getElementById('noVNC_password_dlg')
|
||||||
|
.classList.add('noVNC_open');
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
document.getElementById('noVNC_password_input').focus();
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
if (typeof msg === 'undefined') {
|
||||||
|
msg = "Password is required";
|
||||||
|
}
|
||||||
|
UI.updateState(null, "warning", null, msg);
|
||||||
|
},
|
||||||
|
|
||||||
setPassword: function() {
|
setPassword: function() {
|
||||||
UI.rfb.sendPassword(document.getElementById('noVNC_password_input').value);
|
UI.rfb.sendPassword(document.getElementById('noVNC_password_input').value);
|
||||||
document.getElementById('noVNC_password_dlg')
|
document.getElementById('noVNC_password_dlg')
|
||||||
|
@ -985,7 +998,7 @@ var UI;
|
||||||
},
|
},
|
||||||
|
|
||||||
/* ------^-------
|
/* ------^-------
|
||||||
* /CONNECTION
|
* /PASSWORD
|
||||||
* ==============
|
* ==============
|
||||||
* FULLSCREEN
|
* FULLSCREEN
|
||||||
* ------v------*/
|
* ------v------*/
|
||||||
|
|
15
core/rfb.js
15
core/rfb.js
|
@ -158,7 +158,7 @@
|
||||||
|
|
||||||
// Callback functions
|
// Callback functions
|
||||||
'onUpdateState': function () { }, // onUpdateState(rfb, state, oldstate, statusMsg): state update/change
|
'onUpdateState': function () { }, // onUpdateState(rfb, state, oldstate, statusMsg): state update/change
|
||||||
'onPasswordRequired': function () { }, // onPasswordRequired(rfb): VNC password is required
|
'onPasswordRequired': function () { }, // onPasswordRequired(rfb, msg): VNC password is required
|
||||||
'onClipboard': function () { }, // onClipboard(rfb, text): RFB clipboard contents received
|
'onClipboard': function () { }, // onClipboard(rfb, text): RFB clipboard contents received
|
||||||
'onBell': function () { }, // onBell(rfb): RFB Bell message received
|
'onBell': function () { }, // onBell(rfb): RFB Bell message received
|
||||||
'onFBUReceive': function () { }, // onFBUReceive(rfb, fbu): RFB FBU received but not yet processed
|
'onFBUReceive': function () { }, // onFBUReceive(rfb, fbu): RFB FBU received but not yet processed
|
||||||
|
@ -269,7 +269,6 @@
|
||||||
|
|
||||||
sendPassword: function (passwd) {
|
sendPassword: function (passwd) {
|
||||||
this._rfb_password = passwd;
|
this._rfb_password = passwd;
|
||||||
this._rfb_state = 'Authentication';
|
|
||||||
setTimeout(this._init_msg.bind(this), 0);
|
setTimeout(this._init_msg.bind(this), 0);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -433,7 +432,6 @@
|
||||||
* ProtocolVersion
|
* ProtocolVersion
|
||||||
* Security
|
* Security
|
||||||
* Authentication
|
* Authentication
|
||||||
* password - waiting for password, not part of RFB
|
|
||||||
* SecurityResult
|
* SecurityResult
|
||||||
* ClientInitialization - not triggered by server message
|
* ClientInitialization - not triggered by server message
|
||||||
* ServerInitialization (to normal)
|
* ServerInitialization (to normal)
|
||||||
|
@ -737,9 +735,9 @@
|
||||||
var xvp_sep = this._xvp_password_sep;
|
var xvp_sep = this._xvp_password_sep;
|
||||||
var xvp_auth = this._rfb_password.split(xvp_sep);
|
var xvp_auth = this._rfb_password.split(xvp_sep);
|
||||||
if (xvp_auth.length < 3) {
|
if (xvp_auth.length < 3) {
|
||||||
this._updateState('password', 'XVP credentials required (user' + xvp_sep +
|
var msg = 'XVP credentials required (user' + xvp_sep +
|
||||||
'target' + xvp_sep + 'password) -- got only ' + this._rfb_password);
|
'target' + xvp_sep + 'password) -- got only ' + this._rfb_password;
|
||||||
this._onPasswordRequired(this);
|
this._onPasswordRequired(this, msg);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -755,9 +753,6 @@
|
||||||
|
|
||||||
_negotiate_std_vnc_auth: function () {
|
_negotiate_std_vnc_auth: function () {
|
||||||
if (this._rfb_password.length === 0) {
|
if (this._rfb_password.length === 0) {
|
||||||
// Notify via both callbacks since it's kind of
|
|
||||||
// an RFB state change and a UI interface issue
|
|
||||||
this._updateState('password', "Password Required");
|
|
||||||
this._onPasswordRequired(this);
|
this._onPasswordRequired(this);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1326,7 +1321,7 @@
|
||||||
|
|
||||||
// Callback functions
|
// Callback functions
|
||||||
['onUpdateState', 'rw', 'func'], // onUpdateState(rfb, state, oldstate, statusMsg): RFB state update/change
|
['onUpdateState', 'rw', 'func'], // onUpdateState(rfb, state, oldstate, statusMsg): RFB state update/change
|
||||||
['onPasswordRequired', 'rw', 'func'], // onPasswordRequired(rfb): VNC password is required
|
['onPasswordRequired', 'rw', 'func'], // onPasswordRequired(rfb, msg): VNC password is required
|
||||||
['onClipboard', 'rw', 'func'], // onClipboard(rfb, text): RFB clipboard contents received
|
['onClipboard', 'rw', 'func'], // onClipboard(rfb, text): RFB clipboard contents received
|
||||||
['onBell', 'rw', 'func'], // onBell(rfb): RFB Bell message received
|
['onBell', 'rw', 'func'], // onBell(rfb): RFB Bell message received
|
||||||
['onFBUReceive', 'rw', 'func'], // onFBUReceive(rfb, fbu): RFB FBU received but not yet processed
|
['onFBUReceive', 'rw', 'func'], // onFBUReceive(rfb, fbu): RFB FBU received but not yet processed
|
||||||
|
|
|
@ -126,10 +126,9 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
beforeEach(function () { this.clock = sinon.useFakeTimers(); });
|
beforeEach(function () { this.clock = sinon.useFakeTimers(); });
|
||||||
afterEach(function () { this.clock.restore(); });
|
afterEach(function () { this.clock.restore(); });
|
||||||
|
|
||||||
it('should set the state to "Authentication"', function () {
|
it('should set the rfb password properly"', function () {
|
||||||
client._rfb_state = "blah";
|
|
||||||
client.sendPassword('pass');
|
client.sendPassword('pass');
|
||||||
expect(client._rfb_state).to.equal('Authentication');
|
expect(client._rfb_password).to.equal('pass');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call init_msg "soon"', function () {
|
it('should call init_msg "soon"', function () {
|
||||||
|
@ -728,9 +727,13 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
client._rfb_version = 3.8;
|
client._rfb_version = 3.8;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should transition to the "password" state if missing a password', function () {
|
it('should call the passwordRequired callback if missing a password', function () {
|
||||||
|
client.set_onPasswordRequired(sinon.spy());
|
||||||
send_security(2, client);
|
send_security(2, client);
|
||||||
expect(client._rfb_state).to.equal('password');
|
|
||||||
|
var spy = client.get_onPasswordRequired();
|
||||||
|
expect(client._rfb_password.length).to.equal(0);
|
||||||
|
expect(spy).to.have.been.calledOnce;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should encrypt the password with DES and then send it back', function () {
|
it('should encrypt the password with DES and then send it back', function () {
|
||||||
|
@ -777,15 +780,23 @@ describe('Remote Frame Buffer Protocol Client', function() {
|
||||||
expect(client._negotiate_std_vnc_auth).to.have.been.calledOnce;
|
expect(client._negotiate_std_vnc_auth).to.have.been.calledOnce;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should transition to the "password" state if the passwords is missing', function() {
|
it('should call the passwordRequired callback if the password is missing', function() {
|
||||||
|
client.set_onPasswordRequired(sinon.spy());
|
||||||
|
client._rfb_password = '';
|
||||||
send_security(22, client);
|
send_security(22, client);
|
||||||
expect(client._rfb_state).to.equal('password');
|
|
||||||
|
var spy = client.get_onPasswordRequired();
|
||||||
|
expect(client._rfb_password.length).to.equal(0);
|
||||||
|
expect(spy).to.have.been.calledOnce;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should transition to the "password" state if the passwords is improperly formatted', function() {
|
it('should call the passwordRequired callback if the password is improperly formatted', function() {
|
||||||
|
client.set_onPasswordRequired(sinon.spy());
|
||||||
client._rfb_password = 'user@target';
|
client._rfb_password = 'user@target';
|
||||||
send_security(22, client);
|
send_security(22, client);
|
||||||
expect(client._rfb_state).to.equal('password');
|
|
||||||
|
var spy = client.get_onPasswordRequired();
|
||||||
|
expect(spy).to.have.been.calledOnce;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should split the password, send the first two parts, and pass on the last part', function () {
|
it('should split the password, send the first two parts, and pass on the last part', function () {
|
||||||
|
|
|
@ -102,15 +102,18 @@
|
||||||
UIresize();
|
UIresize();
|
||||||
rfb.set_onFBUComplete(function() { });
|
rfb.set_onFBUComplete(function() { });
|
||||||
}
|
}
|
||||||
function passwordRequired(rfb) {
|
function passwordRequired(rfb, msg) {
|
||||||
var msg;
|
if (typeof msg === 'undefined') {
|
||||||
msg = '<form onsubmit="return setPassword();"';
|
msg = 'Password Required: ';
|
||||||
msg += ' style="margin-bottom: 0px">';
|
}
|
||||||
msg += 'Password Required: ';
|
var html;
|
||||||
msg += '<input type=password size=10 id="password_input" class="noVNC_status">';
|
html = '<form onsubmit="return setPassword();"';
|
||||||
msg += '<\/form>';
|
html += ' style="margin-bottom: 0px">';
|
||||||
|
html += msg;
|
||||||
|
html += '<input type=password size=10 id="password_input" class="noVNC_status">';
|
||||||
|
html += '<\/form>';
|
||||||
document.getElementById('noVNC_status_bar').setAttribute("class", "noVNC_status_warn");
|
document.getElementById('noVNC_status_bar').setAttribute("class", "noVNC_status_warn");
|
||||||
document.getElementById('noVNC_status').innerHTML = msg;
|
document.getElementById('noVNC_status').innerHTML = html;
|
||||||
}
|
}
|
||||||
function setPassword() {
|
function setPassword() {
|
||||||
rfb.sendPassword(document.getElementById('password_input').value);
|
rfb.sendPassword(document.getElementById('password_input').value);
|
||||||
|
|
Loading…
Reference in New Issue