pywallter/scripts/set_mail_passwd

109 lines
2.2 KiB
Plaintext
Raw Normal View History

2022-08-06 18:22:24 +02:00
#!/bin/sh
. /etc/mailconfig
2023-03-18 23:08:43 +01:00
exit_failure(){
mess=$1
code_exit=$2
echo "$mess";
exit "$code_exit";
}
2022-08-06 18:22:24 +02:00
check_domain()
{
mail=$1
domain=`echo $mail | awk -F '@' '{ print $2 }'`
2023-03-18 23:08:43 +01:00
[[ "$domain" = `hostname` ]] || exit_failure "Bad domain " 1
2022-08-06 18:22:24 +02:00
}
2023-03-18 23:08:43 +01:00
2022-08-06 18:22:24 +02:00
check_alias()
{
mail=$1
2023-03-18 23:08:43 +01:00
aliases=$(grep -v "$mail" $ALIAS_FILE)
echo "$aliases" | grep -q "$mail" && exit_failure "Address already exist in alias" 2 || true
2022-08-06 18:22:24 +02:00
}
check_app_mail()
{
2023-03-18 23:08:43 +01:00
alias=$1
grep -q "$alias" "$APP_MAIL" && exit_failure "This e-mail address already exist in app mail" 2 || true
2022-08-06 18:22:24 +02:00
}
2023-03-18 23:08:43 +01:00
set_password()
2022-08-06 18:22:24 +02:00
{
2023-03-18 23:08:43 +01:00
mail=$1
password=$2
cat $PASSWD_FILE | grep -w -v -e "$mail" > /tmp/passwd.tmp
print "$mail":`encrypt "$password"` >> /tmp/passwd.tmp
2022-08-06 18:22:24 +02:00
mv /tmp/passwd.tmp $PASSWD_FILE
}
add_mailbox()
{
2023-03-18 23:08:43 +01:00
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
2022-08-06 18:22:24 +02:00
}
delete_mail_account()
{
2023-03-18 23:08:43 +01:00
mail=$1
cat $PASSWD_FILE | grep -w -v -e "$mail" > /tmp/passwd.tmp
2022-08-06 18:22:24 +02:00
mv /tmp/passwd.tmp $PASSWD_FILE
2023-03-18 23:08:43 +01:00
cat $ALIAS_FILE | grep -v "$mail" >> /tmp/virtuals.tmp
2022-08-06 18:22:24 +02:00
mv /tmp/virtuals.tmp $ALIAS_FILE
# rm -fr repertoir mail.
}
usage(){
print "This program ask 2 arguments : \n"
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"
2023-03-18 23:08:43 +01:00
print "Example:\n\t $0 add example@`hostname` 'yourverysecurepassword' "
2022-08-06 18:22:24 +02:00
print "For delete a mail account:\n"
print "$0 del test@`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
case $1 in
"del")
check_domain "$2"
delete_mail_account "$2"
2023-03-18 23:08:43 +01:00
smtpctl update table passwd
smtpctl update table virtuals
2023-03-18 23:08:43 +01:00
;;
2022-08-06 18:22:24 +02:00
*)
check_domain "$1"
check_alias "$1"
check_app_mail "$1"
2023-03-18 23:08:43 +01:00
set_password "$1" "$2"
2022-08-06 18:22:24 +02:00
add_mailbox "$1"
2023-03-18 23:08:43 +01:00
smtpctl update table passwd
smtpctl update table virtuals
2023-03-18 23:08:43 +01:00
;;
2022-08-06 18:22:24 +02:00
esac