quarta-feira, 11 de janeiro de 2012

Script para atualizar periodicamente blacklists selecionadas do squidGuard


O script abaixo irá baixar os arquivos tar.gz de blacklist dos sites squidguard.mesd.k12.or.us e www.shallalist.de, após isso ele irá descompactar os arquivos e copiar as pastas de blacklists, que estejam listados por você nos arquivos bls_mesd.txt e bls_shalla.txt, para o diretório de blacklists do squidGuard, após isso mudará o dono dos diretórios de blacklists do squidGuard para o usuário squid e por ultimo ele irá recompilar as blacklists transformando-as em arquivo de banco de dados para o squidGuard. O conteúdo da pasta utlizada para baixar e descompactar os tar.gz será limpa no final do processo.

-> PARA AGENDAR A EXECUÇÃO DO SCRIPT UTILIZE O crontab. 


#!/bin/bash
############################################################### 
# Atualizando blacklists selecionadas para o squidGuard
# Por Leonardo Couto Conrado 
# Em 11/01/2012 
############################################################### 
# README:
# Crie o diretorio da variavel dirWork
# Crie o arquivo de log da variavel logUpBlackLists
# Crie o arquivo /usr/local/upblacklists/bls_mesd.txt ele deverá conter as blacklists desejadas da mesd squidguard.mesd.k12.or.us para serem copiadas para as blacklists do squidGuard
# Crie o arquivo /usr/local/upblacklists/bls_shalla.txt ele deverá conter as blacklists desejadas da shalla www.shallalist.de para serem copiadas para as blacklists do squidGuard

clockNow=$(date +%d.%m.%Y-%H:%M)
dirBlackListSquidGuard=/usr/local/squidGuard/db/blacklists/
dirWork=/usr/local/upblacklists/work/
dirUpBlackLists=/usr/local/upblacklists/
squidGuardCreateDBs="/usr/local/squidGuard/bin/squidGuard -C all"
 
urlListMesd=http://squidguard.mesd.k12.or.us/blacklists.tgz
urlListShalla=http://www.shallalist.de/Downloads/shallalist.tar.gz
fileTgzMesd=blacklists.tgz
fileTgzShalla=shallalist.tar.gz
fileBlacklistsMesd=blacklists/
fileBlacklistsShalla=BL/
 
logUpBlackLists=/var/log/updatebacklists.log
 
numBlsMesd=$(cat $dirUpBlackLists"bls_mesd.txt" | wc -l)
numBlsShalla=$(cat $dirUpBlackLists"bls_shalla.txt" | wc -l)
 
counter=1
 
# INICIO
 
cd $dirWork
 
wget -c $urlListMesd
wget -c $urlListShalla
 
if [ $? = 0 ]; then
        tar -xzf $dirWork$fileTgzMesd
        tar -xzf $dirWork$fileTgzShalla
 
        cd $dirWork$fileBlacklistsMesd
              echo $clockNow  " - ANDAMENTO COPIA DAS BLS DA MESD: " >> $logUpBlackLists
                while [ $counter -le $numBlsMesd ]; do
                        blMesd=$(cat $dirUpBlackLists"bls_mesd.txt" | awk -v VAR=$counter 'NR == VAR {print $0}')
                        /bin/cp -fv $dirWork$fileBlacklistsMesd$blMesd/domains $dirBlackListSquidGuard$blMesd >> $logUpBlackLists
                        /bin/cp -fv $dirWork$fileBlacklistsMesd$blMesd/urls $dirBlackListSquidGuard$blMesd >> $logUpBlackLists
                        let counter=counter+1
                done
       counter=1
 
        cd $dirWork$fileBlacklistsShalla
                echo $clockNow  " - ANDAMENTO COPIA DAS BLS DA SHALA: " >> $logUpBlackLists
                while [ $counter -le $numBlsShalla ]; do
                        blShalla=$(cat $dirUpBlackLists"bls_shalla.txt" | awk -v VAR=$counter 'NR == VAR {print $0}')
                        /bin/cp -fv $dirWork$fileBlacklistsShalla$blShalla/domains $dirBlackListSquidGuard$blShalla >> $logUpBlackLists
                        /bin/cp -fv $dirWork$fileBlacklistsShalla$blShalla/urls $dirBlackListSquidGuard$blShalla >> $logUpBlackLists
                        let counter=counter+1
                done
      
       echo $clockNow  " - ANDAMENTO DAS PERMISSOES PARA SQUID NAS BLS DO SQUIDGUARD: " >> $logUpBlackLists
        chown squid -R -v $dirBlackListSquidGuard >> $logUpBlackLists
      
       echo $clockNow  " - RECOMPILANDO AS DBS DO SQUIDGUARD: " >> $logUpBlackLists
       echo `$squidGuardCreateDBs` >> $logUpBlackLists
 
       echo $clockNow  " - LIMPANDO DIRETORIO WORKS: " >> $logUpBlackLists
        cd $dirWork && rm -rf ./
else
   echo $clockNow ' - FALHOU DOWNLOAD DE UMA DAS BLS: ' >> $logUpBlackLists
 
fi
 
exit 0
 



4 comentários:

  1. Este comentário foi removido pelo autor.

    ResponderExcluir
  2. Como faço para atualizar todo squid?

    ResponderExcluir
  3. We are the worlds leading publisher of Squid 'Native ACL' formatted blacklists, that allow for web filtering directly with Squid proxy. Of course we also offer alternative formats for the most widely used third party plugins, such as DansGuardian and Squidguard. And while our blacklists are subscription based, they are as a result of our efforts, of a much higher degree of quality than the free alternatives.

    We hope to serve you,

    --
    Signed,

    Benjamin E. Nichols
    http://www.squidblacklist.org

    ResponderExcluir

Seguidores