Sophie

Sophie

distrib > Mageia > 6 > armv5tl > by-pkgid > 27c9e495b756d2cf1662d26c720c3cc2 > files > 4

dansguardian-children-blacklists-0.0.7-6.mga6.src.rpm

#!/bin/bash
###
# update-dansguardian-blacklists - refresh DansGuardian Blacklists
#
# Version: 0.9.4
# Date: Apr 17 2014
# Author: AlexL <loginov.alex.valer@gmail.com>, based on
# the work of Fernand Jonker <fernand@futuragts.com> and
# Christopher Rath <christopher@rath.ca>
#
# A sysadmin named Mike posted the original script to one of the
# ClarkConnect Forums.  It was then rewritten quite extensively by
# Christopher Rath to make it more configurable and to include error
# checking. Thereafter it was customized by Fernand Jonker for
# use with DansGuardian.
#
# Have cron periodically run it to keep your blacklists updated.
# Please limit automated downloads to twice or ideally once a week
# to prevent bandwidth wastage. There is also no point in downloading
# more often as the lists won't change that much.
#
# Ensure you have wget installed
#
# When update-dansguardian-blacklists moves the new Blacklists into
# place it only replaces Blacklists; that is, if a new Blacklist
# is not downloaded for a particular category then the old list
# will remain in place.
#
# Info on Dansguardian and Blacklists can be found at:
#     http://www.dansguardian.org/
#     http://urlblacklist.com/
#     http://dsi.ut-capitole.fr/blacklists/download/
#
# No copyright retained.  This script is from the Public Domain:
# http://urlblacklist.com/downloads/OriginalUpdateBL
# This package is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# License: GPLv3 and later
###

###
# History
#
# 0.9	- Sept 1, 2002 - original release.
# 0.9.1 - Sept 4, 2002 - changed DG restart command and added cron
#			information - minor cosmetic changes.
# 0.9.2 - Sept 9, 2002 - changed default download to the small test
#			file and added history
# 0.9.3 - Oct 20, 2013 - updated for using 11 years later, translation
# 0.9.4 - Apr 17, 2014 - minor changes
#
###

# Don't allow undefined variables.
set -u

export BL_URL=${BL_URL:="http://cri.univ-tlse1.fr/blacklists/download/blacklists.tar.gz"}
export DB_PATH=${DB_PATH:="/etc/dansguardian/lists/blacklists"}
export HOME_DIR="/tmp"
export SG_UGID=${SG_UGID:="root:root"}
export UNCOMP_CMD="tar"
export UNCOMP_CMD_PARAMS="-zxf"
export UNTAR_DIR="blacklists"
export VERS="0.9.4"

# Create a few working variables.
export BL_TAR_BASE="`basename ${BL_URL}`"
export TMP_DIR="${HOME_DIR}/${UNTAR_DIR}"
export BL_TAR_FULL="${TMP_DIR}/${BL_TAR_BASE}"

export LANG0='en'

#Russian (Русский)
export LOCALE0=`export|grep LANG|grep ru`
if [ ! "$LOCALE0" = "" ]
then
   export LANG0='ru'
fi
#Украинский (Ukrainian)
export LOCALE0=`export|grep LANG|grep uk`
if [ ! "$LOCALE0" = "" ]
then
   export LANG0='ru'
fi
#Белорусский (Belarusian)
export LOCALE0=`export|grep LANG|grep be`
if [ ! "$LOCALE0" = "" ]
then
   export LANG0='ru'
fi
#Башкирский (Bashkir)
export LOCALE0=`export|grep LANG|grep ba`
if [ ! "$LOCALE0" = "" ]
then
   export LANG0='ru'
fi
#Болгарский (Bulgarian)
export LOCALE0=`export|grep LANG|grep bg`
if [ ! "$LOCALE0" = "" ]
then
   export LANG0='ru'
fi
#Чеченский (Chechen)
export LOCALE0=`export|grep LANG|grep ce`
if [ ! "$LOCALE0" = "" ]
then
   export LANG0='ru'
fi
#Церковнославянский (Church Slavic)
export LOCALE0=`export|grep LANG|grep cu`
if [ ! "$LOCALE0" = "" ]
then
   export LANG0='ru'
fi
#Чувашский (Chuvash)
export LOCALE0=`export|grep LANG|grep cv`
if [ ! "$LOCALE0" = "" ]
then
   export LANG0='ru'
fi
#Казахский (Kazakh)
export LOCALE0=`export|grep LANG|grep kk`
if [ ! "$LOCALE0" = "" ]
then
   export LANG0='ru'
fi
#Коми (Komi)
export LOCALE0=`export|grep LANG|grep kv`
if [ ! "$LOCALE0" = "" ]
then
   export LANG0='ru'
fi
#Молдавский (Moldavian)
export LOCALE0=`export|grep LANG|grep mo`
if [ ! "$LOCALE0" = "" ]
then
   export LANG0='ru'
fi
#Татарский (Tatar)
export LOCALE0=`export|grep LANG|grep tt`
if [ ! "$LOCALE0" = "" ]
then
   export LANG0='ru'
fi

if [ "$LANG0" = "ru" ]
then
   MES0="Запуск обновления чёрных списков"
   MES1="ОШИБКА: не получилось перейти в рабочую директорию,"
   MES2="Запускается wget для получения новых списков. Пожалуйста, подождите."
   MES3="ОШИБКА: не получилось получить новые списки,"
   MES4="        обновление чёрных списков прервано."
   MES5="Новые списки были успешно получены."
   MES6="Распаковка архива чёрных списков,"
   MES7="ОШИБКА: не получилось извлечь новые списки,"
   MES8="Перемещение новых списков по местоназначению."
   MES9="Удаление временных файлов и директорий."
   MES10="Смена владельца и прав."
   MES11="Перезапуск Dansguardian."
   MES12="Обновление чёрных списков завершено:"
   MES13="Только пользователь с правами root может обновлять чёрные списки."
   MES14="Отсутствует wget. Пожалуйста, установите пакет wget."
else
   MES0="Starting Blacklist update"
   MES1="ERROR: unable to cd into working directory,"
   MES2="Running wget to retrieve new lists. Please wait."
   MES3="ERROR: unable to retrieve new lists,"
   MES4="       aborting blacklists refresh."
   MES5="Succesfully retrieved new lists."
   MES6="Untaring Blacklist archive,"
   MES7="ERROR: unable to extract new lists,"
   MES8="Moving new lists into place."
   MES9="Remove temporary files and folders."
   MES10="Change owner and permissions."
   MES11="Restarting Dansguardian."
   MES12="Finished Blacklist update:"
   MES13="Only a user with root privileges can update Blacklist."
   MES14="There is no wget. Please install wget package."
fi

export USER0=`whoami`
if [ "$USER0" != "root" ]
then
  echo "$MES13"
  exit 1
fi

export WGET0=`which wget`
if [ "$WGET0" = "" ]
then
  echo "$MES14"
  exit 1
fi

# Output a quick startup message.
echo "==="
echo "$MES0 v${VERS}: `date '+%Y/%m/%d %T'`"

echo "$MES9"
rm -rf "${TMP_DIR}"
mkdir -p "${TMP_DIR}"

cd "${TMP_DIR}"

if [ "$?" != "0" ]
then
    echo "$MES1"
    echo "       ${TMP_DIR}"
    exit 1
else
    echo "$MES2"
    wget -nv "${BL_URL}"
    if [ "$?" != "0" ]
    then
        echo "$MES3"
        echo "$MES4"
        exit 1
    else
        echo "$MES5"

        echo "$MES6 ${BL_TAR_BASE}"
        "${UNCOMP_CMD}" "${UNCOMP_CMD_PARAMS}" "${BL_TAR_BASE}"

        if [ "$?" != "0" ]
        then
            echo "$MES7"
            echo "$MES4"
            exit 1
	else
	    #Remove symlinks and pdf
            rm -f "${UNTAR_DIR}"/ads
            rm -f "${UNTAR_DIR}"/aggressive
            rm -f "${UNTAR_DIR}"/drugs
            rm -f "${UNTAR_DIR}"/mail
            rm -f "${UNTAR_DIR}"/porn
            rm -f "${UNTAR_DIR}"/proxy
            rm -f "${UNTAR_DIR}"/violence
            rm -f "${UNTAR_DIR}"/*.pdf
            echo "$MES8"
            for i in "${UNTAR_DIR}"/*
            do
                export ib="`basename ${i}`"
                if [ -d "${DB_PATH}/${ib}" ]
                then
                    rm -rf "${DB_PATH}/${ib}"
                fi

                mv "${UNTAR_DIR}/${ib}" "${DB_PATH}"

            done

	    echo "$MES9"
	    rm -rf ${TMP_DIR}

            echo "$MES10"
            chown -R "${SG_UGID}" "${DB_PATH}"
            chmod -R 755 "${DB_PATH}"

            echo "$MES11"
            service dansguardian restart

	    # Output a quick end message.
	    echo "$MES12 `date '+%Y/%m/%d %T'`"
	    echo "==="

            exit $?
            ####
            #### If everything went well, we exited here.
            ####
        fi
    fi
fi