1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/sogo_ynh.git synced 2024-09-03 20:26:07 +02:00
sogo_ynh/scripts/_common.sh

92 lines
2.9 KiB
Bash
Raw Normal View History

2018-08-14 22:18:22 +02:00
#!/bin/bash
#=================================================
2024-01-30 23:33:35 +01:00
# COMMON VARIABLES
2018-08-14 22:18:22 +02:00
#=================================================
#=================================================
2024-01-30 23:33:35 +01:00
# PERSONAL HELPERS
2018-08-14 22:18:22 +02:00
#=================================================
config_nginx() {
2024-01-30 23:33:35 +01:00
nginx_config="$YNH_APP_BASEDIR/conf/nginx.conf"
2018-08-14 22:18:22 +02:00
2024-01-30 23:33:35 +01:00
# shellcheck disable=SC2016
principals_block='
# For IOS 7
2018-08-14 22:18:22 +02:00
location = /principals/ {
2024-01-30 23:52:55 +01:00
rewrite ^ https://$server_name/SOGo/dav;
2018-08-14 22:18:22 +02:00
allow all;
2024-01-30 23:33:35 +01:00
}'
# shellcheck disable=SC2016
activesync_block='
# For ActiveSync
2018-08-14 22:18:22 +02:00
location /Microsoft-Server-ActiveSync/ {
2024-01-30 23:52:55 +01:00
proxy_pass http://127.0.0.1:__PORT__/SOGo/Microsoft-Server-ActiveSync/;
2024-01-30 23:33:35 +01:00
}'
# shellcheck disable=SC2016
caldav_block='
# For Caldav
location /.well-known/caldav {
2024-01-30 23:52:55 +01:00
rewrite ^ https://$server_name/SOGo/dav/;
2024-01-30 23:33:35 +01:00
}'
# shellcheck disable=SC2016
carddav_block='
# For Carddav
location /.well-known/carddav {
2024-01-30 23:52:55 +01:00
rewrite ^ https://$server_name/SOGo/dav/;
2024-01-30 23:33:35 +01:00
}'
if ! is_url_handled -d "$domain" -p "/principals"; then
echo "$principals_block" >> "$nginx_config"
fi
if ! is_url_handled -d "$domain" -p "/Microsoft-Server-ActiveSync"; then
echo "$activesync_block" >> "$nginx_config"
fi
if ! is_url_handled -d "$domain" -p "/.well-known/caldav"; then
echo "$caldav_block" >> "$nginx_config"
fi
if ! is_url_handled -d "$domain" -p "/.wellk-nown/carddav"; then
echo "$carddav_block" >> "$nginx_config"
fi
ynh_add_nginx_config
2019-01-29 09:19:08 +01:00
}
2024-01-30 23:33:35 +01:00
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
2018-08-14 22:18:22 +02:00
2024-01-30 23:33:35 +01:00
is_url_handled() {
# Declare an array to define the options of this helper.
local legacy_args=dp
declare -Ar args_array=( [d]=domain= [p]=path= )
local domain
local path
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
2018-08-14 22:18:22 +02:00
2024-01-30 23:33:35 +01:00
# Try to get the url with curl, and keep the http code and an eventual redirection url.
local curl_output="$(curl --insecure --silent --output /dev/null \
--write-out '%{http_code};%{redirect_url}' https://127.0.0.1$path --header "Host: $domain" --resolve $domain:443:127.0.0.1)"
# Cut the output and keep only the first part to keep the http code
local http_code="${curl_output%%;*}"
# Do the same thing but keep the second part, the redirection url
local redirection="${curl_output#*;}"
# Return 1 if the url isn't handled.
# Which means either curl got a 404 (or the admin) or the sso.
# A handled url should redirect to a publicly accessible url.
# Return 1 if the url has returned 404
if [ "$http_code" = "404" ] || [[ $redirection =~ "/yunohost/admin" ]]; then
return 1
# Return 1 if the url is redirected to the SSO
elif [[ $redirection =~ "/yunohost/sso" ]]; then
return 1
fi
}
2024-01-30 23:33:35 +01:00
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================