From cc21dc5fa3c951c181653a9487bd7e8c151cbfc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Mon, 18 Jul 2016 21:47:30 +0200 Subject: [PATCH] [fix] Improve how .well-known path is checked --- scripts/_common.sh | 9 +++++++++ scripts/install | 8 +++----- scripts/upgrade | 8 +++----- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 8391d83..a0e6de8 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -71,3 +71,12 @@ exec_occ() { (cd "$WORKDIR" && exec_as "$AS_USER" \ php occ --no-interaction --no-ansi "$@") } + +# Check if an URL is already handled +# usage: is_url_handled URL +is_url_handled() { + local OUTPUT=($(curl -k -s -o /dev/null \ + -w 'x%{redirect_url} %{http_code}' "$1")) + # it's handled if it does not redirect to the SSO nor return 404 + [[ ! ${OUTPUT[0]} =~ \/yunohost\/sso\/ && ${OUTPUT[1]} != 404 ]] +} diff --git a/scripts/install b/scripts/install index 1913afe..5bb2286 100755 --- a/scripts/install +++ b/scripts/install @@ -70,12 +70,10 @@ sed -i "s@#APP#@${app}@g" ../conf/nginx.conf sed -i "s@#PATH#@${path}@g" ../conf/nginx.conf sed -i "s@#LOCATION#@${path:-/}@g" ../conf/nginx.conf sed -i "s@#DESTDIR#@${DESTDIR}@g" ../conf/nginx.conf -# check if .well-known is already served on the domain -if [[ $(curl -s -o /dev/null -w '%{http_code}' \ - "https://${domain}/.well-known/caldav") =~ ^[23] ]] ; then - # ... and delete it from nginx configuration +# do not serve .well-known if it's already served on the domain +if is_url_handled "https://${domain}/.well-known/caldav" ; then sed -ri '/^location = \/\.well\-known\/(caldav|carddav) \{/,/\}/d' \ - ../conf/nginx.conf + ../conf/nginx.conf fi sudo cp ../conf/nginx.conf "$nginx_conf" diff --git a/scripts/upgrade b/scripts/upgrade index 5bbcc4e..855f3b7 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -91,12 +91,10 @@ sed -i "s@#APP#@${app}@g" ../conf/nginx.conf sed -i "s@#PATH#@${path}@g" ../conf/nginx.conf sed -i "s@#LOCATION#@${path:-/}@g" ../conf/nginx.conf sed -i "s@#DESTDIR#@${DESTDIR}@g" ../conf/nginx.conf -# check if .well-known is already served on the domain -if [[ $(curl -s -o /dev/null -w '%{http_code}' \ - "https://${domain}/.well-known/caldav") =~ ^[23] ]] ; then - # ... and delete it from nginx configuration +# do not serve .well-known if it's already served on the domain +if is_url_handled "https://${domain}/.well-known/caldav" ; then sed -ri '/^location = \/\.well\-known\/(caldav|carddav) \{/,/\}/d' \ - ../conf/nginx.conf + ../conf/nginx.conf fi sudo cp ../conf/nginx.conf "$nginx_conf"