mirror of
https://github.com/myvesta/vesta
synced 2025-08-21 13:54:28 -07:00
mail api 100% completed
This commit is contained in:
parent
f2133f9776
commit
b825490946
24 changed files with 1159 additions and 50 deletions
|
@ -2,7 +2,7 @@
|
|||
# info: add mail account alias aka nickname
|
||||
# options: user domain account alias
|
||||
#
|
||||
# The function add new email account.
|
||||
# The function add new email alias.
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
|
|
|
@ -36,7 +36,7 @@ is_object_valid 'mail' 'DOMAIN' "$domain"
|
|||
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
|
||||
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
|
||||
is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
|
||||
is_object_value_empty "mail/$domain" 'ACCOUNT' "$domain" '$AUTOREPLY'
|
||||
# is_object_value_empty "mail/$domain" 'ACCOUNT' "$account" '$AUTOREPLY'
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
|
@ -55,7 +55,7 @@ chmod 660 $HOMEDIR/$user/conf/mail/$domain/autoreply.$account.msg
|
|||
# Adding vesta alias
|
||||
echo -e "$autoreply" > $USER_DATA/mail/$account@$domain.msg
|
||||
chmod 660 $USER_DATA/mail/$account@$domain.msg
|
||||
update_object_value "mail/$domain" 'ACCOUNT' "$domain" '$AUTOREPLY' 'yes'
|
||||
update_object_value "mail/$domain" 'ACCOUNT' "$account" '$AUTOREPLY' 'yes'
|
||||
|
||||
# Logging
|
||||
log_history "$EVENT"
|
||||
|
|
73
bin/v_add_mail_account_forward
Executable file
73
bin/v_add_mail_account_forward
Executable file
|
@ -0,0 +1,73 @@
|
|||
#!/bin/bash
|
||||
# info: add mail account forward address
|
||||
# options: user domain account forward
|
||||
#
|
||||
# The function add new email account.
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# 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")
|
||||
account=$3
|
||||
forward=$4
|
||||
|
||||
# Includes
|
||||
source $VESTA/conf/vesta.conf
|
||||
source $VESTA/func/shared.sh
|
||||
source $VESTA/func/domain.sh
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Verifications #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
check_args '4' "$#" 'user domain account forward'
|
||||
validate_format 'user' 'domain' 'account' 'forward'
|
||||
is_system_enabled "$MAIL_SYSTEM"
|
||||
is_object_valid 'user' 'USER' "$user"
|
||||
is_object_unsuspended 'user' 'USER' "$user"
|
||||
is_object_valid 'mail' 'DOMAIN' "$domain"
|
||||
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
|
||||
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
|
||||
is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
|
||||
fwd=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$FWD')
|
||||
if [ ! -z "$(echo $fwd | grep -w $forward)" ]; then
|
||||
echo "Error: forward $forward exists"
|
||||
log_event "$E_EXISTS $EVENT"
|
||||
exit $E_EXISTS
|
||||
fi
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Action #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Adding forward to exim
|
||||
if [ -z "$fwd" ]; then
|
||||
fwd="$forward"
|
||||
else
|
||||
fwd="$fwd,$forward"
|
||||
fi
|
||||
|
||||
sed -i "/^$account@$domain:/ d" $HOMEDIR/$user/conf/mail/$domain/aliases
|
||||
echo "$account@$domain:$fwd" >> $HOMEDIR/$user/conf/mail/$domain/aliases
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Vesta #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Updating config
|
||||
update_object_value "mail/$domain" 'ACCOUNT' "$account" '$FWD' "$fwd"
|
||||
|
||||
# Logging
|
||||
log_history "$EVENT"
|
||||
log_event "$OK" "$EVENT"
|
||||
|
||||
exit
|
65
bin/v_change_mail_account_password
Executable file
65
bin/v_change_mail_account_password
Executable file
|
@ -0,0 +1,65 @@
|
|||
#!/bin/bash
|
||||
# info: change mail account password
|
||||
# options: user domain account password
|
||||
#
|
||||
# The function changes email account password.
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# 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")
|
||||
account=$3
|
||||
password=$4
|
||||
|
||||
# Includes
|
||||
source $VESTA/conf/vesta.conf
|
||||
source $VESTA/func/shared.sh
|
||||
source $VESTA/func/domain.sh
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Verifications #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
check_args '4' "$#" 'user domain account password'
|
||||
validate_format 'user' 'domain' 'account' 'password'
|
||||
is_system_enabled "$MAIL_SYSTEM"
|
||||
is_object_valid 'user' 'USER' "$user"
|
||||
is_object_unsuspended 'user' 'USER' "$user"
|
||||
is_object_valid 'mail' 'DOMAIN' "$domain"
|
||||
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
|
||||
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
|
||||
is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Action #
|
||||
#----------------------------------------------------------#
|
||||
md5=$(/usr/sbin/dovecotpw -s md5 -p "$password")
|
||||
sed -i "/^$account:/d" $HOMEDIR/$user/conf/mail/$domain/passwd
|
||||
str="$account:$md5:$user:mail::$HOMEDIR/$user:$quota"
|
||||
echo $str >> $HOMEDIR/$user/conf/mail/$domain/passwd
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Vesta #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Update md5
|
||||
update_object_value "mail/$domain" 'ACCOUNT' "$account" '$MD5' "$md5"
|
||||
|
||||
# Hiding password
|
||||
EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT'"
|
||||
EVENT="$EVENT ARGUMENTS='$user $domain *****'"
|
||||
|
||||
# Logging
|
||||
log_history "$EVENT"
|
||||
log_event "$OK" "$EVENT"
|
||||
|
||||
exit
|
62
bin/v_change_mail_account_quota
Executable file
62
bin/v_change_mail_account_quota
Executable file
|
@ -0,0 +1,62 @@
|
|||
#!/bin/bash
|
||||
# info: change mail account quota
|
||||
# options: user domain account quota
|
||||
#
|
||||
# The function changes email account disk quota.
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# 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")
|
||||
account=$3
|
||||
quota=$4
|
||||
|
||||
# Includes
|
||||
source $VESTA/conf/vesta.conf
|
||||
source $VESTA/func/shared.sh
|
||||
source $VESTA/func/domain.sh
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Verifications #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
check_args '4' "$#" 'user domain account quota'
|
||||
validate_format 'user' 'domain' 'account' 'quota'
|
||||
is_system_enabled "$MAIL_SYSTEM"
|
||||
is_object_valid 'user' 'USER' "$user"
|
||||
is_object_unsuspended 'user' 'USER' "$user"
|
||||
is_object_valid 'mail' 'DOMAIN' "$domain"
|
||||
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
|
||||
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
|
||||
is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Action #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
md5=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$MD5')
|
||||
sed -i "/^$account:/d" $HOMEDIR/$user/conf/mail/$domain/passwd
|
||||
str="$account:$md5:$user:mail::$HOMEDIR/$user:$quota"
|
||||
echo $str >> $HOMEDIR/$user/conf/mail/$domain/passwd
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Vesta #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Update quota
|
||||
update_object_value "mail/$domain" 'ACCOUNT' "$account" '$QUOTA' "$quota"
|
||||
|
||||
# Logging
|
||||
log_history "$EVENT"
|
||||
log_event "$OK" "$EVENT"
|
||||
|
||||
exit
|
65
bin/v_delete_mail_account
Executable file
65
bin/v_delete_mail_account
Executable file
|
@ -0,0 +1,65 @@
|
|||
#!/bin/bash
|
||||
# info: delete mail account
|
||||
# options: user domain account
|
||||
#
|
||||
# The function deletes email account.
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# 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")
|
||||
account=$3
|
||||
|
||||
# Includes
|
||||
source $VESTA/conf/vesta.conf
|
||||
source $VESTA/func/shared.sh
|
||||
source $VESTA/func/domain.sh
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Verifications #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
check_args '3' "$#" 'user domain account'
|
||||
validate_format 'user' 'domain' 'account'
|
||||
is_system_enabled "$MAIL_SYSTEM"
|
||||
is_object_valid 'user' 'USER' "$user"
|
||||
is_object_unsuspended 'user' 'USER' "$user"
|
||||
is_object_valid 'mail' 'DOMAIN' "$domain"
|
||||
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
|
||||
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
|
||||
is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Action #
|
||||
#----------------------------------------------------------#
|
||||
aliases=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$ALIAS')
|
||||
for al in ${aliases//,/ }; do
|
||||
sed -i "/^$al@$domain:$account/d" $HOMEDIR/$user/conf/mail/$domain/aliases
|
||||
done
|
||||
|
||||
sed -i "/^$account@$domain:/d" $HOMEDIR/$user/conf/mail/$domain/aliases
|
||||
sed -i "/^$account:/d" $HOMEDIR/$user/conf/mail/$domain/passwd
|
||||
rm -rf $HOMEDIR/$user/mail/$domain/$account
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Vesta #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Update config
|
||||
sed -i "/ACCOUNT='$account'/d" $USER_DATA/mail/$domain.conf
|
||||
|
||||
|
||||
# Logging
|
||||
log_history "$EVENT"
|
||||
log_event "$OK" "$EVENT"
|
||||
|
||||
exit
|
70
bin/v_delete_mail_account_alias
Executable file
70
bin/v_delete_mail_account_alias
Executable file
|
@ -0,0 +1,70 @@
|
|||
#!/bin/bash
|
||||
# info: delete mail account alias aka nickname
|
||||
# options: user domain account alias
|
||||
#
|
||||
# The function deletes email account alias.
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# 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")
|
||||
account=$3
|
||||
malias=$4
|
||||
|
||||
# Includes
|
||||
source $VESTA/conf/vesta.conf
|
||||
source $VESTA/func/shared.sh
|
||||
source $VESTA/func/domain.sh
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Verifications #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
check_args '4' "$#" 'user domain account alias'
|
||||
validate_format 'user' 'domain' 'account' 'malias'
|
||||
is_system_enabled "$MAIL_SYSTEM"
|
||||
is_object_valid 'user' 'USER' "$user"
|
||||
is_object_unsuspended 'user' 'USER' "$user"
|
||||
is_object_valid 'mail' 'DOMAIN' "$domain"
|
||||
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
|
||||
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
|
||||
is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
|
||||
aliases=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$ALIAS')
|
||||
if [ -z "$(echo $aliases | grep -w $malias)" ]; then
|
||||
echo "Error: alias $malias is not exist"
|
||||
log_event "$E_NOTEXIST $EVENT"
|
||||
exit $E_NOTEXIST
|
||||
fi
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Action #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
sed -i "/^$malias@$domain:$account/d" $HOMEDIR/$user/conf/mail/$domain/aliases
|
||||
aliases=$(echo "$aliases" |\
|
||||
sed -e "s/,/\n/g"|\
|
||||
sed -e "s/^$malias$//g"|\
|
||||
sed -e "/^$/d"|\
|
||||
sed -e ':a;N;$!ba;s/\n/,/g')
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Vesta #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Update config
|
||||
update_object_value "mail/$domain" 'ACCOUNT' "$account" '$ALIAS' "$aliases"
|
||||
|
||||
# Logging
|
||||
log_history "$EVENT"
|
||||
log_event "$OK" "$EVENT"
|
||||
|
||||
exit
|
61
bin/v_delete_mail_account_autoreply
Executable file
61
bin/v_delete_mail_account_autoreply
Executable file
|
@ -0,0 +1,61 @@
|
|||
#!/bin/bash
|
||||
# info: delete mail account autoreply message
|
||||
# options: user domain account alias
|
||||
#
|
||||
# The function delete email account autoreply.
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# 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")
|
||||
account=$3
|
||||
malias=$4
|
||||
|
||||
# Includes
|
||||
source $VESTA/conf/vesta.conf
|
||||
source $VESTA/func/shared.sh
|
||||
source $VESTA/func/domain.sh
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Verifications #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
check_args '3' "$#" 'user domain account'
|
||||
validate_format 'user' 'domain' 'account'
|
||||
is_system_enabled "$MAIL_SYSTEM"
|
||||
is_object_valid 'user' 'USER' "$user"
|
||||
is_object_unsuspended 'user' 'USER' "$user"
|
||||
is_object_valid 'mail' 'DOMAIN' "$domain"
|
||||
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
|
||||
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
|
||||
is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
|
||||
is_object_value_exist "mail/$domain" 'ACCOUNT' "$account" '$AUTOREPLY'
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Action #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
rm -f $HOMEDIR/$user/conf/mail/$domain/autoreply.$account.msg
|
||||
rm -f $USER_DATA/mail/$domain/$account@$domain.msg
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Vesta #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Update config
|
||||
update_object_value "mail/$domain" 'ACCOUNT' "$account" '$AUTOREPLY' 'no'
|
||||
|
||||
# Logging
|
||||
log_history "$EVENT"
|
||||
log_event "$OK" "$EVENT"
|
||||
|
||||
exit
|
72
bin/v_delete_mail_account_forward
Executable file
72
bin/v_delete_mail_account_forward
Executable file
|
@ -0,0 +1,72 @@
|
|||
#!/bin/bash
|
||||
# info: delte mail account forward
|
||||
# options: user domain account email
|
||||
#
|
||||
# The function add delete email account forward address.
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# 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")
|
||||
account=$3
|
||||
forward=$4
|
||||
|
||||
# Includes
|
||||
source $VESTA/conf/vesta.conf
|
||||
source $VESTA/func/shared.sh
|
||||
source $VESTA/func/domain.sh
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Verifications #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
check_args '4' "$#" 'user domain account forward'
|
||||
validate_format 'user' 'domain' 'account' 'forward'
|
||||
is_system_enabled "$MAIL_SYSTEM"
|
||||
is_object_valid 'user' 'USER' "$user"
|
||||
is_object_unsuspended 'user' 'USER' "$user"
|
||||
is_object_valid 'mail' 'DOMAIN' "$domain"
|
||||
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
|
||||
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
|
||||
is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
|
||||
fwd=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$FWD')
|
||||
if [ -z "$(echo $fwd | grep -w $forward)" ]; then
|
||||
echo "Error: forward $forward is not exist"
|
||||
log_event "$E_NOTEXIST $EVENT"
|
||||
exit $E_NOTEXIST
|
||||
fi
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Action #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
fwd=$(echo "$fwd" |\
|
||||
sed -e "s/,/\n/g"|\
|
||||
sed -e "s/^$forward$//g"|\
|
||||
sed -e "/^$/d"|\
|
||||
sed -e ':a;N;$!ba;s/\n/,/g')
|
||||
|
||||
sed -i "/^$account@$domain:/ d" $HOMEDIR/$user/conf/mail/$domain/aliases
|
||||
echo "$account@$domain:$fwd" >> $HOMEDIR/$user/conf/mail/$domain/aliases
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Vesta #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Update config
|
||||
update_object_value "mail/$domain" 'ACCOUNT' "$account" '$FWD' "$fwd"
|
||||
|
||||
# Logging
|
||||
log_history "$EVENT"
|
||||
log_event "$OK" "$EVENT"
|
||||
|
||||
exit
|
94
bin/v_list_mail_account
Executable file
94
bin/v_list_mail_account
Executable file
|
@ -0,0 +1,94 @@
|
|||
#!/bin/bash
|
||||
# info: list mail domain account
|
||||
# options: user domain account [format]
|
||||
#
|
||||
# The function of obtaining the list of account parameters.
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Variable&Function #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Argument defenition
|
||||
user=$1
|
||||
domain=$2
|
||||
account=$3
|
||||
format=${4-shell}
|
||||
|
||||
# Includes
|
||||
source $VESTA/func/shared.sh
|
||||
|
||||
# Json function
|
||||
json_list_account() {
|
||||
i=1
|
||||
fileds_count=$(echo "$fields" | wc -w)
|
||||
line=$(grep "ACCOUNT='$account'" $conf)
|
||||
echo '{'
|
||||
eval $line
|
||||
for field in $fields; do
|
||||
eval value=$field
|
||||
if [ "$i" -eq 1 ]; then
|
||||
echo -e "\t\"$value\": {"
|
||||
else
|
||||
if [ "$fileds_count" -eq "$i" ]; then
|
||||
echo -e "\t\t\"${field//$/}\": \"$value\","
|
||||
else
|
||||
echo -e "\t\t\"${field//$/}\": \"$value\""
|
||||
fi
|
||||
fi
|
||||
(( ++i))
|
||||
done
|
||||
if [ -n "$value" ]; then
|
||||
echo -e ' }'
|
||||
fi
|
||||
echo -e "}"
|
||||
}
|
||||
|
||||
# Shell function
|
||||
shell_list_account() {
|
||||
line=$(grep "ACCOUNT='$account'" $conf)
|
||||
eval $line
|
||||
for field in $fields; do
|
||||
eval key="$field"
|
||||
if [ -z "$key" ]; then
|
||||
key=NULL
|
||||
fi
|
||||
echo "${field//$/}: $key "
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Verifications #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
check_args '3' "$#" 'user domain account [format]'
|
||||
is_object_valid 'user' 'USER' "$user"
|
||||
is_object_valid 'mail' 'DOMAIN' "$domain"
|
||||
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
|
||||
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Action #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Defining config and fields to select
|
||||
conf=$USER_DATA/mail/$domain.conf
|
||||
fields="\$ACCOUNT \$ALIAS \$FWD \$QUOTA \$AUTOREPLY \$U_DISK \$SUSPENDED"
|
||||
fields="$fields \$TIME \$DATE"
|
||||
|
||||
# Listing domains
|
||||
case $format in
|
||||
json) json_list_account ;;
|
||||
plain) nohead=1; shell_list_account ;;
|
||||
shell) shell_list_account |column -t ;;
|
||||
*) check_args '2' '0' 'user domain account [format]'
|
||||
esac
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Vesta #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
exit
|
72
bin/v_list_mail_account_autoreply
Executable file
72
bin/v_list_mail_account_autoreply
Executable file
|
@ -0,0 +1,72 @@
|
|||
#!/bin/bash
|
||||
# info: list mail account autoreply
|
||||
# options: user domain account [format]
|
||||
#
|
||||
# The function of obtainin mail account autoreply message.
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Variable&Function #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Argument defenition
|
||||
user=$1
|
||||
domain=$2
|
||||
account=$3
|
||||
format=${4-shell}
|
||||
|
||||
# Includes
|
||||
source $VESTA/func/shared.sh
|
||||
|
||||
# Json function
|
||||
json_list_msg() {
|
||||
i='1' # iterator
|
||||
echo '{'
|
||||
echo -e "\t\"$account\": {"
|
||||
echo " \"MSG\": \"$msg\""
|
||||
echo -e "\t}\n}"
|
||||
}
|
||||
|
||||
# Shell function
|
||||
shell_list_msg() {
|
||||
if [ ! -z "$msg" ]; then
|
||||
echo -e "$msg"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Verifications #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
check_args '2' "$#" 'user domain [format]'
|
||||
is_object_valid 'user' 'USER' "$user"
|
||||
is_object_valid 'mail' 'DOMAIN' "$domain"
|
||||
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
|
||||
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
|
||||
is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Action #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
if [ -e "$USER_DATA/mail/$account@$domain.msg" ]; then
|
||||
msg=$(cat $USER_DATA/mail/$account@$domain.msg |\
|
||||
sed -e ':a;N;$!ba;s/\n/\\n/g' )
|
||||
fi
|
||||
|
||||
# Listing domains
|
||||
case $format in
|
||||
json) json_list_msg ;;
|
||||
plain) nohead=1; shell_list_msg ;;
|
||||
shell) shell_list_msg ;;
|
||||
*) check_args '1' '0' '[format]'
|
||||
esac
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Vesta #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
exit
|
|
@ -34,13 +34,14 @@ is_object_valid 'mail' 'DOMAIN' "$domain"
|
|||
|
||||
# Defining fileds to select
|
||||
conf=$USER_DATA/mail/$domain.conf
|
||||
fields="\$ACCOUNT \$ALIAS \$FWD \$AUTOREPLY \$U_DISK \$SUSPENDED \$DATE"
|
||||
fields="\$ACCOUNT \$ALIAS \$FWD \$AUTOREPLY \$QUOTA \$U_DISK \$SUSPENDED"
|
||||
fields="$fields \$TIME \$DATE"
|
||||
|
||||
# Listing domain accounts
|
||||
case $format in
|
||||
json) json_list ;;
|
||||
plain) nohead=1; shell_list ;;
|
||||
shell) fields='$ACCOUNT $ALIAS $FWD $AUTOREPLY $U_DISK $DATE';
|
||||
shell) fields='$ACCOUNT $AUTOREPLY $QUOTA $U_DISK $SUSPENDED $TIME $DATE';
|
||||
shell_list | column -t ;;
|
||||
*) check_args '1' '0' 'user [format]'
|
||||
esac
|
||||
|
|
|
@ -56,7 +56,14 @@ shell_list_users() {
|
|||
|
||||
for USER in $(ls $VESTA/data/users/); do
|
||||
source $VESTA/data/users/$USER/user.conf
|
||||
eval echo "$fields"
|
||||
for field in $fields; do
|
||||
eval value=$field
|
||||
if [ -z "$value" ]; then
|
||||
value='NULL'
|
||||
fi
|
||||
echo -n "$value "
|
||||
done
|
||||
echo
|
||||
done
|
||||
}
|
||||
|
||||
|
|
|
@ -46,13 +46,14 @@ if [ ! -d "$USER_DATA/mail" ]; then
|
|||
fi
|
||||
|
||||
# Starting loop
|
||||
for domain in $(search_objects 'dns' 'SUSPENDED' "*" 'DOMAIN'); do
|
||||
|
||||
for domain in $(search_objects 'mail' 'SUSPENDED' "*" 'DOMAIN'); do
|
||||
# Defining variables
|
||||
get_domain_values 'mail'
|
||||
|
||||
# Rebuilding config structure
|
||||
rm -f /etc/exim/domains/$domain
|
||||
mkdir -p $HOMEDIR/$user/conf/mail/$domain
|
||||
ln -s $HOMEDIR/$user/conf/mail/$domain /etc/exim/domains/
|
||||
rm -f $HOMEDIR/$user/conf/mail/$domain/aliases
|
||||
rm -f $HOMEDIR/$user/conf/mail/$domain/protection
|
||||
rm -f $HOMEDIR/$user/conf/mail/$domain/passwd
|
||||
|
@ -60,8 +61,10 @@ for domain in $(search_objects 'dns' 'SUSPENDED' "*" 'DOMAIN'); do
|
|||
touch $HOMEDIR/$user/conf/mail/$domain/protection
|
||||
touch $HOMEDIR/$user/conf/mail/$domain/passwd
|
||||
chown -R root:mail $HOMEDIR/$user/conf/mail/$domain
|
||||
chown -R root:mail /etc/exim/domains/$domain
|
||||
chmod 770 $HOMEDIR/$user/conf/mail/$domain
|
||||
chmod 660 $HOMEDIR/$user/conf/mail/$domain*
|
||||
chmod 660 /etc/exim/domains/$domain
|
||||
|
||||
# Adding antispam protection
|
||||
if [ "$ANTISPAM" = 'yes' ]; then
|
||||
|
@ -106,9 +109,10 @@ for domain in $(search_objects 'dns' 'SUSPENDED' "*" 'DOMAIN'); do
|
|||
fi
|
||||
fi
|
||||
|
||||
# Adding antispam protection
|
||||
if [ "$SUSPENDED" != 'yes' ]; then
|
||||
ln -s $HOMEDIR/$user/conf/mail/$domain /etc/exim/domains/
|
||||
# Removing symbolic link
|
||||
if [ "$SUSPENDED" = 'yes' ]; then
|
||||
SUSPENDED_MAIL=$((SUSPENDED_MAIL +1))
|
||||
rm -f /etc/exim/domains/$domain
|
||||
fi
|
||||
|
||||
if [ ! -e $HOMEDIR/$user/mail/$domain ]; then
|
||||
|
@ -117,9 +121,45 @@ for domain in $(search_objects 'dns' 'SUSPENDED' "*" 'DOMAIN'); do
|
|||
chown $user:mail $HOMEDIR/$user/mail/$domain
|
||||
chmod 770 $HOMEDIR/$user/mail/$domain
|
||||
|
||||
# Rebuild counters
|
||||
dom_aliases=$HOMEDIR/$user/conf/mail/$domain/aliases
|
||||
if [ ! -z "$CATCHALL" ]; then
|
||||
echo "*@$domain:$CATCHALL" >> $dom_aliases
|
||||
fi
|
||||
|
||||
# Rebuild domain accounts
|
||||
accs=0
|
||||
dom_diks=0
|
||||
if [ -e "$USER_DATA/mail/$domain.conf" ]; then
|
||||
accounts=$(search_objects "mail/$domain" 'SUSPENDED' "no" 'ACCOUNT')
|
||||
else
|
||||
accounts=''
|
||||
fi
|
||||
|
||||
for account in $accounts; do
|
||||
(( ++accs))
|
||||
dom_diks=$((dom_diks + U_DISK))
|
||||
object=$(grep "ACCOUNT='$account'" $USER_DATA/mail/$domain.conf)
|
||||
eval "$object"
|
||||
if [ "$SUSPENDED" = 'yes' ]; then
|
||||
MD5='SUSPENDED'
|
||||
fi
|
||||
|
||||
str="$account:$MD5:$user:mail::$HOMEDIR/$user:$QUOTA"
|
||||
echo $str >> $HOMEDIR/$user/conf/mail/$domain/passwd
|
||||
|
||||
for malias in ${ALIAS//,/ }; do
|
||||
echo "$malias@$domain:$account@$domain" >> $dom_aliases
|
||||
done
|
||||
if [ ! -z "$FWD" ]; then
|
||||
echo "$account@$domain:$FWD" >> $dom_aliases
|
||||
fi
|
||||
|
||||
done
|
||||
update_object_value 'mail' 'DOMAIN' "$domain" '$ACCOUNTS' "$accs"
|
||||
update_object_value 'mail' 'DOMAIN' "$domain" '$U_DISK' "$dom_diks"
|
||||
U_MAIL_ACCOUNTS=$((U_MAIL_ACCOUNTS + accs))
|
||||
U_DISK_MAIL=$((U_DISK_MAIL + dom_diks))
|
||||
U_MAIL_DOMAINS=$((U_MAIL_DOMAINS + 1))
|
||||
U_DISK_MAIL=$((U_DISK_MAIL + U_DISK))
|
||||
done
|
||||
|
||||
|
||||
|
@ -128,15 +168,11 @@ done
|
|||
#----------------------------------------------------------#
|
||||
|
||||
# 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"
|
||||
recalc_user_disk_usage
|
||||
|
||||
# Logging
|
||||
log_event "$OK" "$EVENT"
|
||||
|
|
37
bin/v_restart_mail
Executable file
37
bin/v_restart_mail
Executable file
|
@ -0,0 +1,37 @@
|
|||
#!/bin/bash
|
||||
# info: restart mail service
|
||||
# options: none
|
||||
#
|
||||
# The function tells Exim service to reload configuration files.
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Variable&Function #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Includes
|
||||
source $VESTA/conf/vesta.conf
|
||||
source $VESTA/func/shared.sh
|
||||
EVENT=${1-$EVENT}
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Action #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
if [ "$MAIL_SYSTEM" = 'exim' ]; then
|
||||
/etc/init.d/exim reload &>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
/etc/init.d/exim restart &>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
log_event "$E_RESTART" "$EVENT"
|
||||
exit $E_RESTART
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Vesta #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
exit
|
61
bin/v_suspend_mail_account
Executable file
61
bin/v_suspend_mail_account
Executable file
|
@ -0,0 +1,61 @@
|
|||
#!/bin/bash
|
||||
# info: suspend mail account
|
||||
# options: user domain account
|
||||
#
|
||||
# The function suspends mail account.
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# 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")
|
||||
account=$3
|
||||
|
||||
# Includes
|
||||
source $VESTA/conf/vesta.conf
|
||||
source $VESTA/func/shared.sh
|
||||
source $VESTA/func/domain.sh
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Verifications #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
check_args '3' "$#" 'user domain account'
|
||||
validate_format 'user' 'domain' 'account'
|
||||
is_system_enabled "$MAIL_SYSTEM"
|
||||
is_object_valid 'user' 'USER' "$user"
|
||||
is_object_unsuspended 'user' 'USER' "$user"
|
||||
is_object_valid 'mail' 'DOMAIN' "$domain"
|
||||
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
|
||||
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
|
||||
is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Action #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
quota=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$QUOTA')
|
||||
sed -i "/^$account:/d" $HOMEDIR/$user/conf/mail/$domain/passwd
|
||||
str="$account:SUSPENDED:$user:mail::$HOMEDIR/$user:$quota"
|
||||
echo $str >> $HOMEDIR/$user/conf/mail/$domain/passwd
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Vesta #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Update config
|
||||
update_object_value "mail/$domain" 'ACCOUNT' "$account" '$SUSPENDED' 'yes'
|
||||
|
||||
# Logging
|
||||
log_history "$EVENT"
|
||||
log_event "$OK" "$EVENT"
|
||||
|
||||
exit
|
54
bin/v_suspend_mail_accounts
Executable file
54
bin/v_suspend_mail_accounts
Executable file
|
@ -0,0 +1,54 @@
|
|||
#!/bin/bash
|
||||
# info: suspend all mail domain accounts
|
||||
# options: user domain
|
||||
#
|
||||
# The function suspends all mail domain accounts.
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# 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")
|
||||
|
||||
# Includes
|
||||
source $VESTA/conf/vesta.conf
|
||||
source $VESTA/func/shared.sh
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Verifications #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
check_args '2' "$#" 'user domain'
|
||||
validate_format 'user' 'domain'
|
||||
is_system_enabled "$MAIL_SYSTEM"
|
||||
is_object_valid 'user' 'USER' "$user"
|
||||
is_object_unsuspended 'user' 'USER' "$user"
|
||||
is_object_valid 'mail' 'DOMAIN' "$domain"
|
||||
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Action #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Starting suspend loop
|
||||
for account in $(search_objects "mail/$domain" 'SUSPENDED' "no" 'ACCOUNT'); do
|
||||
$BIN/v_suspend_mail_account "$user" "$domain" "$account"
|
||||
done
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Vesta #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Logging
|
||||
log_history "$EVENT"
|
||||
log_event "$OK" "$EVENT"
|
||||
|
||||
exit
|
62
bin/v_unsuspend_mail_account
Executable file
62
bin/v_unsuspend_mail_account
Executable file
|
@ -0,0 +1,62 @@
|
|||
#!/bin/bash
|
||||
# info: unsuspend mail account
|
||||
# options: user domain account
|
||||
#
|
||||
# The function unsuspends mail account.
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# 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")
|
||||
account=$3
|
||||
|
||||
# Includes
|
||||
source $VESTA/conf/vesta.conf
|
||||
source $VESTA/func/shared.sh
|
||||
source $VESTA/func/domain.sh
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Verifications #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
check_args '3' "$#" 'user domain account'
|
||||
validate_format 'user' 'domain' 'account'
|
||||
is_system_enabled "$MAIL_SYSTEM"
|
||||
is_object_valid 'user' 'USER' "$user"
|
||||
is_object_unsuspended 'user' 'USER' "$user"
|
||||
is_object_valid 'mail' 'DOMAIN' "$domain"
|
||||
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
|
||||
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
|
||||
is_object_suspended "mail/$domain" 'ACCOUNT' "$account"
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Action #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
md5=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$MD5')
|
||||
quota=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$QUOTA')
|
||||
sed -i "/^$account:/d" $HOMEDIR/$user/conf/mail/$domain/passwd
|
||||
str="$account:$md5:$user:mail::$HOMEDIR/$user:$quota"
|
||||
echo $str >> $HOMEDIR/$user/conf/mail/$domain/passwd
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Vesta #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Update config
|
||||
update_object_value "mail/$domain" 'ACCOUNT' "$account" '$SUSPENDED' 'no'
|
||||
|
||||
# Logging
|
||||
log_history "$EVENT"
|
||||
log_event "$OK" "$EVENT"
|
||||
|
||||
exit
|
54
bin/v_unsuspend_mail_accounts
Executable file
54
bin/v_unsuspend_mail_accounts
Executable file
|
@ -0,0 +1,54 @@
|
|||
#!/bin/bash
|
||||
# info: unsuspend all mail domain accounts
|
||||
# options: user domain
|
||||
#
|
||||
# The function unsuspends all mail domain accounts.
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# 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")
|
||||
|
||||
# Includes
|
||||
source $VESTA/conf/vesta.conf
|
||||
source $VESTA/func/shared.sh
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Verifications #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
check_args '2' "$#" 'user domain'
|
||||
validate_format 'user' 'domain'
|
||||
is_system_enabled "$MAIL_SYSTEM"
|
||||
is_object_valid 'user' 'USER' "$user"
|
||||
is_object_unsuspended 'user' 'USER' "$user"
|
||||
is_object_valid 'mail' 'DOMAIN' "$domain"
|
||||
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Action #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Starting unsuspend loop
|
||||
for account in $(search_objects "mail/$domain" 'SUSPENDED' 'yes' 'ACCOUNT'); do
|
||||
$BIN/v_unsuspend_mail_account "$user" "$domain" "$account"
|
||||
done
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Vesta #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Logging
|
||||
log_history "$EVENT"
|
||||
log_event "$OK" "$EVENT"
|
||||
|
||||
exit
|
|
@ -12,7 +12,7 @@
|
|||
# Argument defenition
|
||||
user=$1
|
||||
|
||||
# Importing variables
|
||||
# Includes
|
||||
source $VESTA/conf/vesta.conf
|
||||
source $VESTA/func/shared.sh
|
||||
source $VESTA/func/domain.sh
|
||||
|
|
65
bin/v_update_mail_domain_disk
Executable file
65
bin/v_update_mail_domain_disk
Executable file
|
@ -0,0 +1,65 @@
|
|||
#!/bin/bash
|
||||
# info: update mail domain disk usage
|
||||
# options: user domain
|
||||
#
|
||||
# The function updates domain disk usage.
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# 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")
|
||||
|
||||
# Includes
|
||||
source $VESTA/conf/vesta.conf
|
||||
source $VESTA/func/shared.sh
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Verifications #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
check_args '2' "$#" 'user domain'
|
||||
validate_format 'user' 'domain'
|
||||
is_system_enabled "$MAIL_SYSTEM"
|
||||
is_object_valid 'user' 'USER' "$user"
|
||||
is_object_unsuspended 'user' 'USER' "$user"
|
||||
is_object_valid 'mail' 'DOMAIN' "$domain"
|
||||
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Action #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Starting loop
|
||||
dom_diks=0
|
||||
for account in $(search_objects "mail/$domain" 'SUSPENDED' "no" 'ACCOUNT'); do
|
||||
home_dir=$HOMEDIR/$user/mail/$domain/$account
|
||||
if [ -e "$home_dir" ]; then
|
||||
udisk=$(nice -n 19 du -shm $home_dir | cut -f 1 )
|
||||
else
|
||||
udisk=0
|
||||
fi
|
||||
update_object_value "mail/$domain" 'ACCOUNT' "$account" '$U_DISK' "$udisk"
|
||||
dom_diks=$((dom_diks + udisk))
|
||||
done
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Vesta #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
update_object_value 'mail' 'DOMAIN' "$domain" '$U_DISK' "$dom_diks"
|
||||
recalc_user_disk_usage
|
||||
|
||||
# Logging
|
||||
log_history "$EVENT"
|
||||
log_event "$OK" "$EVENT"
|
||||
|
||||
exit
|
64
bin/v_update_mail_domains_disk
Executable file
64
bin/v_update_mail_domains_disk
Executable file
|
@ -0,0 +1,64 @@
|
|||
#!/bin/bash
|
||||
# info: calculate disk usage for all mail domains
|
||||
# options: user
|
||||
#
|
||||
# The function calculates disk usage for all mail domains.
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Variable&Function #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Argument defenition
|
||||
user=$1
|
||||
|
||||
# Includes
|
||||
source $VESTA/conf/vesta.conf
|
||||
source $VESTA/func/shared.sh
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Verifications #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
check_args '1' "$#" 'user'
|
||||
validate_format 'user'
|
||||
is_system_enabled "$MAIL_SYSTEM"
|
||||
is_object_valid 'user' 'USER' "$user"
|
||||
is_object_unsuspended 'user' 'USER' "$user"
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Action #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
# Starting loop
|
||||
for domain in $(search_objects 'mail' 'SUSPENDED' "no" 'DOMAIN'); do
|
||||
dom_diks=0
|
||||
accounts=$(search_objects "mail/$domain" 'SUSPENDED' "no" 'ACCOUNT')
|
||||
for account in $accounts; do
|
||||
home_dir=$HOMEDIR/$user/mail/$domain/$account
|
||||
if [ -e "$home_dir" ]; then
|
||||
udisk=$(nice -n 19 du -shm $home_dir | cut -f 1 )
|
||||
else
|
||||
udisk=0
|
||||
fi
|
||||
update_object_value "mail/$domain" 'ACCOUNT' "$account" '$U_DISK' "$udisk"
|
||||
dom_diks=$((dom_diks + udisk))
|
||||
done
|
||||
update_object_value 'mail' 'DOMAIN' "$domain" '$U_DISK' "$dom_diks"
|
||||
done
|
||||
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Vesta #
|
||||
#----------------------------------------------------------#
|
||||
|
||||
|
||||
recalc_user_disk_usage
|
||||
|
||||
# Logging
|
||||
log_history "$EVENT"
|
||||
log_event "$OK" "$EVENT"
|
||||
|
||||
exit
|
Loading…
Add table
Add a link
Reference in a new issue