Unverified Commit 4eae42c8 authored by Kroese's avatar Kroese Committed by GitHub
Browse files

feat: Make webserver port configurable (#849)

parent c380257f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ COPY --chmod=755 ./src /run/
COPY --chmod=755 ./web /var/www/
COPY --chmod=664 ./web/conf/defaults.json /usr/share/novnc
COPY --chmod=664 ./web/conf/mandatory.json /usr/share/novnc
COPY --chmod=744 ./web/conf/nginx.conf /etc/nginx/sites-enabled/web.conf
COPY --chmod=744 ./web/conf/nginx.conf /etc/nginx/default.conf

VOLUME /storage
EXPOSE 22 5900 8006
+1 −1
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ if [[ "${DISPLAY,,}" == "web" ]]; then
  rm -f "$PAGE"
else
  if [[ "${DISPLAY,,}" == "vnc" ]]; then
    html "You can now connect to VNC on port 5900." "0"
    html "You can now connect to VNC on port $VNC_PORT." "0"
  else
    html "The virtual machine was booted successfully." "0"
  fi
+2 −2
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ case "${DISPLAY,,}" in
    DISPLAY_OPTS="-display vnc=:0 -vga $VGA"
    ;;
  "web" )
    DISPLAY_OPTS="-display vnc=:0,websocket=5700 -vga $VGA"
    DISPLAY_OPTS="-display vnc=:0,websocket=$WSS_PORT -vga $VGA"
    ;;
  "disabled" )
    DISPLAY_OPTS="-display none -vga $VGA"
@@ -43,7 +43,7 @@ DISPLAY_OPTS="-display egl-headless,rendernode=$RENDERNODE"
DISPLAY_OPTS+=" -device $VGA"

[[ "${DISPLAY,,}" == "vnc" ]] && DISPLAY_OPTS+=" -vnc :0"
[[ "${DISPLAY,,}" == "web" ]] && DISPLAY_OPTS+=" -vnc :0,websocket=5700"
[[ "${DISPLAY,,}" == "web" ]] && DISPLAY_OPTS+=" -vnc :0,websocket=$WSS_PORT"

[ ! -d /dev/dri ] && mkdir -m 755 /dev/dri

+5 −5
Original line number Diff line number Diff line
@@ -173,14 +173,14 @@ getUserPorts() {

getHostPorts() {

  local list=$1
  local vnc="5900"
  local web="8006"
  local list="$1"

  [ -z "$list" ] && list="$web" || list+=",$web"
  if [[ "${WEB:-}" != [Nn]* ]]; then
    [ -z "$list" ] && list="$WEB_PORT" || list+=",$WEB_PORT"
  fi

  if [[ "${DISPLAY,,}" == "vnc" || "${DISPLAY,,}" == "web" ]]; then
    [ -z "$list" ] && list="$vnc" || list+=",$vnc"
    [ -z "$list" ] && list="$VNC_PORT" || list+=",$VNC_PORT"
  fi

  [ -z "$list" ] && echo "" && return 0
+21 −20
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ echo "❯ For support visit $SUPPORT"

# Docker environment variables

: "${BOOT:=""}"            # URL of the ISO file
: "${BOOT:=""}"            # Path of ISO file
: "${DEBUG:="N"}"          # Disable debugging
: "${MACHINE:="q35"}"      # Machine selection
: "${ALLOCATE:=""}"        # Preallocate diskspace
@@ -157,35 +157,36 @@ addPackage() {
  return 0
}

: "${VNC_PORT:="5900"}"    # VNC port
: "${WEB_PORT:="8006"}"    # Webserver port
: "${WSS_PORT:="5700"}"    # Websockets port

cp -r /var/www/* /run/shm
html "Starting $APP for Docker..."

if [[ "${WEB:-}" != [Nn]* ]]; then

  cp /etc/nginx/default.conf /etc/nginx/sites-enabled/web.conf

  user="admin"
  [ -n "${USER:-}" ] && user="${USER:-}"

  if [ -n "${PASS:-}" ]; then

    sed -i "s/auth_basic off/auth_basic \"NoVNC\"/g" /etc/nginx/sites-enabled/web.conf
  
  else
    # Set password
    echo "$user:{PLAIN}${PASS:-}" > /etc/nginx/.htpasswd

    sed -i "s/auth_basic \"NoVNC\"/auth_basic off/g" /etc/nginx/sites-enabled/web.conf
    sed -i "s/auth_basic off/auth_basic \"NoVNC\"/g" /etc/nginx/sites-enabled/web.conf

  fi

  # Set password
  echo "$user:{PLAIN}${PASS:-}" > /etc/nginx/.htpasswd
  sed -i "s/listen 8006 default_server;/listen $WEB_PORT default_server;/g" /etc/nginx/sites-enabled/web.conf
  sed -i "s/proxy_pass http://127.0.0.1:5700/;/proxy_pass http://127.0.0.1:$WSS_PORT/;/g" /etc/nginx/sites-enabled/web.conf

  # shellcheck disable=SC2143
  if [ -f /proc/net/if_inet6 ] && [ -n "$(ifconfig -a | grep inet6)" ]; then

    sed -i "s/listen 8006 default_server;/listen [::]:8006 default_server ipv6only=off;/g" /etc/nginx/sites-enabled/web.conf
  
  else
  
    sed -i "s/listen [::]:8006 default_server ipv6only=off;/listen 8006 default_server;/g" /etc/nginx/sites-enabled/web.conf
    sed -i "s/listen $WEB_PORT default_server;/listen [::]:$WEB_PORT default_server ipv6only=off;/g" /etc/nginx/sites-enabled/web.conf

  fi