Skip to content

Commit

Permalink
[VNC] support RealVNC servers that are listening on port 5900
Browse files Browse the repository at this point in the history
  • Loading branch information
junhaoliao committed Aug 22, 2021
1 parent 5bd77ac commit 5988a34
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 11 deletions.
5 changes: 5 additions & 0 deletions application/VNC.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ def get_vnc_password(self):
else:
return True, decrypt_passwd(bytearray.fromhex(hexdump))

def check_5900_open(self):
_, _, stdout, _ = self.exec_command_blocking('netstat -tln | grep :5900')
result = stdout.readline()
return result != ''

def remove_vnc_settings(self):
remove_cmd_lst = [
"killall -q -w Xtigervnc",
Expand Down
13 changes: 11 additions & 2 deletions application/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,19 +184,28 @@ def generate():

yield int_to_bytes(ICtrlStep.VNC.CHECK_LOAD)

# use5900: usually a RealVNC server listening on port 5900
# which we don't know how to parse the password
use5900 = False
yield int_to_bytes(ICtrlStep.VNC.PARSE_PASSWD)
session_is_ecf = is_ecf(session_id)
if session_is_ecf:
password = None
else:
status, password = vnc.get_vnc_password()
if not status:
yield int_to_bytes(ICtrlError.VNC.PASSWD_MISSING)
return
use5900 = vnc.check_5900_open()
if use5900:
password = None
else:
yield int_to_bytes(ICtrlError.VNC.PASSWD_MISSING)
return

yield int_to_bytes(ICtrlStep.VNC.LAUNCH_VNC)
if session_is_ecf:
vnc_port = 1000
elif use5900:
vnc_port = 5900
else:
vnc_port = vnc.launch_vnc()

Expand Down
42 changes: 33 additions & 9 deletions client/src/actions/vnc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ import {isIOS} from './utils';
const setupDOM = (port, passwd) => {
/* Creating a new RFB object and start a new connection */
const url = `ws://127.0.0.1:${port}`;
const rfb = new RFB(
document.getElementById('screen'),
url,
{credentials: {password: passwd}});
const rfb = passwd ?
new RFB(
document.getElementById('screen'),
url,
{credentials: {password: passwd}}) :
new RFB(
document.getElementById('screen'),
url)
;

/* Setup the VNC default options */
// Reference: https://github.com/novnc/noVNC/blob/master/docs/API.md
Expand All @@ -25,9 +30,26 @@ const setupDOM = (port, passwd) => {
return rfb;
};

const setupCredentialsHandlers = (rfb) => {
rfb.addEventListener('credentialsrequired', (ev) => {
const credentials = {};
for (let type of ev.detail.types) {
credentials[type] = prompt(`[!! Any text enter below will be in PLAIN TEXT !!]\nPlease enter the VNC ${type}:`);
}
rfb.sendCredentials(credentials);
});

rfb.addEventListener('securityfailure', (ev) => {
if (!alert(`[Code ${ev.detail.status}] ${ev.detail.reason}\nClick OK to reload`)) {
window.location.reload();
}
});

};

const setupForwardBackwardKeys = (rfb) => {
window.addEventListener('auxclick', (ev)=>{
if (ev.button === 3){
window.addEventListener('auxclick', (ev) => {
if (ev.button === 3) {
rfb.sendKey(KeyTable.XK_Alt_L, 'AltLeft', true);
rfb.sendKey(KeyTable.XK_Left, 'ArrowLeft');
rfb.sendKey(KeyTable.XK_Alt_L, 'AltLeft', false);
Expand All @@ -36,8 +58,8 @@ const setupForwardBackwardKeys = (rfb) => {
rfb.sendKey(KeyTable.XK_Right, 'ArrowRight');
rfb.sendKey(KeyTable.XK_Alt_L, 'AltLeft', false);
}
})
}
});
};

const setupOnScreenKeyboard = (vncViewer) => {
/* Setup touch keyboard */
Expand Down Expand Up @@ -175,9 +197,11 @@ export const vncConnect = async (vncViewer) => {

vncViewer.rfb = setupDOM(port, passwd);

setupCredentialsHandlers(vncViewer.rfb);

// when the VNC session is successfully established
vncViewer.rfb.addEventListener('connect', () => {
setupForwardBackwardKeys(vncViewer.rfb)
setupForwardBackwardKeys(vncViewer.rfb);
setupOnScreenKeyboard(vncViewer);
setupClipboard(vncViewer.rfb);

Expand Down

0 comments on commit 5988a34

Please sign in to comment.