Skip to content

Commit

Permalink
Fix cloudflare quicktunnels for https://localhost
Browse files Browse the repository at this point in the history
  • Loading branch information
robballantyne committed Aug 3, 2024
1 parent ad44151 commit 4bde918
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 12 deletions.
1 change: 1 addition & 0 deletions build/COPY_ROOT_0/opt/ai-dock/bin/build/layer0/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ $APT_INSTALL \
file \
fonts-dejavu \
fonts-freefont-ttf \
fonts-ubuntu \
fuse3 \
git \
git-lfs \
Expand Down
16 changes: 12 additions & 4 deletions build/COPY_ROOT_0/opt/ai-dock/bin/direct-url.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion build/COPY_ROOT_0/opt/ai-dock/bin/supervisor-quicktunnel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<li id="direct-{{ context.port }}">
<i class="fa-solid fa-fw fa-link"></i>
<a href="{{ context.url }}" target="_blank" class="icon">
Direct / Default
Direct Link
</a>
</li>
{% else %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@ <h1 id="status">Service List
<div>{{ service["service_name"] }}</div>
<div>
<ul>
{% if context.namedtunnels == True %}
{% if context.direct_address %}
<li id='cfqt-{{ service["proxy_port"] }}'
hx-post="/namedtunnel"
hx-post="/direct"
hx-vals='{"port": "{{ service["proxy_port"] }}", "path": "/ai-dock/pre-auth?token={{ context.auth_token }}" }'
hx-trigger="load"
hx-swap="outerHTML"
>
</li>
{% endif %}
{% if context.quicktunnels == True %}
{% if context.namedtunnels == True %}
<li id='cfqt-{{ service["proxy_port"] }}'
hx-post="/quicktunnel"
hx-post="/namedtunnel"
hx-vals='{"port": "{{ service["proxy_port"] }}", "path": "/ai-dock/pre-auth?token={{ context.auth_token }}" }'
hx-trigger="load"
hx-swap="outerHTML"
>
</li>
{% endif %}
{% if context.direct_address %}
{% if context.quicktunnels == True %}
<li id='cfqt-{{ service["proxy_port"] }}'
hx-post="/direct"
hx-post="/quicktunnel"
hx-vals='{"port": "{{ service["proxy_port"] }}", "path": "/ai-dock/pre-auth?token={{ context.auth_token }}" }'
hx-trigger="load"
hx-swap="outerHTML"
Expand Down
43 changes: 43 additions & 0 deletions cb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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

0 comments on commit 4bde918

Please sign in to comment.