mirror of
https://github.com/YunoHost-Apps/reverseproxy_ynh.git
synced 2024-09-03 20:16:23 +02:00
Merge pull request #16 from YunoHost-Apps/fix-deprecated-practices
Fix deprecated practices
This commit is contained in:
commit
09cf1c6b98
6 changed files with 41 additions and 61 deletions
|
@ -10,8 +10,8 @@
|
||||||
"fr": "Créer une redirection ou un proxy vers un autre emplacement"
|
"fr": "Créer une redirection ou un proxy vers un autre emplacement"
|
||||||
},
|
},
|
||||||
"version": "1.0.0~ynh2",
|
"version": "1.0.0~ynh2",
|
||||||
"url": "https://github.com/YunoHost-Apps/redirect_ynh",
|
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
|
"url": "https://github.com/YunoHost-Apps/redirect_ynh",
|
||||||
"maintainer": {
|
"maintainer": {
|
||||||
"name": "opi",
|
"name": "opi",
|
||||||
"email": "opi@zeropi.net"
|
"email": "opi@zeropi.net"
|
||||||
|
@ -43,6 +43,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "redirect_path",
|
"name": "redirect_path",
|
||||||
|
"type": "string",
|
||||||
"ask": {
|
"ask": {
|
||||||
"en": "Redirect destination path",
|
"en": "Redirect destination path",
|
||||||
"fr": "Emplacement de destination"
|
"fr": "Emplacement de destination"
|
||||||
|
@ -57,6 +58,10 @@
|
||||||
"en": "Is it a public redirect?",
|
"en": "Is it a public redirect?",
|
||||||
"fr": "Est-ce une redirection publique ?"
|
"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
|
"default": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -38,8 +38,8 @@ ynh_abort_if_errors
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
# Retrieve arguments
|
# Retrieve arguments
|
||||||
domain=$(yunohost app setting $app domain)
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
|
|
||||||
# Copy the conf files
|
# Copy the conf files
|
||||||
mkdir -p ./conf
|
mkdir -p ./conf
|
||||||
cp -a "/etc/nginx/conf.d/${domain}.d/${app}.conf" ./conf/nginx.conf
|
cp -a "/etc/nginx/conf.d/${domain}.d/${app}.conf" ./conf/nginx.conf
|
||||||
|
|
|
@ -34,43 +34,39 @@ app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
# Retrieve arguments
|
# Retrieve arguments
|
||||||
domain=$YNH_APP_ARG_DOMAIN
|
domain=$YNH_APP_ARG_DOMAIN
|
||||||
path=$YNH_APP_ARG_PATH
|
path_url=$YNH_APP_ARG_PATH
|
||||||
is_public=$YNH_APP_ARG_IS_PUBLIC
|
is_public=$YNH_APP_ARG_IS_PUBLIC
|
||||||
redirect_type=$YNH_APP_ARG_REDIRECT_TYPE
|
redirect_type=$YNH_APP_ARG_REDIRECT_TYPE
|
||||||
redirect_path=$YNH_APP_ARG_REDIRECT_PATH
|
redirect_path=$YNH_APP_ARG_REDIRECT_PATH
|
||||||
|
|
||||||
# Remove trailing slash to path
|
|
||||||
path=${path%/}
|
|
||||||
#force location to be / or /foo
|
|
||||||
location=${path:-/}
|
|
||||||
|
|
||||||
# Check domain/path availability
|
# Check domain/path availability
|
||||||
yunohost app checkurl $domain$path -a $app \
|
ynh_webpath_register $app $domain $path_url
|
||||||
|| ynh_die "Path not available: $domain$path"
|
|
||||||
|
|
||||||
# Validate redirect path
|
# Validate redirect path
|
||||||
url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
|
url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
|
||||||
[[ ! $redirect_path =~ $url_regex ]] && ynh_die \
|
[[ ! $redirect_path =~ $url_regex ]] && ynh_die "Invalid destination: $redirect_path" 1
|
||||||
"Invalid destination: $redirect_path" 1
|
|
||||||
|
|
||||||
# Save extra settings
|
# Save extra settings
|
||||||
yunohost app setting $app is_public -v "$is_public"
|
ynh_app_setting_set $app is_public "$is_public"
|
||||||
yunohost app setting $app redirect_type -v "$redirect_type"
|
ynh_app_setting_set $app redirect_type "$redirect_type"
|
||||||
yunohost app setting $app redirect_path -v "$redirect_path"
|
ynh_app_setting_set $app redirect_path "$redirect_path"
|
||||||
|
|
||||||
# Nginx configuration
|
# 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" "$path_url" $FILE
|
||||||
|
done
|
||||||
if [ "$redirect_type" = "visible_302" ];
|
if [ "$redirect_type" = "visible_302" ];
|
||||||
then
|
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
|
cp ../conf/nginx-visible-302.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||||
elif [ "$redirect_type" = "visible_301" ];
|
elif [ "$redirect_type" = "visible_301" ];
|
||||||
then
|
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
|
cp ../conf/nginx-visible-301.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||||
elif [ "$redirect_type" = "proxy" ];
|
elif [ "$redirect_type" = "proxy" ];
|
||||||
then
|
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
|
cp ../conf/nginx-proxy.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -78,12 +74,12 @@ fi
|
||||||
# SETUP SSOWAT
|
# SETUP SSOWAT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
if [[ "$is_public" -eq 0 ]]
|
if [ $is_public -eq 0 ]
|
||||||
then # Remove the public access
|
then # Remove the public access
|
||||||
ynh_app_setting_delete "$app" skipped_uris
|
ynh_app_setting_delete "$app" skipped_uris
|
||||||
fi
|
fi
|
||||||
# Make app public if necessary
|
# Make app public if necessary
|
||||||
if [[ "$is_public" -eq 1 ]]
|
if [ $is_public -eq 1 ]
|
||||||
then
|
then
|
||||||
# unprotected_uris allows SSO credentials to be passed anyway.
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
||||||
ynh_app_setting_set "$app" unprotected_uris "/"
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
||||||
|
@ -92,4 +88,3 @@ fi
|
||||||
|
|
||||||
# Reload Nginx and regenerate SSOwat conf
|
# Reload Nginx and regenerate SSOwat conf
|
||||||
service nginx reload
|
service nginx reload
|
||||||
yunohost app ssowatconf
|
|
||||||
|
|
|
@ -26,11 +26,10 @@ source /usr/share/yunohost/helpers
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
# Retrieve arguments
|
# Retrieve arguments
|
||||||
domain=$(yunohost app setting $app domain)
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
|
|
||||||
# Remove configuration files
|
# 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
|
# Restart services
|
||||||
service nginx reload
|
service nginx reload
|
||||||
yunohost app ssowatconf
|
|
||||||
|
|
|
@ -39,28 +39,18 @@ app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
# Retrieve arguments
|
# Retrieve arguments
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
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)
|
is_public=$(ynh_app_setting_get "$app" is_public)
|
||||||
redirect_type=$(ynh_app_setting_get "$app" redirect_type)
|
redirect_type=$(ynh_app_setting_get "$app" redirect_type)
|
||||||
redirect_path=$(ynh_app_setting_get "$app" redirect_path)
|
redirect_path=$(ynh_app_setting_get "$app" redirect_path)
|
||||||
|
|
||||||
# Remove trailing slash to 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."
|
|
||||||
|
|
||||||
# Validate redirect path
|
# Validate redirect path
|
||||||
url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
|
url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
|
||||||
[[ ! $redirect_path =~ $url_regex ]] && ynh_die \
|
[[ ! $redirect_path =~ $url_regex ]] && ynh_die "Invalid destination: $redirect_path" 1
|
||||||
"Invalid destination: $redirect_path" 1
|
|
||||||
|
|
||||||
# Check configuration files
|
# Check configuration files
|
||||||
NGINX_CONF="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
NGINX_CONF="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
||||||
[[ -f $NGINX_CONF ]] && die \
|
[[ -f $NGINX_CONF ]] && ynh_die "The NGINX configuration already exists at '${NGINX_CONF}'. You should safely delete it before restoring this app."
|
||||||
"The NGINX configuration already exists at '${NGINX_CONF}'.
|
|
||||||
You should safely delete it before restoring this app."
|
|
||||||
|
|
||||||
# Restore configuration files
|
# Restore configuration files
|
||||||
cp -a ./conf/nginx.conf "$NGINX_CONF"
|
cp -a ./conf/nginx.conf "$NGINX_CONF"
|
||||||
|
@ -69,12 +59,12 @@ cp -a ./conf/nginx.conf "$NGINX_CONF"
|
||||||
# SETUP SSOWAT
|
# SETUP SSOWAT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
if [[ "$is_public" -eq 0 ]]
|
if [ "$is_public" -eq 0 ]
|
||||||
then # Remove the public access
|
then # Remove the public access
|
||||||
ynh_app_setting_delete "$app" skipped_uris
|
ynh_app_setting_delete "$app" skipped_uris
|
||||||
fi
|
fi
|
||||||
# Make app public if necessary
|
# Make app public if necessary
|
||||||
if [[ "$is_public" -eq 1 ]]
|
if [ "$is_public" -eq 1 ]
|
||||||
then
|
then
|
||||||
# unprotected_uris allows SSO credentials to be passed anyway.
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
||||||
ynh_app_setting_set "$app" unprotected_uris "/"
|
ynh_app_setting_set "$app" unprotected_uris "/"
|
||||||
|
@ -82,4 +72,3 @@ fi
|
||||||
|
|
||||||
# Reload Nginx and regenerate SSOwat conf
|
# Reload Nginx and regenerate SSOwat conf
|
||||||
service nginx reload
|
service nginx reload
|
||||||
yunohost app ssowatconf
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
# Retrieve arguments
|
# Retrieve arguments
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
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)
|
is_public=$(ynh_app_setting_get "$app" is_public)
|
||||||
redirect_type=$(ynh_app_setting_get "$app" redirect_type)
|
redirect_type=$(ynh_app_setting_get "$app" redirect_type)
|
||||||
redirect_path=$(ynh_app_setting_get "$app" redirect_path)
|
redirect_path=$(ynh_app_setting_get "$app" redirect_path)
|
||||||
|
@ -69,33 +69,26 @@ ynh_clean_setup () {
|
||||||
# Exit if an error occurs during the execution of the script
|
# Exit if an error occurs during the execution of the script
|
||||||
ynh_abort_if_errors
|
ynh_abort_if_errors
|
||||||
|
|
||||||
# Remove trailing slash to path
|
|
||||||
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
|
# Validate redirect path
|
||||||
url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
|
url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
|
||||||
[[ ! $redirect_path =~ $url_regex ]] && ynh_die \
|
[[ ! $redirect_path =~ $url_regex ]] && ynh_die "Invalid destination: $redirect_path" 1
|
||||||
"Invalid destination: $redirect_path" 1
|
|
||||||
|
|
||||||
# Nginx configuration
|
# 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" "$path_url" $FILE
|
||||||
|
done
|
||||||
if [ "$redirect_type" = "visible_302" ];
|
if [ "$redirect_type" = "visible_302" ];
|
||||||
then
|
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
|
cp ../conf/nginx-visible-302.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||||
elif [ "$redirect_type" = "visible_301" ];
|
elif [ "$redirect_type" = "visible_301" ];
|
||||||
then
|
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
|
cp ../conf/nginx-visible-301.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||||
elif [ "$redirect_type" = "proxy" ];
|
elif [ "$redirect_type" = "proxy" ];
|
||||||
then
|
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
|
cp ../conf/nginx-proxy.conf /etc/nginx/conf.d/$domain.d/$app.conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -103,12 +96,12 @@ fi
|
||||||
# SETUP SSOWAT
|
# SETUP SSOWAT
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
if [[ "$is_public" -eq 0 ]]
|
if [ "$is_public" -eq 0 ]
|
||||||
then # Remove the public access
|
then # Remove the public access
|
||||||
ynh_app_setting_delete "$app" skipped_uris
|
ynh_app_setting_delete "$app" skipped_uris
|
||||||
fi
|
fi
|
||||||
# Make app public if necessary
|
# Make app public if necessary
|
||||||
if [[ "$is_public" -eq 1 ]]
|
if [ "$is_public" -eq 1 ]
|
||||||
then
|
then
|
||||||
# unprotected_uris allows SSO credentials to be passed anyway.
|
# unprotected_uris allows SSO credentials to be passed anyway.
|
||||||
ynh_app_setting_set "$app" unprotected_uris -v "/"
|
ynh_app_setting_set "$app" unprotected_uris -v "/"
|
||||||
|
@ -116,4 +109,3 @@ fi
|
||||||
|
|
||||||
# Reload Nginx and regenerate SSOwat conf
|
# Reload Nginx and regenerate SSOwat conf
|
||||||
service nginx reload
|
service nginx reload
|
||||||
yunohost app ssowatconf
|
|
||||||
|
|
Loading…
Reference in a new issue