diff --git a/scripts/pma-gateway/create_pma_gateway.sh b/scripts/pma-gateway/create_pma_gateway.sh index 8c7c4ff..ac3546c 100644 --- a/scripts/pma-gateway/create_pma_gateway.sh +++ b/scripts/pma-gateway/create_pma_gateway.sh @@ -62,12 +62,23 @@ if ! [[ "$SLUG" =~ ^[a-zA-Z0-9_-]{1,64}$ ]]; then fi # Determine public hostname for gateway URL (main domain with valid SSL cert) -# In Jelastic environments, JELASTIC_ENV_DOMAIN is always the canonical public domain -if [[ -z "${JELASTIC_ENV_DOMAIN:-}" ]]; then - echo "FATAL: JELASTIC_ENV_DOMAIN not set. Cannot determine public hostname." >&2 - exit 1 +# Try JELASTIC_ENV_DOMAIN first, then fallback to hostname detection +if [[ -n "${JELASTIC_ENV_DOMAIN:-}" ]]; then + PUBLIC_HOST="$JELASTIC_ENV_DOMAIN" +else + # Fallback: Extract domain from hostname (remove node prefix and subdomain) + ENV_HOST=$(hostname -f) + ENV_HOST=${ENV_HOST#node*-} # strip nodeXXXX- + # Extract the main domain (e.g., newtestenv.mightybox.cloud from node123-newtestenv.mightybox.cloud) + PUBLIC_HOST=$(echo "$ENV_HOST" | sed -E 's/^[^.]*\.([^.]+\.[^.]+)$/\1/') + + # If extraction failed, use the hostname as-is + if [[ -z "$PUBLIC_HOST" ]] || [[ "$PUBLIC_HOST" == "$ENV_HOST" ]]; then + PUBLIC_HOST="$ENV_HOST" + fi + + echo "WARNING: JELASTIC_ENV_DOMAIN not set. Using detected hostname: $PUBLIC_HOST" >&2 fi -PUBLIC_HOST="$JELASTIC_ENV_DOMAIN" # Use standard Jelastic LLSMP main document root MAIN_DOCROOT="/var/www/webroot/ROOT" @@ -194,10 +205,6 @@ if [[ -f "$VHOST_CONFIG" ]]; then NEEDS_RESTART=1 fi -# Secure the phpMyAdmin vhost with Rewrite Rules to block direct access -# VHOST_CONFIG="/usr/share/phpMyAdmin/vhost.conf" -# NEEDS_RESTART=0 - # ============================================================================== # Step 4: Automatically inject security rules into main vhost configuration # ============================================================================== @@ -342,4 +349,4 @@ echo " • Served through main domain (port 443) with CDN protection" >&2 echo " • Port 8443 exposure has been removed for security" >&2 echo " • phpMyAdmin symlinked to /phpmyadmin/ with full protection" >&2 echo " • Security rules automatically injected into main vhost" >&2 -echo "" >&2 +echo "" >&2 \ No newline at end of file