Skip to content

Commit 62e5d3d

Browse files
committed
mail api 60% completed
1 parent 46f8f8e commit 62e5d3d

File tree

7 files changed

+365
-0
lines changed

7 files changed

+365
-0
lines changed

bin/v_add_mail_domain

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ touch $V_HOME/$user/conf/mail/$domain/passwd
6464
chown -R root:mail $V_HOME/$user/conf/mail/$domain
6565
chmod 770 $V_HOME/$user/conf/mail/$domain
6666
chmod 660 $V_HOME/$user/conf/mail/$domain*
67+
mkdir $V_HOME/$user/mail/$domain
68+
chown $user:mail $V_HOME/$user/mail/$domain
69+
chmod 770 $V_HOME/$user/mail/$domain
6770

6871
# Adding symlink
6972
ln -s $V_HOME/$user/conf/mail/$domain /etc/exim/domains/

bin/v_delete_mail_domain

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
# info: delete mail domain
3+
# options: user domain
4+
#
5+
# The function for deleting MAIL domain. By deleting it all accounts will
6+
# also be deleted.
7+
8+
9+
#----------------------------------------------------------#
10+
# Variable&Function #
11+
#----------------------------------------------------------#
12+
13+
# Argument defenition
14+
user=$1
15+
domain=$(idn -t --quiet -u "$2" )
16+
17+
# Importing variables
18+
source $VESTA/conf/vars.conf
19+
source $V_CONF/vesta.conf
20+
source $V_FUNC/shared.func
21+
source $V_FUNC/domain.func
22+
23+
24+
#----------------------------------------------------------#
25+
# Verifications #
26+
#----------------------------------------------------------#
27+
28+
# Checking arg number
29+
check_args '2' "$#" 'user domain'
30+
31+
# Checking argument format
32+
format_validation 'user' 'domain'
33+
34+
# Checking web system is enabled
35+
is_system_enabled 'MAIL_SYSTEM'
36+
37+
# Checking user
38+
is_user_valid
39+
40+
# Checking user is active
41+
is_user_suspended
42+
43+
# Checking domain exist
44+
is_domain_valid 'mail'
45+
46+
47+
#----------------------------------------------------------#
48+
# Action #
49+
#----------------------------------------------------------#
50+
51+
# Get domain values
52+
get_domain_values 'mail'
53+
accounts=$(wc -l $V_USERS/$user/mail/$domain|cut -f 1 -d ' ')
54+
55+
rm -f /etc/exim/domains/$domain
56+
rm -rf $V_HOME/$user/conf/$domain
57+
rm -rf $V_HOME/$user/mail/$domain
58+
59+
60+
#----------------------------------------------------------#
61+
# Vesta #
62+
#----------------------------------------------------------#
63+
64+
# Delete domain config
65+
sed -i "/DOMAIN='$domain'/ d" $V_USERS/$user/mail.conf
66+
rm -f $V_USERS/$user/mail/$domain
67+
rm -f $V_USERS/$user/mail/$domain.pem
68+
rm -f $V_USERS/$user/mail/$domain.pub
69+
# autoreply
70+
71+
# Decreasing domain value
72+
decrease_user_value "$user" '$U_MAIL_DOMAINS'
73+
decrease_user_value "$user" '$U_MAIL_ACCOUNTS' "$accounts"
74+
75+
# Logging
76+
cmd='"v_add_mail_domain'
77+
log_history "$V_EVENT" "$cmd $user $domain $ANTISPAM $ANTIVIRUS $DKIM"
78+
log_event 'system' "$V_EVENT"
79+
80+
exit

bin/v_rebuild_mail_domains

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ for domain in $domains; do
122122
fi
123123
fi
124124

125+
# Adding antispam protection
126+
if [ "$SUSPENDED" != 'yes' ]; then
127+
ln -s $V_HOME/$user/conf/mail/$domain /etc/exim/domains/
128+
fi
129+
130+
if [ ! -e $V_HOME/$user/mail/$domain ]; then
131+
mkdir $V_HOME/$user/mail/$domain
132+
fi
133+
chown $user:mail $V_HOME/$user/mail/$domain
134+
chmod 770 $V_HOME/$user/mail/$domain
135+
125136
# Rebuild counters
126137
U_MAIL_DOMAINS=$((U_MAIL_DOMAINS + 1))
127138
U_DISK_MAIL=$((U_DISK_MAIL + U_DISK))

bin/v_suspend_mail_domain

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
# info: suspend mail domain
3+
# options: user domain
4+
#
5+
# The function suspends mail domain.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=$1
14+
domain=$(idn -t --quiet -u "$2" )
15+
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
16+
domain_idn=$(idn -t --quiet -a "$domain")
17+
18+
# Importing variables
19+
source $VESTA/conf/vars.conf
20+
source $V_CONF/vesta.conf
21+
source $V_FUNC/shared.func
22+
source $V_FUNC/domain.func
23+
24+
25+
#----------------------------------------------------------#
26+
# Verifications #
27+
#----------------------------------------------------------#
28+
29+
# Checking arg number
30+
check_args '2' "$#" 'user domain'
31+
32+
# Checking argument format
33+
format_validation 'user' 'domain'
34+
35+
# Checking dns system is enabled
36+
is_system_enabled 'MAIL_SYSTEM'
37+
38+
# Checking user
39+
is_user_valid
40+
41+
# Checking user is active
42+
is_user_suspended
43+
44+
# Checking domain
45+
is_domain_valid 'mail'
46+
47+
# Checking domain is not suspened
48+
is_domain_suspended 'mail'
49+
50+
51+
#----------------------------------------------------------#
52+
# Action #
53+
#----------------------------------------------------------#
54+
55+
# Deleting symbolic link
56+
rm -f /etc/exim/domains/$domain
57+
58+
59+
#----------------------------------------------------------#
60+
# Vesta #
61+
#----------------------------------------------------------#
62+
63+
# Updating config
64+
update_domain_value 'mail' '$SUSPENDED' 'yes'
65+
66+
# Logging
67+
log_event 'system' "$V_EVENT"
68+
69+
exit

bin/v_suspend_mail_domains

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
# info: suspend mail domains
3+
# options: user
4+
#
5+
# The function suspends all user's MAIL domains.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=$1
14+
15+
# Importing variables
16+
source $VESTA/conf/vars.conf
17+
source $V_CONF/vesta.conf
18+
source $V_FUNC/shared.func
19+
source $V_FUNC/domain.func
20+
21+
22+
#----------------------------------------------------------#
23+
# Verifications #
24+
#----------------------------------------------------------#
25+
26+
# Checking arg number
27+
check_args '1' "$#" 'user'
28+
29+
# Checking argument format
30+
format_validation 'user'
31+
32+
# Checking dns system is enabled
33+
is_system_enabled 'MAIL_SYSTEM'
34+
35+
# Checking user
36+
is_user_valid
37+
38+
39+
#----------------------------------------------------------#
40+
# Action #
41+
#----------------------------------------------------------#
42+
43+
# Defining config
44+
conf="$V_USERS/$user/mail.conf"
45+
46+
# Defining fileds to select
47+
field='$DOMAIN'
48+
search_string="SUSPENDED='no'"
49+
domains=$(dom_clear_search)
50+
51+
# Starting suspend loop
52+
for domain in $domains; do
53+
$V_BIN/v_suspend_mail_domain "$user" "$domain"
54+
done
55+
56+
57+
#----------------------------------------------------------#
58+
# Vesta #
59+
#----------------------------------------------------------#
60+
61+
# Logging
62+
log_event 'system' "$V_EVENT"
63+
64+
exit

bin/v_unsuspend_mail_domain

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
# info: unsuspend mail domain
3+
# options: user domain
4+
#
5+
# The function unsuspends mail domain.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=$1
14+
domain=$(idn -t --quiet -u "$2" )
15+
domain=$(echo $domain | tr '[:upper:]' '[:lower:]')
16+
domain_idn=$(idn -t --quiet -a "$domain")
17+
18+
# Importing variables
19+
source $VESTA/conf/vars.conf
20+
source $V_CONF/vesta.conf
21+
source $V_FUNC/shared.func
22+
source $V_FUNC/domain.func
23+
24+
25+
#----------------------------------------------------------#
26+
# Verifications #
27+
#----------------------------------------------------------#
28+
29+
# Checking arg number
30+
check_args '2' "$#" 'user domain'
31+
32+
# Checking argument format
33+
format_validation 'user' 'domain'
34+
35+
# Checking dns system is enabled
36+
is_system_enabled 'MAIL_SYSTEM'
37+
38+
# Checking user
39+
is_user_valid
40+
41+
# Checking user is active
42+
is_user_suspended
43+
44+
# Checking domain
45+
is_domain_valid 'mail'
46+
47+
# Checking domain is not suspened
48+
is_domain_value_exist 'mail' '$SUSPENDED'
49+
50+
51+
#----------------------------------------------------------#
52+
# Action #
53+
#----------------------------------------------------------#
54+
55+
# Add symbolic link
56+
ln -s $V_HOME/$user/conf/mail/$domain /etc/exim/domains/
57+
58+
59+
#----------------------------------------------------------#
60+
# Vesta #
61+
#----------------------------------------------------------#
62+
63+
# Updating config
64+
update_domain_value 'mail' '$SUSPENDED' 'no'
65+
66+
# Logging
67+
log_event 'system' "$V_EVENT"
68+
69+
exit

bin/v_unsuspend_mail_domains

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
# info: unsuspend mail domains
3+
# options: user
4+
#
5+
# The function unsuspends all user's MAIL domains.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument defenition
13+
user=$1
14+
15+
# Importing variables
16+
source $VESTA/conf/vars.conf
17+
source $V_CONF/vesta.conf
18+
source $V_FUNC/shared.func
19+
source $V_FUNC/domain.func
20+
21+
22+
#----------------------------------------------------------#
23+
# Verifications #
24+
#----------------------------------------------------------#
25+
26+
# Checking arg number
27+
check_args '1' "$#" 'user'
28+
29+
# Checking argument format
30+
format_validation 'user'
31+
32+
# Checking dns system is enabled
33+
is_system_enabled 'MAIL_SYSTEM'
34+
35+
# Checking user
36+
is_user_valid
37+
38+
39+
#----------------------------------------------------------#
40+
# Action #
41+
#----------------------------------------------------------#
42+
43+
# Defining config
44+
conf="$V_USERS/$user/mail.conf"
45+
46+
# Defining fileds to select
47+
field='$DOMAIN'
48+
49+
# Defining search string
50+
search_string="SUSPENDED='yes'"
51+
52+
# Parsing suspeneded domains
53+
domains=$(dom_clear_search)
54+
55+
56+
# Starting unsuspend loop
57+
for domain in $domains; do
58+
$V_BIN/v_unsuspend_mail_domain "$user" "$domain"
59+
done
60+
61+
62+
#----------------------------------------------------------#
63+
# Vesta #
64+
#----------------------------------------------------------#
65+
66+
# Logging
67+
log_event 'system' "$V_EVENT"
68+
69+
exit

0 commit comments

Comments
 (0)