#!/bin/bash
# to prevent dependency on nfs disk  /blacklist/dnsbl/ we are going to copy original
# every 5 minutes.
#
# attackcountries -> /blacklist/dnsbl/attackers/attackcountries
# attackers -> /blacklist/dnsbl/attackers/attackers
# attackipcounts -> /blacklist/dnsbl/attackers/attackipcounts
# attackipcounts2 -> /blacklist/dnsbl/attackers/attackipcounts2
# dropPort.log -> /blacklist/dnsbl/attackers/dropPort.log
# machinescount -> /blacklist/dnsbl/attackers/machinescount
# sbl.drop -> /blacklist/dnsbl/spamhaus/sbl.drop
# sbl.edrop -> /blacklist/dnsbl/spamhaus/sbl.edrop

dest="/var/www/html/DROP"
src="/blacklist/drop"

#
attackers="$src/attackers"
dropfiles=('attackcountries' 
    'attackers' 
    'attackipcounts' 
    'attackipcounts2'
    'dropPort.log'
    'machinescount'
)

for file in "${dropfiles[@]}"
do
    fileName="$attackers/$file"
    destName="$dest/$file"
    #   echo "copying $destName"
        /bin/cp  -fp $fileName $destName.new
	if [ -e $fileName ]; then
   	  if [ -h $destName ];then
	    echo "remove  $destName"
	    mv  $destName.old
  	  fi
	mv  $destName.new $destName
       fi
done

exit;

#no longer needed as we dont do spamcheck anymore
spamahaus="$src/spamhaus"
spamfiles=('sbl.drop' 'sbl.edrop')
#
for file in "${spamfiles[@]}"
do
    fileName="$spamahaus/$file"
    destName="$dest/$file"
    if [ -e $fileName ]; then
	if [ -h $destName ];then
	    echo "remove link $destName"
	    /bin/rm $destName
	fi
     #   echo "copying $destName"
        /bin/cp  -fp $fileName $destName
    fi
done
