pywallter/scripts/set_mail_alias

127 lines
2.0 KiB
Plaintext
Raw Normal View History

2022-08-06 18:22:24 +02:00
#!/bin/sh
. /etc/mailconfig
check_domain()
2022-08-06 18:22:24 +02:00
{
mail=$1
2022-08-06 18:22:24 +02:00
domain=`echo $mail | awk -F '@' '{ print $2 }'`
if [ "$domain" != `hostname` ]; then
echo "bad domain"
exit 1
fi;
}
check_alias()
{
alias=$1
echo "$alias"
alias_exist=`egrep "$alias" "$ALIAS_FILE"`
2022-08-06 18:22:24 +02:00
echo "$alias_exist"
if [ "$alias_exist" != "" ]; then
echo "Address already exist in alias!"
exit 1
fi
2022-08-06 18:22:24 +02:00
}
check_app_mail()
{
mail=$1
while read line; do
2022-08-07 04:03:55 +02:00
if [ "$mail" == "$line" ]; then
2022-08-06 18:22:24 +02:00
echo "Adress already exist"
exit 2;
fi;
done < $APP_MAIL
}
add_alias()
{
2022-08-07 04:03:55 +02:00
print "$2":" $1" >> "$ALIAS_FILE"
2022-08-06 18:22:24 +02:00
}
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(){
alias_c="$1: $2"
alias_exist=`egrep "$alias_c" "$ALIAS_FILE" `
if [ -z "$alias_exist" ]; then
print "This alias doesn't exist"
exit 2
fi
}
2022-08-06 18:22:24 +02:00
del_alias()
{
alias_line="$1: $2"
egrep -v "$alias_line" "$ALIAS_FILE" > /tmp/alias.tmp
mv /tmp/alias.tmp "$ALIAS_FILE"
2022-08-06 18:22:24 +02:00
}
usage(){
print "This program ask 3 arguments : \n"
print "First is email with domain name of this host second is add or del for \n"
print "add or delete an alias "
print "\t$0 email-adresse del alias@`hostname`\n"
print "Other example:\n\t $0 test@`hostname` add myalias@`hostname` "
print "This script require root privilèges"
}
if [ `id -u` -ne 0 ]; then
usage
exit 4;
fi
if [ -z $1 ];
then
usage
exit 3;
fi
if [ -z $2 ];
then
usage
exit 3;
fi
check_domain $1
2022-08-06 18:22:24 +02:00
case $2 in
"add")
check_mail_exist $3
check_alias $3
check_app_mail $3
2022-08-06 18:22:24 +02:00
add_alias $1 $3
2022-08-07 04:06:29 +02:00
smtpctl update table virtuals
2022-08-06 18:22:24 +02:00
;;
"del")
check_alias_exist $3 $1
2022-08-06 18:22:24 +02:00
del_alias $3 $1
2022-08-07 04:03:55 +02:00
smtpctl update table virtuals
2022-08-06 18:22:24 +02:00
;;
*)
usage
exit 4;
;;
esac