#!/bin/bash # Export the path PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin export PATH # Set the time / date locale to kernel default export LC_TIME=C # Set some variables CNT=0 FILE="" LASTMOD="" #PROXY="http://Your_Proxy_Here:Your_Proxy_Port_Here/" TMPDATE=$(date +%s) URL="" ZONE="Your_Zone_Here" ZONEFILE="Your_Zone_File_Here" getlastmod() { # Does the file exist if [ -f $FILE ] then # Figure out file date and convert to HTTP Last-Modified date LASTMOD=$(date -u +"%a, %d %b %Y %H:%M:%S GMT" \ --date="$(ls -l --time-style=+"%a, %d %b %Y %H:%M:%S %z" $FILE | \ awk '{print $6 " " $7 " " $8 " " $9 " " $10 " " $11}' | \ head -n1)") else # Use epoch zero LASTMOD="Thu, 01 Jan 1970 00:00:00 GMT" fi echo "Current lastmod: ${LASTMOD}" } getfile() { # Get the file if newer then LASTMOD TMP="/tmp/${FILE}-${TMPDATE}-${$}" if ( curl -f -H "If-Modified-Since: ${LASTMOD}" -o "${TMP}" -R "${URL}" ) then # No errors if [ -s "${TMP}" ] then # Non zero rm "${FILE}.old" mv "${FILE}" "${FILE}.old" mv "${TMP}" "${FILE}" chown root:staff "${FILE}" let CNT+=1 echo "New ${FILE}" else rm "${TMP}" echo "${FILE} not modified" fi else echo "Error fetching ${URL}" fi } if [ -d /var/local/lib/bind/ ] then cd /var/local/lib/bind/ else echo "Create /var/local/lib/bind/" exit 1 fi #FILE="drop.lasso" #URL="https://www.spamhaus.org/drop/drop.lasso" FILE="drop.txt" URL="https://www.spamhaus.org/drop/drop.txt" getlastmod getfile FILE="edrop.txt" URL="https://www.spamhaus.org/drop/edrop.txt" getlastmod getfile FILE="dropv6.txt" URL="https://www.spamhaus.org/drop/dropv6.txt" getlastmod getfile if [ $CNT -eq 0 ] then # No changes echo "No change in ${ZONEFILE}" exit 0 fi DATE=$( date +%Y%m%d01 ) rm "${ZONEFILE}.old" mv "${ZONEFILE}" "${ZONEFILE}.old" cat /etc/bind/local-rbl-head | sed -e "s/SERIAL/${DATE}/g" > "${ZONEFILE}" #cat drop.lasso | procdrop >> "${ZONEFILE}" cat drop.txt | procdrop >> "${ZONEFILE}" echo "" >> "${ZONEFILE}" cat edrop.txt | procdrop >> "${ZONEFILE}" echo "" >> "${ZONEFILE}" cat dropv6.txt | procdrop >> "${ZONEFILE}" echo "" >> "${ZONEFILE}" if ( named-checkzone "${ZONE}" "${ZONEFILE}" > /dev/null ) then if ( diff "${ZONEFILE}" "/etc/bind/${ZONEFILE}" > /dev/null ) then echo "No change in ${ZONEFILE}" else cp "${ZONEFILE}" /etc/bind/ echo "New version of ${ZONEFILE}" echo "${CNT} new files" fi fi