update scripts
This commit is contained in:
@@ -2,67 +2,59 @@
|
||||
|
||||
. /etc/mailconfig
|
||||
|
||||
exit_failure(){
|
||||
mess=$1
|
||||
code_exit=$2
|
||||
echo "$mess";
|
||||
exit "$code_exit";
|
||||
}
|
||||
|
||||
check_domain()
|
||||
{
|
||||
mail=$1
|
||||
domain=`echo $mail | awk -F '@' '{ print $2 }'`
|
||||
|
||||
if [ "$domain" != `hostname` ]; then
|
||||
echo "bad domain"
|
||||
exit 1
|
||||
fi;
|
||||
[[ "$domain" = `hostname` ]] || exit_failure "Bad domain " 1
|
||||
|
||||
}
|
||||
|
||||
|
||||
check_alias()
|
||||
{
|
||||
mail=$1
|
||||
|
||||
while read line; do
|
||||
alias=`echo $line | awk -F ':' '{ print $1 }'`
|
||||
isvmail=`echo $line | awk -F ':' '{ print $2 }'`
|
||||
if [ "$mail" = "$ALIAS_FILE" ] && [ "$isvmail" != " vmail" ]; then
|
||||
echo "Address already exist in alias!"
|
||||
exit 2;
|
||||
fi;
|
||||
done < $ALIAS_FILE
|
||||
aliases=$(grep -v "$mail" $ALIAS_FILE)
|
||||
echo "$aliases" | grep -q "$mail" && exit_failure "Address already exist in alias" 2 || true
|
||||
}
|
||||
|
||||
check_app_mail()
|
||||
{
|
||||
mail=$1
|
||||
while read line; do
|
||||
if [ "$mail" == "$line" ]; then
|
||||
echo "Adress already exist"
|
||||
exit 2;
|
||||
fi;
|
||||
done < $APP_MAIL
|
||||
alias=$1
|
||||
grep -q "$alias" "$APP_MAIL" && exit_failure "This e-mail address already exist in app mail" 2 || true
|
||||
}
|
||||
|
||||
change_password()
|
||||
|
||||
set_password()
|
||||
{
|
||||
cat $PASSWD_FILE | grep -w -v -e "$1" > /tmp/passwd.tmp
|
||||
print "$1":`encrypt "$2"` >> /tmp/passwd.tmp
|
||||
mail=$1
|
||||
password=$2
|
||||
cat $PASSWD_FILE | grep -w -v -e "$mail" > /tmp/passwd.tmp
|
||||
print "$mail":`encrypt "$password"` >> /tmp/passwd.tmp
|
||||
mv /tmp/passwd.tmp $PASSWD_FILE
|
||||
}
|
||||
|
||||
add_mailbox()
|
||||
{
|
||||
mailbox="$1"': vmail'
|
||||
egrep "$mailbox" "$ALIAS_FILE";
|
||||
if [ "$?" -eq "1" ]; then
|
||||
print "$mailbox" >> $ALIAS_FILE
|
||||
fi
|
||||
|
||||
mail=$1
|
||||
cat $ALIAS_FILE | grep -w -v -e "$mail: vmail" > /tmp/virtuals.tmp
|
||||
print "$1: vmail" >> /tmp/virtuals.tmp
|
||||
mv /tmp/virtuals.tmp $ALIAS_FILE
|
||||
}
|
||||
|
||||
delete_mail_account()
|
||||
{
|
||||
mail_account=$1
|
||||
cat $PASSWD_FILE | grep -w -v -e "$mail_account" > /tmp/passwd.tmp
|
||||
mail=$1
|
||||
cat $PASSWD_FILE | grep -w -v -e "$mail" > /tmp/passwd.tmp
|
||||
mv /tmp/passwd.tmp $PASSWD_FILE
|
||||
cat $ALIAS_FILE | grep -w -v -e "$mail_account" >> /tmp/virtuals.tmp
|
||||
cat $ALIAS_FILE | grep -v "$mail" >> /tmp/virtuals.tmp
|
||||
mv /tmp/virtuals.tmp $ALIAS_FILE
|
||||
# rm -fr repertoir mail.
|
||||
}
|
||||
@@ -72,7 +64,7 @@ usage(){
|
||||
print "For add or change password of mail account :\: "
|
||||
print "First is email with domain name of this host second is password \n:"
|
||||
print "\t$0 email-adresse 'password'\n"
|
||||
print "Example:\n\t $0 test@`hostname` 'yourverysecurepassword' "
|
||||
print "Example:\n\t $0 add example@`hostname` 'yourverysecurepassword' "
|
||||
|
||||
print "For delete a mail account:\n"
|
||||
print "$0 del test@`hostname`"
|
||||
@@ -101,16 +93,16 @@ case $1 in
|
||||
"del")
|
||||
check_domain "$2"
|
||||
delete_mail_account "$2"
|
||||
smtpctl update table passwd
|
||||
smtpctl update table passwd
|
||||
smtpctl update table virtuals
|
||||
;;
|
||||
;;
|
||||
*)
|
||||
check_domain "$1"
|
||||
check_alias "$1"
|
||||
check_app_mail "$1"
|
||||
set_password "$1" "$2"
|
||||
add_mailbox "$1"
|
||||
change_password "$1" "$2"
|
||||
smtpctl update table passwd
|
||||
smtpctl update table passwd
|
||||
smtpctl update table virtuals
|
||||
;;
|
||||
;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user