From 62e5d3dc30700b37179e50eeac89704c8c4abe37 Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Wed, 29 Feb 2012 15:23:19 +0200 Subject: [PATCH] mail api 60% completed --- bin/v_add_mail_domain | 3 ++ bin/v_delete_mail_domain | 80 ++++++++++++++++++++++++++++++++++++ bin/v_rebuild_mail_domains | 11 +++++ bin/v_suspend_mail_domain | 69 +++++++++++++++++++++++++++++++ bin/v_suspend_mail_domains | 64 +++++++++++++++++++++++++++++ bin/v_unsuspend_mail_domain | 69 +++++++++++++++++++++++++++++++ bin/v_unsuspend_mail_domains | 69 +++++++++++++++++++++++++++++++ 7 files changed, 365 insertions(+) create mode 100755 bin/v_delete_mail_domain create mode 100755 bin/v_suspend_mail_domain create mode 100755 bin/v_suspend_mail_domains create mode 100755 bin/v_unsuspend_mail_domain create mode 100755 bin/v_unsuspend_mail_domains diff --git a/bin/v_add_mail_domain b/bin/v_add_mail_domain index cbdffa2d..a45e744c 100755 --- a/bin/v_add_mail_domain +++ b/bin/v_add_mail_domain @@ -64,6 +64,9 @@ 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* +mkdir $V_HOME/$user/mail/$domain +chown $user:mail $V_HOME/$user/mail/$domain +chmod 770 $V_HOME/$user/mail/$domain # Adding symlink ln -s $V_HOME/$user/conf/mail/$domain /etc/exim/domains/ diff --git a/bin/v_delete_mail_domain b/bin/v_delete_mail_domain new file mode 100755 index 00000000..4f388314 --- /dev/null +++ b/bin/v_delete_mail_domain @@ -0,0 +1,80 @@ +#!/bin/bash +# info: delete mail domain +# options: user domain +# +# The function for deleting MAIL domain. By deleting it all accounts will +# also be deleted. + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +user=$1 +domain=$(idn -t --quiet -u "$2" ) + +# 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 web system is enabled +is_system_enabled 'MAIL_SYSTEM' + +# Checking user +is_user_valid + +# Checking user is active +is_user_suspended + +# Checking domain exist +is_domain_valid 'mail' + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Get domain values +get_domain_values 'mail' +accounts=$(wc -l $V_USERS/$user/mail/$domain|cut -f 1 -d ' ') + +rm -f /etc/exim/domains/$domain +rm -rf $V_HOME/$user/conf/$domain +rm -rf $V_HOME/$user/mail/$domain + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Delete domain config +sed -i "/DOMAIN='$domain'/ d" $V_USERS/$user/mail.conf +rm -f $V_USERS/$user/mail/$domain +rm -f $V_USERS/$user/mail/$domain.pem +rm -f $V_USERS/$user/mail/$domain.pub +# autoreply + +# Decreasing domain value +decrease_user_value "$user" '$U_MAIL_DOMAINS' +decrease_user_value "$user" '$U_MAIL_ACCOUNTS' "$accounts" + +# Logging +cmd='"v_add_mail_domain' +log_history "$V_EVENT" "$cmd $user $domain $ANTISPAM $ANTIVIRUS $DKIM" +log_event 'system' "$V_EVENT" + +exit diff --git a/bin/v_rebuild_mail_domains b/bin/v_rebuild_mail_domains index fc6d2cc7..a540486d 100755 --- a/bin/v_rebuild_mail_domains +++ b/bin/v_rebuild_mail_domains @@ -122,6 +122,17 @@ for domain in $domains; do fi fi + # Adding antispam protection + if [ "$SUSPENDED" != 'yes' ]; then + ln -s $V_HOME/$user/conf/mail/$domain /etc/exim/domains/ + fi + + if [ ! -e $V_HOME/$user/mail/$domain ]; then + mkdir $V_HOME/$user/mail/$domain + fi + chown $user:mail $V_HOME/$user/mail/$domain + chmod 770 $V_HOME/$user/mail/$domain + # Rebuild counters U_MAIL_DOMAINS=$((U_MAIL_DOMAINS + 1)) U_DISK_MAIL=$((U_DISK_MAIL + U_DISK)) diff --git a/bin/v_suspend_mail_domain b/bin/v_suspend_mail_domain new file mode 100755 index 00000000..daae4ea2 --- /dev/null +++ b/bin/v_suspend_mail_domain @@ -0,0 +1,69 @@ +#!/bin/bash +# info: suspend mail domain +# options: user domain +# +# The function suspends mail domain. + + +#----------------------------------------------------------# +# 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' + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Deleting symbolic link +rm -f /etc/exim/domains/$domain + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Updating config +update_domain_value 'mail' '$SUSPENDED' 'yes' + +# Logging +log_event 'system' "$V_EVENT" + +exit diff --git a/bin/v_suspend_mail_domains b/bin/v_suspend_mail_domains new file mode 100755 index 00000000..ee9cbbee --- /dev/null +++ b/bin/v_suspend_mail_domains @@ -0,0 +1,64 @@ +#!/bin/bash +# info: suspend mail domains +# options: user +# +# The function suspends all user's 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 dns system is enabled +is_system_enabled 'MAIL_SYSTEM' + +# Checking user +is_user_valid + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Defining config +conf="$V_USERS/$user/mail.conf" + +# Defining fileds to select +field='$DOMAIN' +search_string="SUSPENDED='no'" +domains=$(dom_clear_search) + +# Starting suspend loop +for domain in $domains; do + $V_BIN/v_suspend_mail_domain "$user" "$domain" +done + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Logging +log_event 'system' "$V_EVENT" + +exit diff --git a/bin/v_unsuspend_mail_domain b/bin/v_unsuspend_mail_domain new file mode 100755 index 00000000..5e836ae7 --- /dev/null +++ b/bin/v_unsuspend_mail_domain @@ -0,0 +1,69 @@ +#!/bin/bash +# info: unsuspend mail domain +# options: user domain +# +# The function unsuspends mail domain. + + +#----------------------------------------------------------# +# 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_value_exist 'mail' '$SUSPENDED' + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Add symbolic link +ln -s $V_HOME/$user/conf/mail/$domain /etc/exim/domains/ + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Updating config +update_domain_value 'mail' '$SUSPENDED' 'no' + +# Logging +log_event 'system' "$V_EVENT" + +exit diff --git a/bin/v_unsuspend_mail_domains b/bin/v_unsuspend_mail_domains new file mode 100755 index 00000000..3957219d --- /dev/null +++ b/bin/v_unsuspend_mail_domains @@ -0,0 +1,69 @@ +#!/bin/bash +# info: unsuspend mail domains +# options: user +# +# The function unsuspends all user's 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 dns system is enabled +is_system_enabled 'MAIL_SYSTEM' + +# Checking user +is_user_valid + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Defining config +conf="$V_USERS/$user/mail.conf" + +# Defining fileds to select +field='$DOMAIN' + +# Defining search string +search_string="SUSPENDED='yes'" + +# Parsing suspeneded domains +domains=$(dom_clear_search) + + +# Starting unsuspend loop +for domain in $domains; do + $V_BIN/v_unsuspend_mail_domain "$user" "$domain" +done + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Logging +log_event 'system' "$V_EVENT" + +exit