Skip to content

Commit

Permalink
Remove limitations on subdomains so SSL wildcards and www works on in…
Browse files Browse the repository at this point in the history
…ternational domains and/or several levels deep of prefixes of subdomains
  • Loading branch information
demyxco committed Mar 27, 2024
1 parent f5f40e9 commit 74fecb0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 34 deletions.
36 changes: 16 additions & 20 deletions function/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1210,28 +1210,24 @@ demyx_config_www() {
DEMYX_APP_STACK
"

if [[ -n "$(demyx_subdomain "$DEMYX_APP_DOMAIN")" ]]; then
demyx_warning "$DEMYX_ARG_2 is a subdomain, skipping --www flag ..."
else
DEMYX_CONFIG_COMPOSE=true
DEMYX_CONFIG_COMPOSE=true

case "$DEMYX_CONFIG_FLAG_WWW" in
false)
demyx_execute "Updating domain to ${DEMYX_APP_DOMAIN}" \
"demyx_wordpress_ready; \
demyx_wp $DEMYX_APP_DOMAIN search-replace --precise --all-tables $(demyx_app_proto)://www.${DEMYX_APP_DOMAIN} $(demyx_app_proto)://${DEMYX_APP_DOMAIN}"
;;
true)
demyx_execute "Updating domain to www.${DEMYX_APP_DOMAIN}" \
"demyx_wordpress_ready; \
demyx_wp $DEMYX_APP_DOMAIN search-replace --precise --all-tables $(demyx_app_proto)://${DEMYX_APP_DOMAIN} $(demyx_app_proto)://www.${DEMYX_APP_DOMAIN}"
;;
esac
case "$DEMYX_CONFIG_FLAG_WWW" in
false)
demyx_execute "Updating domain to ${DEMYX_APP_DOMAIN}" \
"demyx_wordpress_ready; \
demyx_wp $DEMYX_APP_DOMAIN search-replace --precise --all-tables $(demyx_app_proto)://www.${DEMYX_APP_DOMAIN} $(demyx_app_proto)://${DEMYX_APP_DOMAIN}"
;;
true)
demyx_execute "Updating domain to www.${DEMYX_APP_DOMAIN}" \
"demyx_wordpress_ready; \
demyx_wp $DEMYX_APP_DOMAIN search-replace --precise --all-tables $(demyx_app_proto)://${DEMYX_APP_DOMAIN} $(demyx_app_proto)://www.${DEMYX_APP_DOMAIN}"
;;
esac

demyx_execute "Setting www to $DEMYX_CONFIG_FLAG_WWW" \
"demyx_app_env_update DEMYX_APP_DOMAIN_WWW=${DEMYX_CONFIG_FLAG_WWW}; \
demyx_yml $DEMYX_APP_STACK"
fi
demyx_execute "Setting www to $DEMYX_CONFIG_FLAG_WWW" \
"demyx_app_env_update DEMYX_APP_DOMAIN_WWW=${DEMYX_CONFIG_FLAG_WWW}; \
demyx_yml $DEMYX_APP_STACK"
}
#
# Configures an app's xmlrpc setting.
Expand Down
11 changes: 2 additions & 9 deletions function/global.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,11 @@ demyx_app_domain() {
local DEMYX_APP_DOMAIN_ARG="${1:-$DEMYX_ARG_2}"
local DEMYX_APP_DOMAIN_ARG_FIND=
DEMYX_APP_DOMAIN_ARG_FIND="$(demyx_app_path "$DEMYX_APP_DOMAIN_ARG")"
local DEMYX_APP_DOMAIN_ARG_SUBDOMAIN_CHECK=
local DEMYX_APP_DOMAIN_ARG_WWW=
DEMYX_APP_DOMAIN_ARG_WWW="$(grep DEMYX_APP_DOMAIN_WWW "$DEMYX_APP_DOMAIN_ARG_FIND"/.env | awk -F '=' '{print $2}' || true)"

if [[ "$DEMYX_APP_DOMAIN_ARG_WWW" = true ]]; then
DEMYX_APP_DOMAIN_ARG_SUBDOMAIN_CHECK="$(awk -F '.' '{print $3}' <<< "$DEMYX_APP_DOMAIN_ARG")"

if [[ -n "$DEMYX_APP_DOMAIN_ARG_SUBDOMAIN_CHECK" ]]; then
echo "${DEMYX_APP_DOMAIN_ARG}"
else
echo "www.${DEMYX_APP_DOMAIN_ARG}"
fi
echo "www.${DEMYX_APP_DOMAIN_ARG}"
else
echo "$DEMYX_APP_DOMAIN_ARG"
fi
Expand Down Expand Up @@ -209,7 +202,7 @@ demyx_arg_valid() {
fi

if [[ "$DEMYX_ARG_2" == "www."* ]]; then
demyx_error custom "www. is not allowed"
DEMYX_ARG_2="${DEMYX_ARG_2/www./}"
fi

if [[ "$DEMYX_ARG_2" == "code."* || "$DEMYX_ARG_2" == "traefik."* ]]; then
Expand Down
2 changes: 0 additions & 2 deletions function/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,6 @@ demyx_run_init() {
if [[ "$DEMYX_RUN_FLAG_SSL" = true || "$DEMYX_RUN_FLAG_SSL_WILDCARD" = true ]]; then
if [[ "$DEMYX_DOMAIN" = localhost || "$DEMYX_EMAIL" = info@localhost ]]; then
demyx_error custom "Please update DEMYX_DOMAIN and DEMYX_EMAIL on the host"
elif [[ -n "$(demyx_subdomain "$DEMYX_ARG_2")" && "$DEMYX_RUN_FLAG_SSL_WILDCARD" = true ]]; then
demyx_error custom "--ssl-wildcard is not supported with subdomains"
elif [[ "$DEMYX_RUN_FLAG_SSL_WILDCARD" = true && "$DEMYX_CF_KEY" = false ]]; then
demyx_error custom "Please update DEMYX_CF_KEY on the host"
fi
Expand Down
7 changes: 4 additions & 3 deletions function/yml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -313,15 +313,16 @@ demyx_yml_http_labels() {
demyx_event
demyx_app_env wp "
DEMYX_APP_DOMAIN
DEMYX_APP_DOMAIN_WWW
DEMYX_APP_SSL_WILDCARD
"

local DEMYX_YML_HTTP_LABELS_RULES=

if [[ -n "$(demyx_subdomain "$DEMYX_APP_DOMAIN")" ]]; then
DEMYX_YML_HTTP_LABELS_RULES="Host(\`\${DEMYX_APP_DOMAIN}\`)"
else
if [[ "$DEMYX_APP_DOMAIN_WWW" = true ]]; then
DEMYX_YML_HTTP_LABELS_RULES="Host(\`\${DEMYX_APP_DOMAIN}\`) || Host(\`www.\${DEMYX_APP_DOMAIN}\`)"
else
DEMYX_YML_HTTP_LABELS_RULES="Host(\`\${DEMYX_APP_DOMAIN}\`)"
fi

if [[ "$(demyx_app_proto)" = https ]]; then
Expand Down

0 comments on commit 74fecb0

Please sign in to comment.