|
| 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 |
0 commit comments