Procházet zdrojové kódy

Refactoring stage VI (mail)

Serghey Rodin před 14 roky
rodič
revize
f2133f9776

+ 1 - 1
bin/v_add_database

@@ -68,7 +68,7 @@ increase_dbhost_values
 increase_user_value "$user" '$U_DATABASES'
 increase_user_value "$user" '$U_DATABASES'
 
 
 # Adding db to db conf
 # Adding db to db conf
-str="DB='$database' DBUSER='$dbuser' HOST='$host' TYPE='$type'"
+str="DB='$database' DBUSER='$dbuser' MD5='$md5' HOST='$host' TYPE='$type'"
 str="$str CHARSET='$charset' U_DISK='0' SUSPENDED='no' TIME='$TIME'"
 str="$str CHARSET='$charset' U_DISK='0' SUSPENDED='no' TIME='$TIME'"
 str="$str DATE='$DATE'"
 str="$str DATE='$DATE'"
 echo "$str" >> $USER_DATA/db.conf
 echo "$str" >> $USER_DATA/db.conf

+ 1 - 0
bin/v_add_dns_domain_record

@@ -61,6 +61,7 @@ zone="$USER_DATA/dns/$domain.conf"
 dns_rec="ID='$id' RECORD='$record' TYPE='$rtype' PRIORITY='$priority'"
 dns_rec="ID='$id' RECORD='$record' TYPE='$rtype' PRIORITY='$priority'"
 dns_rec="$dns_rec VALUE='$dvalue' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
 dns_rec="$dns_rec VALUE='$dvalue' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
 echo "$dns_rec" >> $zone
 echo "$dns_rec" >> $zone
+chmod 660 $zone
 
 
 # Sorting records
 # Sorting records
 sort_dns_records 
 sort_dns_records 

+ 17 - 30
bin/v_add_mail_account

@@ -18,7 +18,7 @@ account=$3
 password=$4
 password=$4
 quota=${5-0}
 quota=${5-0}
 
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/shared.sh
 source $VESTA/func/domain.sh
 source $VESTA/func/domain.sh
@@ -28,39 +28,22 @@ source $VESTA/func/domain.sh
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Checking arg number
-check_args '4' "$#" 'user domain account password quota'
-
-# Checking argument format
+check_args '4' "$#" 'user domain account password [quota]'
 validate_format 'user' 'domain' 'account' 'password' 'quota'
 validate_format 'user' 'domain' 'account' 'password' 'quota'
-
-# Checking dns system is enabled
-is_system_enabled 'MAIL_SYSTEM'
-
-# Checking user
+is_system_enabled "$MAIL_SYSTEM"
 is_object_valid 'user' 'USER' "$user"
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user is active
 is_object_unsuspended 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
-
-# Checking domain
-is_domain_valid 'mail'
-
-# Checking domain is not suspened
-is_domain_suspended 'mail'
-
-# Checking package
+is_object_valid 'mail' 'DOMAIN' "$domain"
+is_object_unsuspended 'mail' 'DOMAIN' "$domain"
 is_package_full 'MAIL_ACCOUNTS'
 is_package_full 'MAIL_ACCOUNTS'
-
-# Checking account
-is_mail_account_free
+is_mail_new "$account"
 
 
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 #                       Action                             #
 #                       Action                             #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
-password=$(/usr/sbin/dovecotpw -s md5 -p "$password")
-str="$account:$password:$user:mail::$HOMEDIR/$user:$quota"
+md5=$(/usr/sbin/dovecotpw -s md5 -p "$password")
+str="$account:$md5:$user:mail::$HOMEDIR/$user:$quota"
 echo $str >> $HOMEDIR/$user/conf/mail/$domain/passwd
 echo $str >> $HOMEDIR/$user/conf/mail/$domain/passwd
 
 
 
 
@@ -69,17 +52,21 @@ echo $str >> $HOMEDIR/$user/conf/mail/$domain/passwd
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 str="ACCOUNT='$account' ALIAS='' QUOTA='$quota' AUTOREPLY='no' FWD=''"
 str="ACCOUNT='$account' ALIAS='' QUOTA='$quota' AUTOREPLY='no' FWD=''"
-str="$str U_DISK='0' SUSPENDED='no' DATE='$DATE'"
+str="$str MD5='$md5' U_DISK='0' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
 echo "$str" >> $USER_DATA/mail/$domain.conf
 echo "$str" >> $USER_DATA/mail/$domain.conf
+chmod 660 $USER_DATA/mail/$domain.conf
 
 
 # Increase mail accounts counter
 # Increase mail accounts counter
-accounts=$(wc -l $USER_DATA/mail/$domain.conf|cut -f 1 -d ' ')
+accounts=$(wc -l $USER_DATA/mail/$domain.conf | cut -f 1 -d ' ')
 increase_user_value "$user" '$U_MAIL_ACCOUNTS'
 increase_user_value "$user" '$U_MAIL_ACCOUNTS'
-update_domain_value 'mail' '$ACCOUNTS' "$accounts"
+update_object_value 'mail' 'DOMAIN' "$domain" '$ACCOUNTS' "$accounts"
+
+# Hiding password
+EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT'"
+EVENT="$EVENT ARGUMENTS='$user $domain ***** $quota'"
 
 
 # Logging
 # Logging
-EVENT="$DATE $SCRIPT $user $domain ***** $quota"
-log_history "$EVENT" "v_delete_mail_account $user $domain $account"
+log_history "$EVENT"
 log_event "$OK" "$EVENT"
 log_event "$OK" "$EVENT"
 
 
 exit
 exit

+ 11 - 28
bin/v_add_mail_account_alias

@@ -17,7 +17,7 @@ domain_idn=$(idn -t --quiet -a "$domain")
 account=$3
 account=$3
 malias=$4
 malias=$4
 
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/shared.sh
 source $VESTA/func/domain.sh
 source $VESTA/func/domain.sh
@@ -27,32 +27,16 @@ source $VESTA/func/domain.sh
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Checking arg number
 check_args '4' "$#" 'user domain account alias'
 check_args '4' "$#" 'user domain account alias'
-
-# Checking argument format
 validate_format 'user' 'domain' 'account' 'malias'
 validate_format 'user' 'domain' 'account' 'malias'
-
-# Checking dns system is enabled
-is_system_enabled 'MAIL_SYSTEM'
-
-# Checking user
+is_system_enabled "$MAIL_SYSTEM"
 is_object_valid 'user' 'USER' "$user"
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user is active
 is_object_unsuspended 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
-
-# Checking domain
-is_domain_valid 'mail'
-
-# Checking domain is not suspened
-is_domain_suspended 'mail'
-
-# Checking account
-is_mail_account_valid
-
-# Checking account
-is_mail_account_free "$malias"
+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_mail_new "$malias"
 
 
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
@@ -60,7 +44,7 @@ is_mail_account_free "$malias"
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 # Adding exim alias
 # Adding exim alias
-str="$mailas@$domain:$account@$domain"
+str="$malias@$domain:$account@$domain"
 echo "$str" >> $HOMEDIR/$user/conf/mail/$domain/aliases
 echo "$str" >> $HOMEDIR/$user/conf/mail/$domain/aliases
 
 
 
 
@@ -69,17 +53,16 @@ echo "$str" >> $HOMEDIR/$user/conf/mail/$domain/aliases
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 # Adding vesta alias
 # Adding vesta alias
-aliases=$(get_domain_value "mail/$domain" '$ALIAS' "ACCOUNT='$account'")
+aliases=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$ALIAS')
 if [ -z "$aliases" ]; then
 if [ -z "$aliases" ]; then
     aliases="$malias"
     aliases="$malias"
 else
 else
     aliases="$aliases,$malias"
     aliases="$aliases,$malias"
 fi
 fi
-update_domain_value "mail/$domain" '$ALIAS' "$aliases" "ACCOUNT='$account'"
+update_object_value "mail/$domain" 'ACCOUNT' "$account"  '$ALIAS' "$aliases"
 
 
 # Logging
 # Logging
-cmd='v_delete_mail_account_alias'
-log_history "$EVENT" "$cmd $user $domain $account $malias"
+log_history "$EVENT"
 log_event "$OK" "$EVENT"
 log_event "$OK" "$EVENT"
 
 
 exit
 exit

+ 16 - 20
bin/v_add_mail_account_autoreply

@@ -15,9 +15,9 @@ domain=$(idn -t --quiet -u "$2" )
 domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
 domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
 domain_idn=$(idn -t --quiet -a "$domain")
 domain_idn=$(idn -t --quiet -a "$domain")
 account=$3
 account=$3
-malias=$4
+autoreply=$4
 
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/shared.sh
 source $VESTA/func/domain.sh
 source $VESTA/func/domain.sh
@@ -26,25 +26,26 @@ source $VESTA/func/domain.sh
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
-check_args '4' "$#" 'user domain account alias'
-validate_format 'user' 'domain' 'account' 'malias'
-is_system_enabled 'MAIL_SYSTEM'
+
+check_args '4' "$#" 'user domain account autoreply'
+validate_format 'user' 'domain' 'account' 'autoreply'
+is_system_enabled "$MAIL_SYSTEM"
 is_object_valid 'user' 'USER' "$user"
 is_object_valid 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
 is_object_valid 'mail' 'DOMAIN' "$domain"
 is_object_valid 'mail' 'DOMAIN' "$domain"
 is_object_unsuspended 'mail' 'DOMAIN' "$domain"
 is_object_unsuspended 'mail' 'DOMAIN' "$domain"
 is_object_valid "mail/$domain" 'ACCOUNT' "$account"
 is_object_valid "mail/$domain" 'ACCOUNT' "$account"
 is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
 is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
-is_key_empty "mail/$domain" '' '$AUTOREPLY'
-exit
+is_object_value_empty "mail/$domain" 'ACCOUNT' "$domain" '$AUTOREPLY'
+
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 #                       Action                             #
 #                       Action                             #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
-exit
-# Adding exim alias
-str="$mailas@$domain:$account@$domain"
-echo "$str" >> $HOMEDIR/$user/conf/mail/$domain/aliases
+# Add exim autoreply
+echo -e "$autoreply" > $HOMEDIR/$user/conf/mail/$domain/autoreply.$account.msg
+chown -R root:mail $HOMEDIR/$user/conf/mail/$domain/autoreply.$account.msg
+chmod 660 $HOMEDIR/$user/conf/mail/$domain/autoreply.$account.msg
 
 
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
@@ -52,17 +53,12 @@ echo "$str" >> $HOMEDIR/$user/conf/mail/$domain/aliases
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 # Adding vesta alias
 # Adding vesta alias
-aliases=$(get_domain_value "mail/$domain" '$ALIAS' "ACCOUNT='$account'")
-if [ -z "$aliases" ]; then
-    aliases="$malias"
-else
-    aliases="$aliases,$malias"
-fi
-update_domain_value "mail/$domain" '$ALIAS' "$aliases" "ACCOUNT='$account'"
+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'
 
 
 # Logging
 # Logging
-cmd='v_delete_mail_account_alias'
-log_history "$EVENT" "$cmd $user $domain $account $malias"
+log_history "$EVENT"
 log_event "$OK" "$EVENT"
 log_event "$OK" "$EVENT"
 
 
 exit
 exit

+ 7 - 18
bin/v_add_mail_domain

@@ -19,7 +19,7 @@ antivirus=${4-yes}
 dkim=${5-yes}
 dkim=${5-yes}
 dkim_size=${6-512}
 dkim_size=${6-512}
 
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/shared.sh
 source $VESTA/func/domain.sh
 source $VESTA/func/domain.sh
@@ -29,25 +29,12 @@ source $VESTA/func/domain.sh
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Checking arg number
 check_args '2' "$#" 'user domain [antispam] [antivirus] [dkim] [dkim_size]'
 check_args '2' "$#" 'user domain [antispam] [antivirus] [dkim] [dkim_size]'
-
-# Checking argument format
 validate_format 'user' 'domain' 'antispam' 'antivirus' 'dkim' 'dkim_size'
 validate_format 'user' 'domain' 'antispam' 'antivirus' 'dkim' 'dkim_size'
-
-# Checking dns system is enabled
-is_system_enabled 'MAIL_SYSTEM'
-
-# Checking user
+is_system_enabled "$MAIL_SYSTEM"
 is_object_valid 'user' 'USER' "$user"
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user is active
 is_object_unsuspended 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
-
-# Checking domain
 is_domain_new 'mail'
 is_domain_new 'mail'
-
-# Checking package
 is_package_full 'MAIL_DOMAINS'
 is_package_full 'MAIL_DOMAINS'
 
 
 
 
@@ -92,7 +79,7 @@ if [ "$dkim" = 'yes' ]; then
     chmod 660 $HOMEDIR/$user/conf/mail/$domain/dkim.pem
     chmod 660 $HOMEDIR/$user/conf/mail/$domain/dkim.pem
 
 
     # Adding dkim dns records
     # Adding dkim dns records
-    check_dns_domain=$(is_domain_valid 'dns')
+    check_dns_domain=$(is_object_valid 'dns' 'DOMAIN' "$domain")
     if [ "$?" -eq 0 ]; then
     if [ "$?" -eq 0 ]; then
         p=$(cat $USER_DATA/mail/$domain.pub|grep -v ' KEY---'|tr -d '\n')
         p=$(cat $USER_DATA/mail/$domain.pub|grep -v ' KEY---'|tr -d '\n')
         record='_domainkey'
         record='_domainkey'
@@ -107,7 +94,9 @@ fi
 
 
 # Adding domain to vesta db
 # Adding domain to vesta db
 s="DOMAIN='$domain' ANTIVIRUS='$antivirus' ANTISPAM='$antispam' DKIM='$dkim'"
 s="DOMAIN='$domain' ANTIVIRUS='$antivirus' ANTISPAM='$antispam' DKIM='$dkim'"
-s="$s ACCOUNTS='0' U_DISK='0' CATCHALL='' SUSPENDED='no' DATE='$DATE'"
+s="$s ACCOUNTS='0' U_DISK='0' CATCHALL='' SUSPENDED='no' TIME='$TIME'"
+s="$s DATE='$DATE'"
+
 echo $s >> $USER_DATA/mail.conf
 echo $s >> $USER_DATA/mail.conf
 touch $USER_DATA/mail/$domain.conf
 touch $USER_DATA/mail/$domain.conf
 chmod 660 $USER_DATA/mail.conf
 chmod 660 $USER_DATA/mail.conf
@@ -122,7 +111,7 @@ chmod 660 $USER_DATA/mail/$domain.conf
 increase_user_value "$user" '$U_MAIL_DOMAINS'
 increase_user_value "$user" '$U_MAIL_DOMAINS'
 
 
 # Logging
 # Logging
-log_history "$EVENT" "v_delete_mail_domain $user $domain"
+log_history "$EVENT"
 log_event "$OK" "$EVENT"
 log_event "$OK" "$EVENT"
 
 
 exit
 exit

+ 8 - 23
bin/v_add_mail_domain_antispam

@@ -15,7 +15,7 @@ domain=$(idn -t --quiet -u "$2" )
 domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
 domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
 domain_idn=$(idn -t --quiet -a "$domain")
 domain_idn=$(idn -t --quiet -a "$domain")
 
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/shared.sh
 source $VESTA/func/domain.sh
 source $VESTA/func/domain.sh
@@ -25,29 +25,14 @@ source $VESTA/func/domain.sh
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Checking arg number
 check_args '2' "$#" 'user domain'
 check_args '2' "$#" 'user domain'
-
-# Checking argument format
 validate_format 'user' 'domain'
 validate_format 'user' 'domain'
-
-# Checking dns system is enabled
-is_system_enabled 'MAIL_SYSTEM'
-
-# Checking user
+is_system_enabled "$MAIL_SYSTEM"
 is_object_valid 'user' 'USER' "$user"
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user is active
 is_object_unsuspended 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
-
-# Checking domain
-is_domain_valid 'mail'
-
-# Checking domain is not suspened
-is_domain_suspended 'mail'
-
-# Checking errorlog is not added
-is_domain_key_empty 'mail' '$ANTISPAM'
+is_object_valid 'mail' 'DOMAIN' "$domain"
+is_object_unsuspended 'mail' 'DOMAIN' "$domain"
+is_object_value_empty 'mail' 'DOMAIN' "$domain" '$ANTISPAM'
 
 
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
@@ -55,7 +40,7 @@ is_domain_key_empty 'mail' '$ANTISPAM'
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 # Adding antispam key to config
 # Adding antispam key to config
-if [ -z "$(grep 'antispam' $HOMEDIR/$user/conf/mail/$domain/protection)" ]; then
+if [ -z "$(grep spam $HOMEDIR/$user/conf/mail/$domain/protection)" ]; then
     echo 'antispam' >> $HOMEDIR/$user/conf/mail/$domain/protection
     echo 'antispam' >> $HOMEDIR/$user/conf/mail/$domain/protection
 fi
 fi
 
 
@@ -64,10 +49,10 @@ fi
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 # Adding antispam in config
 # Adding antispam in config
-update_domain_value 'mail' '$ANTISPAM' 'yes'
+update_object_value 'mail' 'DOMAIN' "$domain" '$ANTISPAM' 'yes'
 
 
 # Logging
 # Logging
-log_history "$EVENT" "v_delete_mail_domain_antispam $user $domain"
+log_history "$EVENT"
 log_event "$OK" "$EVENT"
 log_event "$OK" "$EVENT"
 
 
 exit
 exit

+ 8 - 22
bin/v_add_mail_domain_antivirus

@@ -15,7 +15,7 @@ domain=$(idn -t --quiet -u "$2" )
 domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
 domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
 domain_idn=$(idn -t --quiet -a "$domain")
 domain_idn=$(idn -t --quiet -a "$domain")
 
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/shared.sh
 source $VESTA/func/domain.sh
 source $VESTA/func/domain.sh
@@ -25,29 +25,14 @@ source $VESTA/func/domain.sh
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Checking arg number
 check_args '2' "$#" 'user domain'
 check_args '2' "$#" 'user domain'
-
-# Checking argument format
 validate_format 'user' 'domain'
 validate_format 'user' 'domain'
-
-# Checking dns system is enabled
-is_system_enabled 'MAIL_SYSTEM'
-
-# Checking user
+is_system_enabled "$MAIL_SYSTEM"
 is_object_valid 'user' 'USER' "$user"
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user is active
 is_object_unsuspended 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
-
-# Checking domain
-is_domain_valid 'mail'
-
-# Checking domain is not suspened
-is_domain_suspended 'mail'
-
-# Checking current value
-is_domain_key_empty 'mail' '$ANTIVIRUS'
+is_object_valid 'mail' 'DOMAIN' "$domain"
+is_object_unsuspended 'mail' 'DOMAIN' "$domain"
+is_object_value_empty 'mail' 'DOMAIN' "$domain" '$ANTIVIRUS'
 
 
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
@@ -59,15 +44,16 @@ if [ -z "$(grep 'virus' $HOMEDIR/$user/conf/mail/$domain/protection)" ]; then
     echo 'antivirus' >> $HOMEDIR/$user/conf/mail/$domain/protection
     echo 'antivirus' >> $HOMEDIR/$user/conf/mail/$domain/protection
 fi
 fi
 
 
+
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 #                       Vesta                              #
 #                       Vesta                              #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 # Adding antivirus in config
 # Adding antivirus in config
-update_domain_value 'mail' '$ANTIVIRUS' 'yes'
+update_object_value 'mail' 'DOMAIN' "$domain" '$ANTIVIRUS' 'yes'
 
 
 # Logging
 # Logging
-log_history "$EVENT" "v_delete_mail_domain_antivirus $user $domain"
+log_history "$EVENT"
 log_event "$OK" "$EVENT"
 log_event "$OK" "$EVENT"
 
 
 exit
 exit

+ 10 - 24
bin/v_add_mail_domain_cactchall

@@ -16,7 +16,7 @@ domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
 domain_idn=$(idn -t --quiet -a "$domain")
 domain_idn=$(idn -t --quiet -a "$domain")
 email="$3"
 email="$3"
 
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/shared.sh
 source $VESTA/func/domain.sh
 source $VESTA/func/domain.sh
@@ -26,29 +26,14 @@ source $VESTA/func/domain.sh
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Checking arg number
 check_args '3' "$#" 'user domain email'
 check_args '3' "$#" 'user domain email'
-
-# Checking argument format
 validate_format 'user' 'domain' 'email'
 validate_format 'user' 'domain' 'email'
-
-# Checking dns system is enabled
-is_system_enabled 'MAIL_SYSTEM'
-
-# Checking user
+is_system_enabled "$MAIL_SYSTEM"
 is_object_valid 'user' 'USER' "$user"
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user is active
 is_object_unsuspended 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
-
-# Checking domain
-is_domain_valid 'mail'
-
-# Checking domain is not suspened
-is_domain_suspended 'mail'
-
-# Checking errorlog is not added
-is_domain_key_empty 'mail' '$CATCHALL'
+is_object_valid 'mail' 'DOMAIN' "$domain"
+is_object_unsuspended 'mail' 'DOMAIN' "$domain"
+is_object_value_empty 'mail' 'DOMAIN' "$domain" '$CATCHALL'
 
 
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
@@ -56,8 +41,8 @@ is_domain_key_empty 'mail' '$CATCHALL'
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 # Adding catchall alias
 # Adding catchall alias
-sed -i "/*@demo.vestacp.com:/d" $HOMEDIR/$user/conf/mail/$domain/aliases
-echo "*@demo.vestacp.com:$email" >> $HOMEDIR/$user/conf/mail/$domain/aliases
+sed -i "/*@$domain:/d" $HOMEDIR/$user/conf/mail/$domain/aliases
+echo "*@$domain:$email" >> $HOMEDIR/$user/conf/mail/$domain/aliases
 
 
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
@@ -65,10 +50,11 @@ echo "*@demo.vestacp.com:$email" >> $HOMEDIR/$user/conf/mail/$domain/aliases
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 # Adding antispam in config
 # Adding antispam in config
-update_domain_value 'mail' '$CATCHALL' "$email"
+update_object_value 'mail' 'DOMAIN' "$domain" '$CATCHALL' "$email"
+
 
 
 # Logging
 # Logging
-log_history "$EVENT" "v_delete_mail_domain_catchall $user $domain"
+log_history "$EVENT"
 log_event "$OK" "$EVENT"
 log_event "$OK" "$EVENT"
 
 
 exit
 exit

+ 8 - 23
bin/v_add_mail_domain_dkim

@@ -16,7 +16,7 @@ domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
 domain_idn=$(idn -t --quiet -a "$domain")
 domain_idn=$(idn -t --quiet -a "$domain")
 dkim_size=${3-512}
 dkim_size=${3-512}
 
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/shared.sh
 source $VESTA/func/domain.sh
 source $VESTA/func/domain.sh
@@ -26,29 +26,14 @@ source $VESTA/func/domain.sh
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Checking arg number
 check_args '2' "$#" 'user domain [dkim_size]'
 check_args '2' "$#" 'user domain [dkim_size]'
-
-# Checking argument format
 validate_format 'user' 'domain' 'dkim_size'
 validate_format 'user' 'domain' 'dkim_size'
-
-# Checking dns system is enabled
-is_system_enabled 'MAIL_SYSTEM'
-
-# Checking user
+is_system_enabled "$MAIL_SYSTEM"
 is_object_valid 'user' 'USER' "$user"
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user is active
 is_object_unsuspended 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
-
-# Checking domain
-is_domain_valid 'mail'
-
-# Checking domain is not suspened
-is_domain_suspended 'mail'
-
-# Checking errorlog is not added
-is_domain_key_empty 'mail' '$DKIM'
+is_object_valid 'mail' 'DOMAIN' "$domain"
+is_object_unsuspended 'mail' 'DOMAIN' "$domain"
+is_object_value_empty 'mail' 'DOMAIN' "$domain" '$DKIM'
 
 
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
@@ -67,7 +52,7 @@ chown root:mail $HOMEDIR/$user/conf/mail/$domain/dkim.pem
 chmod 660 $HOMEDIR/$user/conf/mail/$domain/dkim.pem
 chmod 660 $HOMEDIR/$user/conf/mail/$domain/dkim.pem
 
 
 # Checking dns domain
 # Checking dns domain
-check_dns_domain=$(is_domain_valid 'dns')
+check_dns_domain=$(is_object_valid 'dns' 'DOMAIN' "$domain")
 if [ "$?" -eq 0 ]; then
 if [ "$?" -eq 0 ]; then
     # Adding dkim dns records
     # Adding dkim dns records
     p=$(cat $USER_DATA/mail/$domain.pub|grep -v ' KEY---'|tr -d '\n')
     p=$(cat $USER_DATA/mail/$domain.pub|grep -v ' KEY---'|tr -d '\n')
@@ -86,10 +71,10 @@ fi
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 # Adding dkim in config
 # Adding dkim in config
-update_domain_value 'mail' '$DKIM' 'yes'
+update_object_value 'mail' 'DOMAIN' "$domain" '$DKIM' 'yes'
 
 
 # Logging
 # Logging
-log_history "$EVENT" "v_delete_mail_domain_dkim $user $domain"
+log_history "$EVENT"
 log_event "$OK" "$EVENT"
 log_event "$OK" "$EVENT"
 
 
 exit
 exit

+ 1 - 0
bin/v_add_user

@@ -172,6 +172,7 @@ PACKAGE='$package'
 $package_data
 $package_data
 CONTACT='$email'
 CONTACT='$email'
 CRON_REPORTS='yes'
 CRON_REPORTS='yes'
+MD5='$(awk -v user=$user -F : 'user == $1 {print $2}' /etc/shadow)'
 RKEY='$(gen_password)'
 RKEY='$(gen_password)'
 SUSPENDED='no'
 SUSPENDED='no'
 SUSPENDED_USERS='0'
 SUSPENDED_USERS='0'

+ 2 - 2
bin/v_add_web_domain

@@ -182,8 +182,8 @@ increase_user_value "$user" '$U_WEB_ALIASES'
 # Defining domain variables
 # Defining domain variables
 str="DOMAIN='$domain' IP='$ip' IP6='' ALIAS='$aliases' TPL='$template'"
 str="DOMAIN='$domain' IP='$ip' IP6='' ALIAS='$aliases' TPL='$template'"
 str="$str $template_data SSL='no' SSL_HOME='single' NGINX='' NGINX_EXT=''"
 str="$str $template_data SSL='no' SSL_HOME='single' NGINX='' NGINX_EXT=''"
-str="$str STATS='' STATS_USER='' U_DISK='0' U_BANDWIDTH='0' SUSPENDED='no'"
-str="$str TIME='$TIME' DATE='$DATE'"
+str="$str STATS='' STATS_USER='' STATS_CRYPT='' U_DISK='0' U_BANDWIDTH='0'"
+str="$str SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
 
 
 # Registering domain
 # Registering domain
 echo "$str" >> $USER_DATA/web.conf
 echo "$str" >> $USER_DATA/web.conf

+ 3 - 2
bin/v_add_web_domain_stats_user

@@ -32,7 +32,7 @@ is_object_valid 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
 is_object_valid 'web' 'DOMAIN' "$domain"
 is_object_valid 'web' 'DOMAIN' "$domain"
 is_object_unsuspended 'web' 'DOMAIN' "$domain"
 is_object_unsuspended 'web' 'DOMAIN' "$domain"
-is_object_value_empty 'web' 'DOMAIN' "$domain" '$STATS_USER'
+is_object_value_exist 'web' 'DOMAIN' "$domain" '$STATS'
 
 
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
@@ -52,7 +52,7 @@ Require valid-user" > $stats_dir/.htaccess
 # Generating htaccess user and password
 # Generating htaccess user and password
 rm -f $stats_dir/.htpasswd
 rm -f $stats_dir/.htpasswd
 htpasswd -bc $stats_dir/.htpasswd "$stats_user" "$stats_pass" &>/dev/null
 htpasswd -bc $stats_dir/.htpasswd "$stats_user" "$stats_pass" &>/dev/null
-
+stats_crypt=$(grep $stats_user: $stats_dir/.htpasswd |cut -f 2 -d :)
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 #                       Vesta                              #
 #                       Vesta                              #
@@ -60,6 +60,7 @@ htpasswd -bc $stats_dir/.htpasswd "$stats_user" "$stats_pass" &>/dev/null
 
 
 # Adding stats user in config
 # Adding stats user in config
 update_object_value 'web' 'DOMAIN' "$domain" '$STATS_USER' "$stats_user"
 update_object_value 'web' 'DOMAIN' "$domain" '$STATS_USER' "$stats_user"
+update_object_value 'web' 'DOMAIN' "$domain" '$STATS_CRYPT' "$stats_crypt"
 
 
 # Hiding password
 # Hiding password
 EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT'"
 EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT'"

+ 3 - 0
bin/v_change_database_password

@@ -50,6 +50,9 @@ esac
 #                       Vesta                              #
 #                       Vesta                              #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
+# Update config value
+update_object_value 'db' 'DB' "$database" '$MD5' "$md5"
+
 # Hiding password
 # Hiding password
 EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT'"
 EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT'"
 EVENT="$EVENT ARGUMENTS='$user $database *****'"
 EVENT="$EVENT ARGUMENTS='$user $database *****'"

+ 9 - 24
bin/v_change_mail_domain_cactchall

@@ -16,7 +16,7 @@ domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
 domain_idn=$(idn -t --quiet -a "$domain")
 domain_idn=$(idn -t --quiet -a "$domain")
 email="$3"
 email="$3"
 
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/shared.sh
 source $VESTA/func/domain.sh
 source $VESTA/func/domain.sh
@@ -26,38 +26,22 @@ source $VESTA/func/domain.sh
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Checking arg number
 check_args '3' "$#" 'user domain email'
 check_args '3' "$#" 'user domain email'
-
-# Checking argument format
 validate_format 'user' 'domain' 'email'
 validate_format 'user' 'domain' 'email'
-
-# Checking dns system is enabled
-is_system_enabled 'MAIL_SYSTEM'
-
-# Checking user
+is_system_enabled "$MAIL_SYSTEM"
 is_object_valid 'user' 'USER' "$user"
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user is active
 is_object_unsuspended 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
-
-# Checking domain
-is_domain_valid 'mail'
-
-# Checking domain is not suspened
-is_domain_suspended 'mail'
+is_object_valid 'mail' 'DOMAIN' "$domain"
+is_object_unsuspended 'mail' 'DOMAIN' "$domain"
 
 
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 #                       Action                             #
 #                       Action                             #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Get old catchall 
-catchall=$(get_domain_value 'mail' '$CATCHALL')
-
 # Change cathcall alias
 # Change cathcall alias
-sed -i "/*@demo.vestacp.com:/d" $HOMEDIR/$user/conf/mail/$domain/aliases
-echo "*@demo.vestacp.com:$email" >> $HOMEDIR/$user/conf/mail/$domain/aliases
+sed -i "/*@$domain:/d" $HOMEDIR/$user/conf/mail/$domain/aliases
+echo "*@$domain:$email" >> $HOMEDIR/$user/conf/mail/$domain/aliases
 
 
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
@@ -65,10 +49,11 @@ echo "*@demo.vestacp.com:$email" >> $HOMEDIR/$user/conf/mail/$domain/aliases
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 # Change catchall in config
 # Change catchall in config
-update_domain_value 'mail' '$CATCHALL' "$email"
+update_object_value 'mail' 'DOMAIN' "$domain" '$CATCHALL' "$email"
+
 
 
 # Logging
 # Logging
-log_history "$EVENT" "v_change_mail_domain_catchall $user $domain $catchall"
+log_history "$EVENT"
 log_event "$OK" "$EVENT"
 log_event "$OK" "$EVENT"
 
 
 exit
 exit

+ 1 - 0
bin/v_change_user_package

@@ -75,6 +75,7 @@ SHELL='$SHELL'
 BACKUPS='$BACKUPS'
 BACKUPS='$BACKUPS'
 CONTACT='$CONTACT'
 CONTACT='$CONTACT'
 CRON_REPORTS='$CRON_REPORTS'
 CRON_REPORTS='$CRON_REPORTS'
+MD5='$MD5'
 RKEY='$RKEY'
 RKEY='$RKEY'
 SUSPENDED='$SUSPENDED'
 SUSPENDED='$SUSPENDED'
 SUSPENDED_USERS='$SUSPENDED_USERS'
 SUSPENDED_USERS='$SUSPENDED_USERS'

+ 2 - 0
bin/v_change_user_password

@@ -34,6 +34,7 @@ is_object_unsuspended 'user' 'USER' "$user"
 
 
 # Changing user password
 # Changing user password
 echo "$password" | /usr/bin/passwd "$user" --stdin &>/dev/null
 echo "$password" | /usr/bin/passwd "$user" --stdin &>/dev/null
+md5=$(awk -v user=$user -F : 'user == $1 {print $2}' /etc/shadow)
 
 
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
@@ -42,6 +43,7 @@ echo "$password" | /usr/bin/passwd "$user" --stdin &>/dev/null
 
 
 # Changing RKEY value
 # Changing RKEY value
 update_user_value "$user" '$RKEY' "$(gen_password)"
 update_user_value "$user" '$RKEY' "$(gen_password)"
+update_user_value "$user" '$MD5' "$md5"
 
 
 # Hiding password
 # Hiding password
 EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT' ARGUMENTS='$user *****'"
 EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT' ARGUMENTS='$user *****'"

+ 6 - 17
bin/v_delete_mail_domain

@@ -14,7 +14,7 @@
 user=$1
 user=$1
 domain=$(idn -t --quiet -u "$2" )
 domain=$(idn -t --quiet -u "$2" )
 
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/shared.sh
 source $VESTA/func/domain.sh
 source $VESTA/func/domain.sh
@@ -24,23 +24,13 @@ source $VESTA/func/domain.sh
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Checking arg number
 check_args '2' "$#" 'user domain'
 check_args '2' "$#" 'user domain'
-
-# Checking argument format
 validate_format 'user' 'domain'
 validate_format 'user' 'domain'
-
-# Checking web system is enabled
-is_system_enabled 'MAIL_SYSTEM'
-
-# Checking user
+is_system_enabled "$MAIL_SYSTEM"
 is_object_valid 'user' 'USER' "$user"
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user is active
 is_object_unsuspended 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
-
-# Checking domain exist
-is_domain_valid 'mail'
+is_object_valid 'mail' 'DOMAIN' "$domain"
+is_object_unsuspended 'mail' 'DOMAIN' "$domain"
 
 
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
@@ -65,15 +55,14 @@ sed -i "/DOMAIN='$domain'/ d" $USER_DATA/mail.conf
 rm -f $USER_DATA/mail/$domain.conf
 rm -f $USER_DATA/mail/$domain.conf
 rm -f $USER_DATA/mail/$domain.pem
 rm -f $USER_DATA/mail/$domain.pem
 rm -f $USER_DATA/mail/$domain.pub
 rm -f $USER_DATA/mail/$domain.pub
-# autoreply
+rm -f $USER_DATA/mail/*@$domain.msg
 
 
 # Decreasing domain value
 # Decreasing domain value
 decrease_user_value "$user" '$U_MAIL_DOMAINS'
 decrease_user_value "$user" '$U_MAIL_DOMAINS'
 decrease_user_value "$user" '$U_MAIL_ACCOUNTS' "$accounts"
 decrease_user_value "$user" '$U_MAIL_ACCOUNTS' "$accounts"
 
 
 # Logging
 # Logging
-cmd='"v_add_mail_domain'
-log_history "$EVENT" "$cmd $user $domain $ANTISPAM $ANTIVIRUS $DKIM"
+log_history "$EVENT"
 log_event "$OK" "$EVENT"
 log_event "$OK" "$EVENT"
 
 
 exit
 exit

+ 7 - 22
bin/v_delete_mail_domain_antispam

@@ -15,7 +15,7 @@ domain=$(idn -t --quiet -u "$2" )
 domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
 domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
 domain_idn=$(idn -t --quiet -a "$domain")
 domain_idn=$(idn -t --quiet -a "$domain")
 
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/shared.sh
 source $VESTA/func/domain.sh
 source $VESTA/func/domain.sh
@@ -25,29 +25,14 @@ source $VESTA/func/domain.sh
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Checking arg number
 check_args '2' "$#" 'user domain'
 check_args '2' "$#" 'user domain'
-
-# Checking argument format
 validate_format 'user' 'domain'
 validate_format 'user' 'domain'
-
-# Checking dns system is enabled
-is_system_enabled 'MAIL_SYSTEM'
-
-# Checking user
+is_system_enabled "$MAIL_SYSTEM"
 is_object_valid 'user' 'USER' "$user"
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user is active
 is_object_unsuspended 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
-
-# Checking domain
-is_domain_valid 'mail'
-
-# Checking domain is not suspened
-is_domain_suspended 'mail'
-
-# Checking current value
-is_domain_value_exist 'mail' '$ANTISPAM'
+is_object_valid 'mail' 'DOMAIN' "$domain"
+is_object_unsuspended 'mail' 'DOMAIN' "$domain"
+is_object_value_exist 'mail' 'DOMAIN' "$domain" '$ANTISPAM'
 
 
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
@@ -63,10 +48,10 @@ sed -i "/antispam/d" $HOMEDIR/$user/conf/mail/$domain/protection
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 # Delete antispam in config
 # Delete antispam in config
-update_domain_value 'mail' '$ANTISPAM' 'no'
+update_object_value 'mail' 'DOMAIN' "$domain" '$ANTISPAM' 'no'
 
 
 # Logging
 # Logging
-log_history "$EVENT" "v_add_mail_domain_antispam $user $domain"
+log_history "$EVENT"
 log_event "$OK" "$EVENT"
 log_event "$OK" "$EVENT"
 
 
 exit
 exit

+ 7 - 22
bin/v_delete_mail_domain_antivirus

@@ -15,7 +15,7 @@ domain=$(idn -t --quiet -u "$2" )
 domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
 domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
 domain_idn=$(idn -t --quiet -a "$domain")
 domain_idn=$(idn -t --quiet -a "$domain")
 
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/shared.sh
 source $VESTA/func/domain.sh
 source $VESTA/func/domain.sh
@@ -25,29 +25,14 @@ source $VESTA/func/domain.sh
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Checking arg number
 check_args '2' "$#" 'user domain'
 check_args '2' "$#" 'user domain'
-
-# Checking argument format
 validate_format 'user' 'domain'
 validate_format 'user' 'domain'
-
-# Checking dns system is enabled
-is_system_enabled 'MAIL_SYSTEM'
-
-# Checking user
+is_system_enabled "$MAIL_SYSTEM"
 is_object_valid 'user' 'USER' "$user"
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user is active
 is_object_unsuspended 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
-
-# Checking domain
-is_domain_valid 'mail'
-
-# Checking domain is not suspened
-is_domain_suspended 'mail'
-
-# Checking current value
-is_domain_value_exist 'mail' '$ANTIVIRUS'
+is_object_valid 'mail' 'DOMAIN' "$domain"
+is_object_unsuspended 'mail' 'DOMAIN' "$domain"
+is_object_value_exist 'mail' 'DOMAIN' "$domain" '$ANTIVIRUS'
 
 
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
@@ -63,10 +48,10 @@ sed -i "/antivirus/d" $HOMEDIR/$user/conf/mail/$domain/protection
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 # Delete antivirus in config
 # Delete antivirus in config
-update_domain_value 'mail' '$ANTIVIRUS' 'no'
+update_object_value 'mail' 'DOMAIN' "$domain" '$ANTIVIRUS' 'no'
 
 
 # Logging
 # Logging
-log_history "$EVENT" "v_add_mail_domain_antivirus $user $domain"
+log_history "$EVENT"
 log_event "$OK" "$EVENT"
 log_event "$OK" "$EVENT"
 
 
 exit
 exit

+ 8 - 26
bin/v_delete_mail_domain_cactchall

@@ -15,7 +15,7 @@ domain=$(idn -t --quiet -u "$2" )
 domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
 domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
 domain_idn=$(idn -t --quiet -a "$domain")
 domain_idn=$(idn -t --quiet -a "$domain")
 
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/shared.sh
 source $VESTA/func/domain.sh
 source $VESTA/func/domain.sh
@@ -25,40 +25,22 @@ source $VESTA/func/domain.sh
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Checking arg number
 check_args '2' "$#" 'user domain'
 check_args '2' "$#" 'user domain'
-
-# Checking argument format
 validate_format 'user' 'domain'
 validate_format 'user' 'domain'
-
-# Checking dns system is enabled
-is_system_enabled 'MAIL_SYSTEM'
-
-# Checking user
+is_system_enabled "$MAIL_SYSTEM"
 is_object_valid 'user' 'USER' "$user"
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user is active
 is_object_unsuspended 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
-
-# Checking domain
-is_domain_valid 'mail'
-
-# Checking domain is not suspened
-is_domain_suspended 'mail'
-
-# Checking current value
-is_domain_value_exist 'mail' '$CATCHALL'
+is_object_valid 'mail' 'DOMAIN' "$domain"
+is_object_unsuspended 'mail' 'DOMAIN' "$domain"
+is_object_value_exist 'mail' 'DOMAIN' "$domain" '$CATCHALL'
 
 
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 #                       Action                             #
 #                       Action                             #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Get old catchall 
-email=$(get_domain_value 'mail' '$CATCHALL')
-
 # Delete cathcall alias
 # Delete cathcall alias
-sed -i "/*@demo.vestacp.com:/d" $HOMEDIR/$user/conf/mail/$domain/aliases
+sed -i "/*@$domain:/d" $HOMEDIR/$user/conf/mail/$domain/aliases
 
 
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
@@ -66,10 +48,10 @@ sed -i "/*@demo.vestacp.com:/d" $HOMEDIR/$user/conf/mail/$domain/aliases
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 # Delete catchall in config
 # Delete catchall in config
-update_domain_value 'mail' '$CATCHALL' ''
+update_object_value 'mail' 'DOMAIN' "$domain" '$CATCHALL' ''
 
 
 # Logging
 # Logging
-log_history "$EVENT" "v_add_mail_domain_catchall $user $domain $email"
+log_history "$EVENT"
 log_event "$OK" "$EVENT"
 log_event "$OK" "$EVENT"
 
 
 exit
 exit

+ 10 - 25
bin/v_delete_mail_domain_dkim

@@ -14,7 +14,7 @@ user=$1
 domain=$(idn -t --quiet -u "$2" )
 domain=$(idn -t --quiet -u "$2" )
 domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
 domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
 
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/shared.sh
 source $VESTA/func/domain.sh
 source $VESTA/func/domain.sh
@@ -24,29 +24,14 @@ source $VESTA/func/domain.sh
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Checking arg number
 check_args '2' "$#" 'user domain'
 check_args '2' "$#" 'user domain'
-
-# Checking argument format
 validate_format 'user' 'domain'
 validate_format 'user' 'domain'
-
-# Checking dns system is enabled
-is_system_enabled 'MAIL_SYSTEM'
-
-# Checking user
+is_system_enabled "$MAIL_SYSTEM"
 is_object_valid 'user' 'USER' "$user"
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user is active
 is_object_unsuspended 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
-
-# Checking domain
-is_domain_valid 'mail'
-
-# Checking domain is not suspened
-is_domain_suspended 'mail'
-
-# Checking errorlog is not added
-is_domain_value_exist 'mail' '$DKIM'
+is_object_valid 'mail' 'DOMAIN' "$domain"
+is_object_unsuspended 'mail' 'DOMAIN' "$domain"
+is_object_value_exist 'mail' 'DOMAIN' "$domain" '$DKIM'
 
 
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
@@ -59,10 +44,10 @@ rm -f $USER_DATA/mail/$domain.pub
 rm -f $HOMEDIR/$user/conf/mail/$domain/dkim.pem
 rm -f $HOMEDIR/$user/conf/mail/$domain/dkim.pem
 
 
 # Checking dns domain
 # Checking dns domain
-check_dns_domain=$(is_domain_valid 'dns')
+check_dns_domain=$(is_object_valid 'dns' 'DOMAIN' "$domain")
 if [ "$?" -eq 0 ]; then
 if [ "$?" -eq 0 ]; then
     records=$($BIN/v_list_dns_domain_records $user $domain plain)
     records=$($BIN/v_list_dns_domain_records $user $domain plain)
-    dkim_records=$(echo "$records" |grep -w '_domainkey'|cut -f 1 -d ' ')
+    dkim_records=$(echo "$records" |grep -w '_domainkey' | cut -f 1 -d ' ')
     for id in $dkim_records; do
     for id in $dkim_records; do
         $BIN/v_delete_dns_domain_record $user $domain $id
         $BIN/v_delete_dns_domain_record $user $domain $id
     done
     done
@@ -73,11 +58,11 @@ fi
 #                       Vesta                              #
 #                       Vesta                              #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Adding dkim in config
-update_domain_value 'mail' '$DKIM' 'no'
+# Updatoing config
+update_object_value 'mail' 'DOMAIN' "$domain" '$DKIM' 'no'
 
 
 # Logging
 # Logging
-log_history "$EVENT" "v_add_mail_domain_dkim $user $domain"
+log_history "$EVENT"
 log_event "$OK" "$EVENT"
 log_event "$OK" "$EVENT"
 
 
 exit
 exit

+ 2 - 0
bin/v_delete_web_domain_stats_user

@@ -51,6 +51,8 @@ rm -f $HOMEDIR/$user/web/$domain/stats/.htaccess
 
 
 # Update config
 # Update config
 update_object_value 'web' 'DOMAIN' "$domain" '$STATS_USER' ''
 update_object_value 'web' 'DOMAIN' "$domain" '$STATS_USER' ''
+update_object_value 'web' 'DOMAIN' "$domain" '$STATS_CRYPT' ''
+
 
 
 # Logging
 # Logging
 log_history "$EVENT"
 log_history "$EVENT"

+ 3 - 12
bin/v_list_mail_accounts

@@ -14,7 +14,7 @@ user=$1
 domain=$2
 domain=$2
 format=${3-shell}
 format=${3-shell}
 
 
-# Importing variables
+# Includes
 source $VESTA/func/shared.sh
 source $VESTA/func/shared.sh
 
 
 
 
@@ -22,27 +22,18 @@ source $VESTA/func/shared.sh
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Checking args
 check_args '2' "$#" 'user domain [format]'
 check_args '2' "$#" 'user domain [format]'
-
-# Checking argument format
 validate_format 'user' 'domain'
 validate_format 'user' 'domain'
-
-# Checking user
 is_object_valid 'user' 'USER' "$user"
 is_object_valid 'user' 'USER' "$user"
-
-# Checking domain
-is_domain_valid 'mail'
+is_object_valid 'mail' 'DOMAIN' "$domain"
 
 
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 #                       Action                             #
 #                       Action                             #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Defining config
-conf=$USER_DATA/mail/$domain.conf
-
 # Defining fileds to select
 # Defining fileds to select
+conf=$USER_DATA/mail/$domain.conf
 fields="\$ACCOUNT \$ALIAS \$FWD \$AUTOREPLY \$U_DISK \$SUSPENDED \$DATE"
 fields="\$ACCOUNT \$ALIAS \$FWD \$AUTOREPLY \$U_DISK \$SUSPENDED \$DATE"
 
 
 # Listing domain accounts
 # Listing domain accounts

+ 3 - 26
bin/v_list_mail_domain

@@ -15,7 +15,7 @@ user=$1
 domain=$2
 domain=$2
 format=${3-shell}
 format=${3-shell}
 
 
-# Importing variables
+# Includes
 source $VESTA/func/shared.sh
 source $VESTA/func/shared.sh
 
 
 # Json function
 # Json function
@@ -23,19 +23,10 @@ json_list_domain() {
     i=1
     i=1
     fileds_count=$(echo "$fields" | wc -w)
     fileds_count=$(echo "$fields" | wc -w)
     line=$(grep "DOMAIN='$domain'" $conf)
     line=$(grep "DOMAIN='$domain'" $conf)
-
-    # Print top bracket
     echo '{'
     echo '{'
-
-    # Assing key=value
     eval $line
     eval $line
-
-    # Starting output loop
     for field in $fields; do
     for field in $fields; do
-        # Parsing key=value
         eval value=$field
         eval value=$field
-
-        # Checking first field
         if [ "$i" -eq 1 ]; then
         if [ "$i" -eq 1 ]; then
             echo -e "\t\"$value\": {"
             echo -e "\t\"$value\": {"
         else
         else
@@ -45,26 +36,19 @@ json_list_domain() {
                 echo -e "\t\t\"${field//$/}\": \"$value\""
                 echo -e "\t\t\"${field//$/}\": \"$value\""
             fi
             fi
         fi
         fi
-        # Updating iterator
         (( ++i))
         (( ++i))
     done
     done
 
 
-    # If there was any output
     if [ -n "$value" ]; then
     if [ -n "$value" ]; then
         echo -e '        }'
         echo -e '        }'
     fi
     fi
-    # Printing bottom json bracket
     echo -e "}"
     echo -e "}"
 }
 }
 
 
 # Shell function
 # Shell function
 shell_list_domain() {
 shell_list_domain() {
     line=$(grep "DOMAIN='$domain'" $conf)
     line=$(grep "DOMAIN='$domain'" $conf)
-
-    # Parsing key=value
     eval $line
     eval $line
-
-    # Print result line
     for field in $fields; do
     for field in $fields; do
         eval key="$field"
         eval key="$field"
         echo "${field//$/}: $key "
         echo "${field//$/}: $key "
@@ -76,24 +60,17 @@ shell_list_domain() {
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Checking args
 check_args '2' "$#" 'user domain [format]'
 check_args '2' "$#" 'user domain [format]'
-
-# Checking user
 is_object_valid 'user' 'USER' "$user"
 is_object_valid 'user' 'USER' "$user"
-
-# Checking domain exist
-is_domain_valid 'mail'
+is_object_valid 'mail' 'DOMAIN' "$domain"
 
 
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 #                       Action                             #
 #                       Action                             #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Defining config
-conf=$USER_DATA/mail.conf
-
 # Defining fileds to select
 # Defining fileds to select
+conf=$USER_DATA/mail.conf
 fields='$DOMAIN $ANTIVIRUS $ANTISPAM $DKIM $ACCOUNTS $U_DISK $CATCHALL
 fields='$DOMAIN $ANTIVIRUS $ANTISPAM $DKIM $ACCOUNTS $U_DISK $CATCHALL
 $SUSPENDED $DATE'
 $SUSPENDED $DATE'
 
 

+ 2 - 7
bin/v_list_mail_domain_dkim

@@ -14,7 +14,7 @@ user=$1
 domain=$2
 domain=$2
 format=${3-shell}
 format=${3-shell}
 
 
-# Importing variables
+# Includes
 source $VESTA/func/shared.sh
 source $VESTA/func/shared.sh
 
 
 # Json function
 # Json function
@@ -41,14 +41,9 @@ shell_list_ssl() {
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Checking args
 check_args '2' "$#" 'user domain [format]'
 check_args '2' "$#" 'user domain [format]'
-
-# Checking user
 is_object_valid 'user' 'USER' "$user"
 is_object_valid 'user' 'USER' "$user"
-
-# Checking domain exist
-is_domain_valid 'mail'
+is_object_valid 'mail' 'DOMAIN' "$domain"
 
 
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#

+ 3 - 10
bin/v_list_mail_domains

@@ -13,7 +13,7 @@
 user=$1
 user=$1
 format=${2-shell}
 format=${2-shell}
 
 
-# Importing variables
+# Includes
 source $VESTA/func/shared.sh
 source $VESTA/func/shared.sh
 
 
 
 
@@ -21,13 +21,8 @@ source $VESTA/func/shared.sh
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Checking args
 check_args '1' "$#" 'user [format]'
 check_args '1' "$#" 'user [format]'
-
-# Checking argument format
 validate_format 'user'
 validate_format 'user'
-
-# Checking user
 is_object_valid 'user' 'USER' "$user"
 is_object_valid 'user' 'USER' "$user"
 
 
 
 
@@ -35,12 +30,10 @@ is_object_valid 'user' 'USER' "$user"
 #                       Action                             #
 #                       Action                             #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Defining config
-conf=$USER_DATA/mail.conf
-
 # Defining fileds to select
 # Defining fileds to select
+conf=$USER_DATA/mail.conf
 fields="\$DOMAIN \$ANTIVIRUS \$ANTISPAM \$DKIM \$ACCOUNTS \$U_DISK \$CATCHALL"
 fields="\$DOMAIN \$ANTIVIRUS \$ANTISPAM \$DKIM \$ACCOUNTS \$U_DISK \$CATCHALL"
-fields="$fields \$SUSPENDED \$DATE"
+fields="$fields \$SUSPENDED \$TIME \$DATE"
 
 
 # Listing domains
 # Listing domains
 case $format in 
 case $format in 

+ 4 - 22
bin/v_rebuild_mail_domains

@@ -12,7 +12,7 @@
 # Argument defenition
 # Argument defenition
 user=$1
 user=$1
 
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/shared.sh
 source $VESTA/func/domain.sh
 source $VESTA/func/domain.sh
@@ -22,19 +22,10 @@ source $VESTA/func/domain.sh
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Checking arg number
 check_args '1' "$#" 'user'
 check_args '1' "$#" 'user'
-
-# Checking argument format
 validate_format 'user'
 validate_format 'user'
-
-# Checking mail system is enabled
-is_system_enabled 'MAIL_SYSTEM'
-
-# Checking user
+is_system_enabled "$MAIL_SYSTEM"
 is_object_valid 'user' 'USER' "$user"
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user is active
 is_object_unsuspended 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
 
 
 
 
@@ -54,14 +45,8 @@ if [ ! -d "$USER_DATA/mail" ]; then
     mkdir $USER_DATA/mail
     mkdir $USER_DATA/mail
 fi
 fi
 
 
-# Defining config
-conf="$USER_DATA/mail.conf"
-search_string="DOMAIN"
-field='$DOMAIN'
-domains=$(dom_clear_search)
-
 # Starting loop
 # Starting loop
-for domain in $domains; do
+for domain in $(search_objects 'dns' 'SUSPENDED' "*" 'DOMAIN'); do
 
 
     # Defining variables
     # Defining variables
     get_domain_values 'mail'
     get_domain_values 'mail'
@@ -108,7 +93,7 @@ for domain in $domains; do
         done
         done
 
 
         # Adding dkim dns records
         # Adding dkim dns records
-        check_dns_domain=$(is_domain_valid 'dns')
+        check_dns_domain=$(is_object_valid 'dns' 'DOMAIN' "$domain")
         if [ "$?" -eq 0 ]; then
         if [ "$?" -eq 0 ]; then
             p=$(cat $pub|grep -v ' KEY---'|tr -d '\n')
             p=$(cat $pub|grep -v ' KEY---'|tr -d '\n')
             record='_domainkey'
             record='_domainkey'
@@ -153,9 +138,6 @@ update_user_value "$user" '$U_MAIL_ACCOUNTS' "$U_MAIL_ACCOUNTS"
 update_user_value "$user" '$SUSPENDED_MAIL' "$SUSPENDED_MAIL"
 update_user_value "$user" '$SUSPENDED_MAIL' "$SUSPENDED_MAIL"
 update_user_value "$user" '$U_DISK_MAIL' "$U_DISK_MAIL"
 update_user_value "$user" '$U_DISK_MAIL' "$U_DISK_MAIL"
 
 
-# Adding task to the vesta pipe
-$BIN/v_restart_mail
-
 # Logging
 # Logging
 log_event "$OK" "$EVENT"
 log_event "$OK" "$EVENT"
 
 

+ 5 - 18
bin/v_suspend_mail_domain

@@ -15,7 +15,7 @@ domain=$(idn -t --quiet -u "$2" )
 domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
 domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
 domain_idn=$(idn -t --quiet -a "$domain")
 domain_idn=$(idn -t --quiet -a "$domain")
 
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/shared.sh
 source $VESTA/func/domain.sh
 source $VESTA/func/domain.sh
@@ -25,26 +25,13 @@ source $VESTA/func/domain.sh
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Checking arg number
 check_args '2' "$#" 'user domain'
 check_args '2' "$#" 'user domain'
-
-# Checking argument format
 validate_format 'user' 'domain'
 validate_format 'user' 'domain'
-
-# Checking dns system is enabled
-is_system_enabled 'MAIL_SYSTEM'
-
-# Checking user
+is_system_enabled "$MAIL_SYSTEM"
 is_object_valid 'user' 'USER' "$user"
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user is active
 is_object_unsuspended 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
-
-# Checking domain
-is_domain_valid 'mail'
-
-# Checking domain is not suspened
-is_domain_suspended 'mail'
+is_object_valid 'mail' 'DOMAIN' "$domain"
+is_object_unsuspended 'mail' 'DOMAIN' "$domain"
 
 
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
@@ -60,7 +47,7 @@ rm -f /etc/exim/domains/$domain
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 # Updating config
 # Updating config
-update_domain_value 'mail' '$SUSPENDED' 'yes'
+update_object_value 'mail' 'DOMAIN' "$domain" '$SUSPENDED' 'yes'
 
 
 # Logging
 # Logging
 log_event "$OK" "$EVENT"
 log_event "$OK" "$EVENT"

+ 3 - 18
bin/v_suspend_mail_domains

@@ -12,7 +12,7 @@
 # Argument defenition
 # Argument defenition
 user=$1
 user=$1
 
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/shared.sh
 source $VESTA/func/domain.sh
 source $VESTA/func/domain.sh
@@ -22,16 +22,9 @@ source $VESTA/func/domain.sh
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Checking arg number
 check_args '1' "$#" 'user'
 check_args '1' "$#" 'user'
-
-# Checking argument format
 validate_format 'user'
 validate_format 'user'
-
-# Checking dns system is enabled
-is_system_enabled 'MAIL_SYSTEM'
-
-# Checking user
+is_system_enabled "$MAIL_SYSTEM"
 is_object_valid 'user' 'USER' "$user"
 is_object_valid 'user' 'USER' "$user"
 
 
 
 
@@ -39,16 +32,8 @@ is_object_valid 'user' 'USER' "$user"
 #                       Action                             #
 #                       Action                             #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Defining config
-conf="$USER_DATA/mail.conf"
-
-# Defining fileds to select
-field='$DOMAIN'
-search_string="SUSPENDED='no'"
-domains=$(dom_clear_search)
-
 # Starting suspend loop
 # Starting suspend loop
-for domain in $domains; do
+for domain in $(search_objects 'mail' 'SUSPENDED' "no" 'DOMAIN'); do
     $BIN/v_suspend_mail_domain "$user" "$domain"
     $BIN/v_suspend_mail_domain "$user" "$domain"
 done
 done
 
 

+ 4 - 18
bin/v_unsuspend_mail_domain

@@ -15,7 +15,7 @@ domain=$(idn -t --quiet -u "$2" )
 domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
 domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
 domain_idn=$(idn -t --quiet -a "$domain")
 domain_idn=$(idn -t --quiet -a "$domain")
 
 
-# Importing variables
+# Includes
 source $VESTA/conf/vesta.conf
 source $VESTA/conf/vesta.conf
 source $VESTA/func/shared.sh
 source $VESTA/func/shared.sh
 source $VESTA/func/domain.sh
 source $VESTA/func/domain.sh
@@ -25,26 +25,12 @@ source $VESTA/func/domain.sh
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Checking arg number
 check_args '2' "$#" 'user domain'
 check_args '2' "$#" 'user domain'
-
-# Checking argument format
 validate_format 'user' 'domain'
 validate_format 'user' 'domain'
-
-# Checking dns system is enabled
 is_system_enabled 'MAIL_SYSTEM'
 is_system_enabled 'MAIL_SYSTEM'
-
-# Checking user
 is_object_valid 'user' 'USER' "$user"
 is_object_valid 'user' 'USER' "$user"
-
-# Checking user is active
-is_object_unsuspended 'user' 'USER' "$user"
-
-# Checking domain
-is_domain_valid 'mail'
-
-# Checking domain is not suspened
-is_domain_value_exist 'mail' '$SUSPENDED'
+is_object_valid 'mail' 'DOMAIN' "$domain"
+is_object_suspended 'mail' 'DOMAIN' "$domain"
 
 
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
@@ -60,7 +46,7 @@ ln -s $HOMEDIR/$user/conf/mail/$domain /etc/exim/domains/
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 # Updating config
 # Updating config
-update_domain_value 'mail' '$SUSPENDED' 'no'
+update_object_value 'mail' 'DOMAIN' "$domain" '$SUSPENDED' 'no'
 
 
 # Logging
 # Logging
 log_event "$OK" "$EVENT"
 log_event "$OK" "$EVENT"

+ 4 - 24
bin/v_unsuspend_mail_domains

@@ -22,16 +22,9 @@ source $VESTA/func/domain.sh
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Checking arg number
 check_args '1' "$#" 'user'
 check_args '1' "$#" 'user'
-
-# Checking argument format
 validate_format 'user'
 validate_format 'user'
-
-# Checking dns system is enabled
-is_system_enabled 'MAIL_SYSTEM'
-
-# Checking user
+is_system_enabled "$MAIL_SYSTEM"
 is_object_valid 'user' 'USER' "$user"
 is_object_valid 'user' 'USER' "$user"
 
 
 
 
@@ -39,23 +32,10 @@ is_object_valid 'user' 'USER' "$user"
 #                       Action                             #
 #                       Action                             #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-# Defining config
-conf="$USER_DATA/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
 # Starting unsuspend loop
-#for domain in $domains; do
-#    $BIN/v_unsuspend_mail_domain "$user" "$domain"
-#done
+for domain in $(search_objects 'mail' 'SUSPENDED' "yes" 'DOMAIN'); do
+    $BIN/v_unsuspend_mail_domain "$user" "$domain"
+done
 
 
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#

+ 16 - 2
func/db.sh

@@ -111,6 +111,10 @@ add_mysql_database() {
     query="GRANT ALL ON $database.* TO '$dbuser'@'localhost'
     query="GRANT ALL ON $database.* TO '$dbuser'@'localhost'
         IDENTIFIED BY '$dbpass'"
         IDENTIFIED BY '$dbpass'"
     mysql -h $HOST -u $USER -p$PASSWORD -P $PORT -e "$query" &> /dev/null
     mysql -h $HOST -u $USER -p$PASSWORD -P $PORT -e "$query" &> /dev/null
+
+    query="SHOW GRANTS FOR '$dbuser'"
+    md5=$(mysql -h $HOST -u $USER -p$PASSWORD -P $PORT -e "$query")
+    md5=$(echo "$md5" |grep 'PASSWORD' |tr ' ' '\n' |tail -n1 |cut -f 2 -d \')
 }
 }
 
 
 # Create PostgreSQL database
 # Create PostgreSQL database
@@ -143,11 +147,14 @@ add_pgsql_database() {
     fi
     fi
     psql -h $HOST -U $USER -p $PORT -c "$query" &> /dev/null
     psql -h $HOST -U $USER -p $PORT -c "$query" &> /dev/null
 
 
-    query="GRANT ALL PRIVILEGES ON DATABASE $database TO $db_user"
+    query="GRANT ALL PRIVILEGES ON DATABASE $database TO $dbuser"
     psql -h $HOST -U $USER -p $PORT -c "$query" &> /dev/null
     psql -h $HOST -U $USER -p $PORT -c "$query" &> /dev/null
 
 
-    query="GRANT CONNECT ON DATABASE template1 to $db_user"
+    query="GRANT CONNECT ON DATABASE template1 to $dbuser"
     psql -h $HOST -U $USER -p $PORT -c "$query" &> /dev/null
     psql -h $HOST -U $USER -p $PORT -c "$query" &> /dev/null
+
+    query="SELECT rolpassword FROM pg_authid WHERE rolname='$dbuser';"
+    md5=$(psql -h $HOST -U $USER -p $PORT -c "$query"|grep md5|cut -f 2 -d \ )
 }
 }
 
 
 # Check if database host do not exist in config 
 # Check if database host do not exist in config 
@@ -214,6 +221,10 @@ change_mysql_password() {
     query="GRANT ALL ON $database.* TO '$DBUSER'@'localhost'
     query="GRANT ALL ON $database.* TO '$DBUSER'@'localhost'
         IDENTIFIED BY '$dbpass'"
         IDENTIFIED BY '$dbpass'"
     mysql -h $HOST -u $USER -p$PASSWORD -P $PORT -e "$query" &> /dev/null
     mysql -h $HOST -u $USER -p$PASSWORD -P $PORT -e "$query" &> /dev/null
+
+    query="SHOW GRANTS FOR '$DBUSER'"
+    md5=$(mysql -h $HOST -u $USER -p$PASSWORD -P $PORT -e "$query")
+    md5=$(echo "$md5" |grep 'PASSWORD' |tr ' ' '\n' |tail -n1 |cut -f 2 -d \')
 }
 }
 
 
 # Change PostgreSQL database password
 # Change PostgreSQL database password
@@ -237,6 +248,9 @@ change_pgsql_password() {
 
 
     query="ALTER ROLE $DBUSER WITH LOGIN PASSWORD '$dbpass'"
     query="ALTER ROLE $DBUSER WITH LOGIN PASSWORD '$dbpass'"
     psql -h $HOST -U $USER -p $PORT -c "$query" &> /dev/null
     psql -h $HOST -U $USER -p $PORT -c "$query" &> /dev/null
+
+    query="SELECT rolpassword FROM pg_authid WHERE rolname='$DBUSER';"
+    md5=$(psql -h $HOST -U $USER -p $PORT -c "$query"|grep md5|cut -f 2 -d \ )
 }
 }
 
 
 # Delete MySQL database
 # Delete MySQL database

+ 24 - 0
func/domain.sh

@@ -56,6 +56,30 @@ is_domain_new() {
     fi
     fi
 }
 }
 
 
+# Checking mail account existance
+is_mail_new() {
+    check_acc=$(grep "ACCOUNT='$1'" $USER_DATA/mail/$domain.conf)
+    if [ ! -z "$check_acc" ]; then
+        echo "Error: mail account $1 exist"
+        log_event "$E_EXISTS" "$EVENT"
+        exit
+    fi
+    check_als=$(awk -F "ALIAS='" '{print $2}' $USER_DATA/mail/$domain.conf )
+    check_als=$(echo "$check_als" | cut -f 1 -d "'" | grep -w $1)
+    if [ ! -z "$check_als" ]; then
+        echo "Error: mail alias $1 exist"
+        log_event "$E_EXISTS" "$EVENT"
+        exit
+    fi
+    check_fwd=$(awk -F "FWD='" '{print $2}' $USER_DATA/mail/$domain.conf )
+    check_fwd=$(echo "$check_fwd" | cut -f 1 -d "'" | grep -w $1)
+    if [ ! -z "$check_fwd" ]; then
+        echo "Error: mail forward $1 exist"
+        log_event "$E_EXISTS" "$EVENT"
+        exit
+    fi
+}
+
 # Update domain zone
 # Update domain zone
 update_domain_zone() {
 update_domain_zone() {
     conf="$HOMEDIR/$user/conf/dns/$domain.db"
     conf="$HOMEDIR/$user/conf/dns/$domain.db"