mirror of
https://github.com/YunoHost-Apps/nextcloud_ynh.git
synced 2024-09-03 19:55:57 +02:00
Merge pull request #201 from YunoHost-Apps/well_known
Handle well-known conflict
This commit is contained in:
commit
8fa044ef72
5 changed files with 65 additions and 12 deletions
|
@ -272,15 +272,40 @@ exec_as() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Check if an URL is already handled
|
# Check if an URL is already handled
|
||||||
# usage: is_url_handled URL
|
# usage: is_url_handled URL
|
||||||
is_url_handled() {
|
is_url_handled() {
|
||||||
local output=($(curl -k -s -o /dev/null \
|
# Declare an array to define the options of this helper.
|
||||||
-w 'x%{redirect_url} %{http_code}' "$1"))
|
declare -Ar args_array=( [u]=url= )
|
||||||
# It's handled if it does not redirect to the SSO nor return 404
|
local url
|
||||||
[[ ! ${output[0]} =~ \/yunohost\/sso\/ && ${output[1]} != 404 ]]
|
# Manage arguments with getopts
|
||||||
|
ynh_handle_getopts_args "$@"
|
||||||
|
|
||||||
|
# Try to get the url with curl, and keep the http code and an eventual redirection url.
|
||||||
|
local curl_output="$(curl --insecure --silent --output /dev/null \
|
||||||
|
--write-out '%{http_code};%{redirect_url}' "$url")"
|
||||||
|
|
||||||
|
# Cut the output and keep only the first part to keep the http code
|
||||||
|
local http_code="${curl_output%%;*}"
|
||||||
|
# Do the same thing but keep the second part, the redirection url
|
||||||
|
local redirection="${curl_output#*;}"
|
||||||
|
|
||||||
|
# Return 1 if the url isn't handled.
|
||||||
|
# Which means either curl got a 404 (or the admin) or the sso.
|
||||||
|
# A handled url should redirect to a publicly accessible url.
|
||||||
|
# Return 1 if the url has returned 404
|
||||||
|
if [ "$http_code" = "404" ] || [[ $redirection =~ "/yunohost/admin" ]]; then
|
||||||
|
return 1
|
||||||
|
# Return 1 if the url is redirected to the SSO
|
||||||
|
elif [[ $redirection =~ "/yunohost/sso" ]]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Make the main steps to migrate an app to its fork.
|
# Make the main steps to migrate an app to its fork.
|
||||||
#
|
#
|
||||||
# This helper has to be used for an app which needs to migrate to a new name or a new fork
|
# This helper has to be used for an app which needs to migrate to a new name or a new fork
|
||||||
|
|
|
@ -100,6 +100,19 @@ then
|
||||||
ynh_replace_string "'overwrite.cli.url' => 'http://${old_domain}'," "'overwrite.cli.url' => 'https://${new_domain}'," "${final_path}/config/config.php"
|
ynh_replace_string "'overwrite.cli.url' => 'http://${old_domain}'," "'overwrite.cli.url' => 'https://${new_domain}'," "${final_path}/config/config.php"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ $change_domain -eq 1 ]
|
||||||
|
then
|
||||||
|
# Check if .well-known is available for this domain
|
||||||
|
if is_url_handled "https://$domain/.well-known/caldav" || is_url_handled "https://$domain/.well-known/carddav"
|
||||||
|
then
|
||||||
|
ynh_print_warn --message="Another app already uses the domain $domain to serve a caldav/carddav feature. You may encounter issues when dealing with your calendar or address book."
|
||||||
|
|
||||||
|
# Remove lines about .well-known/carddav and caldav with sed.
|
||||||
|
sed --in-place --regexp-extended '/^location = \/\.well\-known\/(caldav|carddav) \{/,/\}/d' "/etc/nginx/conf.d/$new_domain.d/$app.conf"
|
||||||
|
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -92,10 +92,13 @@ ynh_setup_source "$final_path"
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_print_info "Configuring nginx web server..."
|
ynh_print_info "Configuring nginx web server..."
|
||||||
|
|
||||||
# Do not serve .well-known if it's already served on the domain
|
# Check if .well-known is available for this domain
|
||||||
if is_url_handled "https://$domain/.well-known/caldav" ; then
|
if is_url_handled "https://$domain/.well-known/caldav" || is_url_handled "https://$domain/.well-known/carddav"
|
||||||
sed -ri '/^location = \/\.well\-known\/(caldav|carddav) \{/,/\}/d' \
|
then
|
||||||
"../conf/nginx.conf"
|
ynh_print_warn --message="Another app already uses the domain $domain to serve a caldav/carddav feature. You may encounter issues when dealing with your calendar or address book."
|
||||||
|
|
||||||
|
# Remove lines about .well-known/carddav and caldav with sed.
|
||||||
|
sed --in-place --regexp-extended '/^location = \/\.well\-known\/(caldav|carddav) \{/,/\}/d' "../conf/nginx.conf"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create a dedicated nginx config
|
# Create a dedicated nginx config
|
||||||
|
|
|
@ -46,6 +46,15 @@ test ! -d $final_path \
|
||||||
|
|
||||||
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
|
|
||||||
|
# Check if .well-known is available for this domain
|
||||||
|
if is_url_handled "https://$domain/.well-known/caldav" || is_url_handled "https://$domain/.well-known/carddav"
|
||||||
|
then
|
||||||
|
ynh_print_warn --message="Another app already uses the domain $domain to serve a caldav/carddav feature. You may encounter issues when dealing with your calendar or address book."
|
||||||
|
|
||||||
|
# Remove lines about .well-known/carddav and caldav with sed.
|
||||||
|
sed --in-place --regexp-extended '/^location = \/\.well\-known\/(caldav|carddav) \{/,/\}/d' "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# RESTORE THE APP MAIN DIR
|
# RESTORE THE APP MAIN DIR
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
|
@ -123,10 +123,13 @@ ynh_backup_if_checksum_is_different "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
ynh_remove_nginx_config
|
ynh_remove_nginx_config
|
||||||
ynh_app_setting_delete $app "checksum__etc_nginx_conf.d_$domain.d_$app.conf" || true
|
ynh_app_setting_delete $app "checksum__etc_nginx_conf.d_$domain.d_$app.conf" || true
|
||||||
|
|
||||||
# Do not serve .well-known if it's already served on the domain
|
# Check if .well-known is available for this domain
|
||||||
if is_url_handled "https://$domain/.well-known/caldav" ; then
|
if is_url_handled "https://$domain/.well-known/caldav" || is_url_handled "https://$domain/.well-known/carddav"
|
||||||
sed -ri '/^location = \/\.well\-known\/(caldav|carddav) \{/,/\}/d' \
|
then
|
||||||
"../conf/nginx.conf"
|
ynh_print_warn --message="Another app already uses the domain $domain to serve a caldav/carddav feature. You may encounter issues when dealing with your calendar or address book."
|
||||||
|
|
||||||
|
# Remove lines about .well-known/carddav and caldav with sed.
|
||||||
|
sed --in-place --regexp-extended '/^location = \/\.well\-known\/(caldav|carddav) \{/,/\}/d' "../conf/nginx.conf"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create a dedicated nginx config
|
# Create a dedicated nginx config
|
||||||
|
|
Loading…
Add table
Reference in a new issue