From 4bde9180e9d3f69d73d25bcd88ef57a40c58727c Mon Sep 17 00:00:00 2001 From: Rob Ballantyne Date: Sun, 4 Aug 2024 00:12:48 +0100 Subject: [PATCH] Fix cloudflare quicktunnels for https://localhost --- .../opt/ai-dock/bin/build/layer0/common.sh | 1 + .../COPY_ROOT_0/opt/ai-dock/bin/direct-url.sh | 16 +++++-- .../opt/ai-dock/bin/supervisor-quicktunnel.sh | 7 ++- .../templates/partials/index/direct_link.html | 2 +- .../templates/partials/index/page.html | 12 +++--- cb | 43 +++++++++++++++++++ 6 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 cb diff --git a/build/COPY_ROOT_0/opt/ai-dock/bin/build/layer0/common.sh b/build/COPY_ROOT_0/opt/ai-dock/bin/build/layer0/common.sh index acbb90d..5abb6ef 100755 --- a/build/COPY_ROOT_0/opt/ai-dock/bin/build/layer0/common.sh +++ b/build/COPY_ROOT_0/opt/ai-dock/bin/build/layer0/common.sh @@ -29,6 +29,7 @@ $APT_INSTALL \ file \ fonts-dejavu \ fonts-freefont-ttf \ + fonts-ubuntu \ fuse3 \ git \ git-lfs \ diff --git a/build/COPY_ROOT_0/opt/ai-dock/bin/direct-url.sh b/build/COPY_ROOT_0/opt/ai-dock/bin/direct-url.sh index 3404cbb..0f09dc4 100755 --- a/build/COPY_ROOT_0/opt/ai-dock/bin/direct-url.sh +++ b/build/COPY_ROOT_0/opt/ai-dock/bin/direct-url.sh @@ -23,6 +23,14 @@ if [[ -z $port ]]; then exit 1 fi +function get_scheme() { + if [[ ${WEB_ENABLE_HTTPS,,} == true && -f /opt/caddy/tls/container.crt && /opt/caddy/tls/container.key ]]; then + echo "https://" + else + echo "http://" + fi +} + function get_url { preset_url=$(jq -r ".service_url" "/run/http_ports/${port}") if [[ -n $preset_url ]]; then @@ -31,19 +39,19 @@ function get_url { elif [[ $DIRECT_ADDRESS == "auto#vast-ai" ]]; then declare -n vast_mapped_port=VAST_TCP_PORT_${port} if [[ -n $vast_mapped_port && -n $PUBLIC_IPADDR ]]; then - url="http://${PUBLIC_IPADDR}:${vast_mapped_port}" + url="$(get_scheme)${PUBLIC_IPADDR}:${vast_mapped_port}" fi # Runpod.io elif [[ $DIRECT_ADDRESS == "auto#runpod-io" ]]; then declare -n runpod_mapped_port=RUNPOD_TCP_PORT_${port} if [[ -n $runpod_mapped_port && -n $RUNPOD_PUBLIC_IP ]]; then - url="http://${RUNPOD_PUBLIC_IP}:${runpod_mapped_port}" + url="$(get_scheme)${RUNPOD_PUBLIC_IP}:${runpod_mapped_port}" elif [[ -n $RUNPOD_POD_ID ]]; then - url="https://${RUNPOD_POD_ID}-${port}.proxy.runpod.net" + url="$(get_scheme)${RUNPOD_POD_ID}-${port}.proxy.runpod.net" fi # Other cloud / local else - url="http://${DIRECT_ADDRESS}:${port}" + url="$(get_scheme)${DIRECT_ADDRESS}:${port}" fi if [[ -n $url ]]; then diff --git a/build/COPY_ROOT_0/opt/ai-dock/bin/supervisor-quicktunnel.sh b/build/COPY_ROOT_0/opt/ai-dock/bin/supervisor-quicktunnel.sh index c23b3c9..49912d3 100755 --- a/build/COPY_ROOT_0/opt/ai-dock/bin/supervisor-quicktunnel.sh +++ b/build/COPY_ROOT_0/opt/ai-dock/bin/supervisor-quicktunnel.sh @@ -26,7 +26,12 @@ function start() { exit 1 else # Tunnel the proxy port so we get authentication - tunnel="--url localhost:${proxy_port}" + if [[ ${WEB_ENABLE_HTTPS,,} == true && -f /opt/caddy/tls/container.crt && /opt/caddy/tls/container.key ]]; then + tunnel="--no-tls-verify --url https://localhost:${proxy_port}" + else + tunnel="--url http://localhost:${proxy_port}" + fi + metrics="--metrics localhost:${metrics_port}" fi diff --git a/build/COPY_ROOT_0/opt/ai-dock/fastapi/serviceportal/templates/partials/index/direct_link.html b/build/COPY_ROOT_0/opt/ai-dock/fastapi/serviceportal/templates/partials/index/direct_link.html index 7c1f5d1..cd70ecf 100644 --- a/build/COPY_ROOT_0/opt/ai-dock/fastapi/serviceportal/templates/partials/index/direct_link.html +++ b/build/COPY_ROOT_0/opt/ai-dock/fastapi/serviceportal/templates/partials/index/direct_link.html @@ -2,7 +2,7 @@
  • - Direct / Default + Direct Link
  • {% else %} diff --git a/build/COPY_ROOT_0/opt/ai-dock/fastapi/serviceportal/templates/partials/index/page.html b/build/COPY_ROOT_0/opt/ai-dock/fastapi/serviceportal/templates/partials/index/page.html index bc18e9d..e3cd1d0 100644 --- a/build/COPY_ROOT_0/opt/ai-dock/fastapi/serviceportal/templates/partials/index/page.html +++ b/build/COPY_ROOT_0/opt/ai-dock/fastapi/serviceportal/templates/partials/index/page.html @@ -16,27 +16,27 @@

    Service List
    {{ service["service_name"] }}
      - {% if context.namedtunnels == True %} + {% if context.direct_address %}
    • {% endif %} - {% if context.quicktunnels == True %} + {% if context.namedtunnels == True %}
    • {% endif %} - {% if context.direct_address %} + {% if context.quicktunnels == True %}