]> git.proxmox.com Git - mirror_novnc.git/blobdiff - utils/launch.sh
noVNC 1.0.0
[mirror_novnc.git] / utils / launch.sh
index 2a0106de504a04e6ce5b6064a153d608dc3eea76..9e650e42e8ec07304a5e87d7217d8db5a3d2bfdd 100755 (executable)
@@ -1,11 +1,15 @@
 #!/usr/bin/env bash
 
+# Copyright 2016 Joel Martin
+# Copyright 2016 Solly Ross
+# Licensed under MPL 2.0 or any later version (see LICENSE.txt)
+
 usage() {
     if [ "$*" ]; then
         echo "$*"
         echo
     fi
-    echo "Usage: ${NAME} [--listen PORT] [--vnc VNC_HOST:PORT] [--cert CERT]"
+    echo "Usage: ${NAME} [--listen PORT] [--vnc VNC_HOST:PORT] [--cert CERT] [--ssl-only]"
     echo
     echo "Starts the WebSockets proxy and a mini-webserver and "
     echo "provides a cut-and-paste URL to go to."
@@ -18,6 +22,8 @@ usage() {
     echo "                          Default: self.pem"
     echo "    --web WEB             Path to web files (e.g. vnc.html)"
     echo "                          Default: ./"
+    echo "    --ssl-only            Disable non-https connections."
+    echo "                                    "
     exit 2
 }
 
@@ -29,6 +35,7 @@ VNC_DEST="localhost:5900"
 CERT=""
 WEB=""
 proxy_pid=""
+SSLONLY=""
 
 die() {
     echo "$*"
@@ -55,6 +62,7 @@ while [ "$*" ]; do
     --vnc)     VNC_DEST="${OPTARG}"; shift        ;;
     --cert)    CERT="${OPTARG}"; shift            ;;
     --web)     WEB="${OPTARG}"; shift            ;;
+    --ssl-only) SSLONLY="--ssl-only"             ;;
     -h|--help) usage                              ;;
     -*) usage "Unknown chrooter option: ${param}" ;;
     *) break                                      ;;
@@ -65,7 +73,7 @@ done
 which netstat >/dev/null 2>&1 \
     || die "Must have netstat installed"
 
-netstat -ltn | grep -qs "${PORT} .*LISTEN" \
+netstat -ltn | grep -qs ":${PORT} .*LISTEN" \
     && die "Port ${PORT} in use. Try --listen PORT"
 
 trap "cleanup" TERM QUIT INT EXIT
@@ -108,7 +116,7 @@ if [[ -e ${HERE}/websockify ]]; then
 
     if [[ ! -x $WEBSOCKIFY ]]; then
         echo "The path ${HERE}/websockify exists, but $WEBSOCKIFY either does not exist or is not executable."
-        echo "If you inteded to use an installed websockify package, please remove ${HERE}/websockify."
+        echo "If you intended to use an installed websockify package, please remove ${HERE}/websockify."
         exit 1
     fi
 
@@ -119,7 +127,7 @@ else
     if [[ $? -ne 0 ]]; then
         echo "No installed websockify, attempting to clone websockify..."
         WEBSOCKIFY=${HERE}/websockify/run
-        git clone https://github.com/kanaka/websockify ${HERE}/websockify
+        git clone https://github.com/novnc/websockify ${HERE}/websockify
 
         if [[ ! -e $WEBSOCKIFY ]]; then
             echo "Unable to locate ${HERE}/websockify/run after downloading"
@@ -134,7 +142,7 @@ fi
 
 echo "Starting webserver and WebSockets proxy on port ${PORT}"
 #${HERE}/websockify --web ${WEB} ${CERT:+--cert ${CERT}} ${PORT} ${VNC_DEST} &
-${WEBSOCKIFY} --web ${WEB} ${CERT:+--cert ${CERT}} ${PORT} ${VNC_DEST} &
+${WEBSOCKIFY} ${SSLONLY} --web ${WEB} ${CERT:+--cert ${CERT}} ${PORT} ${VNC_DEST} &
 proxy_pid="$!"
 sleep 1
 if ! ps -p ${proxy_pid} >/dev/null; then
@@ -144,7 +152,12 @@ if ! ps -p ${proxy_pid} >/dev/null; then
 fi
 
 echo -e "\n\nNavigate to this URL:\n"
-echo -e "    http://$(hostname):${PORT}/vnc.html?host=$(hostname)&port=${PORT}\n"
+if [ "x$SSLONLY" == "x" ]; then
+    echo -e "    http://$(hostname):${PORT}/vnc.html?host=$(hostname)&port=${PORT}\n"
+else
+    echo -e "    https://$(hostname):${PORT}/vnc.html?host=$(hostname)&port=${PORT}\n"
+fi
+
 echo -e "Press Ctrl-C to exit\n\n"
 
 wait ${proxy_pid}