Mail alias script

Iš Žinynas.
Jump to navigation Jump to search

Scriptas skirtas virtualių aliasų sukūrimams/pašalinimams jau sukonfigūruotame pagal šį straipsnį mail serveryje.

#!/bin/bash
DB=mailserveris
DOMAIN_ID=1
if [ `id -u` != 0 ]; then
echo "Scriptas turi buti paleistas is root"
exit 1
fi

if [ "$1" == "" ]; then
echo "Komandos: $0 add/del <vartotojas> <i_ka@forwardinti.lt"
echo "pvz.: $0 add abuse admin@domenas.lt"
echo "Prides aliasa abuse@domenas.lt nupointinta i admin@domenas.lt"
exit 1
fi
if [ "$2" == "" ]; then
        echo "Nenurodytas vartotojo vardas!"
        exit 1
fi
if [ "$1" == "add" ] && [ "$3" == "" ];then
        echo "Nenurodyta i ka forwardinti!"
        exit 1
fi
USER="$2"
DEST="$3"
DOM=$(mysql $DB -se "SELECT name FROM virtual_domains WHERE id=$DOMAIN_ID")
if [ "$1" == "add" ]; then
echo "Naujo alias pridejimas"
mysql --database="$DB" --execute="INSERT INTO virtual_aliases (domain_id, source, destination) VALUES ('${DOMAIN_ID}', '${USER}@${DOM}', '${DEST}');"
echo "Alias sukurtas: $USER@$DOM - Pointina i: $DEST"
elif [ "$1" == "del" ]; then
echo "Seno alias salinimas"
mysql --database="$DB" --execute="DELETE FROM virtual_aliases WHERE source = '$USER@$DOM';"
echo "Pasalintas alias $USER@$DOM"
fi