#!/bin/bash # info: add mail domain account # options: USER DOMAIN ACCOUNT PASSWORD [QUOTA] # # 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=$(echo $3 | tr '[:upper:]' '[:lower:]') password=$4; HIDE=4 quota=${5-unlimited} # Includes source $VESTA/func/main.sh source $VESTA/func/domain.sh source $VESTA/conf/vesta.conf #----------------------------------------------------------# # Verifications # #----------------------------------------------------------# check_args '4' "$#" 'USER DOMAIN ACCOUNT PASSWORD [QUOTA]' validate_format 'user' 'domain' 'account' if [ "$quota" != 'unlimited' ]; then validate_format 'quota' fi is_system_enabled "$MAIL_SYSTEM" '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_package_full 'MAIL_ACCOUNTS' is_mail_new "$account" is_password_valid #----------------------------------------------------------# # Action # #----------------------------------------------------------# # Generating hashed password salt=$(gen_password "$PW_MATRIX" "8") md5="{MD5}$($BIN/v-generate-password-hash md5 $salt <<<$password)" # Adding account info into password file if [[ "$MAIL_SYSTEM" =~ exim ]]; then if [ "$quota" = 'unlimited' ]; then quota='0' fi str="$account:$md5:$user:mail::$HOMEDIR/$user:$quota" echo $str >> $HOMEDIR/$user/conf/mail/$domain/passwd fi #----------------------------------------------------------# # Vesta # #----------------------------------------------------------# if [[ "$quota" -eq '0' ]]; then quota='unlimited' fi str="ACCOUNT='$account' ALIAS='' QUOTA='$quota' AUTOREPLY='no' FWD=''" str="$str FWD_ONLY='' MD5='$md5' U_DISK='0' SUSPENDED='no' TIME='$TIME'" str="$str DATE='$DATE'" echo "$str" >> $USER_DATA/mail/$domain.conf chmod 660 $USER_DATA/mail/$domain.conf # Increase mail accounts counter accounts=$(wc -l $USER_DATA/mail/$domain.conf | cut -f 1 -d ' ') increase_user_value "$user" '$U_MAIL_ACCOUNTS' update_object_value 'mail' 'DOMAIN' "$domain" '$ACCOUNTS' "$accounts" # Logging log_history "added mail account $account@$domain" log_event "$OK" "$EVENT" exit