Line 1... |
Line 1... |
1 |
#/bin/bash
|
1 |
#/bin/bash
|
2 |
|
2 |
|
3 |
# $Id: alcasar-bl.sh 1332 2014-04-23 12:40:53Z richard $
|
3 |
# $Id: alcasar-bl.sh 1339 2014-05-05 12:55:57Z richard $
|
4 |
|
4 |
|
5 |
# alcasar-bl.sh
|
5 |
# alcasar-bl.sh
|
6 |
# by Franck BOUIJOUX and Richard REY
|
6 |
# by Franck BOUIJOUX and Richard REY
|
7 |
# This script is distributed under the Gnu General Public License (GPL)
|
7 |
# This script is distributed under the Gnu General Public License (GPL)
|
8 |
|
8 |
|
Line 34... |
Line 34... |
34 |
BL_SERVER="dsi.ut-capitole.fr"
|
34 |
BL_SERVER="dsi.ut-capitole.fr"
|
35 |
SED="/bin/sed -i"
|
35 |
SED="/bin/sed -i"
|
36 |
|
36 |
|
37 |
# enable/disable the BL & WL categories
|
37 |
# enable/disable the BL & WL categories
|
38 |
function cat_choice (){
|
38 |
function cat_choice (){
|
- |
|
39 |
# saving ip files and ossi category
|
- |
|
40 |
mkdir $DIR_tmp
|
- |
|
41 |
cp $DIR_IP_BL_ENABLED/ossi-* $DIR_tmp
|
- |
|
42 |
cp $DIR_IP_BL/ossi $DIR_tmp
|
39 |
rm -rf $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED # cleaning for dnsmasq and iptables
|
43 |
rm -rf $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED # cleaning for dnsmasq and iptables
|
40 |
$SED "/\.Include/d" $DIR_DG/bannedsitelist $DIR_DG/bannedurllist # cleaning for DG
|
44 |
$SED "/\.Include/d" $DIR_DG/bannedsitelist $DIR_DG/bannedurllist # cleaning for DG
|
41 |
$SED "s?^[^#]?#&?g" $BL_CATEGORIES $WL_CATEGORIES # cleaning BL & WL categories file (comment all lines)
|
45 |
$SED "s?^[^#]?#&?g" $BL_CATEGORIES $WL_CATEGORIES # cleaning BL & WL categories file (comment all lines)
|
42 |
mkdir $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED
|
46 |
mkdir $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED
|
- |
|
47 |
chown apache $DIR_IP_BL_ENABLED
|
43 |
# process the file $BL_CATEGORIES with the choice of categories
|
48 |
# process the file $BL_CATEGORIES with the choice of categories
|
44 |
for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED`
|
49 |
for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED`
|
45 |
do
|
50 |
do
|
46 |
$SED "/\/$ENABLE_CATEGORIE$/d" $BL_CATEGORIES
|
51 |
$SED "/\/$ENABLE_CATEGORIE$/d" $BL_CATEGORIES
|
47 |
$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $BL_CATEGORIES
|
52 |
$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $BL_CATEGORIES
|
Line 59... |
Line 64... |
59 |
$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $WL_CATEGORIES
|
64 |
$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $WL_CATEGORIES
|
60 |
ln -s $DIR_DNS_WL/$ENABLE_CATEGORIE.conf $DIR_DNS_WL_ENABLED/$ENABLE_CATEGORIE
|
65 |
ln -s $DIR_DNS_WL/$ENABLE_CATEGORIE.conf $DIR_DNS_WL_ENABLED/$ENABLE_CATEGORIE
|
61 |
done
|
66 |
done
|
62 |
sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
|
67 |
sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
|
63 |
mv $FILE_tmp $WL_CATEGORIES
|
68 |
mv $FILE_tmp $WL_CATEGORIES
|
- |
|
69 |
# restoring ip files and ossi category
|
- |
|
70 |
mv $DIR_tmp/ossi $DIR_IP_BL
|
- |
|
71 |
chown apache $DIR_IP_BL/ossi
|
- |
|
72 |
mv $DIR_tmp/ossi-* $DIR_IP_BL_ENABLED
|
- |
|
73 |
rm -rf $DIR_tmp
|
64 |
}
|
74 |
}
|
65 |
function bl_enable (){
|
75 |
function bl_enable (){
|
66 |
$SED "s/^reportinglevel =.*/reportinglevel = 3/g" /etc/dansguardian/dansguardian.conf
|
76 |
$SED "s/^reportinglevel =.*/reportinglevel = 3/g" /etc/dansguardian/dansguardian.conf
|
67 |
if [ "$PARENT_SCRIPT" != "alcasar-conf.sh" ] # don't launch on install stage
|
77 |
if [ "$PARENT_SCRIPT" != "alcasar-conf.sh" ] # don't launch on install stage
|
68 |
then
|
78 |
then
|
Line 132... |
Line 142... |
132 |
fi
|
142 |
fi
|
133 |
;;
|
143 |
;;
|
134 |
# Adapt Toulouse BL to ALCASAR architecture (dnsmasq + DG + iptables)
|
144 |
# Adapt Toulouse BL to ALCASAR architecture (dnsmasq + DG + iptables)
|
135 |
-adapt | --adapt)
|
145 |
-adapt | --adapt)
|
136 |
echo -n "Toulouse BlackList migration process. Please wait : "
|
146 |
echo -n "Toulouse BlackList migration process. Please wait : "
|
- |
|
147 |
# Saving ossi category
|
- |
|
148 |
cp $DIR_IP_BL/ossi $DIR_tmp
|
137 |
if [ -f $DIR_tmp/blacklists.tar.gz ]
|
149 |
if [ -f $DIR_tmp/blacklists.tar.gz ]
|
138 |
then
|
150 |
then
|
139 |
[ -d $DIR_DG_BL/ossi ] && mv -f $DIR_DG_BL/ossi $DIR_tmp
|
151 |
[ -d $DIR_DG_BL/ossi ] && mv -f $DIR_DG_BL/ossi $DIR_tmp
|
140 |
rm -rf $DIR_DG_BL
|
152 |
rm -rf $DIR_DG_BL
|
141 |
mkdir $DIR_DG_BL
|
153 |
mkdir $DIR_DG_BL
|
142 |
tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DG/
|
154 |
tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DG/
|
143 |
[ -d $DIR_tmp/ossi ] && mv -f $DIR_tmp/ossi $DIR_DG_BL/
|
155 |
[ -d $DIR_tmp/ossi ] && mv -f $DIR_tmp/ossi $DIR_DG_BL/
|
144 |
rm -rf $DIR_tmp
|
- |
|
145 |
fi
|
156 |
fi
|
146 |
rm -f $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
|
157 |
rm -f $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
|
147 |
rm -rf $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL
|
158 |
rm -rf $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL
|
148 |
touch $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
|
159 |
touch $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
|
149 |
mkdir $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL
|
160 |
mkdir $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL
|
Line 186... |
Line 197... |
186 |
chown dansguardian:apache $PATH_FILE/urls
|
197 |
chown dansguardian:apache $PATH_FILE/urls
|
187 |
fi
|
198 |
fi
|
188 |
$SED "s/\.\{2,10\}/\./g" $PATH_FILE/domains $PATH_FILE/urls # correct some syntax errors
|
199 |
$SED "s/\.\{2,10\}/\./g" $PATH_FILE/domains $PATH_FILE/urls # correct some syntax errors
|
189 |
|
200 |
|
190 |
# retrieve the ip addresses for iptables
|
201 |
# retrieve the ip addresses for iptables
|
191 |
# create an ipset save for the selected category
|
202 |
# create an set save for the selected category
|
192 |
awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/{print "add blacklist_ip_blocked " $0}' $PATH_FILE/domains > $FILE_ip_tmp
|
203 |
awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/{print "add blacklist_ip_blocked " $0}' $PATH_FILE/domains > $FILE_ip_tmp
|
193 |
|
204 |
|
194 |
# for dnsmask, remove IP addesses, accented characters and commented lines.
|
205 |
# for dnsmask, remove IP addesses, accented characters and commented lines.
|
195 |
egrep -v "^([0-9]{1,3}\.){3}[0-9]{1,3}$" $PATH_FILE/domains > $FILE_tmp
|
206 |
egrep -v "^([0-9]{1,3}\.){3}[0-9]{1,3}$" $PATH_FILE/domains > $FILE_tmp
|
196 |
$SED "/[äâëêïîöôüû]/d" $FILE_tmp
|
207 |
$SED "/[äâëêïîöôüû]/d" $FILE_tmp
|
Line 205... |
Line 216... |
205 |
mv $FILE_tmp $DIR_DNS_WL/$DOMAINE.conf
|
216 |
mv $FILE_tmp $DIR_DNS_WL/$DOMAINE.conf
|
206 |
fi
|
217 |
fi
|
207 |
done
|
218 |
done
|
208 |
done
|
219 |
done
|
209 |
rm -f $FILE_tmp $FILE_ip_tmp
|
220 |
rm -f $FILE_tmp $FILE_ip_tmp
|
- |
|
221 |
# Restoring ossi category
|
- |
|
222 |
mv $DIR_tmp/ossi $DIR_IP_BL
|
- |
|
223 |
rm -rf $DIR_tmp
|
210 |
echo
|
224 |
echo
|
211 |
;;
|
225 |
;;
|
212 |
# reload when categories are changed
|
226 |
# reload when categories are changed
|
213 |
-reload | --reload)
|
227 |
-reload | --reload)
|
214 |
# for DG
|
228 |
# for DG
|