From 6cfc25660327db69f8479eb89ce80b4af1ab9631 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 29 Apr 2019 20:49:40 +0200 Subject: [PATCH 1/3] Various fixes for linter warnings / deprecrated practices --- manifest.json | 7 ++++++- scripts/backup | 4 ++-- scripts/install | 24 ++++++++++++------------ scripts/remove | 5 ++--- scripts/restore | 11 +++-------- scripts/upgrade | 16 +++++----------- 6 files changed, 30 insertions(+), 37 deletions(-) diff --git a/manifest.json b/manifest.json index bb22c9d..0419d0f 100644 --- a/manifest.json +++ b/manifest.json @@ -10,8 +10,8 @@ "fr": "Créer une redirection ou un proxy vers un autre emplacement" }, "version": "1.0.0~ynh2", - "url": "https://github.com/YunoHost-Apps/redirect_ynh", "license": "AGPL-3.0-or-later", + "url": "https://github.com/YunoHost-Apps/redirect_ynh", "maintainer": { "name": "opi", "email": "opi@zeropi.net" @@ -43,6 +43,7 @@ }, { "name": "redirect_path", + "type": "string", "ask": { "en": "Redirect destination path", "fr": "Emplacement de destination" @@ -57,6 +58,10 @@ "en": "Is it a public redirect?", "fr": "Est-ce une redirection publique ?" }, + "help": { + "en": "A private redirection will only be effective for logged-in users.", + "fr": "Une redirection privée ne fonctionnera que pour les utilisateurs identifiés." + }, "default": false }, { diff --git a/scripts/backup b/scripts/backup index ddb8155..73bca48 100644 --- a/scripts/backup +++ b/scripts/backup @@ -38,8 +38,8 @@ ynh_abort_if_errors app=$YNH_APP_INSTANCE_NAME # Retrieve arguments -domain=$(yunohost app setting $app domain) +domain=$(ynh_app_setting_get $app domain) # Copy the conf files mkdir -p ./conf -cp -a "/etc/nginx/conf.d/${domain}.d/${app}.conf" ./conf/nginx.conf \ No newline at end of file +cp -a "/etc/nginx/conf.d/${domain}.d/${app}.conf" ./conf/nginx.conf diff --git a/scripts/install b/scripts/install index dc53e28..b3583d9 100644 --- a/scripts/install +++ b/scripts/install @@ -45,32 +45,33 @@ path=${path%/} location=${path:-/} # Check domain/path availability -yunohost app checkurl $domain$path -a $app \ - || ynh_die "Path not available: $domain$path" +ynh_webpath_register $app $domain $path # Validate redirect path url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]' -[[ ! $redirect_path =~ $url_regex ]] && ynh_die \ -"Invalid destination: $redirect_path" 1 +[[ ! $redirect_path =~ $url_regex ]] && ynh_die "Invalid destination: $redirect_path" 1 # Save extra settings -yunohost app setting $app is_public -v "$is_public" -yunohost app setting $app redirect_type -v "$redirect_type" -yunohost app setting $app redirect_path -v "$redirect_path" +ynh_app_setting_set $app is_public "$is_public" +ynh_app_setting_set $app redirect_type "$redirect_type" +ynh_app_setting_set $app redirect_path "$redirect_path" # Nginx configuration -sed -i "s@YNH_LOCATION@$location@g" ../conf/nginx-*.conf +for FILE in $(ls ../conf/nginx-*.conf) +do + ynh_replace_string "YNH_LOCATION" "$location" $FILE +done if [ "$redirect_type" = "visible_302" ]; then - sed -i "s@YNH_REDIRECT_PATH@$redirect_path@g" ../conf/nginx-visible-302.conf + ynh_replace_string "YNH_REDIRECT_PATH" "$redirect_path" ../conf/nginx-visible-302.conf cp ../conf/nginx-visible-302.conf /etc/nginx/conf.d/$domain.d/$app.conf elif [ "$redirect_type" = "visible_301" ]; then - sed -i "s@YNH_REDIRECT_PATH@$redirect_path@g" ../conf/nginx-visible-301.conf + ynh_replace_string "YNH_REDIRECT_PATH" "$redirect_path" ../conf/nginx-visible-301.conf cp ../conf/nginx-visible-301.conf /etc/nginx/conf.d/$domain.d/$app.conf elif [ "$redirect_type" = "proxy" ]; then - sed -i "s@YNH_REDIRECT_PATH@$redirect_path@g" ../conf/nginx-proxy.conf + ynh_replace_string "YNH_REDIRECT_PATH" "$redirect_path" ../conf/nginx-proxy.conf cp ../conf/nginx-proxy.conf /etc/nginx/conf.d/$domain.d/$app.conf fi @@ -92,4 +93,3 @@ fi # Reload Nginx and regenerate SSOwat conf service nginx reload -yunohost app ssowatconf diff --git a/scripts/remove b/scripts/remove index 32159db..0f596fd 100644 --- a/scripts/remove +++ b/scripts/remove @@ -26,11 +26,10 @@ source /usr/share/yunohost/helpers app=$YNH_APP_INSTANCE_NAME # Retrieve arguments -domain=$(yunohost app setting $app domain) +domain=$(ynh_app_setting_get $app domain) # Remove configuration files -rm -f /etc/nginx/conf.d/$domain.d/$app.conf +ynh_secure_remove /etc/nginx/conf.d/$domain.d/$app.conf # Restart services service nginx reload -yunohost app ssowatconf diff --git a/scripts/restore b/scripts/restore index 1a4b8e8..f7c05f6 100644 --- a/scripts/restore +++ b/scripts/restore @@ -48,19 +48,15 @@ redirect_path=$(ynh_app_setting_get "$app" redirect_path) path=${path%/} # Check domain/path availability -yunohost app checkurl $domain$path -a $app \ - || die "The path ${domain}${path} is not available for app installation." +ynh_webpath_register $app $domain $path # Validate redirect path url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]' -[[ ! $redirect_path =~ $url_regex ]] && ynh_die \ -"Invalid destination: $redirect_path" 1 +[[ ! $redirect_path =~ $url_regex ]] && ynh_die "Invalid destination: $redirect_path" 1 # Check configuration files NGINX_CONF="/etc/nginx/conf.d/${domain}.d/${app}.conf" -[[ -f $NGINX_CONF ]] && die \ -"The NGINX configuration already exists at '${NGINX_CONF}'. - You should safely delete it before restoring this app." +[[ -f $NGINX_CONF ]] && ynh_die "The NGINX configuration already exists at '${NGINX_CONF}'. You should safely delete it before restoring this app." # Restore configuration files cp -a ./conf/nginx.conf "$NGINX_CONF" @@ -82,4 +78,3 @@ fi # Reload Nginx and regenerate SSOwat conf service nginx reload -yunohost app ssowatconf diff --git a/scripts/upgrade b/scripts/upgrade index 027b27c..0a53309 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -74,28 +74,23 @@ path=${path%/} #force location to be / or /foo location=${path:-/} -# Check domain/path availability -yunohost app checkurl $domain$path -a $app \ - || ynh_die "Path not available: $domain$path" - # Validate redirect path url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]' -[[ ! $redirect_path =~ $url_regex ]] && ynh_die \ -"Invalid destination: $redirect_path" 1 +[[ ! $redirect_path =~ $url_regex ]] && ynh_die "Invalid destination: $redirect_path" 1 # Nginx configuration -sed -i "s@YNH_LOCATION@$location@g" ../conf/nginx-*.conf +ynh_replace_string "YNH_LOCATION" "$location" ../conf/nginx-*.conf if [ "$redirect_type" = "visible_302" ]; then - sed -i "s@YNH_REDIRECT_PATH@$redirect_path@g" ../conf/nginx-visible-302.conf + ynh_replace_string "YNH_REDIRECT_PATH" "$redirect_path" ../conf/nginx-visible-302.conf cp ../conf/nginx-visible-302.conf /etc/nginx/conf.d/$domain.d/$app.conf elif [ "$redirect_type" = "visible_301" ]; then - sed -i "s@YNH_REDIRECT_PATH@$redirect_path@g" ../conf/nginx-visible-301.conf + ynh_replace_string "YNH_REDIRECT_PATH" "$redirect_path" ../conf/nginx-visible-301.conf cp ../conf/nginx-visible-301.conf /etc/nginx/conf.d/$domain.d/$app.conf elif [ "$redirect_type" = "proxy" ]; then - sed -i "s@YNH_REDIRECT_PATH@$redirect_path@g" ../conf/nginx-proxy.conf + ynh_replace_string "YNH_REDIRECT_PATH" "$redirect_path" ../conf/nginx-proxy.conf cp ../conf/nginx-proxy.conf /etc/nginx/conf.d/$domain.d/$app.conf fi @@ -116,4 +111,3 @@ fi # Reload Nginx and regenerate SSOwat conf service nginx reload -yunohost app ssowatconf From ef4ed69b65dd94465eea99048406ce4a76498a30 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 9 May 2019 19:57:27 +0200 Subject: [PATCH 2/3] Use path_url instead of path, because helpers require it --- scripts/install | 8 ++++---- scripts/restore | 4 ++-- scripts/upgrade | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/install b/scripts/install index b3583d9..bc40133 100644 --- a/scripts/install +++ b/scripts/install @@ -34,18 +34,18 @@ app=$YNH_APP_INSTANCE_NAME # Retrieve arguments domain=$YNH_APP_ARG_DOMAIN -path=$YNH_APP_ARG_PATH +path_url=$YNH_APP_ARG_PATH is_public=$YNH_APP_ARG_IS_PUBLIC redirect_type=$YNH_APP_ARG_REDIRECT_TYPE redirect_path=$YNH_APP_ARG_REDIRECT_PATH # Remove trailing slash to path -path=${path%/} +path_url=${path_url%/} #force location to be / or /foo -location=${path:-/} +location=${path_url:-/} # Check domain/path availability -ynh_webpath_register $app $domain $path +ynh_webpath_register $app $domain $path_url # Validate redirect path url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]' diff --git a/scripts/restore b/scripts/restore index f7c05f6..09c6e2d 100644 --- a/scripts/restore +++ b/scripts/restore @@ -39,13 +39,13 @@ app=$YNH_APP_INSTANCE_NAME # Retrieve arguments domain=$(ynh_app_setting_get "$app" domain) -path=$(ynh_app_setting_get "$app" path) +path_url=$(ynh_app_setting_get "$app" path_url) is_public=$(ynh_app_setting_get "$app" is_public) redirect_type=$(ynh_app_setting_get "$app" redirect_type) redirect_path=$(ynh_app_setting_get "$app" redirect_path) # Remove trailing slash to path -path=${path%/} +path_url=${path_url%/} # Check domain/path availability ynh_webpath_register $app $domain $path diff --git a/scripts/upgrade b/scripts/upgrade index 0a53309..b1a124f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -31,7 +31,7 @@ app=$YNH_APP_INSTANCE_NAME # Retrieve arguments domain=$(ynh_app_setting_get "$app" domain) -path=$(ynh_app_setting_get "$app" path) +path_url=$(ynh_app_setting_get "$app" path) is_public=$(ynh_app_setting_get "$app" is_public) redirect_type=$(ynh_app_setting_get "$app" redirect_type) redirect_path=$(ynh_app_setting_get "$app" redirect_path) @@ -70,9 +70,9 @@ ynh_clean_setup () { ynh_abort_if_errors # Remove trailing slash to path -path=${path%/} +path_url=${path_url%/} #force location to be / or /foo -location=${path:-/} +location=${path_url:-/} # Validate redirect path url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]' From 5ccd094fa9c7870cb9d19017628c4d9543fe01df Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 9 May 2019 23:08:09 +0200 Subject: [PATCH 3/3] Moar misc fixes following tests... --- scripts/install | 11 +++-------- scripts/restore | 12 +++--------- scripts/upgrade | 14 ++++++-------- 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/scripts/install b/scripts/install index bc40133..ebf4b77 100644 --- a/scripts/install +++ b/scripts/install @@ -39,11 +39,6 @@ is_public=$YNH_APP_ARG_IS_PUBLIC redirect_type=$YNH_APP_ARG_REDIRECT_TYPE redirect_path=$YNH_APP_ARG_REDIRECT_PATH -# Remove trailing slash to path -path_url=${path_url%/} -#force location to be / or /foo -location=${path_url:-/} - # Check domain/path availability ynh_webpath_register $app $domain $path_url @@ -59,7 +54,7 @@ ynh_app_setting_set $app redirect_path "$redirect_path" # Nginx configuration for FILE in $(ls ../conf/nginx-*.conf) do - ynh_replace_string "YNH_LOCATION" "$location" $FILE + ynh_replace_string "YNH_LOCATION" "$path_url" $FILE done if [ "$redirect_type" = "visible_302" ]; then @@ -79,12 +74,12 @@ fi # SETUP SSOWAT #================================================= -if [[ "$is_public" -eq 0 ]] +if [ $is_public -eq 0 ] then # Remove the public access ynh_app_setting_delete "$app" skipped_uris fi # Make app public if necessary -if [[ "$is_public" -eq 1 ]] +if [ $is_public -eq 1 ] then # unprotected_uris allows SSO credentials to be passed anyway. ynh_app_setting_set "$app" unprotected_uris "/" diff --git a/scripts/restore b/scripts/restore index 09c6e2d..58d11c4 100644 --- a/scripts/restore +++ b/scripts/restore @@ -39,17 +39,11 @@ app=$YNH_APP_INSTANCE_NAME # Retrieve arguments domain=$(ynh_app_setting_get "$app" domain) -path_url=$(ynh_app_setting_get "$app" path_url) +path_url=$(ynh_app_setting_get "$app" path) is_public=$(ynh_app_setting_get "$app" is_public) redirect_type=$(ynh_app_setting_get "$app" redirect_type) redirect_path=$(ynh_app_setting_get "$app" redirect_path) -# Remove trailing slash to path -path_url=${path_url%/} - -# Check domain/path availability -ynh_webpath_register $app $domain $path - # Validate redirect path url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]' [[ ! $redirect_path =~ $url_regex ]] && ynh_die "Invalid destination: $redirect_path" 1 @@ -65,12 +59,12 @@ cp -a ./conf/nginx.conf "$NGINX_CONF" # SETUP SSOWAT #================================================= -if [[ "$is_public" -eq 0 ]] +if [ "$is_public" -eq 0 ] then # Remove the public access ynh_app_setting_delete "$app" skipped_uris fi # Make app public if necessary -if [[ "$is_public" -eq 1 ]] +if [ "$is_public" -eq 1 ] then # unprotected_uris allows SSO credentials to be passed anyway. ynh_app_setting_set "$app" unprotected_uris "/" diff --git a/scripts/upgrade b/scripts/upgrade index b1a124f..a9c3915 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -69,17 +69,15 @@ ynh_clean_setup () { # Exit if an error occurs during the execution of the script ynh_abort_if_errors -# Remove trailing slash to path -path_url=${path_url%/} -#force location to be / or /foo -location=${path_url:-/} - # Validate redirect path url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]' [[ ! $redirect_path =~ $url_regex ]] && ynh_die "Invalid destination: $redirect_path" 1 # Nginx configuration -ynh_replace_string "YNH_LOCATION" "$location" ../conf/nginx-*.conf +for FILE in $(ls ../conf/nginx-*.conf) +do + ynh_replace_string "YNH_LOCATION" "$path_url" $FILE +done if [ "$redirect_type" = "visible_302" ]; then ynh_replace_string "YNH_REDIRECT_PATH" "$redirect_path" ../conf/nginx-visible-302.conf @@ -98,12 +96,12 @@ fi # SETUP SSOWAT #================================================= -if [[ "$is_public" -eq 0 ]] +if [ "$is_public" -eq 0 ] then # Remove the public access ynh_app_setting_delete "$app" skipped_uris fi # Make app public if necessary -if [[ "$is_public" -eq 1 ]] +if [ "$is_public" -eq 1 ] then # unprotected_uris allows SSO credentials to be passed anyway. ynh_app_setting_set "$app" unprotected_uris -v "/"