Skip to content

Commit f2133f9

Browse files
committed
Refactoring stage VI (mail)
1 parent fb40168 commit f2133f9

34 files changed

+219
-486
lines changed

bin/v_add_database

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ increase_dbhost_values
6868
increase_user_value "$user" '$U_DATABASES'
6969

7070
# Adding db to db conf
71-
str="DB='$database' DBUSER='$dbuser' HOST='$host' TYPE='$type'"
71+
str="DB='$database' DBUSER='$dbuser' MD5='$md5' HOST='$host' TYPE='$type'"
7272
str="$str CHARSET='$charset' U_DISK='0' SUSPENDED='no' TIME='$TIME'"
7373
str="$str DATE='$DATE'"
7474
echo "$str" >> $USER_DATA/db.conf

bin/v_add_dns_domain_record

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ zone="$USER_DATA/dns/$domain.conf"
6161
dns_rec="ID='$id' RECORD='$record' TYPE='$rtype' PRIORITY='$priority'"
6262
dns_rec="$dns_rec VALUE='$dvalue' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
6363
echo "$dns_rec" >> $zone
64+
chmod 660 $zone
6465

6566
# Sorting records
6667
sort_dns_records

bin/v_add_mail_account

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ account=$3
1818
password=$4
1919
quota=${5-0}
2020

21-
# Importing variables
21+
# Includes
2222
source $VESTA/conf/vesta.conf
2323
source $VESTA/func/shared.sh
2424
source $VESTA/func/domain.sh
@@ -28,39 +28,22 @@ source $VESTA/func/domain.sh
2828
# Verifications #
2929
#----------------------------------------------------------#
3030

31-
# Checking arg number
32-
check_args '4' "$#" 'user domain account password quota'
33-
34-
# Checking argument format
31+
check_args '4' "$#" 'user domain account password [quota]'
3532
validate_format 'user' 'domain' 'account' 'password' 'quota'
36-
37-
# Checking dns system is enabled
38-
is_system_enabled 'MAIL_SYSTEM'
39-
40-
# Checking user
33+
is_system_enabled "$MAIL_SYSTEM"
4134
is_object_valid 'user' 'USER' "$user"
42-
43-
# Checking user is active
4435
is_object_unsuspended 'user' 'USER' "$user"
45-
46-
# Checking domain
47-
is_domain_valid 'mail'
48-
49-
# Checking domain is not suspened
50-
is_domain_suspended 'mail'
51-
52-
# Checking package
36+
is_object_valid 'mail' 'DOMAIN' "$domain"
37+
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
5338
is_package_full 'MAIL_ACCOUNTS'
54-
55-
# Checking account
56-
is_mail_account_free
39+
is_mail_new "$account"
5740

5841

5942
#----------------------------------------------------------#
6043
# Action #
6144
#----------------------------------------------------------#
62-
password=$(/usr/sbin/dovecotpw -s md5 -p "$password")
63-
str="$account:$password:$user:mail::$HOMEDIR/$user:$quota"
45+
md5=$(/usr/sbin/dovecotpw -s md5 -p "$password")
46+
str="$account:$md5:$user:mail::$HOMEDIR/$user:$quota"
6447
echo $str >> $HOMEDIR/$user/conf/mail/$domain/passwd
6548

6649

@@ -69,17 +52,21 @@ echo $str >> $HOMEDIR/$user/conf/mail/$domain/passwd
6952
#----------------------------------------------------------#
7053

7154
str="ACCOUNT='$account' ALIAS='' QUOTA='$quota' AUTOREPLY='no' FWD=''"
72-
str="$str U_DISK='0' SUSPENDED='no' DATE='$DATE'"
55+
str="$str MD5='$md5' U_DISK='0' SUSPENDED='no' TIME='$TIME' DATE='$DATE'"
7356
echo "$str" >> $USER_DATA/mail/$domain.conf
57+
chmod 660 $USER_DATA/mail/$domain.conf
7458

7559
# Increase mail accounts counter
76-
accounts=$(wc -l $USER_DATA/mail/$domain.conf|cut -f 1 -d ' ')
60+
accounts=$(wc -l $USER_DATA/mail/$domain.conf | cut -f 1 -d ' ')
7761
increase_user_value "$user" '$U_MAIL_ACCOUNTS'
78-
update_domain_value 'mail' '$ACCOUNTS' "$accounts"
62+
update_object_value 'mail' 'DOMAIN' "$domain" '$ACCOUNTS' "$accounts"
63+
64+
# Hiding password
65+
EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT'"
66+
EVENT="$EVENT ARGUMENTS='$user $domain ***** $quota'"
7967

8068
# Logging
81-
EVENT="$DATE $SCRIPT $user $domain ***** $quota"
82-
log_history "$EVENT" "v_delete_mail_account $user $domain $account"
69+
log_history "$EVENT"
8370
log_event "$OK" "$EVENT"
8471

8572
exit

bin/v_add_mail_account_alias

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ domain_idn=$(idn -t --quiet -a "$domain")
1717
account=$3
1818
malias=$4
1919

20-
# Importing variables
20+
# Includes
2121
source $VESTA/conf/vesta.conf
2222
source $VESTA/func/shared.sh
2323
source $VESTA/func/domain.sh
@@ -27,40 +27,24 @@ source $VESTA/func/domain.sh
2727
# Verifications #
2828
#----------------------------------------------------------#
2929

30-
# Checking arg number
3130
check_args '4' "$#" 'user domain account alias'
32-
33-
# Checking argument format
3431
validate_format 'user' 'domain' 'account' 'malias'
35-
36-
# Checking dns system is enabled
37-
is_system_enabled 'MAIL_SYSTEM'
38-
39-
# Checking user
32+
is_system_enabled "$MAIL_SYSTEM"
4033
is_object_valid 'user' 'USER' "$user"
41-
42-
# Checking user is active
4334
is_object_unsuspended 'user' 'USER' "$user"
44-
45-
# Checking domain
46-
is_domain_valid 'mail'
47-
48-
# Checking domain is not suspened
49-
is_domain_suspended 'mail'
50-
51-
# Checking account
52-
is_mail_account_valid
53-
54-
# Checking account
55-
is_mail_account_free "$malias"
35+
is_object_valid 'mail' 'DOMAIN' "$domain"
36+
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
37+
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
38+
is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
39+
is_mail_new "$malias"
5640

5741

5842
#----------------------------------------------------------#
5943
# Action #
6044
#----------------------------------------------------------#
6145

6246
# Adding exim alias
63-
str="$mailas@$domain:$account@$domain"
47+
str="$malias@$domain:$account@$domain"
6448
echo "$str" >> $HOMEDIR/$user/conf/mail/$domain/aliases
6549

6650

@@ -69,17 +53,16 @@ echo "$str" >> $HOMEDIR/$user/conf/mail/$domain/aliases
6953
#----------------------------------------------------------#
7054

7155
# Adding vesta alias
72-
aliases=$(get_domain_value "mail/$domain" '$ALIAS' "ACCOUNT='$account'")
56+
aliases=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$ALIAS')
7357
if [ -z "$aliases" ]; then
7458
aliases="$malias"
7559
else
7660
aliases="$aliases,$malias"
7761
fi
78-
update_domain_value "mail/$domain" '$ALIAS' "$aliases" "ACCOUNT='$account'"
62+
update_object_value "mail/$domain" 'ACCOUNT' "$account" '$ALIAS' "$aliases"
7963

8064
# Logging
81-
cmd='v_delete_mail_account_alias'
82-
log_history "$EVENT" "$cmd $user $domain $account $malias"
65+
log_history "$EVENT"
8366
log_event "$OK" "$EVENT"
8467

8568
exit

bin/v_add_mail_account_autoreply

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ domain=$(idn -t --quiet -u "$2" )
1515
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
1616
domain_idn=$(idn -t --quiet -a "$domain")
1717
account=$3
18-
malias=$4
18+
autoreply=$4
1919

20-
# Importing variables
20+
# Includes
2121
source $VESTA/conf/vesta.conf
2222
source $VESTA/func/shared.sh
2323
source $VESTA/func/domain.sh
@@ -26,43 +26,39 @@ source $VESTA/func/domain.sh
2626
#----------------------------------------------------------#
2727
# Verifications #
2828
#----------------------------------------------------------#
29-
check_args '4' "$#" 'user domain account alias'
30-
validate_format 'user' 'domain' 'account' 'malias'
31-
is_system_enabled 'MAIL_SYSTEM'
29+
30+
check_args '4' "$#" 'user domain account autoreply'
31+
validate_format 'user' 'domain' 'account' 'autoreply'
32+
is_system_enabled "$MAIL_SYSTEM"
3233
is_object_valid 'user' 'USER' "$user"
3334
is_object_unsuspended 'user' 'USER' "$user"
3435
is_object_valid 'mail' 'DOMAIN' "$domain"
3536
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
3637
is_object_valid "mail/$domain" 'ACCOUNT' "$account"
3738
is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account"
38-
is_key_empty "mail/$domain" '' '$AUTOREPLY'
39-
exit
39+
is_object_value_empty "mail/$domain" 'ACCOUNT' "$domain" '$AUTOREPLY'
40+
4041

4142
#----------------------------------------------------------#
4243
# Action #
4344
#----------------------------------------------------------#
44-
exit
45-
# Adding exim alias
46-
str="$mailas@$domain:$account@$domain"
47-
echo "$str" >> $HOMEDIR/$user/conf/mail/$domain/aliases
45+
# Add exim autoreply
46+
echo -e "$autoreply" > $HOMEDIR/$user/conf/mail/$domain/autoreply.$account.msg
47+
chown -R root:mail $HOMEDIR/$user/conf/mail/$domain/autoreply.$account.msg
48+
chmod 660 $HOMEDIR/$user/conf/mail/$domain/autoreply.$account.msg
4849

4950

5051
#----------------------------------------------------------#
5152
# Vesta #
5253
#----------------------------------------------------------#
5354

5455
# Adding vesta alias
55-
aliases=$(get_domain_value "mail/$domain" '$ALIAS' "ACCOUNT='$account'")
56-
if [ -z "$aliases" ]; then
57-
aliases="$malias"
58-
else
59-
aliases="$aliases,$malias"
60-
fi
61-
update_domain_value "mail/$domain" '$ALIAS' "$aliases" "ACCOUNT='$account'"
56+
echo -e "$autoreply" > $USER_DATA/mail/$account@$domain.msg
57+
chmod 660 $USER_DATA/mail/$account@$domain.msg
58+
update_object_value "mail/$domain" 'ACCOUNT' "$domain" '$AUTOREPLY' 'yes'
6259

6360
# Logging
64-
cmd='v_delete_mail_account_alias'
65-
log_history "$EVENT" "$cmd $user $domain $account $malias"
61+
log_history "$EVENT"
6662
log_event "$OK" "$EVENT"
6763

6864
exit

bin/v_add_mail_domain

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ antivirus=${4-yes}
1919
dkim=${5-yes}
2020
dkim_size=${6-512}
2121

22-
# Importing variables
22+
# Includes
2323
source $VESTA/conf/vesta.conf
2424
source $VESTA/func/shared.sh
2525
source $VESTA/func/domain.sh
@@ -29,25 +29,12 @@ source $VESTA/func/domain.sh
2929
# Verifications #
3030
#----------------------------------------------------------#
3131

32-
# Checking arg number
3332
check_args '2' "$#" 'user domain [antispam] [antivirus] [dkim] [dkim_size]'
34-
35-
# Checking argument format
3633
validate_format 'user' 'domain' 'antispam' 'antivirus' 'dkim' 'dkim_size'
37-
38-
# Checking dns system is enabled
39-
is_system_enabled 'MAIL_SYSTEM'
40-
41-
# Checking user
34+
is_system_enabled "$MAIL_SYSTEM"
4235
is_object_valid 'user' 'USER' "$user"
43-
44-
# Checking user is active
4536
is_object_unsuspended 'user' 'USER' "$user"
46-
47-
# Checking domain
4837
is_domain_new 'mail'
49-
50-
# Checking package
5138
is_package_full 'MAIL_DOMAINS'
5239

5340

@@ -92,7 +79,7 @@ if [ "$dkim" = 'yes' ]; then
9279
chmod 660 $HOMEDIR/$user/conf/mail/$domain/dkim.pem
9380

9481
# Adding dkim dns records
95-
check_dns_domain=$(is_domain_valid 'dns')
82+
check_dns_domain=$(is_object_valid 'dns' 'DOMAIN' "$domain")
9683
if [ "$?" -eq 0 ]; then
9784
p=$(cat $USER_DATA/mail/$domain.pub|grep -v ' KEY---'|tr -d '\n')
9885
record='_domainkey'
@@ -107,7 +94,9 @@ fi
10794

10895
# Adding domain to vesta db
10996
s="DOMAIN='$domain' ANTIVIRUS='$antivirus' ANTISPAM='$antispam' DKIM='$dkim'"
110-
s="$s ACCOUNTS='0' U_DISK='0' CATCHALL='' SUSPENDED='no' DATE='$DATE'"
97+
s="$s ACCOUNTS='0' U_DISK='0' CATCHALL='' SUSPENDED='no' TIME='$TIME'"
98+
s="$s DATE='$DATE'"
99+
111100
echo $s >> $USER_DATA/mail.conf
112101
touch $USER_DATA/mail/$domain.conf
113102
chmod 660 $USER_DATA/mail.conf
@@ -122,7 +111,7 @@ chmod 660 $USER_DATA/mail/$domain.conf
122111
increase_user_value "$user" '$U_MAIL_DOMAINS'
123112

124113
# Logging
125-
log_history "$EVENT" "v_delete_mail_domain $user $domain"
114+
log_history "$EVENT"
126115
log_event "$OK" "$EVENT"
127116

128117
exit

bin/v_add_mail_domain_antispam

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ domain=$(idn -t --quiet -u "$2" )
1515
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
1616
domain_idn=$(idn -t --quiet -a "$domain")
1717

18-
# Importing variables
18+
# Includes
1919
source $VESTA/conf/vesta.conf
2020
source $VESTA/func/shared.sh
2121
source $VESTA/func/domain.sh
@@ -25,37 +25,22 @@ source $VESTA/func/domain.sh
2525
# Verifications #
2626
#----------------------------------------------------------#
2727

28-
# Checking arg number
2928
check_args '2' "$#" 'user domain'
30-
31-
# Checking argument format
3229
validate_format 'user' 'domain'
33-
34-
# Checking dns system is enabled
35-
is_system_enabled 'MAIL_SYSTEM'
36-
37-
# Checking user
30+
is_system_enabled "$MAIL_SYSTEM"
3831
is_object_valid 'user' 'USER' "$user"
39-
40-
# Checking user is active
4132
is_object_unsuspended 'user' 'USER' "$user"
42-
43-
# Checking domain
44-
is_domain_valid 'mail'
45-
46-
# Checking domain is not suspened
47-
is_domain_suspended 'mail'
48-
49-
# Checking errorlog is not added
50-
is_domain_key_empty 'mail' '$ANTISPAM'
33+
is_object_valid 'mail' 'DOMAIN' "$domain"
34+
is_object_unsuspended 'mail' 'DOMAIN' "$domain"
35+
is_object_value_empty 'mail' 'DOMAIN' "$domain" '$ANTISPAM'
5136

5237

5338
#----------------------------------------------------------#
5439
# Action #
5540
#----------------------------------------------------------#
5641

5742
# Adding antispam key to config
58-
if [ -z "$(grep 'antispam' $HOMEDIR/$user/conf/mail/$domain/protection)" ]; then
43+
if [ -z "$(grep spam $HOMEDIR/$user/conf/mail/$domain/protection)" ]; then
5944
echo 'antispam' >> $HOMEDIR/$user/conf/mail/$domain/protection
6045
fi
6146

@@ -64,10 +49,10 @@ fi
6449
#----------------------------------------------------------#
6550

6651
# Adding antispam in config
67-
update_domain_value 'mail' '$ANTISPAM' 'yes'
52+
update_object_value 'mail' 'DOMAIN' "$domain" '$ANTISPAM' 'yes'
6853

6954
# Logging
70-
log_history "$EVENT" "v_delete_mail_domain_antispam $user $domain"
55+
log_history "$EVENT"
7156
log_event "$OK" "$EVENT"
7257

7358
exit

0 commit comments

Comments
 (0)