Subversion Repositories ALCASAR

Rev

Rev 309 | Rev 313 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
1 root 1
#/bin/sh
63 franck 2
# $Id: alcasar-bl.sh 311 2010-11-07 22:31:52Z richard $
3
 
308 richard 4
# Script de gestion de la BL pour le filtrage de domaine (via dnsmasq) et d'URL (via dansguardian)
5
# By 3abtux & rexy
1 root 6
 
308 richard 7
DIR_tmp="/tmp/blacklists"
8
FILE_tmp="/tmp/fileFilter.txt"
311 richard 9
DIR_DANSGUARDIAN="/etc/dansguardian/lists"
10
BL_CATEGORIES_AVAILABLE="/usr/local/etc/alcasar-bl-categories-available"
11
BL_CATEGORIES_DEFAULT="/usr/local/etc/alcasar-bl-categories-default"
308 richard 12
DIR_DNS_FILTER_AVAILABLE="/usr/local/etc/alcasar-dnsfilter-available"
309 richard 13
DIR_DNS_FILTER_ENABLED="/usr/local/etc/alcasar-dnsfilter-enabled"
14
IP_RETOUR="192.168.182.1"
1 root 15
BL_SERVER="cri.univ-tlse1.fr"
16
SED="/bin/sed -i"
308 richard 17
# Récupération de l'archive de la BL Toulouse
1 root 18
function transfert () {
19
	mkdir -p $DIR_tmp
20
	cd $DIR_tmp
21
	wget http://$BL_SERVER/blacklists/download/blacklists.tar.gz
22
}
23
 
308 richard 24
# Décompression de la BL (en conservant la WL)
1 root 25
function install () {
26
	[ -d $DIR_DANSGUARDIAN ] || mkdir -p $DIR_DANSGUARDIAN
27
	[ -d $DIR_DANSGUARDIAN/blacklists/ossi ] && mv -f $DIR_DANSGUARDIAN/blacklists/ossi $DIR_tmp
311 richard 28
	tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DANSGUARDIAN/
1 root 29
	[ -d $DIR_tmp/ossi ] && mv -f $DIR_tmp/ossi $DIR_DANSGUARDIAN/blacklists/
30
	cd /root
31
	rm -rf $DIR_tmp
32
}
33
 
308 richard 34
# Adaptation de la BL Toulouse à la structure Dnsmasq
35
function adapt () {
311 richard 36
	# On récupère le nom des répertoire (catégories)
37
	find $DIR_DANSGUARDIAN -type f -name domains > $BL_CATEGORIES_AVAILABLE
38
	# On supprime le suffice "/domains"
39
	$SED "s?\/domains??g" $BL_CATEGORIES_AVAILABLE
40
	rm -f $DIR_DNS_FILTER_AVAILABLE/*
41
	echo -n "Adaptation de la BL Toulouse. Veuillez patienter : "
42
	# On copie les fichiers de domaine pour chaque catégorie
43
	for PATH_FILE in `cat $BL_CATEGORIES_AVAILABLE`
44
	do
45
        	DOMAINE=`basename $PATH_FILE`
46
		echo -n "."
47
		# suppression des @IP, des lignes commentées et des caractères bizarres comme les ô et û ö ü
48
		egrep  -v "([0-9]{1,3}\.){3}[0-9]{1,3}" $PATH_FILE/domains > /tmp/dnsmasq-bl.tmp
49
		$SED "/[äâëêïîöôüû]/d" /tmp/dnsmasq-bl.tmp
50
		$SED "/^#.*/d" /tmp/dnsmasq-bl.tmp
51
		# Mise en forme dnsmasq
52
		$SED "s?.*?address=/&/$IP_RETOUR?g" /tmp/dnsmasq-bl.tmp
53
		mv /tmp/dnsmasq-bl.tmp $DIR_DNS_FILTER_AVAILABLE/$DOMAINE.conf
54
	done
55
	# on adapte le fichier $BL_CATEGORIES_AVAILABLE au choix de catégorie par défaut
56
	$SED "s?^[^#]?#&?g" $BL_CATEGORIES_AVAILABLE # on commente ce qui ne l'est pas
57
	for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_DEFAULT`
58
	do
59
		$SED "/^.*$ENABLE_CATEGORIE/d" $BL_CATEGORIES_AVAILABLE
60
		$SED "1i\/etc\/dansguardian\/lists\/blacklist\/$ENABLE_CATEGORIE" $BL_CATEGORIES_AVAILABLE
61
	done
62
	echo
308 richard 63
}
64
 
65
# Permet d'activer/désactiver les catégories de la BL
66
function cat_choice (){
311 richard 67
	# un peu de ménage
68
	rm -rf $DIR_DNS_FILTER_ENABLED/*
69
	$SED "/\.Include/d" $DIR_DANSGUARDIAN/bannedsitelist $DIR_DANSGUARDIAN/bannedurllist
70
	# on affecte les catégories
71
	for i in `cat $BL_CATEGORIES_DEFAULT`
72
		do
73
		ln -s $DIR_DNS_FILTER_AVAILABLE/$i.conf $DIR_DNS_FILTER_ENABLED/$i
74
		# echo ".Include<$DIR_DANSGUARDIAN/blacklists/$i/domains>" >> $DIR_DANSGUARDIAN/bannedsitelist
75
		echo ".Include<$DIR_DANSGUARDIAN/blacklists/$i/urls>" >> $DIR_DANSGUARDIAN/bannedurllist
76
		done
308 richard 77
}
1 root 78
usage="Usage: alcasar-bl.sh -on | -off | -download| -reload"
79
nb_args=$#
80
args=$1
81
if [ $nb_args -eq 0 ]
82
then
83
	nb_args=1
84
	args="-h"
85
fi
86
case $args in
87
	-\? | -h* | --h*)
88
		echo "$usage"
89
		exit 0
90
		;;
308 richard 91
	# activation du filtrage
1 root 92
	-on)	
311 richard 93
		cat_choice
1 root 94
		$SED "s/^reportinglevel =.*/reportinglevel = 3/g" /etc/dansguardian/dansguardian.conf
311 richard 95
		service dansguardian restart
260 richard 96
		service dnsmasq restart
1 root 97
		;;
308 richard 98
	# désactivation du filtrage
1 root 99
	-off)
311 richard 100
		rm -rf $DIR_DNS_FILTER_ENABLED/*
1 root 101
		$SED "s/^reportinglevel =.*/reportinglevel = -1/g" /etc/dansguardian/dansguardian.conf
102
		service dansguardian reload
260 richard 103
		service dnsmasq restart
1 root 104
		;;
308 richard 105
	# Mise a jour de la blacklist 'Toulouse' et adaptation à dansguardian et dnsmasq
1 root 106
	-download)
107
		rm -rf /tmp/con_ok.html
108
		`/usr/bin/curl $BL_SERVER -# -o /tmp/con_ok.html`
109
		if [ ! -e /tmp/con_ok.html ]
110
		then
111
			echo "Erreur : le serveur de blacklist ($BL_SERVER) n'est pas joignable"
112
		else 
113
			transfert
114
			install
115
			chown -R dansguardian:apache $DIR_DANSGUARDIAN
116
			chmod -R g+w $DIR_DANSGUARDIAN
117
			DATE=`date '+%d %B %Y - %Hh%M'`
34 richard 118
			echo "Univ-tlse du $DATE " > /var/www/html/VERSION-BL
1 root 119
			rm -rf /tmp/con_ok.html
120
		fi
308 richard 121
		adapt
1 root 122
		;;		
311 richard 123
	# regénération suite à modification de la BL secondaire
1 root 124
	-reload)
308 richard 125
		# pour Dansguardian
1 root 126
		chown -R dansguardian:apache $DIR_DANSGUARDIAN/blacklists/ossi
127
		chmod -R g+w $DIR_DANSGUARDIAN/blacklists/ossi
311 richard 128
		cat_choice
1 root 129
		service dansguardian reload
311 richard 130
		# pour dnsmasq (noms de domaine réhabilités)
131
		if [ `wc -w $DIR_DANSGUARDIAN/exceptionsitelist|cut -d " " -f1` != "0" ]
132
		then
133
			for i in `cat $DIR_DANSGUARDIAN/exceptionsitelist`
134
			do
135
				$SED "/$i/d" $DIR_DNS_FILTER_AVAILABLE/sect.conf
136
			done
137
		fi
308 richard 138
		$SED "s?.*?address=/&/$IP_RETOUR?g" $DIR_DNS_FILTER_AVAILABLE/ossi.conf
139
		service dnsmasq reload
140
;;
1 root 141
	*)
142
		echo "Argument inconnu :$1";
143
		echo "$usage"
144
		exit 1
145
		;;
146
esac
147