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-02-23 00:21:58 +01:00
|
|
|
nginx_config="/etc/nginx/conf.d/$domain/$app.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
|
2019-02-08 10:21:19 +01:00
|
|
|
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
|
2019-02-08 10:21:19 +01:00
|
|
|
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
|
|
|
}'
|
|
|
|
|
2024-02-23 00:21:58 +01:00
|
|
|
ynh_add_nginx_config
|
|
|
|
|
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
|
2024-02-23 00:21:58 +01:00
|
|
|
ynh_store_file_checksum --file="$nginx_config"
|
|
|
|
systemctl reload nginx.service
|
|
|
|
}
|
|
|
|
|
|
|
|
set_permissions() {
|
|
|
|
chown -R "$app:$app" "/etc/$app"
|
|
|
|
chmod -R u=rwX,g=rX,o= "/etc/$app"
|
|
|
|
|
|
|
|
chown -R "$app:$app" "/var/log/$app"
|
|
|
|
chmod -R u=rwX,g=rX,o= "/var/log/$app"
|
|
|
|
|
|
|
|
chown root: "/etc/cron.d/$app"
|
|
|
|
chmod 644 "/etc/cron.d/$app"
|
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
|
2018-08-31 14:34:25 +02:00
|
|
|
}
|
2024-01-30 23:33:35 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# FUTURE OFFICIAL HELPERS
|
|
|
|
#=================================================
|