Ajout support serveur MAIL et XMPP
This commit is contained in:
9
scripts/etc/mailconfig
Normal file
9
scripts/etc/mailconfig
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
# Password file
|
||||
PASSWD_FILE="/etc/mail/passwd"
|
||||
|
||||
# Alias File
|
||||
ALIAS_FILE="/etc/mail/virtuals"
|
||||
|
||||
# APPLICATIONS MAIL ADDRESS
|
||||
APP_MAIL="/etc/mail/reserved"
|
||||
9
scripts/mailconfig
Normal file
9
scripts/mailconfig
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
# Password file
|
||||
PASSWD_FILE="/home/kitoy/prog/shell/passwd"
|
||||
|
||||
# Alias File
|
||||
ALIAS_FILE="/home/kitoy/prog/shell/virtuals"
|
||||
|
||||
#App mail list
|
||||
APP_MAIL=/home/kitoy/prog/shell/app_mail
|
||||
109
scripts/set_mail_alias
Executable file
109
scripts/set_mail_alias
Executable file
@@ -0,0 +1,109 @@
|
||||
#!/bin/sh
|
||||
|
||||
. /etc/mailconfig
|
||||
|
||||
check_mail()
|
||||
{
|
||||
mail=$1
|
||||
domain=`echo $mail | awk -F '@' '{ print $2 }'`
|
||||
|
||||
if [ "$domain" != `hostname` ]; then
|
||||
echo "bad domain"
|
||||
exit 1
|
||||
fi;
|
||||
|
||||
mail_exist=`egrep "$mail" $PASSWD_FILE`
|
||||
if [ -z $mail_exist ]; then
|
||||
print "This address doesn't exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
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" ] && [ "$isvmail" != " vmail" ]; then
|
||||
echo "Address already exist in alias!"
|
||||
exit 2;
|
||||
fi;
|
||||
done < $ALIAS_FILE
|
||||
}
|
||||
|
||||
check_app_mail()
|
||||
{
|
||||
mail=$1
|
||||
while read line; do
|
||||
if ["mail" == "line"]; then
|
||||
echo "Adress already exist"
|
||||
exit 2;
|
||||
fi;
|
||||
done < $APP_MAIL
|
||||
}
|
||||
|
||||
|
||||
add_alias()
|
||||
{
|
||||
print "$2":" $1" >> "$alias_file"
|
||||
}
|
||||
|
||||
del_alias()
|
||||
{
|
||||
while read line; do
|
||||
if [ "$1: $2" = "$line" ]; then
|
||||
cat alias | grep -w -v -e "$1" > /tmp/alias.tmp
|
||||
mv /tmp/alias.tmp "$alias_file"
|
||||
isremove=1
|
||||
fi
|
||||
done < "$ALIAS_FILE"
|
||||
}
|
||||
|
||||
|
||||
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_mail $1
|
||||
|
||||
|
||||
case $2 in
|
||||
"add")
|
||||
check_alias $3
|
||||
check_app_mail $3
|
||||
add_alias $1 $3
|
||||
;;
|
||||
"del")
|
||||
del_alias $3 $1
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
exit 4;
|
||||
;;
|
||||
esac
|
||||
112
scripts/set_mail_passwd
Executable file
112
scripts/set_mail_passwd
Executable file
@@ -0,0 +1,112 @@
|
||||
#!/bin/sh
|
||||
|
||||
. /etc/mailconfig
|
||||
|
||||
|
||||
check_domain()
|
||||
{
|
||||
mail=$1
|
||||
domain=`echo $mail | awk -F '@' '{ print $2 }'`
|
||||
|
||||
if [ "$domain" != `hostname` ]; then
|
||||
echo "bad domain"
|
||||
exit 1
|
||||
fi;
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
check_app_mail()
|
||||
{
|
||||
mail=$1
|
||||
while read line; do
|
||||
if ["mail" == "line"]; then
|
||||
echo "Adress already exist"
|
||||
exit 2;
|
||||
fi;
|
||||
done < $APP_MAIL
|
||||
}
|
||||
|
||||
change_password()
|
||||
{
|
||||
cat $PASSWD_FILE | grep -w -v -e "$1" > /tmp/passwd.tmp
|
||||
print "$1":`encrypt "$2"` >> /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
|
||||
|
||||
}
|
||||
|
||||
delete_mail_account()
|
||||
{
|
||||
mail_account=$1
|
||||
cat $PASSWD_FILE | grep -w -v -e "$mail_account" > /tmp/passwd.tmp
|
||||
mv /tmp/passwd.tmp $PASSWD_FILE
|
||||
cat $ALIAS_FILE | grep -w -v -e "$mail_account" >> /tmp/virtuals.tmp
|
||||
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"
|
||||
print "Example:\n\t $0 test@`hostname` 'yourverysecurepassword' "
|
||||
|
||||
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"
|
||||
;;
|
||||
*)
|
||||
check_domain "$1"
|
||||
check_alias "$1"
|
||||
check_app_mail "$1"
|
||||
add_mailbox "$1"
|
||||
change_password "$1" "$2"
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user