Line 1... |
Line 1... |
1 |
#/bin/bash
|
1 |
#/bin/bash
|
2 |
|
2 |
|
3 |
# $Id: alcasar-bl.sh 1925 2016-06-04 18:38:51Z richard $
|
3 |
# $Id: alcasar-bl.sh 1926 2016-06-05 20:34:25Z 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 19... |
Line 19... |
19 |
FILE_tmp="/tmp/filesfilter.txt"
|
19 |
FILE_tmp="/tmp/filesfilter.txt"
|
20 |
FILE_ip_tmp="/tmp/filesipfilter.txt"
|
20 |
FILE_ip_tmp="/tmp/filesipfilter.txt"
|
21 |
DIR_DG="/etc/dansguardian/lists"
|
21 |
DIR_DG="/etc/dansguardian/lists"
|
22 |
DIR_DG_BL="$DIR_DG/blacklists"
|
22 |
DIR_DG_BL="$DIR_DG/blacklists"
|
23 |
BL_CATEGORIES="$DIR_CONF/alcasar-bl-categories" # list of names of the BL categories
|
23 |
BL_CATEGORIES="$DIR_CONF/alcasar-bl-categories" # list of names of the BL categories
|
24 |
WL_CATEGORIES="$DIR_CONF/alcasar-wl-categories" #' ' WL '
|
24 |
WL_CATEGORIES="$DIR_CONF/alcasar-wl-categories" # ' ' WL categories
|
25 |
BL_CATEGORIES_ENABLED="$DIR_CONF/alcasar-bl-categories-enabled" # ' ' BL enabled categories
|
25 |
BL_CATEGORIES_ENABLED="$DIR_CONF/alcasar-bl-categories-enabled" # ' ' BL enabled categories
|
26 |
WL_CATEGORIES_ENABLED="$DIR_CONF/alcasar-wl-categories-enabled" # ' ' WL enabled categories
|
26 |
WL_CATEGORIES_ENABLED="$DIR_CONF/alcasar-wl-categories-enabled" # ' ' WL enabled categories
|
27 |
DIR_SHARE="/usr/local/share"
|
27 |
DIR_SHARE="/usr/local/share"
|
28 |
DIR_DNS_BL="$DIR_SHARE/dnsmasq-bl" # all the BL in the DNSMASQ format
|
28 |
DIR_DNS_BL="$DIR_SHARE/dnsmasq-bl" # all the BL in the DNSMASQ format
|
29 |
DIR_DNS_WL="$DIR_SHARE/dnsmasq-wl" # all the WL ' ' '
|
29 |
DIR_DNS_WL="$DIR_SHARE/dnsmasq-wl" # all the WL ' ' '
|
Line 204... |
Line 204... |
204 |
# Retrieve custom files (ossi)
|
204 |
# Retrieve custom files (ossi)
|
205 |
for x in $(ls -1 $DIR_tmp | grep "^ossi-*")
|
205 |
for x in $(ls -1 $DIR_tmp | grep "^ossi-*")
|
206 |
do
|
206 |
do
|
207 |
mv $DIR_tmp/$x $DIR_DG_BL
|
207 |
mv $DIR_tmp/$x $DIR_DG_BL
|
208 |
done
|
208 |
done
|
209 |
|
- |
|
210 |
rm -f $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
|
209 |
rm -f $BL_CATEGORIES $WL_CATEGORIES
|
211 |
rm -rf $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
|
210 |
rm -rf $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
|
212 |
touch $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
|
211 |
touch $BL_CATEGORIES $WL_CATEGORIES
|
213 |
mkdir $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
|
212 |
mkdir $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
|
214 |
chown -R dansguardian:apache $DIR_DG $BL_CATEGORIES $WL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES_ENABLED $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
|
213 |
chown -R dansguardian:apache $DIR_DG $BL_CATEGORIES $WL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES_ENABLED $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
|
215 |
chmod -R g+w $DIR_DG $BL_CATEGORIES $WL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES_ENABLED $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
|
214 |
chmod -R g+w $DIR_DG $BL_CATEGORIES $WL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES_ENABLED $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
|
216 |
find $DIR_DG_BL/ -type f -name domains > $FILE_tmp # retrieve directory name where a domain file exist
|
215 |
find $DIR_DG_BL/ -type f -name domains > $FILE_tmp # retrieve directory name where a domain file exist
|
217 |
$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
|
216 |
$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
|
Line 220... |
Line 219... |
220 |
categorie=`echo $dir_categorie|cut -d "/" -f6`
|
219 |
categorie=`echo $dir_categorie|cut -d "/" -f6`
|
221 |
categorie_type=`grep -A1 ^NAME:[$' '$'\t']*$categorie $DIR_DG_BL/global_usage | grep ^DEFAULT_TYPE | cut -d":" -f2 | tr -d " \t"`
|
220 |
categorie_type=`grep -A1 ^NAME:[$' '$'\t']*$categorie $DIR_DG_BL/global_usage | grep ^DEFAULT_TYPE | cut -d":" -f2 | tr -d " \t"`
|
222 |
if [ "$categorie_type" == "white" ]
|
221 |
if [ "$categorie_type" == "white" ]
|
223 |
then
|
222 |
then
|
224 |
echo "$dir_categorie" >> $WL_CATEGORIES
|
223 |
echo "$dir_categorie" >> $WL_CATEGORIES
|
225 |
echo `basename $dir_categorie` >> $WL_CATEGORIES_ENABLED # by default all WL are enabled
|
- |
|
226 |
fi
|
224 |
fi
|
227 |
echo "$dir_categorie" >> $BL_CATEGORIES # By default all categories are in BL
|
225 |
echo "$dir_categorie" >> $BL_CATEGORIES
|
228 |
done
|
226 |
done
|
229 |
rm -f $FILE_tmp
|
227 |
rm -f $FILE_tmp
|
230 |
# Verify that the enabled categories are effectively in the BL (need after an update of the BL)
|
228 |
# Verify that the enabled categories are effectively in the BL (need after an update of the BL)
|
231 |
for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED`
|
229 |
for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED`
|
232 |
do
|
230 |
do
|
Line 234... |
Line 232... |
234 |
if [ $ok != "1" ]
|
232 |
if [ $ok != "1" ]
|
235 |
then
|
233 |
then
|
236 |
$SED "/^$ENABLE_CATEGORIE$/d" $BL_CATEGORIES_ENABLED
|
234 |
$SED "/^$ENABLE_CATEGORIE$/d" $BL_CATEGORIES_ENABLED
|
237 |
fi
|
235 |
fi
|
238 |
done
|
236 |
done
|
- |
|
237 |
# Verify that the enabled categories are effectively in the WL (need after an update of the WL)
|
- |
|
238 |
for ENABLE_CATEGORIE in `cat $WL_CATEGORIES_ENABLED`
|
- |
|
239 |
do
|
- |
|
240 |
ok=`grep /$ENABLE_CATEGORIE$ $WL_CATEGORIES|wc -l`
|
- |
|
241 |
if [ $ok != "1" ]
|
- |
|
242 |
then
|
- |
|
243 |
$SED "/^$ENABLE_CATEGORIE$/d" $WL_CATEGORIES_ENABLED
|
- |
|
244 |
fi
|
- |
|
245 |
done
|
239 |
# Creation of DNSMASQ and Iptables BL and WL
|
246 |
# Creation of DNSMASQ and Iptables BL and WL
|
240 |
for LIST in $BL_CATEGORIES $WL_CATEGORIES # for each list (bl and wl)
|
247 |
for LIST in $BL_CATEGORIES $WL_CATEGORIES # for each list (bl and wl)
|
241 |
do
|
248 |
do
|
242 |
for PATH_FILE in `cat $LIST` # for each category
|
249 |
for PATH_FILE in `cat $LIST` # for each category
|
243 |
do
|
250 |
do
|
Line 267... |
Line 274... |
267 |
mv $FILE_tmp $DIR_DNS_WL/$DOMAINE.conf
|
274 |
mv $FILE_tmp $DIR_DNS_WL/$DOMAINE.conf
|
268 |
fi
|
275 |
fi
|
269 |
done
|
276 |
done
|
270 |
done
|
277 |
done
|
271 |
rm -f $FILE_tmp $FILE_ip_tmp
|
278 |
rm -f $FILE_tmp $FILE_ip_tmp
|
272 |
# Restoring custom files (ossi)
|
- |
|
273 |
rm -rf $DIR_tmp
|
279 |
rm -rf $DIR_tmp
|
274 |
if [ -d $tmp_DIR_IP_BL -a -d $tmp_DIR_IP_WL -a -d $tmp_DIR_DNS_BL -a -d $tmp_DIR_DNS_WL ]
|
- |
|
275 |
then
|
- |
|
276 |
for x in $(ls -1 $tmp_DIR_IP_BL | grep "^ossi*")
|
- |
|
277 |
do
|
- |
|
278 |
mv $tmp_DIR_IP_BL/$x $DIR_IP_BL
|
- |
|
279 |
done
|
- |
|
280 |
for x in $(ls -1 $tmp_DIR_IP_WL | grep "^ossi*")
|
- |
|
281 |
do
|
- |
|
282 |
mv $tmp_DIR_IP_WL/$x $DIR_IP_WL
|
- |
|
283 |
done
|
- |
|
284 |
for x in $(ls -1 $tmp_DIR_DNS_BL | grep "^ossi*")
|
- |
|
285 |
do
|
- |
|
286 |
mv $tmp_DIR_DNS_BL/$x $DIR_DNS_BL
|
- |
|
287 |
done
|
- |
|
288 |
for x in $(ls -1 $tmp_DIR_DNS_WL | grep "^ossi*")
|
- |
|
289 |
do
|
- |
|
290 |
mv $tmp_DIR_DNS_WL/$x $DIR_DNS_WL
|
- |
|
291 |
done
|
- |
|
292 |
rm -rf $tmp_DIR_IP_BL $tmp_DIR_IP_WL $tmp_DIR_DNS_BL $tmp_DIR_DNS_WL
|
- |
|
293 |
fi
|
- |
|
294 |
echo
|
- |
|
295 |
;;
|
280 |
;;
|
296 |
# update the categories which are written in "/usr/local/etc/update_cat.conf" with rsync
|
281 |
# update the categories which are written in "/usr/local/etc/update_cat.conf" with rsync
|
297 |
-update_cat | --update_cat)
|
282 |
-update_cat | --update_cat)
|
298 |
if [ $(cat /usr/local/etc/update_cat.conf | wc -l) -ne 0 ]
|
283 |
if [ $(cat /usr/local/etc/update_cat.conf | wc -l) -ne 0 ]
|
299 |
then
|
284 |
then
|