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