From 6cfc25660327db69f8479eb89ce80b4af1ab9631 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 29 Apr 2019 20:49:40 +0200 Subject: [PATCH 01/14] 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 02/14] 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 03/14] 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 "/" From 238eeb8f57b20a23a5de7173f612bf3364d39d09 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Wed, 15 May 2019 17:34:00 +0200 Subject: [PATCH 04/14] Taking over the app : marking myself as maintainer + bumping version --- manifest.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/manifest.json b/manifest.json index 0419d0f..986b43c 100644 --- a/manifest.json +++ b/manifest.json @@ -9,12 +9,12 @@ "en": "Create a redirection or a proxy to another path.", "fr": "Créer une redirection ou un proxy vers un autre emplacement" }, - "version": "1.0.0~ynh2", + "version": "1.0.0~ynh3", "license": "AGPL-3.0-or-later", "url": "https://github.com/YunoHost-Apps/redirect_ynh", "maintainer": { - "name": "opi", - "email": "opi@zeropi.net" + "name": "alexAubin", + "email": "alex.aubin@mailoo.org" }, "multi_instance": true, "services": [ From 650d69514d9fe8a87bb3f58b05307ebb9b8ccd1a Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Wed, 15 May 2019 18:35:57 +0200 Subject: [PATCH 05/14] is_public was a lie. Only reverse proxy can be private. --- manifest.json | 22 +++++-------------- scripts/install | 15 ++++--------- scripts/restore | 7 +----- scripts/upgrade | 57 +++++++++++++++++++++++++++++++++---------------- 4 files changed, 49 insertions(+), 52 deletions(-) diff --git a/manifest.json b/manifest.json index 986b43c..8f99f0c 100644 --- a/manifest.json +++ b/manifest.json @@ -51,19 +51,6 @@ "example": "http://127.0.0.1:8080/app/", "default": "http://127.0.0.1" }, - { - "name": "is_public", - "type": "boolean", - "ask": { - "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 - }, { "name": "redirect_type", "ask": { @@ -71,11 +58,12 @@ "fr": "Type de redirection" }, "choices": { - "visible_302" : "Visible (302, temporary redirect)", - "visible_301" : "Visible (301, permanent redirect)", - "proxy": "Proxy, invisible (Nginx proxy_pass)" + "public_302" : "Visible redirect (302, temporary). Everybody will be able to access it.", + "public_301" : "Visible redirect (301, permanent). Everybody will be able to access it.", + "public_proxy": "Proxy, invisible (nginx proxy_pass). Everybody will be able to access it.", + "private_proxy": "Proxy, invisible (nginx proxy_pass). Only accessible for allowed users." }, - "default": "visible_302" + "default": "public_302" } ] } diff --git a/scripts/install b/scripts/install index ebf4b77..c108ea5 100644 --- a/scripts/install +++ b/scripts/install @@ -35,7 +35,6 @@ app=$YNH_APP_INSTANCE_NAME # Retrieve arguments domain=$YNH_APP_ARG_DOMAIN 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 @@ -47,7 +46,6 @@ url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%= [[ ! $redirect_path =~ $url_regex ]] && ynh_die "Invalid destination: $redirect_path" 1 # Save extra settings -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" @@ -56,15 +54,15 @@ for FILE in $(ls ../conf/nginx-*.conf) do ynh_replace_string "YNH_LOCATION" "$path_url" $FILE done -if [ "$redirect_type" = "visible_302" ]; +if [ "$redirect_type" = "public_302" ]; then 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" ]; +elif [ "$redirect_type" = "public_301" ]; then 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" ]; +elif [ "$redirect_type" = "public_proxy" ] || [ "$redirect_type" = "private_proxy" ]; then 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 @@ -74,17 +72,12 @@ fi # SETUP SSOWAT #================================================= -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 [ "$redirect_type" != "private_proxy" ] then # unprotected_uris allows SSO credentials to be passed anyway. ynh_app_setting_set "$app" unprotected_uris "/" fi - # Reload Nginx and regenerate SSOwat conf service nginx reload diff --git a/scripts/restore b/scripts/restore index 58d11c4..a5fbbe3 100644 --- a/scripts/restore +++ b/scripts/restore @@ -40,7 +40,6 @@ app=$YNH_APP_INSTANCE_NAME # Retrieve arguments domain=$(ynh_app_setting_get "$app" domain) 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) @@ -59,12 +58,8 @@ cp -a ./conf/nginx.conf "$NGINX_CONF" # SETUP SSOWAT #================================================= -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 [ "$redirect_type" != "private_proxy" ] 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 a9c3915..d8753ab 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -32,7 +32,6 @@ app=$YNH_APP_INSTANCE_NAME # Retrieve arguments domain=$(ynh_app_setting_get "$app" domain) 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) @@ -41,14 +40,6 @@ redirect_path=$(ynh_app_setting_get "$app" redirect_path) #================================================= # Fix is_public as a boolean value -if [ "$is_public" = "Yes" ]; then - ynh_app_setting_set $app is_public 1 - is_public=1 -elif [ "$is_public" = "No" ]; then - ynh_app_setting_set $app is_public 0 - is_public=0 -fi - # Default value for redirect_type if upgrading from https://github.com/scith/redirect_ynh if [ -z "$redirect_type" ]; then @@ -56,6 +47,40 @@ then ynh_app_setting_set $app 'redirect_type' $redirect_type fi +# Migrate away from old stuff with 'is_public' and old redirect type names +is_public=$(ynh_app_setting_get "$app" is_public) +if [ -n "$is_public" ] +then + if [ "$is_public" = "Yes" ]; then + is_public=1 + elif [ "$is_public" = "No" ]; then + is_public=0 + fi + + if [ "$is_public" = "0" ] && [ "$redirect_type" != "proxy" ]; then + echo "WARNING: You previously had a 'supposedly' private 301 or 302 redirection ... but it was found that it was public all along and it is not easy to create such a private redirection. Your 301 or 302 redirection will be re-flagged as public..." >&2 + is_public=1 + fi + + if [ "$redirect_type" == "proxy" ] && [ "$is_public" = "1" ] + then + redirect_type="public_proxy" + elif [ "$redirect_type" == "proxy" ] && [ "$is_public" = "0" ] + then + redirect_type="private_proxy" + elif [ "$redirect_type" == "visible_302" ] + then + redirect_type="public_302" + elif [ "$redirect_type" == "visible_301" ] + then + redirect_type="public_301" + fi + + ynh_app_setting_set $app 'redirect_type' $redirect_type + ynh_app_setting_set $app 'is_public' +fi + + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -78,15 +103,15 @@ for FILE in $(ls ../conf/nginx-*.conf) do ynh_replace_string "YNH_LOCATION" "$path_url" $FILE done -if [ "$redirect_type" = "visible_302" ]; +if [ "$redirect_type" = "public_302" ]; then 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" ]; +elif [ "$redirect_type" = "public_301" ]; then 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" ]; +elif [ "$redirect_type" = "public_proxy" ] || [ "$redirect_type" = "private_proxy" ]; then 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 @@ -96,15 +121,11 @@ fi # SETUP SSOWAT #================================================= -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 [ "$redirect_type" != "private_proxy" ] then # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set "$app" unprotected_uris -v "/" + ynh_app_setting_set "$app" unprotected_uris "/" fi # Reload Nginx and regenerate SSOwat conf From 5a76baaf613d0df3649ce90b800c0c6244c27cfa Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Wed, 15 May 2019 18:42:44 +0200 Subject: [PATCH 06/14] Misc cleaning --- scripts/backup | 22 ++-------------------- scripts/install | 22 +++++++--------------- scripts/remove | 16 ++-------------- scripts/restore | 25 ++++--------------------- scripts/upgrade | 25 +++++++------------------ 5 files changed, 22 insertions(+), 88 deletions(-) diff --git a/scripts/backup b/scripts/backup index 73bca48..8aa1ce6 100644 --- a/scripts/backup +++ b/scripts/backup @@ -6,12 +6,6 @@ # IMPORT GENERIC HELPERS #================================================= -# if [ ! -e _common.sh ]; then - # Get the _common.sh file if it's not in the current directory -# cp ../settings/scripts/_common.sh ./_common.sh -# chmod a+rx _common.sh -# fi -# source _common.sh source /usr/share/yunohost/helpers #================================================= @@ -25,21 +19,9 @@ ynh_abort_if_errors # LOAD SETTINGS #================================================= -# This is a multi-instance app, meaning it can be installed several times independently -# The id of the app as stated in the manifest is available as $YNH_APP_ID -# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) -# The app instance name is available as $YNH_APP_INSTANCE_NAME -# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample -# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2 -# - ynhexample__{N} for the subsequent installations, with N=3,4, ... -# The app instance name is probably what you are interested the most, since this is -# guaranteed to be unique. This is a good unique identifier to define installation path, -# db names, ... -app=$YNH_APP_INSTANCE_NAME - # Retrieve arguments +app=$YNH_APP_INSTANCE_NAME 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 +ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" diff --git a/scripts/install b/scripts/install index c108ea5..8d3f55e 100644 --- a/scripts/install +++ b/scripts/install @@ -6,7 +6,6 @@ # IMPORT GENERIC HELPERS #================================================= -# source _common.sh source /usr/share/yunohost/helpers #================================================= @@ -20,19 +19,8 @@ ynh_abort_if_errors # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= -# This is a multi-instance app, meaning it can be installed several times independently -# The id of the app as stated in the manifest is available as $YNH_APP_ID -# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) -# The app instance name is available as $YNH_APP_INSTANCE_NAME -# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample -# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2 -# - ynhexample__{N} for the subsequent installations, with N=3,4, ... -# The app instance name is probably what you are interested the most, since this is -# guaranteed to be unique. This is a good unique identifier to define installation path, -# db names, ... -app=$YNH_APP_INSTANCE_NAME - # Retrieve arguments +app=$YNH_APP_INSTANCE_NAME domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH redirect_type=$YNH_APP_ARG_REDIRECT_TYPE @@ -49,6 +37,10 @@ url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%= ynh_app_setting_set $app redirect_type "$redirect_type" ynh_app_setting_set $app redirect_path "$redirect_path" +#================================================= +# CONFIGURE NGINX +#================================================= + # Nginx configuration for FILE in $(ls ../conf/nginx-*.conf) do @@ -69,7 +61,7 @@ then fi #================================================= -# SETUP SSOWAT +# CONFIGURE SSOWAT #================================================= # Make app public if necessary @@ -80,4 +72,4 @@ then fi # Reload Nginx and regenerate SSOwat conf -service nginx reload +systemctl reload nginx diff --git a/scripts/remove b/scripts/remove index 0f596fd..82109e4 100644 --- a/scripts/remove +++ b/scripts/remove @@ -6,30 +6,18 @@ # IMPORT GENERIC HELPERS #================================================= -# source _common.sh source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -# This is a multi-instance app, meaning it can be installed several times independently -# The id of the app as stated in the manifest is available as $YNH_APP_ID -# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) -# The app instance name is available as $YNH_APP_INSTANCE_NAME -# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample -# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2 -# - ynhexample__{N} for the subsequent installations, with N=3,4, ... -# The app instance name is probably what you are interested the most, since this is -# guaranteed to be unique. This is a good unique identifier to define installation path, -# db names, ... -app=$YNH_APP_INSTANCE_NAME - # Retrieve arguments +app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) # Remove configuration files ynh_secure_remove /etc/nginx/conf.d/$domain.d/$app.conf # Restart services -service nginx reload +systemctl reload nginx diff --git a/scripts/restore b/scripts/restore index a5fbbe3..0ec55b3 100644 --- a/scripts/restore +++ b/scripts/restore @@ -6,12 +6,6 @@ # IMPORT GENERIC HELPERS #================================================= -# if [ ! -e _common.sh ]; then - # Get the _common.sh file if it's not in the current directory -# cp ../settings/scripts/_common.sh ./_common.sh -# chmod a+rx _common.sh -# fi -# source _common.sh source /usr/share/yunohost/helpers #================================================= @@ -25,19 +19,8 @@ ynh_abort_if_errors # LOAD SETTINGS #================================================= -# This is a multi-instance app, meaning it can be installed several times independently -# The id of the app as stated in the manifest is available as $YNH_APP_ID -# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) -# The app instance name is available as $YNH_APP_INSTANCE_NAME -# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample -# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2 -# - ynhexample__{N} for the subsequent installations, with N=3,4, ... -# The app instance name is probably what you are interested the most, since this is -# guaranteed to be unique. This is a good unique identifier to define installation path, -# db names, ... -app=$YNH_APP_INSTANCE_NAME - # Retrieve arguments +app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get "$app" domain) path_url=$(ynh_app_setting_get "$app" path) redirect_type=$(ynh_app_setting_get "$app" redirect_type) @@ -52,10 +35,10 @@ NGINX_CONF="/etc/nginx/conf.d/${domain}.d/${app}.conf" [[ -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" +ynh_restore_file "$NGINX_CONF" #================================================= -# SETUP SSOWAT +# CONFIGURE SSOWAT #================================================= # Make app public if necessary @@ -66,4 +49,4 @@ then fi # Reload Nginx and regenerate SSOwat conf -service nginx reload +systemctl reload nginx diff --git a/scripts/upgrade b/scripts/upgrade index d8753ab..280fc98 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -7,29 +7,14 @@ # IMPORT GENERIC HELPERS #================================================= -# source _common.sh source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -# This is a multi-instance app, meaning it can be installed several times independently -# The id of the app as stated in the manifest is available as $YNH_APP_ID -# The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...) -# The app instance name is available as $YNH_APP_INSTANCE_NAME -# - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample -# - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2 -# - ynhexample__{N} for the subsequent installations, with N=3,4, ... -# The app instance name is probably what you are interested the most, since this is -# guaranteed to be unique. This is a good unique identifier to define installation path, -# db names, ... -app=$YNH_APP_INSTANCE_NAME - -# Source app helpers -. /usr/share/yunohost/helpers - # Retrieve arguments +app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get "$app" domain) path_url=$(ynh_app_setting_get "$app" path) redirect_type=$(ynh_app_setting_get "$app" redirect_type) @@ -98,6 +83,10 @@ ynh_abort_if_errors url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]' [[ ! $redirect_path =~ $url_regex ]] && ynh_die "Invalid destination: $redirect_path" 1 +#================================================= +# CONFIGURE NGINX +#================================================= + # Nginx configuration for FILE in $(ls ../conf/nginx-*.conf) do @@ -118,7 +107,7 @@ then fi #================================================= -# SETUP SSOWAT +# CONFIGURE SSOWAT #================================================= # Make app public if necessary @@ -129,4 +118,4 @@ then fi # Reload Nginx and regenerate SSOwat conf -service nginx reload +systemctl reload nginx From de44880bf990d3a62a6ec1e60358dbc77e8c238a Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Thu, 16 May 2019 15:43:56 +0200 Subject: [PATCH 07/14] Fix / update check_process --- check_process | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/check_process b/check_process index 32179d7..2aa8bd2 100644 --- a/check_process +++ b/check_process @@ -7,35 +7,21 @@ ; Manifest domain="domain.tld" (DOMAIN) path="/path" (PATH) - is_public=1 (PUBLIC|public=1|private=0) - redirect_type="visible_302" + redirect_type="public_302" redirect_path="http://127.0.0.1" ; Checks pkg_linter=1 setup_sub_dir=1 setup_root=1 setup_nourl=0 - setup_private=1 + setup_private=0 setup_public=1 upgrade=1 backup_restore=1 multi_instance=1 - incorrect_path=1 + incorrect_path=0 port_already_use=0 change_url=0 -;;; Levels - Level 1=auto - Level 2=auto - Level 3=auto -# Level 4: - Level 4=0 -# Level 5: - Level 5=auto - Level 6=auto - Level 7=auto - Level 8=0 - Level 9=0 - Level 10=0 ;;; Options Email= -Notification=none \ No newline at end of file +Notification=none From bc73fbc62cc69719a5c3429160a5a1893f401150 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 17 May 2019 22:32:41 +0200 Subject: [PATCH 08/14] Update manifest.json --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 8f99f0c..0a5f67d 100644 --- a/manifest.json +++ b/manifest.json @@ -9,7 +9,7 @@ "en": "Create a redirection or a proxy to another path.", "fr": "Créer une redirection ou un proxy vers un autre emplacement" }, - "version": "1.0.0~ynh3", + "version": "1.0.0~ynh4", "license": "AGPL-3.0-or-later", "url": "https://github.com/YunoHost-Apps/redirect_ynh", "maintainer": { From a3e72e8412b4b580c5c48a234af328369d8da461 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Wed, 28 Oct 2020 16:41:18 +0100 Subject: [PATCH 09/14] Bump requirement to 3.8 --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 0a5f67d..c345323 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "id": "redirect", "packaging_format": 1, "requirements": { - "yunohost": ">= 2.7.12" + "yunohost": ">= 3.8" }, "description": { "en": "Create a redirection or a proxy to another path.", From 346fb7fa57e7cd127f21639e47a3d0deeb1fe760 Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Sat, 23 Jan 2021 15:21:17 +0100 Subject: [PATCH 10/14] Fix linter warnings --- README.md | 15 ++++++++------- check_process | 1 - manifest.json | 9 +++++---- scripts/backup | 11 +++++++++++ scripts/install | 24 ++++++++++++++++++------ scripts/remove | 21 ++++++++++++++++++--- scripts/restore | 16 +++++++++++++--- scripts/upgrade | 16 +++++++++++++--- 8 files changed, 86 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 8818b1f..8b3b9aa 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,11 @@ -# Redirect App +# Redirect App for Yunohost + +[![Integration level](https://dash.yunohost.org/integration/redirect.svg)](https://dash.yunohost.org/appci/app/redirect) ![](https://ci-apps.yunohost.org/ci/badges/redirect.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/redirect.maintain.svg) +[![Install Redirect with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=redirect) **Add a link on your user panel redirecting to another page or app, which can be protected behind your panel for some**. -It could be an invisible redirect, an external link, another app on your local network, a reverse proxy to an app or a Docker container... Some apps can be even be protected behind your panel (meaning that you will have to log-in to access them). The only limit is your imagination - and Nginx ;). +It could be an invisible redirect, an external link, another app on your local network, a reverse proxy to an app or a Docker container... Some apps can be even be protected behind your panel (meaning that you will have to log-in to access them). The only limit is your imagination - and NGINX ;). This app only adds a Nginx configuration file with `redirect` or `proxy_pass` rule, and a YunoHost tile. Nothing more. @@ -10,20 +13,18 @@ This app only adds a Nginx configuration file with `redirect` or `proxy_pass` ru ### Visible redirect -Visitor's address bar will change. Helpfull to add a user link to another -website +Visitor's address bar will change. Helpfull to add a user link to another website you-domain.com -> another-domain.net you-domain.com/foo -> another-domain.net/bar ### Invisible (proxy) redirect -Visitor's address bar will remain the same. Mostly use to serve local webserver -for a personnal application. +Visitor's address bar will remain the same. Mostly use to serve local webserver for a personnal application. you-domain.com/foo -> http://172.0.0.1:8080/app -**IMPORTANT:** the redirect.conf file might need to be updated according to your situation! +**IMPORTANT:** the `redirect.conf` file might need to be updated according to your situation! **WARNING:** Many apps do not support being redirected to a different path due to relative links! This means that some apps being hosted for example on http://127.0.0.1:5050/app/ HAVE TO be redirected to http://domain.tld/app/ and NOT http://domain.tld/someotherapp/ diff --git a/check_process b/check_process index 2aa8bd2..fa373d2 100644 --- a/check_process +++ b/check_process @@ -19,7 +19,6 @@ upgrade=1 backup_restore=1 multi_instance=1 - incorrect_path=0 port_already_use=0 change_url=0 ;;; Options diff --git a/manifest.json b/manifest.json index c345323..7a1f148 100644 --- a/manifest.json +++ b/manifest.json @@ -2,19 +2,19 @@ "name": "Redirect", "id": "redirect", "packaging_format": 1, - "requirements": { - "yunohost": ">= 3.8" - }, "description": { "en": "Create a redirection or a proxy to another path.", "fr": "Créer une redirection ou un proxy vers un autre emplacement" }, - "version": "1.0.0~ynh4", + "version": "1.0.0~ynh5", "license": "AGPL-3.0-or-later", "url": "https://github.com/YunoHost-Apps/redirect_ynh", "maintainer": { "name": "alexAubin", "email": "alex.aubin@mailoo.org" + }, + "requirements": { + "yunohost": ">= 3.8.1" }, "multi_instance": true, "services": [ @@ -53,6 +53,7 @@ }, { "name": "redirect_type", + "type": "string", "ask": { "en": "Redirect type", "fr": "Type de redirection" diff --git a/scripts/backup b/scripts/backup index 8aa1ce6..cc3bbed 100644 --- a/scripts/backup +++ b/scripts/backup @@ -18,10 +18,21 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_print_info --message="Loading installation settings..." # Retrieve arguments app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) +#================================================= +# BACKUP THE NGINX CONFIGURATION +#================================================= + # Copy the conf files ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/install b/scripts/install index 8d3f55e..66b72c6 100644 --- a/scripts/install +++ b/scripts/install @@ -27,19 +27,20 @@ redirect_type=$YNH_APP_ARG_REDIRECT_TYPE redirect_path=$YNH_APP_ARG_REDIRECT_PATH # Check domain/path availability -ynh_webpath_register $app $domain $path_url +ynh_webpath_register --app=$app --domain=$domain --path_url=$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 # Save extra settings -ynh_app_setting_set $app redirect_type "$redirect_type" -ynh_app_setting_set $app redirect_path "$redirect_path" +ynh_app_setting_set --app=$app --key=redirect_type --value=$redirect_type +ynh_app_setting_set --app=$app --key=redirect_path --value=$redirect_path #================================================= # CONFIGURE NGINX #================================================= +ynh_script_progression --message="Configuring NGINX web server..." --weight=1 # Nginx configuration for FILE in $(ls ../conf/nginx-*.conf) @@ -63,13 +64,24 @@ fi #================================================= # CONFIGURE SSOWAT #================================================= +ynh_script_progression --message="Configuring permissions..." --weight=2 # Make app public if necessary if [ "$redirect_type" != "private_proxy" ] then # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set "$app" unprotected_uris "/" + ynh_permission_update --permission="main" --add="visitors" fi -# Reload Nginx and regenerate SSOwat conf -systemctl reload nginx +#================================================= +# RELOAD NGINX +#================================================= +ynh_script_progression --message="Reloading NGINX web server..." --weight=1 + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/remove b/scripts/remove index 82109e4..304eab7 100644 --- a/scripts/remove +++ b/scripts/remove @@ -11,13 +11,28 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading installation settings..." --weight=1 # Retrieve arguments app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) +domain=$(ynh_app_setting_get --app=$app --key=domain) + +#================================================= +# REMOVE NGINX CONFIGURATION +#================================================= # Remove configuration files ynh_secure_remove /etc/nginx/conf.d/$domain.d/$app.conf -# Restart services -systemctl reload nginx +#================================================= +# RELOAD NGINX AND PHP-FPM +#================================================= +ynh_script_progression --message="Reloading NGINX web server..." --weight=1 + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Removal of $app completed" --last diff --git a/scripts/restore b/scripts/restore index 0ec55b3..5c4c3a6 100644 --- a/scripts/restore +++ b/scripts/restore @@ -45,8 +45,18 @@ ynh_restore_file "$NGINX_CONF" if [ "$redirect_type" != "private_proxy" ] then # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set "$app" unprotected_uris "/" + ynh_permission_update --permission="main" --add="visitors" fi -# Reload Nginx and regenerate SSOwat conf -systemctl reload nginx +#================================================= +# RELOAD NGINX AND PHP-FPM +#================================================= +ynh_script_progression --message="Reloading NGINX web server..." --weight=1 + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index 280fc98..7b9df56 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -114,8 +114,18 @@ fi if [ "$redirect_type" != "private_proxy" ] then # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set "$app" unprotected_uris "/" + ynh_permission_update --permission="main" --add="visitors" fi -# Reload Nginx and regenerate SSOwat conf -systemctl reload nginx +#================================================= +# RELOAD NGINX +#================================================= +ynh_script_progression --message="Reloading NGINX web server..." --weight=1 + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Upgrade of $app completed" --last From 6c80ac0b18e052990ff50a6e45a84a11ece6fd9b Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Fri, 4 Jun 2021 16:26:13 +0200 Subject: [PATCH 11/14] Add templates --- .github/ISSUE_TEMPLATE.md | 55 ++++++++++++++++++++++++++++++++ .github/PULL_REQUEST_TEMPLATE.md | 16 ++++++++++ check_process | 10 ++---- doc/DISCLAIMER.md | 49 ++++++++++++++++++++++++++++ manifest.json | 6 +++- 5 files changed, 127 insertions(+), 9 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 doc/DISCLAIMER.md diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..2729a6b --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,55 @@ +--- +name: Bug report +about: When creating a bug report, please use the following template to provide all the relevant information and help debugging efficiently. + +--- + +**How to post a meaningful bug report** +1. *Read this whole template first.* +2. *Determine if you are on the right place:* + - *If you were performing an action on the app from the webadmin or the CLI (install, update, backup, restore, change_url...), you are on the right place!* + - *Otherwise, the issue may be due to the app itself. Refer to its documentation or repository for help.* + - *When in doubt, post here and we will figure it out together.* +3. *Delete the italic comments as you write over them below, and remove this guide.* +--- + +### Describe the bug + +*A clear and concise description of what the bug is.* + +### Context + +- Hardware: *VPS bought online / Old laptop or computer / Raspberry Pi at home / Internet Cube with VPN / Other ARM board / ...* +- YunoHost version: x.x.x +- I have access to my server: *Through SSH | through the webadmin | direct access via keyboard / screen | ...* +- Are you in a special context or did you perform some particular tweaking on your YunoHost instance?: *no / yes* + - If yes, please explain: +- Using, or trying to install package version/branch: +- If upgrading, current package version: *can be found in the admin, or with `yunohost app info $app_id`* + +### Steps to reproduce + +- *If you performed a command from the CLI, the command itself is enough. For example:* + ```sh + sudo yunohost app install the_app + ``` +- *If you used the webadmin, please perform the equivalent command from the CLI first.* +- *If the error occurs in your browser, explain what you did:* + 1. *Go to '...'* + 2. *Click on '...'* + 3. *Scroll down to '...'* + 4. *See error* + +### Expected behavior + +*A clear and concise description of what you expected to happen. You can remove this section if the command above is enough to understand your intent.* + +### Logs + +*When an operation fails, YunoHost provides a simple way to share the logs.* +- *In the webadmin, the error message contains a link to the relevant log page. On that page, you will be able to 'Share with Yunopaste'. If you missed it, the logs of previous operations are also available under Tools > Logs.* +- *In command line, the command to share the logs is displayed at the end of the operation and looks like `yunohost log display [log name] --share`. If you missed it, you can find the log ID of a previous operation using `yunohost log list`.* + +*After sharing the log, please copypaste directly the link provided by YunoHost (to help readability, no need to copypaste the entire content of the log here, just the link is enough...)* + +*If applicable and useful, add screenshots to help explain your problem.* diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..ef70e18 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,16 @@ +## Problem + +- *Description of why you made this PR* + +## Solution + +- *And how do you fix that problem* + +## PR Status + +- [ ] Code finished and ready to be reviewed/tested +- [ ] The fix/enhancement were manually tested (if applicable) + +## Automatic tests + +Automatic tests can be triggered on https://ci-apps-dev.yunohost.org/ *after creating the PR*, by commenting "!testme", "!gogogadgetoci" or "By the power of systemd, I invoke The Great App CI to test this Pull Request!". (N.B. : for this to work you need to be a member of the Yunohost-Apps organization) diff --git a/check_process b/check_process index fa373d2..da9f0ab 100644 --- a/check_process +++ b/check_process @@ -1,12 +1,7 @@ -# See here for more informations -# https://github.com/YunoHost/package_check#syntax-check_process-file - -# Move this file from check_process.default to check_process when you have filled it. - ;; Test complet ; Manifest - domain="domain.tld" (DOMAIN) - path="/path" (PATH) + domain="domain.tld" + path="/path" redirect_type="public_302" redirect_path="http://127.0.0.1" ; Checks @@ -19,7 +14,6 @@ upgrade=1 backup_restore=1 multi_instance=1 - port_already_use=0 change_url=0 ;;; Options Email= diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md new file mode 100644 index 0000000..48b5c67 --- /dev/null +++ b/doc/DISCLAIMER.md @@ -0,0 +1,49 @@ +**Add a link on your user panel redirecting to another page or app, which can be protected behind your panel for some**. + +It could be an invisible redirect, an external link, another app on your local network, a reverse proxy to an app or a Docker container... Some apps can be even be protected behind your panel (meaning that you will have to log-in to access them). The only limit is your imagination - and NGINX ;). + +This app only adds a Nginx configuration file with `redirect` or `proxy_pass` rule, and a YunoHost tile. Nothing more. + +## Redirect type + +### Visible redirect + +Visitor's address bar will change. Helpfull to add a user link to another website + + you-domain.com -> another-domain.net + you-domain.com/foo -> another-domain.net/bar + +### Invisible (proxy) redirect + +Visitor's address bar will remain the same. Mostly use to serve local webserver for a personnal application. + + you-domain.com/foo -> http://172.0.0.1:8080/app + +**IMPORTANT:** the `redirect.conf` file might need to be updated according to your situation! + +**WARNING:** Many apps do not support being redirected to a different path due to relative links! This means that some apps being hosted for example on http://127.0.0.1:5050/app/ HAVE TO be redirected to http://domain.tld/app/ and NOT http://domain.tld/someotherapp/ + +*Concrete example:* the Odoo Docker container runs on http://127.0.0.1:8069/. You will not be able to redirect it to http://domain.tld/odoo/ ! You have to redirect it to the root, so for example http://odoo.domain.tld/ + +## Public or private redirect + +In case of a private redirect, the app will be available to logged in users only. This could be useful if you want to protect behind the SSO an app from your local network or from the server (e.g., a Docker container or an app that does not have user management or password protection). + +**IMPORTANT:** Make sure that the app you want to protect CANNOT be accessed by its port or another direct link. Otherwise, your app will only be protected in YunoHost but would still be available through its direct link. In the case of a Docker container, the port of the container will have to be local (e.g., -p 127.0.0.1:9000:9000). + +## Case examples + +- **Creating a tile for a Docker container** with a local port (e.g., -p 127.0.0.1:PORT:PORT): proxy redirect to http://127.0.0.1:PORT-OF-THE-CONTAINER/ + +- **Redirecting to an external website**: visible redirect to the URL + +- [CozyCloud behind YunoHost?](https://forum.cozy.io/t/cozy-cloud-sous-yunohost/616/11) + +- **Creating a tile and protecting apps that are difficult to package natively (or for prototyping)** + + +**_Feel free to [share your case examples and customized Nginx files on the forum](https://forum.yunohost.org/t/2182)._** + +## Credits + +Insprired by [scith](https://github.com/scith) work. diff --git a/manifest.json b/manifest.json index 7a1f148..374d433 100644 --- a/manifest.json +++ b/manifest.json @@ -9,12 +9,16 @@ "version": "1.0.0~ynh5", "license": "AGPL-3.0-or-later", "url": "https://github.com/YunoHost-Apps/redirect_ynh", + "upstream": { + "license": "AGPL-3.0-or-later", + "website": "https://github.com/YunoHost-Apps/redirect_ynh" + }, "maintainer": { "name": "alexAubin", "email": "alex.aubin@mailoo.org" }, "requirements": { - "yunohost": ">= 3.8.1" + "yunohost": ">= 4.2.0" }, "multi_instance": true, "services": [ From 5a649f2173aa86e91b6482d13b170e030ac21603 Mon Sep 17 00:00:00 2001 From: Yunohost-Bot <> Date: Fri, 4 Jun 2021 14:26:21 +0000 Subject: [PATCH 12/14] Auto-update README --- README.md | 41 +++++++++++++++++++++++- README_fr.md | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 README_fr.md diff --git a/README.md b/README.md index 8b3b9aa..1bfe75e 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,28 @@ -# Redirect App for Yunohost + + +# Redirect for YunoHost [![Integration level](https://dash.yunohost.org/integration/redirect.svg)](https://dash.yunohost.org/appci/app/redirect) ![](https://ci-apps.yunohost.org/ci/badges/redirect.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/redirect.maintain.svg) [![Install Redirect with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=redirect) +*[Lire ce readme en français.](./README_fr.md)* + +> *This package allows you to install Redirect quickly and simply on a YunoHost server. +If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.* + +## Overview + +Create a redirection or a proxy to another path. + +**Shipped version:** 1.0.0~ynh5 + + + +## Disclaimers / important information + **Add a link on your user panel redirecting to another page or app, which can be protected behind your panel for some**. It could be an invisible redirect, an external link, another app on your local network, a reverse proxy to an app or a Docker container... Some apps can be even be protected behind your panel (meaning that you will have to log-in to access them). The only limit is your imagination - and NGINX ;). @@ -52,3 +72,22 @@ In case of a private redirect, the app will be available to logged in users only ## Credits Insprired by [scith](https://github.com/scith) work. + +## Documentation and resources + +* Official app website: https://github.com/YunoHost-Apps/redirect_ynh +* YunoHost documentation for this app: https://yunohost.org/app_redirect +* Report a bug: https://github.com/YunoHost-Apps/redirect_ynh/issues + +## Developer info + +Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/redirect_ynh/tree/testing). + +To try the testing branch, please proceed like that. +``` +sudo yunohost app install https://github.com/YunoHost-Apps/redirect_ynh/tree/testing --debug +or +sudo yunohost app upgrade redirect -u https://github.com/YunoHost-Apps/redirect_ynh/tree/testing --debug +``` + +**More info regarding app packaging:** https://yunohost.org/packaging_apps \ No newline at end of file diff --git a/README_fr.md b/README_fr.md new file mode 100644 index 0000000..9bf3438 --- /dev/null +++ b/README_fr.md @@ -0,0 +1,89 @@ +# Redirect pour YunoHost + +[![Niveau d'intégration](https://dash.yunohost.org/integration/redirect.svg)](https://dash.yunohost.org/appci/app/redirect) ![](https://ci-apps.yunohost.org/ci/badges/redirect.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/redirect.maintain.svg) +[![Installer Redirect avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=redirect) + +*[Read this readme in english.](./README.md)* +*[Lire ce readme en français.](./README_fr.md)* + +> *Ce package vous permet d'installer Redirect rapidement et simplement sur un serveur YunoHost. +Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment l'installer et en profiter.* + +## Vue d'ensemble + +Créer une redirection ou un proxy vers un autre emplacement + +**Version incluse :** 1.0.0~ynh5 + + + +## Avertissements / informations importantes + +**Add a link on your user panel redirecting to another page or app, which can be protected behind your panel for some**. + +It could be an invisible redirect, an external link, another app on your local network, a reverse proxy to an app or a Docker container... Some apps can be even be protected behind your panel (meaning that you will have to log-in to access them). The only limit is your imagination - and NGINX ;). + +This app only adds a Nginx configuration file with `redirect` or `proxy_pass` rule, and a YunoHost tile. Nothing more. + +## Redirect type + +### Visible redirect + +Visitor's address bar will change. Helpfull to add a user link to another website + + you-domain.com -> another-domain.net + you-domain.com/foo -> another-domain.net/bar + +### Invisible (proxy) redirect + +Visitor's address bar will remain the same. Mostly use to serve local webserver for a personnal application. + + you-domain.com/foo -> http://172.0.0.1:8080/app + +**IMPORTANT:** the `redirect.conf` file might need to be updated according to your situation! + +**WARNING:** Many apps do not support being redirected to a different path due to relative links! This means that some apps being hosted for example on http://127.0.0.1:5050/app/ HAVE TO be redirected to http://domain.tld/app/ and NOT http://domain.tld/someotherapp/ + +*Concrete example:* the Odoo Docker container runs on http://127.0.0.1:8069/. You will not be able to redirect it to http://domain.tld/odoo/ ! You have to redirect it to the root, so for example http://odoo.domain.tld/ + +## Public or private redirect + +In case of a private redirect, the app will be available to logged in users only. This could be useful if you want to protect behind the SSO an app from your local network or from the server (e.g., a Docker container or an app that does not have user management or password protection). + +**IMPORTANT:** Make sure that the app you want to protect CANNOT be accessed by its port or another direct link. Otherwise, your app will only be protected in YunoHost but would still be available through its direct link. In the case of a Docker container, the port of the container will have to be local (e.g., -p 127.0.0.1:9000:9000). + +## Case examples + +- **Creating a tile for a Docker container** with a local port (e.g., -p 127.0.0.1:PORT:PORT): proxy redirect to http://127.0.0.1:PORT-OF-THE-CONTAINER/ + +- **Redirecting to an external website**: visible redirect to the URL + +- [CozyCloud behind YunoHost?](https://forum.cozy.io/t/cozy-cloud-sous-yunohost/616/11) + +- **Creating a tile and protecting apps that are difficult to package natively (or for prototyping)** + + +**_Feel free to [share your case examples and customized Nginx files on the forum](https://forum.yunohost.org/t/2182)._** + +## Credits + +Insprired by [scith](https://github.com/scith) work. + +## Documentations et ressources + +* Site officiel de l'app : https://github.com/YunoHost-Apps/redirect_ynh +* Documentation YunoHost pour cette app : https://yunohost.org/app_redirect +* Signaler un bug : https://github.com/YunoHost-Apps/redirect_ynh/issues + +## Informations pour les développeurs + +Merci de faire vos pull request sur la [branche testing](https://github.com/YunoHost-Apps/redirect_ynh/tree/testing). + +Pour essayer la branche testing, procédez comme suit. +``` +sudo yunohost app install https://github.com/YunoHost-Apps/redirect_ynh/tree/testing --debug +ou +sudo yunohost app upgrade redirect -u https://github.com/YunoHost-Apps/redirect_ynh/tree/testing --debug +``` + +**Plus d'infos sur le packaging d'applications :** https://yunohost.org/packaging_apps \ No newline at end of file From c65b05bacc3c537537345ccb82d40389298ad9d1 Mon Sep 17 00:00:00 2001 From: ericgaspar Date: Fri, 4 Jun 2021 16:26:34 +0200 Subject: [PATCH 13/14] Update manifest.json --- manifest.json | 8 -------- 1 file changed, 8 deletions(-) diff --git a/manifest.json b/manifest.json index 374d433..bf3ef78 100644 --- a/manifest.json +++ b/manifest.json @@ -29,19 +29,11 @@ { "name": "domain", "type": "domain", - "ask": { - "en": "Choose a domain for your redirect", - "fr": "Choisissez un domaine pour votre redirection" - }, "example": "domain.org" }, { "name": "path", "type": "path", - "ask": { - "en": "Choose a path for your redirect", - "fr": "Choisissez un chemin pour votre redirection" - }, "example": "/redirect", "default": "/redirect" }, From 21846580e861b9d0e1fd822789cef63fbaa566e6 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sun, 6 Jun 2021 17:42:43 +0200 Subject: [PATCH 14/14] Update manifest.json --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index bf3ef78..23ecefe 100644 --- a/manifest.json +++ b/manifest.json @@ -17,7 +17,7 @@ "name": "alexAubin", "email": "alex.aubin@mailoo.org" }, - "requirements": { + "requirements": { "yunohost": ">= 4.2.0" }, "multi_instance": true,