This commit is contained in:
Pierre Ossman 2023-10-27 12:57:09 +02:00
commit 7d2dad0f9e
2 changed files with 33 additions and 19 deletions

View File

@ -3,13 +3,13 @@
.SH NAME .SH NAME
novnc_proxy - noVNC proxy server novnc_proxy - noVNC proxy server
.SH SYNOPSIS .SH SYNOPSIS
.B novnc_proxy [--listen PORT] [--vnc VNC_HOST:PORT] [--cert CERT] [--ssl-only] .B novnc_proxy [--listen [HOST:]PORT] [--vnc VNC_HOST:PORT] [--cert CERT] [--ssl-only]
Starts the WebSockets proxy and a mini-webserver and Starts the WebSockets proxy and a mini-webserver and
provides a cut-and-paste URL to go to. provides a cut-and-paste URL to go to.
--listen PORT Port for proxy/webserver to listen on --listen [HOST:]PORT Port for proxy/webserver to listen on
Default: 6080 Default: 6080 (on all interfaces)
--vnc VNC_HOST:PORT VNC server host:port proxy target --vnc VNC_HOST:PORT VNC server host:port proxy target
Default: localhost:5900 Default: localhost:5900
--cert CERT Path to combined cert/key file, or just --cert CERT Path to combined cert/key file, or just

View File

@ -8,13 +8,13 @@ usage() {
echo "$*" echo "$*"
echo echo
fi fi
echo "Usage: ${NAME} [--listen PORT] [--vnc VNC_HOST:PORT] [--cert CERT] [--ssl-only]" echo "Usage: ${NAME} [--listen [HOST:]PORT] [--vnc VNC_HOST:PORT] [--cert CERT] [--ssl-only]"
echo echo
echo "Starts the WebSockets proxy and a mini-webserver and " echo "Starts the WebSockets proxy and a mini-webserver and "
echo "provides a cut-and-paste URL to go to." echo "provides a cut-and-paste URL to go to."
echo echo
echo " --listen PORT Port for proxy/webserver to listen on" echo " --listen [HOST:]PORT Port for proxy/webserver to listen on"
echo " Default: 6080" echo " Default: 6080 (on all interfaces)"
echo " --vnc VNC_HOST:PORT VNC server host:port proxy target" echo " --vnc VNC_HOST:PORT VNC server host:port proxy target"
echo " Default: localhost:5900" echo " Default: localhost:5900"
echo " --cert CERT Path to combined cert/key file, or just" echo " --cert CERT Path to combined cert/key file, or just"
@ -47,7 +47,9 @@ usage() {
NAME="$(basename $0)" NAME="$(basename $0)"
REAL_NAME="$(readlink -f $0)" REAL_NAME="$(readlink -f $0)"
HERE="$(cd "$(dirname "$REAL_NAME")" && pwd)" HERE="$(cd "$(dirname "$REAL_NAME")" && pwd)"
HOST=""
PORT="6080" PORT="6080"
LISTEN="$PORT"
VNC_DEST="localhost:5900" VNC_DEST="localhost:5900"
CERT="" CERT=""
KEY="" KEY=""
@ -86,7 +88,7 @@ cleanup() {
while [ "$*" ]; do while [ "$*" ]; do
param=$1; shift; OPTARG=$1 param=$1; shift; OPTARG=$1
case $param in case $param in
--listen) PORT="${OPTARG}"; shift ;; --listen) LISTEN="${OPTARG}"; shift ;;
--vnc) VNC_DEST="${OPTARG}"; shift ;; --vnc) VNC_DEST="${OPTARG}"; shift ;;
--cert) CERT="${OPTARG}"; shift ;; --cert) CERT="${OPTARG}"; shift ;;
--key) KEY="${OPTARG}"; shift ;; --key) KEY="${OPTARG}"; shift ;;
@ -107,14 +109,23 @@ while [ "$*" ]; do
esac esac
done done
if [ "$LISTEN" != "$PORT" ]; then
HOST=${LISTEN%:*}
PORT=${LISTEN##*:}
# if no host was given, restore
[ "$HOST" = "$PORT" ] && HOST=""
fi
# Sanity checks # Sanity checks
if bash -c "exec 7<>/dev/tcp/localhost/${PORT}" &> /dev/null; then if [ -z "${HOST}" ]; then
exec 7<&- if bash -c "exec 7<>/dev/tcp/localhost/${PORT}" &> /dev/null; then
exec 7>&- exec 7<&-
die "Port ${PORT} in use. Try --listen PORT" exec 7>&-
else die "Port ${PORT} in use. Try --listen PORT"
exec 7<&- else
exec 7>&- exec 7<&-
exec 7>&-
fi
fi fi
trap "cleanup" TERM QUIT INT EXIT trap "cleanup" TERM QUIT INT EXIT
@ -191,9 +202,8 @@ else
fi fi
fi fi
echo "Starting webserver and WebSockets proxy on port ${PORT}" echo "Starting webserver and WebSockets proxy on${HOST:+ host ${HOST}} port ${PORT}"
#${HERE}/websockify --web ${WEB} ${CERT:+--cert ${CERT}} ${PORT} ${VNC_DEST} & ${WEBSOCKIFY} ${SYSLOG_ARG} ${SSLONLY} ${FILEONLY_ARG} --web ${WEB} ${CERT:+--cert ${CERT}} ${KEY:+--key ${KEY}} ${LISTEN} ${VNC_DEST} ${HEARTBEAT_ARG} ${IDLETIMEOUT_ARG} ${RECORD_ARG} ${TIMEOUT_ARG} ${WEBAUTH_ARG} ${AUTHPLUGIN_ARG} ${AUTHSOURCE_ARG} &
${WEBSOCKIFY} ${SYSLOG_ARG} ${SSLONLY} ${FILEONLY_ARG} --web ${WEB} ${CERT:+--cert ${CERT}} ${KEY:+--key ${KEY}} ${PORT} ${VNC_DEST} ${HEARTBEAT_ARG} ${IDLETIMEOUT_ARG} ${RECORD_ARG} ${TIMEOUT_ARG} ${WEBAUTH_ARG} ${AUTHPLUGIN_ARG} ${AUTHSOURCE_ARG} &
proxy_pid="$!" proxy_pid="$!"
sleep 1 sleep 1
if [ -z "$proxy_pid" ] || ! ps -eo pid= | grep -w "$proxy_pid" > /dev/null; then if [ -z "$proxy_pid" ] || ! ps -eo pid= | grep -w "$proxy_pid" > /dev/null; then
@ -202,11 +212,15 @@ if [ -z "$proxy_pid" ] || ! ps -eo pid= | grep -w "$proxy_pid" > /dev/null; then
exit 1 exit 1
fi fi
if [ -z "$HOST" ]; then
HOST=$(hostname)
fi
echo -e "\n\nNavigate to this URL:\n" echo -e "\n\nNavigate to this URL:\n"
if [ "x$SSLONLY" == "x" ]; then if [ "x$SSLONLY" == "x" ]; then
echo -e " http://$(hostname):${PORT}/vnc.html?host=$(hostname)&port=${PORT}\n" echo -e " http://${HOST}:${PORT}/vnc.html?host=${HOST}&port=${PORT}\n"
else else
echo -e " https://$(hostname):${PORT}/vnc.html?host=$(hostname)&port=${PORT}\n" echo -e " https://${HOST}:${PORT}/vnc.html?host=${HOST}&port=${PORT}\n"
fi fi
echo -e "Press Ctrl-C to exit\n\n" echo -e "Press Ctrl-C to exit\n\n"