diff --git a/scripts/pma-gateway/create_pma_gateway.sh b/scripts/pma-gateway/create_pma_gateway.sh index e619812..7bad42a 100644 --- a/scripts/pma-gateway/create_pma_gateway.sh +++ b/scripts/pma-gateway/create_pma_gateway.sh @@ -43,6 +43,8 @@ fi # 3) hostname-derived domain # Additionally, if a legacy *.sites.mightybox.dev candidate is seen, # derive *.sites.mightybox.cloud as a compatibility fallback. +# If a regional sites domain is seen, also derive short .mightybox.cloud +# as preferred public URL host candidate. HOSTNAME_DOMAIN=$(hostname -f) HOSTNAME_DOMAIN=${HOSTNAME_DOMAIN#node*-} @@ -62,6 +64,15 @@ for candidate in "$CERT_DOMAIN" "${JELASTIC_ENV_DOMAIN:-}" "$HOSTNAME_DOMAIN"; d echo "INFO: Added cloud fallback domain candidate '$cloud_candidate' from legacy '$candidate'." >&2 fi fi + + if [[ "$candidate" =~ ^([^.]+)\.[^.]+\.sites\.mightybox\.(dev|cloud)$ ]]; then + short_cloud_candidate="${BASH_REMATCH[1]}.mightybox.cloud" + if [[ -n "$short_cloud_candidate" ]] && [[ "$SEEN_DOMAINS" != *"|$short_cloud_candidate|"* ]]; then + DOMAIN_CANDIDATES+=("$short_cloud_candidate") + SEEN_DOMAINS="${SEEN_DOMAINS}${short_cloud_candidate}|" + echo "INFO: Added short cloud domain candidate '$short_cloud_candidate' from '$candidate'." >&2 + fi + fi done # Never use legacy *.sites.mightybox.dev domains for PMA gateway certificates. @@ -87,6 +98,15 @@ if [[ -z "$CONTACT_EMAIL" ]] && [[ -n "${JELASTIC_USER_EMAIL:-}" ]]; then fi ENV_HOST="${DOMAIN_CANDIDATES[0]}" +URL_HOST="$ENV_HOST" + +# Prefer short site-name.mightybox.cloud for user-facing gateway links. +for candidate in "${DOMAIN_CANDIDATES[@]}"; do + if [[ "$candidate" =~ ^[^.]+\.mightybox\.cloud$ ]]; then + URL_HOST="$candidate" + break + fi +done PMADB_DIR="/usr/share/phpMyAdmin" GATEWAY_FILE="$PMADB_DIR/access-db-$SLUG.php" @@ -506,5 +526,10 @@ if [[ "${NEEDS_RESTART:-0}" -eq 1 ]]; then fi fi -URL="https://$ENV_HOST:8443/access-db-$SLUG.php?token=$token" +if [[ -z "${URL_HOST:-}" ]]; then + URL_HOST="$ENV_HOST" +fi + +echo "INFO: Gateway URL host selected: $URL_HOST" >&2 +URL="https://$URL_HOST:8443/access-db-$SLUG.php?token=$token" echo "$URL" \ No newline at end of file