From 3e521cb8a2f8e4a0ed5dfd6d4db7c463ba279878 Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Wed, 13 Nov 2013 11:40:23 +0200 Subject: [PATCH] fwd-only flag --- bin/v-add-mail-account | 3 +- bin/v-add-mail-account-fwd-only | 79 ++++++++++++++++++++++++++ bin/v-delete-mail-account-fwd-only | 59 +++++++++++++++++++ bin/v-list-mail-account | 4 +- bin/v-list-mail-accounts | 4 +- func/main.sh | 11 ++++ func/rebuild.sh | 5 ++ web/add/mail/index.php | 7 ++- web/edit/mail/index.php | 15 +++++ web/templates/admin/add_mail_acc.html | 11 ++++ web/templates/admin/edit_mail_acc.html | 10 ++++ 11 files changed, 202 insertions(+), 6 deletions(-) create mode 100755 bin/v-add-mail-account-fwd-only create mode 100755 bin/v-delete-mail-account-fwd-only diff --git a/bin/v-add-mail-account b/bin/v-add-mail-account index 6e2cccf3..2c0d7ce8 100755 --- a/bin/v-add-mail-account +++ b/bin/v-add-mail-account @@ -63,7 +63,8 @@ echo $str >> $HOMEDIR/$user/conf/mail/$domain/passwd #----------------------------------------------------------# str="ACCOUNT='$account' ALIAS='' QUOTA='$quota' AUTOREPLY='no' FWD=''" -str="$str MD5='$md5' U_DISK='0' SUSPENDED='no' TIME='$TIME' DATE='$DATE'" +str="$str FWD_ONLY='' MD5='$md5' U_DISK='0' SUSPENDED='no' TIME='$TIME'" +str="$str DATE='$DATE'" echo "$str" >> $USER_DATA/mail/$domain.conf chmod 660 $USER_DATA/mail/$domain.conf diff --git a/bin/v-add-mail-account-fwd-only b/bin/v-add-mail-account-fwd-only new file mode 100755 index 00000000..9baffc14 --- /dev/null +++ b/bin/v-add-mail-account-fwd-only @@ -0,0 +1,79 @@ +#!/bin/bash +# info: add mail account forward-only flag +# options: USER DOMAIN ACCOUNT +# +# The function adds fwd-only flag + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +user=$1 +domain=$(idn -t --quiet -u "$2" ) +domain=$(echo $domain | tr '[:upper:]' '[:lower:]') +domain_idn=$(idn -t --quiet -a "$domain") +account=$3 + +# Includes +source $VESTA/func/main.sh +source $VESTA/func/domain.sh +source $VESTA/conf/vesta.conf + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + +check_args '3' "$#" 'USER DOMAIN ACCOUNT' +validate_format 'user' 'domain' 'account' +is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM' +is_object_valid 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" +is_object_valid 'mail' 'DOMAIN' "$domain" +is_object_unsuspended 'mail' 'DOMAIN' "$domain" +is_object_valid "mail/$domain" 'ACCOUNT' "$account" +is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account" +fwd=$(get_object_value "mail/$domain" 'ACCOUNT' "$account" '$FWD') +if [ -z "$fwd" ]; then + echo "Error: forward doesn't exist" + log_event "$E_NOTEXIST $EVENT" + exit $E_NOTEXIST +fi + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Adding account to fwd_only +touch $HOMEDIR/$user/conf/mail/$domain/fwd_only +check_fwd=$(grep "^$account$" $HOMEDIR/$user/conf/mail/$domain/fwd_only) +if [ -z "$check_fwd" ]; then + echo "$account" > $HOMEDIR/$user/conf/mail/$domain/fwd_only +fi + +# Set ownership +if [ "$MAIL_SYSTEM" = 'exim' ]; then + mail_user=exim +fi +if [ "$MAIL_SYSTEM" = 'exim4' ]; then + mail_user=Debian-exim +fi +chown -R $mail_user:mail $HOMEDIR/$user/conf/mail/$domain/fwd_only + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Updating config +add_object_key "mail/$domain" 'ACCOUNT' "$account" 'FWD_ONLY' 'MD5' +update_object_value "mail/$domain" 'ACCOUNT' "$account" '$FWD_ONLY' "yes" + +# Logging +log_history "added fwd_only flag for $account@$domain" +log_event "$OK" "$EVENT" + +exit diff --git a/bin/v-delete-mail-account-fwd-only b/bin/v-delete-mail-account-fwd-only new file mode 100755 index 00000000..0fb95ab9 --- /dev/null +++ b/bin/v-delete-mail-account-fwd-only @@ -0,0 +1,59 @@ +#!/bin/bash +# info: delete mail account forward-only flag +# options: USER DOMAIN ACCOUNT +# +# The function deletes fwd-only flag + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +user=$1 +domain=$(idn -t --quiet -u "$2" ) +domain=$(echo $domain | tr '[:upper:]' '[:lower:]') +domain_idn=$(idn -t --quiet -a "$domain") +account=$3 + +# Includes +source $VESTA/func/main.sh +source $VESTA/func/domain.sh +source $VESTA/conf/vesta.conf + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + +check_args '3' "$#" 'USER DOMAIN ACCOUNT' +validate_format 'user' 'domain' 'account' +is_system_enabled "$MAIL_SYSTEM" 'MAIL_SYSTEM' +is_object_valid 'user' 'USER' "$user" +is_object_unsuspended 'user' 'USER' "$user" +is_object_valid 'mail' 'DOMAIN' "$domain" +is_object_unsuspended 'mail' 'DOMAIN' "$domain" +is_object_valid "mail/$domain" 'ACCOUNT' "$account" +is_object_unsuspended "mail/$domain" 'ACCOUNT' "$account" + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Deleting account from fwd_only +sed -i "/^$account$/d" $HOMEDIR/$user/conf/mail/$domain/fwd_only + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Updating config +update_object_value "mail/$domain" 'ACCOUNT' "$account" '$FWD_ONLY' '' + +# Logging +log_history "deleted fwd_only flag for $account@$domain" +log_event "$OK" "$EVENT" + +exit diff --git a/bin/v-list-mail-account b/bin/v-list-mail-account index eb18c6a2..94a441a3 100755 --- a/bin/v-list-mail-account +++ b/bin/v-list-mail-account @@ -75,8 +75,8 @@ is_object_valid "mail/$domain" 'ACCOUNT' "$account" # Defining config and fields to select conf=$USER_DATA/mail/$domain.conf -fields="\$ACCOUNT \$ALIAS \$FWD \$QUOTA \$AUTOREPLY \$U_DISK \$SUSPENDED" -fields="$fields \$TIME \$DATE" +fields="\$ACCOUNT \$ALIAS \$FWD \$FWD_ONLY \$QUOTA \$AUTOREPLY \$U_DISK" +fields="$fields \$SUSPENDED \$TIME \$DATE" # Listing domains case $format in diff --git a/bin/v-list-mail-accounts b/bin/v-list-mail-accounts index 15a07187..9c1f399b 100755 --- a/bin/v-list-mail-accounts +++ b/bin/v-list-mail-accounts @@ -34,8 +34,8 @@ is_object_valid 'mail' 'DOMAIN' "$domain" # Defining fileds to select conf=$USER_DATA/mail/$domain.conf -fields="\$ACCOUNT \$ALIAS \$FWD \$AUTOREPLY \$QUOTA \$U_DISK \$SUSPENDED" -fields="$fields \$TIME \$DATE" +fields="\$ACCOUNT \$ALIAS \$FWD \$FWD_ONLY \$QUOTA \$AUTOREPLY \$U_DISK" +fields="$fields \$SUSPENDED \$TIME \$DATE" # Listing domain accounts case $format in diff --git a/func/main.sh b/func/main.sh index 9117b40b..3e5ce972 100644 --- a/func/main.sh +++ b/func/main.sh @@ -287,6 +287,17 @@ update_object_value() { $USER_DATA/$1.conf } +# Add object key +add_object_key() { + row=$(grep -n "$2='$3'" $USER_DATA/$1.conf) + lnr=$(echo $row | cut -f 1 -d ':') + object=$(echo $row | sed "s/^$lnr://") + if [ -z "$(echo $object |grep $4=)" ]; then + eval old="$4" + sed -i "$lnr s/$5='/$4='' $5='/" $USER_DATA/$1.conf + fi +} + # Search objects search_objects() { OLD_IFS="$IFS" diff --git a/func/rebuild.sh b/func/rebuild.sh index e7c8d9b9..a101d7bb 100644 --- a/func/rebuild.sh +++ b/func/rebuild.sh @@ -435,8 +435,10 @@ rebuild_mail_domain_conf() { rm -f $HOMEDIR/$user/conf/mail/$domain/antivirus rm -f $HOMEDIR/$user/conf/mail/$domain/protection rm -f $HOMEDIR/$user/conf/mail/$domain/passwd + rm -f $HOMEDIR/$user/conf/mail/$domain/fwd_only touch $HOMEDIR/$user/conf/mail/$domain/aliases touch $HOMEDIR/$user/conf/mail/$domain/passwd + touch $HOMEDIR/$user/conf/mail/$domain/fwd_only # Adding antispam protection if [ "$ANTISPAM" = 'yes' ]; then @@ -519,6 +521,9 @@ rebuild_mail_domain_conf() { if [ ! -z "$FWD" ]; then echo "$account@$domain:$FWD" >> $dom_aliases fi + if [ "$FWD_ONLY" = 'yes' ]; then + echo "$account" >> $HOMEDIR/$user/conf/mail/$domain/fwd_only + fi done # Set permissions diff --git a/web/add/mail/index.php b/web/add/mail/index.php index 66a246c2..b0058465 100644 --- a/web/add/mail/index.php +++ b/web/add/mail/index.php @@ -130,8 +130,13 @@ if (!empty($_POST['ok_acc'])) { } unset($output); } + // Add fwd_only flag + if ((!empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) { + exec (VESTA_CMD."v-add-mail-account-fwd-only ".$user." ".$v_domain." ".$v_account, $output, $return_var); + check_return_code($return_var,$output); + unset($output); + } } - unset($output); if (empty($_SESSION['error_msg'])) { list($http_host, $port) = explode(':', $_SERVER["HTTP_HOST"].":"); diff --git a/web/edit/mail/index.php b/web/edit/mail/index.php index b4fba9d4..c70c6c89 100644 --- a/web/edit/mail/index.php +++ b/web/edit/mail/index.php @@ -140,6 +140,7 @@ if ((!empty($_GET['domain'])) && (empty($_GET['account']))) { $valiases = explode(",", $data[$v_account]['ALIAS']); $v_fwd = str_replace(',', "\n", $data[$v_account]['FWD']); $vfwd = explode(",", $data[$v_account]['FWD']); + $v_fwd_only = $data[$v_account]['FWD_ONLY']; $v_quota = $data[$v_account]['QUOTA']; $v_autoreply = $data[$v_account]['AUTOREPLY']; if ( $v_autoreply == 'yes' ) { @@ -234,6 +235,20 @@ if ((!empty($_GET['domain'])) && (empty($_GET['account']))) { } } + // FWD_ONLY flag + if (($v_fwd_only == 'yes') && (empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) { + exec (VESTA_CMD."v-delete-mail-account-fwd-only ".$v_username." ".$v_domain." ".$v_account, $output, $return_var); + check_return_code($return_var,$output); + unset($output); + $v_fwd_only = ''; + } + if (($v_fwd_only != 'yes') && (!empty($_POST['v_fwd_only'])) && (empty($_SESSION['error_msg']))) { + exec (VESTA_CMD."v-add-mail-account-fwd-only ".$v_username." ".$v_domain." ".$v_account, $output, $return_var); + check_return_code($return_var,$output); + unset($output); + $v_fwd_only = 'yes'; + } + // Autoreply if (($v_autoreply == 'yes') && (empty($_POST['v_autoreply'])) && (empty($_SESSION['error_msg']))) { exec (VESTA_CMD."v-delete-mail-account-autoreply ".$v_username." ".$v_domain." ".$v_account, $output, $return_var); diff --git a/web/templates/admin/add_mail_acc.html b/web/templates/admin/add_mail_acc.html index 188e7b2c..5fff1e46 100644 --- a/web/templates/admin/add_mail_acc.html +++ b/web/templates/admin/add_mail_acc.html @@ -127,6 +127,17 @@ + + + + + + + + > + + + diff --git a/web/templates/admin/edit_mail_acc.html b/web/templates/admin/edit_mail_acc.html index 1d40cc56..f51fb60d 100644 --- a/web/templates/admin/edit_mail_acc.html +++ b/web/templates/admin/edit_mail_acc.html @@ -118,6 +118,16 @@ + + + + + + + + > + +