51 lines
1.2 KiB
Bash
Executable File
51 lines
1.2 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
function usage() {
|
|
|
|
echo
|
|
|
|
if [ -n "$1" ];then
|
|
echo -e "Error: $1\n"
|
|
fi
|
|
echo -e "\nPrints the password for a given email address or"
|
|
echo -e "prints all username/password combinations from a give domain\n"
|
|
echo -e "\tusage: `basename $0` <email address | email domain>\n"
|
|
exit 1
|
|
}
|
|
|
|
|
|
|
|
[ $# -eq "0" -o $# -gt "2" ] && usage "wrong number of arguments"
|
|
|
|
address="$1"
|
|
|
|
domain=`echo $address | cut -d'@' -f2`
|
|
|
|
mysql=false
|
|
mysql_user=backup
|
|
mysql_password=backup
|
|
mysql_db=postfix
|
|
|
|
#echo "address...: $address"
|
|
#echo "domain....: $domain"
|
|
|
|
echo ""
|
|
if $mysql ; then
|
|
if [ "$domain" = "$address" ] ; then
|
|
mysql -u$mysql_user -p$mysql_password $mysql_db -N -s -e "select username,password from mailbox where domain = '$address'"
|
|
else
|
|
mysql -u$mysql_user -p$mysql_password $mysql_db -N -s -e "select username,password from mailbox where username = '$address'"
|
|
fi
|
|
else
|
|
if [ "$domain" = "$address" ] ; then
|
|
su - postgres -c"psql postfix -t -q -c\"select username,password from mailbox where domain = '$address'\""
|
|
else
|
|
su - postgres -c"psql postfix -t -q -c\"select username,password from mailbox where username = '$address'\""
|
|
fi
|
|
fi
|
|
echo ""
|
|
|
|
|
|
|
|
exit 0
|