| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- #!/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=$3
- password=$4
- quota=${5-0}
- # Includes
- source $VESTA/conf/vesta.conf
- source $VESTA/func/main.sh
- source $VESTA/func/domain.sh
- # Hiding password
- A4='******'
- EVENT="DATE='$DATE' TIME='$TIME' CMD='$SCRIPT' A1='$A1' A2='$A2' A3='$A3'"
- EVENT="$EVENT A4='$A4' A5='$A5' A6='$A6' A7='$A7' A8='$A8' A9='$A9'"
- #----------------------------------------------------------#
- # Verifications #
- #----------------------------------------------------------#
- check_args '4' "$#" 'user domain account password [quota]'
- validate_format 'user' 'domain' 'account' 'password' '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_package_full 'MAIL_ACCOUNTS'
- is_mail_new "$account"
- #----------------------------------------------------------#
- # Action #
- #----------------------------------------------------------#
- md5=$(/usr/sbin/dovecotpw -s md5 -p "$password")
- str="$account:$md5:$user:mail::$HOMEDIR/$user:$quota"
- echo $str >> $HOMEDIR/$user/conf/mail/$domain/passwd
- #----------------------------------------------------------#
- # Vesta #
- #----------------------------------------------------------#
- str="ACCOUNT='$account' ALIAS='' QUOTA='$quota' AUTOREPLY='no' FWD=''"
- str="$str MD5='$md5' U_DISK='0' SUSPENDED='no' TIME='$TIME' 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 "$EVENT"
- log_event "$OK" "$EVENT"
- exit
|