| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- #!/bin/bash
- # info: add webmail support for a domain
- # options: USER DOMAIN WEBMAIL [RESTART] [QUIET]
- # labels: hestia
- #
- # example: v-add-sys-webmail user domain.com
- #
- # this function adds support for webmail services
- # to a mail domain.
- #----------------------------------------------------------#
- # Variable&Function #
- #----------------------------------------------------------#
- # Argument definition
- user=$1
- domain=$2
- webmail=$3
- restart="$4"
- quiet=$5
- # Additional argument formatting
- if [[ "$domain" =~ [[:upper:]] ]]; then
- domain=$(echo "$domain" |tr '[:upper:]' '[:lower:]')
- fi
- if [[ "$domain" =~ ^www\..* ]]; then
- domain=$(echo "$domain" |sed -e "s/^www.//")
- fi
- if [[ "$domain" =~ .*\.$ ]]; then
- domain=$(echo "$domain" |sed -e "s/\.$//")
- fi
- domain_idn=$(idn -t --quiet -a "$domain")
- # Includes
- source $HESTIA/func/main.sh
- source $HESTIA/func/domain.sh
- source $HESTIA/func/ip.sh
- source $HESTIA/conf/hestia.conf
- # Additional argument formatting
- format_domain
- format_domain_idn
- #----------------------------------------------------------#
- # Verifications #
- #----------------------------------------------------------#
- if [ -z "$webmail" ]; then
- for client in ${WEBMAIL_SYSTEM//,/ };do
- webmail="$client"
- done
- fi
- check_args '3' "$#" 'USER DOMAIN WEBMAIL [RESTART]'
- is_format_valid 'user' 'domain'
- is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
- is_system_enabled "$IMAP_SYSTEM" 'IMAP_SYSTEM'
- is_type_valid "$WEBMAIL_SYSTEM" "$webmail"
- is_object_valid 'user' 'USER' "$user"
- is_object_unsuspended 'user' 'USER' "$user"
- is_object_valid 'mail' 'DOMAIN' "$domain"
- is_object_unsuspended 'mail' 'DOMAIN' "$domain"
- # Perform verification if read-only mode is enabled
- check_hestia_demo_mode
- #----------------------------------------------------------#
- # Action #
- #----------------------------------------------------------#
- # Inherit web domain local ip address
- domain_ip=$(get_object_value 'web' 'DOMAIN' "$domain" '$IP')
- if [ ! -z "$domain_ip" ]; then
- local_ip=$(get_real_ip "$domain_ip")
- is_ip_valid "$local_ip" "$user"
- ip=$local_ip
- nat_ip=$(get_ip_value '$NAT')
- if [ ! -z "$nat_ip" ]; then
- ip=$nat_ip
- fi
- else
- get_user_ip
- fi
- # Verify that webmail alias variable exists and create it if it does not
- if [ -z "$WEBMAIL_ALIAS" ]; then
- $BIN/v-change-sys-config-value 'WEBMAIL_ALIAS' "webmail"
- else
- # Ensure DNS record exists if Hestia is hosting DNS zones
- if [ ! -z "$DNS_SYSTEM" ]; then
- dns_domain=$($BIN/v-list-dns-domains $user | grep $domain | cut -d' ' -f1)
- webmail_record=$($BIN/v-list-dns-records $user $domain | grep -i $WEBMAIL_ALIAS | cut -d' ' -f1)
- if [ "$dns_domain" = "$domain" ]; then
- if [ -z "$webmail_record" ]; then
- $BIN/v-add-dns-record $user $domain $WEBMAIL_ALIAS A $ip
- else
- $BIN/v-delete-dns-record $user $domain $webmail_record
- $BIN/v-add-dns-record $user $domain $WEBMAIL_ALIAS A $ip
- fi
- fi
- fi
-
- if [ "$webmail" == "roundcube" ]; then
- WEBMAIL_TEMPLATE="default"
- if [ ! -z "$PROXY_SYSTEM" ]; then
- PROXY_TEMPLATE="default"
- fi
- # Add webmail configuration to mail domain
- WEBMAIL_TEMPLATE="default"
- if [ "$WEB_SYSTEM" = "nginx" ]; then
- WEBMAIL_TEMPLATE="web_system"
- fi
- else
- WEBMAIL_TEMPLATE="rainloop"
- if [ ! -z "$PROXY_SYSTEM" ]; then
- PROXY_TEMPLATE="default_rainloop"
- fi
- fi
-
- add_webmail_config "$WEB_SYSTEM" "${WEBMAIL_TEMPLATE}.tpl"
- if [ ! -z "$PROXY_SYSTEM" ]; then
- add_webmail_config "$PROXY_SYSTEM" "${PROXY_TEMPLATE}.tpl"
- fi
- # Enable SSL for webmail if available
- if [ -f $HOMEDIR/$user/conf/mail/$domain/ssl/$domain.crt ] || [ "$SSL" = 'yes' ]; then
- add_webmail_config "$WEB_SYSTEM" "${WEBMAIL_TEMPLATE}.stpl"
- if [ ! -z "$PROXY_SYSTEM" ]; then
- add_webmail_config "$PROXY_SYSTEM" "${PROXY_TEMPLATE}.stpl"
- fi
- fi
- fi
- WEBMAIL=$(get_object_value 'web' 'DOMAIN' "$domain" "$WEBMAIL")
- if [ -z "$WEBMAIL" ]; then
- add_object_key 'mail' 'DOMAIN' "$domain" 'WEBMAIL' 'SSL'
- fi
- # Set SSL as enabled in configuration
- update_object_value 'mail' 'DOMAIN' "$domain" '$WEBMAIL' "$webmail"
- #----------------------------------------------------------#
- # Hestia #
- #----------------------------------------------------------#
- if [ "$restart" = 'yes' ]; then
- # Restarting web server
- $BIN/v-restart-web $restart
- check_result $? "Web restart failed" >/dev/null
- $BIN/v-restart-proxy $restart
- check_result $? "Proxy restart failed" >/dev/null
- fi
- # Logging
- if [ "$quiet" != 'yes' ]; then
- log_history "enabled webmail support for $domain"
- fi
- log_event "$OK" "$ARGUMENTS"
- exit
|