From 1211690d064225ba2766732f66769c6ce5491f2b Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Mon, 27 Feb 2012 01:33:58 +0200 Subject: [PATCH] mail api 50% completed --- bin/v_change_mail_domain_cactchall | 75 ++++++++++++++ bin/v_delete_mail_domain_cactchall | 76 +++++++++++++++ bin/v_list_mail_domain | 2 +- bin/v_rebuild_mail_domains | 152 +++++++++++++++++++++++++++++ 4 files changed, 304 insertions(+), 1 deletion(-) create mode 100755 bin/v_change_mail_domain_cactchall create mode 100755 bin/v_delete_mail_domain_cactchall create mode 100755 bin/v_rebuild_mail_domains diff --git a/bin/v_change_mail_domain_cactchall b/bin/v_change_mail_domain_cactchall new file mode 100755 index 00000000..19159e0e --- /dev/null +++ b/bin/v_change_mail_domain_cactchall @@ -0,0 +1,75 @@ +#!/bin/bash +# info: change mail domain catchall email +# options: user domain email +# +# The function changes mail domain cathcall. + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +user=$1 +domain=$(idn -t --quiet -u "$2" ) +domain=$(echo $domain | tr '[:upper:]' '[:lower:]') +domain_idn=$(idn -t --quiet -a "$domain") +email="$3" + +# Importing variables +source $VESTA/conf/vars.conf +source $V_CONF/vesta.conf +source $V_FUNC/shared.func +source $V_FUNC/domain.func + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + +# Checking arg number +check_args '3' "$#" 'user domain email' + +# Checking argument format +format_validation 'user' 'domain' 'email' + +# Checking dns system is enabled +is_system_enabled 'MAIL_SYSTEM' + +# Checking user +is_user_valid + +# Checking user is active +is_user_suspended + +# Checking domain +is_domain_valid 'mail' + +# Checking domain is not suspened +is_domain_suspended 'mail' + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Get old catchall +catchall=$(get_domain_value 'mail' '$CATCHALL') + +# Change cathcall alias +sed -i "/*@demo.vestacp.com:/d" $V_HOME/$user/conf/mail/$domain/aliases +echo "*@demo.vestacp.com:$email" >> $V_HOME/$user/conf/mail/$domain/aliases + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Change catchall in config +update_domain_value 'mail' '$CATCHALL' "$email" + +# Logging +log_history "$V_EVENT" "v_change_mail_domain_catchall $user $domain $catchall" +log_event 'system' "$V_EVENT" + +exit diff --git a/bin/v_delete_mail_domain_cactchall b/bin/v_delete_mail_domain_cactchall new file mode 100755 index 00000000..90611390 --- /dev/null +++ b/bin/v_delete_mail_domain_cactchall @@ -0,0 +1,76 @@ +#!/bin/bash +# info: delete mail domain catchall email +# options: user domain +# +# The function disables mail domain cathcall. + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +user=$1 +domain=$(idn -t --quiet -u "$2" ) +domain=$(echo $domain | tr '[:upper:]' '[:lower:]') +domain_idn=$(idn -t --quiet -a "$domain") + +# Importing variables +source $VESTA/conf/vars.conf +source $V_CONF/vesta.conf +source $V_FUNC/shared.func +source $V_FUNC/domain.func + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + +# Checking arg number +check_args '2' "$#" 'user domain' + +# Checking argument format +format_validation 'user' 'domain' + +# Checking dns system is enabled +is_system_enabled 'MAIL_SYSTEM' + +# Checking user +is_user_valid + +# Checking user is active +is_user_suspended + +# Checking domain +is_domain_valid 'mail' + +# Checking domain is not suspened +is_domain_suspended 'mail' + +# Checking current value +is_domain_value_exist 'mail' '$CATCHALL' + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Get old catchall +email=$(get_domain_value 'mail' '$CATCHALL') + +# Delete cathcall alias +sed -i "/*@demo.vestacp.com:/d" $V_HOME/$user/conf/mail/$domain/aliases + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Delete catchall in config +update_domain_value 'mail' '$CATCHALL' '' + +# Logging +log_history "$V_EVENT" "v_add_mail_domain_catchall $user $domain $email" +log_event 'system' "$V_EVENT" + +exit diff --git a/bin/v_list_mail_domain b/bin/v_list_mail_domain index 419544ed..d755e1ce 100755 --- a/bin/v_list_mail_domain +++ b/bin/v_list_mail_domain @@ -85,7 +85,7 @@ check_args '2' "$#" 'user domain [format]' is_user_valid # Checking domain exist -is_domain_valid 'web' +is_domain_valid 'mail' #----------------------------------------------------------# diff --git a/bin/v_rebuild_mail_domains b/bin/v_rebuild_mail_domains new file mode 100755 index 00000000..fc6d2cc7 --- /dev/null +++ b/bin/v_rebuild_mail_domains @@ -0,0 +1,152 @@ +#!/bin/bash +# info: rebuild mail domains +# options: user +# +# The function rebuilds EXIM configuration files for all mail domains. + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +user=$1 + +# Importing variables +source $VESTA/conf/vars.conf +source $V_CONF/vesta.conf +source $V_FUNC/shared.func +source $V_FUNC/domain.func + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + +# Checking arg number +check_args '1' "$#" 'user' + +# Checking argument format +format_validation 'user' + +# Checking mail system is enabled +is_system_enabled 'MAIL_SYSTEM' + +# Checking user +is_user_valid + +# Checking user is active +is_user_suspended + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Reset counters +U_MAIL_DOMAINS='0' +U_MAIL_ACCOUNTS='0' +SUSPENDED_MAIL='0' +U_DISK_MAIL='0' + +# Checking mail folder +if [ ! -d "$V_USERS/$user/mail" ]; then + rm -f $V_USERS/$user/mail + mkdir $V_USERS/$user/mail +fi + +# Defining config +conf="$V_USERS/$user/mail.conf" +search_string="DOMAIN" +field='$DOMAIN' +domains=$(dom_clear_search) + +# Starting loop +for domain in $domains; do + + # Defining variables + get_domain_values 'mail' + + # Rebuilding config structure + mkdir -p $V_HOME/$user/conf/mail/$domain + rm -f $V_HOME/$user/conf/mail/$domain/aliases + rm -f $V_HOME/$user/conf/mail/$domain/protection + rm -f $V_HOME/$user/conf/mail/$domain/passwd + touch $V_HOME/$user/conf/mail/$domain/aliases + touch $V_HOME/$user/conf/mail/$domain/protection + touch $V_HOME/$user/conf/mail/$domain/passwd + chown -R root:mail $V_HOME/$user/conf/mail/$domain + chmod 770 $V_HOME/$user/conf/mail/$domain + chmod 660 $V_HOME/$user/conf/mail/$domain* + + # Adding antispam protection + if [ "$ANTISPAM" = 'yes' ]; then + echo 'antispam' >> $V_HOME/$user/conf/mail/$domain/protection + fi + + # Adding antivirus protection + if [ "$ANTIVIRUS" = 'yes' ]; then + echo 'antivirus' >> $V_HOME/$user/conf/mail/$domain/protection + fi + + # Adding dkim + if [ "$DKIM" = 'yes' ]; then + pem="$V_USERS/$user/mail/$domain.pem" + pub="$V_USERS/$user/mail/$domain.pub" + openssl genrsa -out $pem 512 2>/dev/null + openssl rsa -pubout -in $pem -out $pub 2>/dev/null + chmod 660 $V_USERS/$user/mail/$domain.* + + cp $pem $V_HOME/$user/conf/mail/$domain/dkim.pem + chown root:mail $V_HOME/$user/conf/mail/$domain/dkim.pem + chmod 660 $V_HOME/$user/conf/mail/$domain/dkim.pem + + # Deleting old dkim records + records=$($V_BIN/v_list_dns_domain_records $user $domain plain) + dkim_records=$(echo "$records" |grep -w '_domainkey'|cut -f 1 -d ' ') + for id in $dkim_records; do + $V_BIN/v_delete_dns_domain_record $user $domain $id + done + + # Adding dkim dns records + check_dns_domain=$(is_domain_valid 'dns') + if [ "$?" -eq 0 ]; then + p=$(cat $pub|grep -v ' KEY---'|tr -d '\n') + record='_domainkey' + policy="\"t=y; o=~;\"" + $V_BIN/v_add_dns_domain_record $user $domain $record TXT "$policy" + + record='mail._domainkey' + slct="\"k=rsa\; p=$p\"" + $V_BIN/v_add_dns_domain_record $user $domain $record TXT "$slct" + fi + fi + + # Rebuild counters + U_MAIL_DOMAINS=$((U_MAIL_DOMAINS + 1)) + U_DISK_MAIL=$((U_DISK_MAIL + U_DISK)) +done + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Updating counters +U_MAIL_DOMAINS='0' +U_MAIL_ACCOUNTS='0' +SUSPENDED_MAIL='0' +U_DISK_MAIL='0' + +update_user_value "$user" '$U_MAIL_DOMAINS' "$U_MAIL_DOMAINS" +update_user_value "$user" '$U_MAIL_ACCOUNTS' "$U_MAIL_ACCOUNTS" +update_user_value "$user" '$SUSPENDED_MAIL' "$SUSPENDED_MAIL" +update_user_value "$user" '$U_DISK_MAIL' "$U_DISK_MAIL" + +# Adding task to the vesta pipe +restart_schedule 'mail' + +# Logging +log_event 'system' "$V_EVENT" + +exit