From e20447f68b3385a53f2585014632eedb814a4518 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Wed, 23 Feb 2022 22:04:21 -0500 Subject: xvnc "-r" option: working solution! Works around regression in xvncviewer where reverse connections no longer work. We now use direct connections for -r. Also, we now default to direct connections without '-r', since reverse connections fail to forward mouse+keyboard. The occupation of the port on both connection sides is not ideal. Also note that this also shares the local desktop with all other local users. Limiting the port to the calling user would be a good security feature! This may be relevant: https://serverfault.com/questions/127794/forward-local-port-or-socket-file-to-remote-socket-file/753733#753733 Not sure if either x11vnc or xvncviewer can use socket files. --- dot/local/bin/xvnc | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/dot/local/bin/xvnc b/dot/local/bin/xvnc index 957fa2b..e1e99a1 100755 --- a/dot/local/bin/xvnc +++ b/dot/local/bin/xvnc @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # x11vnc option '-noxrecord' added as workaround for crashing bug # See https://github.com/LibVNC/x11vnc/issues/61 @@ -40,6 +40,49 @@ reverse_connection() kill $pid } +ssh() +{ + command ssh "$@" 2>&1 | sed 's/^/REMOTE> /' +} + +share_display_direct() +{ + if [ "$DEBUG" ] + then + set -x + fi + + port=5500 + while fuser -vk $port/tcp + do + sleep 0.1 + done + x11vnc -noxrecord -q -nopw -ncache -ncache_cr -localhost -display "${local_display}" -rfbport "$port" & + X11VNC=$! + trap 'if [ ! "$DEBUG" ]; then exec 2>/dev/null; fi; set -- "$X11VNC" "$SSH"; ps hu "$@"; kill "$@"' EXIT + + while ! fuser -v $port/tcp + do + [ -e /proc/"$X11VNC" ] || break + sleep 0.1 + done + + # TODO: spin waiting for port 5500 + ssh -n \ + ${remote_port:+ -p "$remote_port" } \ + "$remote_host" \ + "fuser -vk $port/tcp && sleep 1" + ssh -n \ + -o ControlPath=none \ + -o ExitOnForwardFailure=yes \ + -R "localhost:$port:localhost:$port" \ + ${remote_port:+ -p "$remote_port" } \ + "$remote_host" \ + "DISPLAY=${remote_display} xvncviewer localhost:$port" 2>&1 & + SSH=$! + wait -n +} + share_display() { set -x @@ -60,13 +103,14 @@ share_display() if [ "$1" = -r ] then shift - cmd=share_display + cmd=share_display_direct elif [ "$1" = -d ] then shift cmd=direct_connection else - cmd=reverse_connection + # cmd=reverse_connection + cmd=direct_connection fi remote_host=${1:-blackboard} -- cgit v1.2.3