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