diff --git a/scripts/_common.sh b/scripts/_common.sh new file mode 100644 index 0000000..dee0ea0 --- /dev/null +++ b/scripts/_common.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +#================================================= +# COMMON VARIABLES +#================================================= + +#================================================= +# PERSONAL HELPERS +#================================================= + +URL_REGEX_VALID='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]' +URL_REGEX_SECURE='^(http://(127\.[0-9]+\.[0-9]+\.[0-9]+|localhost)|https://.*)(:[0-9]+)?(/.*)?$' + +_validate_redirect_uri() { + if [[ ! $target =~ $URL_REGEX_VALID ]]; then + ynh_die "Invalid destination: $target" 1 + fi + + # Avoid uncrypted remote destination with reverse proxy mode + # Indeed the SSO send the password in all requests in HTTP headers + if [[ "$redirect_type" = "proxy" ]] && [[ ! $target =~ $URL_REGEX_SECURE ]]; then + ynh_die "For secure reason, you can't use an unencrypted http remote destination couple with ssowat for your reverse proxy: $target" 1 + fi +} + +#================================================= +# EXPERIMENTAL HELPERS +#================================================= + +#================================================= +# FUTURE OFFICIAL HELPERS +#================================================= diff --git a/scripts/install b/scripts/install index 979fcfd..351e62d 100644 --- a/scripts/install +++ b/scripts/install @@ -6,20 +6,17 @@ # IMPORT GENERIC HELPERS #================================================= +source _common.sh source /usr/share/yunohost/helpers -# Avoid uncrypted remote destination with reverse proxy mode -# Indeed the SSO send the password in all requests in HTTP headers -url_regex='^(http://(127\.[0-9]+\.[0-9]+\.[0-9]+|localhost)|https://.*)(:[0-9]+)?(/.*)?$' -[[ "$redirect_type" = "reverseproxy" ]] && [[ ! "$target" =~ $url_regex ]] && ynh_die \ -"For secure reason, you can't use an unencrypted http remote destination coupled with ssowat for your reverse proxy: $target" 1 +_validate_redirect_uri #================================================= # CONFIGURE NGINX #================================================= ynh_script_progression --message="Configuring NGINX web server..." --weight=1 -mv ../conf/{nginx-$redirect_type.conf,nginx.conf} +mv ../conf/{"nginx-$redirect_type.conf",nginx.conf} ynh_add_nginx_config #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 3605880..639b139 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,5 +1,6 @@ #!/bin/bash +source _common.sh source /usr/share/yunohost/helpers #=================================================