Page 1 of 1

Script for operations on Black and White list tables

Posted: 03 Nov 2017 19:51
by SupportOU
Hola,

I have automated a lot of stuff for allowing new users and departments on my platform. Is there a piece of script with which I can add or delete black and white list entries? Or should I create something myself with the mySQL credentials in the conf files? And are the tables straight forward?

And is there a bulk export script or should I create one myself as well?

Grtz,
Ronald

Re: Script for operations on Black and White list tables

Posted: 12 Nov 2017 11:20
by shawniverson

Re: Script for operations on Black and White list tables

Posted: 16 Nov 2017 14:47
by SupportOU
Indeed a good start! I my case I only have to modify the blacklist automated. Thanks! :clap: :clap:

# adding domain to mysql db mailscanner table blacklist
MAILWATCHSQLPWD=`grep MAILWATCHSQLPWD /etc/EFA-Config | sed 's/.*://'`
if [[ -z $MAILWATCHSQLPWD ]]; then
echo "Unable to access SQL password from /etc/EFA-Config, exiting."
exit
fi

# check if there already
echo 'checking mailwatch'
A=`mysql -u mailwatch --password=$MAILWATCHSQLPWD mailscanner -e "SELECT COUNT(*) from blacklist WHERE from_address='$1';" | awk '!/COUNT/{print $1}'`
if [ -z "$A" ]; then
echo "something went wrong quering mailwatch, exit"
fi

if [ "$A" == "0" ]; then
echo "adding $1 to blacklist in mailwatch"
mysql -u mailwatch --password=$MAILWATCHSQLPWD mailscanner -e "INSERT INTO blacklist (to_address, to_domain, from_address) VALUES ('default','','$1')"
else
echo "$1 already in mailwatch black list"
fi