#!/bin/bash if [ "$1" == 'debug' ]; then set -x; shift; fi if [ "$1" == 'debug2' ]; then set -xvT; shift; fi #------------------------ REALPATH=`realpath $0` WHERE=`dirname $REALPATH` ME=`basename $REALPATH` cd $WHERE . ../../system.conf . ../../common.conf . ../../common.bashlib #------------------------ . ../WatchMX/WatchMX.conf # Listen to mother's voice . WatchMB.conf trap cleanup 0 1 2 9 15 cleanup() { : echo "Cleaning up ..." } LOADER=MB LOADFILE=$POOL/ipset.Loadfile-$LOADER log "$ME started loading from $DB ..." # # Read the mailhogs.db and fill the load file # ### Remove trash at first ... $SQL "delete from mailhogs where IP='' or IP='unknown';" >$LOADFILE MAILHOGS=`$SQL "select IP,type,class from mailhogs where state='DROP' and origin='$MODULE' order by IP;"` echo "$MAILHOGS" |\ awk -v loadfile=$LOADFILE -v setname=$MYSET -v settype="$SETTYP" -v setopts="$SETOPTS" ' BEGIN {} { split ($0,parts,"|") mailhogs[parts[1]]=parts[2]","parts[3] } END { printf "-exist create %s %s %s\n", setname, settype, setopts > loadfile for (mailhog in mailhogs) { CLASS=mailhogs[mailhog] COMMENT="DB,"CLASS if ( mailhog != "" ) printf "add %s %s comment \"%s\"\n", setname, mailhog,COMMENT >> loadfile } } ' have_it=`ipset -n list | grep $MYSET` if [ -z "$have_it" ] then mk-ipset $MYSET "$SETTYP" "$SETOPTS" fi $IPSET flush $MYSET $IPSET -file $LOADFILE restore log "$ME finished loading ..."