Line 1... |
Line 1... |
1 |
#!/bin/bash
|
1 |
#!/bin/bash
|
2 |
|
2 |
|
3 |
# $Id: alcasar-bl.sh 2474 2017-12-30 02:00:04Z tom.houdayer $
|
3 |
# $Id: alcasar-bl.sh 2521 2018-04-02 19:46:16Z armand.ito $
|
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 |
|
9 |
# Gestion de la BL pour le filtrage de domaine (via dnsmasq) et d'URL (via Dansguardian)
|
9 |
# Gestion de la BL pour le filtrage de domaine (via dnsmasq) et d'URL (via E2guardian)
|
10 |
# Manage the BL for DnsBlackHole (dnsmasq) and URL filtering (Dansguardian)
|
10 |
# Manage the BL for DnsBlackHole (dnsmasq) and URL filtering (E2guardian)
|
11 |
|
11 |
|
12 |
DIR_CONF="/usr/local/etc"
|
12 |
DIR_CONF="/usr/local/etc"
|
13 |
CONF_FILE="$DIR_CONF/alcasar.conf"
|
13 |
CONF_FILE="$DIR_CONF/alcasar.conf"
|
14 |
private_ip_mask=`grep ^PRIVATE_IP= $CONF_FILE|cut -d"=" -f2`
|
14 |
private_ip_mask=`grep ^PRIVATE_IP= $CONF_FILE|cut -d"=" -f2`
|
15 |
private_ip_mask=${private_ip_mask:=192.168.182.1/24}
|
15 |
private_ip_mask=${private_ip_mask:=192.168.182.1/24}
|
16 |
PRIVATE_IP=`echo $private_ip_mask | cut -d"/" -f1` # ALCASAR LAN IP address
|
16 |
PRIVATE_IP=`echo $private_ip_mask | cut -d"/" -f1` # ALCASAR LAN IP address
|
17 |
DIR_tmp="/tmp/blacklists"
|
17 |
DIR_tmp="/tmp/blacklists"
|
18 |
DIR_WL_tmp="/tmp/whitelists"
|
18 |
DIR_WL_tmp="/tmp/whitelists"
|
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/e2guardian/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 categories
|
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
|
Line 63... |
Line 63... |
63 |
|
63 |
|
64 |
# process the file $BL_CATEGORIES with the choice of categories
|
64 |
# process the file $BL_CATEGORIES with the choice of categories
|
65 |
for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED`
|
65 |
for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED`
|
66 |
do
|
66 |
do
|
67 |
$SED "/\/$ENABLE_CATEGORIE$/d" $BL_CATEGORIES
|
67 |
$SED "/\/$ENABLE_CATEGORIE$/d" $BL_CATEGORIES
|
68 |
$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $BL_CATEGORIES
|
68 |
$SED "1i\/etc\/e2guardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $BL_CATEGORIES
|
69 |
ln -sf $DIR_DNS_BL/$ENABLE_CATEGORIE.conf $DIR_DNS_BL_ENABLED/$ENABLE_CATEGORIE
|
69 |
ln -sf $DIR_DNS_BL/$ENABLE_CATEGORIE.conf $DIR_DNS_BL_ENABLED/$ENABLE_CATEGORIE
|
70 |
ln -sf $DIR_IP_BL/$ENABLE_CATEGORIE $DIR_IP_BL_ENABLED/$ENABLE_CATEGORIE
|
70 |
ln -sf $DIR_IP_BL/$ENABLE_CATEGORIE $DIR_IP_BL_ENABLED/$ENABLE_CATEGORIE
|
71 |
# echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/domains>" >> $DIR_DG/bannedsitelist # Blacklisted domains are managed by dnsmasq
|
71 |
# echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/domains>" >> $DIR_DG/bannedsitelist # Blacklisted domains are managed by dnsmasq
|
72 |
echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/urls>" >> $DIR_DG/bannedurllist
|
72 |
echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/urls>" >> $DIR_DG/bannedurllist
|
73 |
done
|
73 |
done
|
Line 80... |
Line 80... |
80 |
|
80 |
|
81 |
# process the file $WL_CATEGORIES with the choice of categories
|
81 |
# process the file $WL_CATEGORIES with the choice of categories
|
82 |
for ENABLE_CATEGORIE in `cat $WL_CATEGORIES_ENABLED`
|
82 |
for ENABLE_CATEGORIE in `cat $WL_CATEGORIES_ENABLED`
|
83 |
do
|
83 |
do
|
84 |
$SED "/\/$ENABLE_CATEGORIE$/d" $WL_CATEGORIES
|
84 |
$SED "/\/$ENABLE_CATEGORIE$/d" $WL_CATEGORIES
|
85 |
$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $WL_CATEGORIES
|
85 |
$SED "1i\/etc\/e2guardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $WL_CATEGORIES
|
86 |
ln -sf $DIR_DNS_WL/$ENABLE_CATEGORIE.conf $DIR_DNS_WL_ENABLED/$ENABLE_CATEGORIE
|
86 |
ln -sf $DIR_DNS_WL/$ENABLE_CATEGORIE.conf $DIR_DNS_WL_ENABLED/$ENABLE_CATEGORIE
|
87 |
done
|
87 |
done
|
88 |
sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
|
88 |
sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
|
89 |
mv $FILE_tmp $WL_CATEGORIES
|
89 |
mv $FILE_tmp $WL_CATEGORIES
|
90 |
sort +0.0 -0.2 $WL_CATEGORIES_ENABLED -o $FILE_tmp
|
90 |
sort +0.0 -0.2 $WL_CATEGORIES_ENABLED -o $FILE_tmp
|
Line 152... |
Line 152... |
152 |
mv $DIR_DG_BL/$x $DIR_tmp
|
152 |
mv $DIR_DG_BL/$x $DIR_tmp
|
153 |
done
|
153 |
done
|
154 |
rm -rf $DIR_DG_BL $DIR_IP_BL
|
154 |
rm -rf $DIR_DG_BL $DIR_IP_BL
|
155 |
mkdir $DIR_DG_BL $DIR_IP_BL
|
155 |
mkdir $DIR_DG_BL $DIR_IP_BL
|
156 |
tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DG/
|
156 |
tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DG/
|
157 |
chown -R dansguardian:apache $DIR_DG
|
157 |
chown -R e2guardian:apache $DIR_DG
|
158 |
chmod -R 770 $DIR_DG
|
158 |
chmod -R 770 $DIR_DG
|
159 |
# Add the two local categories (ossi-bl & ossi-wl) to the usage file
|
159 |
# Add the two local categories (ossi-bl & ossi-wl) to the usage file
|
160 |
# Add the custom categories (ossi-tor_nodes) to the usage file
|
160 |
# Add the custom categories (ossi-tor_nodes) to the usage file
|
161 |
cat <<EOF >> $DIR_DG_BL/global_usage
|
161 |
cat <<EOF >> $DIR_DG_BL/global_usage
|
162 |
|
162 |
|
Line 236... |
Line 236... |
236 |
DOMAIN=`basename $PATH_FILE`
|
236 |
DOMAIN=`basename $PATH_FILE`
|
237 |
echo -n "$DOMAIN, "
|
237 |
echo -n "$DOMAIN, "
|
238 |
if [ ! -f $PATH_FILE/urls ] # create 'urls' file if it doesn't exist
|
238 |
if [ ! -f $PATH_FILE/urls ] # create 'urls' file if it doesn't exist
|
239 |
then
|
239 |
then
|
240 |
touch $PATH_FILE/urls
|
240 |
touch $PATH_FILE/urls
|
241 |
chown dansguardian:apache $PATH_FILE/urls
|
241 |
chown e2guardian:apache $PATH_FILE/urls
|
242 |
fi
|
242 |
fi
|
243 |
cp $PATH_FILE/domains $FILE_tmp
|
243 |
cp $PATH_FILE/domains $FILE_tmp
|
244 |
clean_split # clean ossi custom files & split them for dnsmasq and for iptables
|
244 |
clean_split # clean ossi custom files & split them for dnsmasq and for iptables
|
245 |
if [ "$LIST" == "$BL_CATEGORIES" ]
|
245 |
if [ "$LIST" == "$BL_CATEGORIES" ]
|
246 |
then
|
246 |
then
|
Line 292... |
Line 292... |
292 |
fi
|
292 |
fi
|
293 |
rm -f $FILE_tmp $FILE_ip_tmp
|
293 |
rm -f $FILE_tmp $FILE_ip_tmp
|
294 |
done
|
294 |
done
|
295 |
/usr/bin/systemctl restart dnsmasq-whitelist
|
295 |
/usr/bin/systemctl restart dnsmasq-whitelist
|
296 |
/usr/bin/systemctl restart dnsmasq-blacklist
|
296 |
/usr/bin/systemctl restart dnsmasq-blacklist
|
297 |
/usr/bin/systemctl restart dansguardian
|
297 |
/usr/bin/systemctl restart e2guardian
|
298 |
/usr/local/bin/alcasar-iptables.sh
|
298 |
/usr/local/bin/alcasar-iptables.sh
|
299 |
else
|
299 |
else
|
300 |
echo -n "/usr/local/etc/update_cat.conf is empty ..."
|
300 |
echo -n "/usr/local/etc/update_cat.conf is empty ..."
|
301 |
fi
|
301 |
fi
|
302 |
echo
|
302 |
echo
|
Line 348... |
Line 348... |
348 |
mv $FILE_ip_tmp $DIR_IP_WL/$ossi_categorie
|
348 |
mv $FILE_ip_tmp $DIR_IP_WL/$ossi_categorie
|
349 |
enabled=`grep ^$ossi_categorie$ $WL_CATEGORIES_ENABLED | wc -l`
|
349 |
enabled=`grep ^$ossi_categorie$ $WL_CATEGORIES_ENABLED | wc -l`
|
350 |
if [ $enabled == "1" ]
|
350 |
if [ $enabled == "1" ]
|
351 |
then
|
351 |
then
|
352 |
$SED "/\/$ossi_categorie$/d" $WL_CATEGORIES
|
352 |
$SED "/\/$ossi_categorie$/d" $WL_CATEGORIES
|
353 |
$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ossi_categorie" $WL_CATEGORIES
|
353 |
$SED "1i\/etc\/e2guardian\/lists\/blacklists\/$ossi_categorie" $WL_CATEGORIES
|
354 |
ln -sf $DIR_DNS_WL/$ossi_categorie.conf $DIR_DNS_WL_ENABLED/$ossi_categorie
|
354 |
ln -sf $DIR_DNS_WL/$ossi_categorie.conf $DIR_DNS_WL_ENABLED/$ossi_categorie
|
355 |
ln -sf $DIR_IP_WL/$ossi_categorie $DIR_IP_WL_ENABLED/$ossi_categorie
|
355 |
ln -sf $DIR_IP_WL/$ossi_categorie $DIR_IP_WL_ENABLED/$ossi_categorie
|
356 |
fi
|
356 |
fi
|
357 |
else
|
357 |
else
|
358 |
# for the BL
|
358 |
# for the BL
|
Line 361... |
Line 361... |
361 |
mv $FILE_ip_tmp $DIR_IP_BL/$ossi_categorie
|
361 |
mv $FILE_ip_tmp $DIR_IP_BL/$ossi_categorie
|
362 |
enabled=`grep ^$ossi_categorie$ $BL_CATEGORIES_ENABLED | wc -l`
|
362 |
enabled=`grep ^$ossi_categorie$ $BL_CATEGORIES_ENABLED | wc -l`
|
363 |
if [ $enabled == "1" ]
|
363 |
if [ $enabled == "1" ]
|
364 |
then
|
364 |
then
|
365 |
$SED "/\/$ossi_categorie$/d" $BL_CATEGORIES
|
365 |
$SED "/\/$ossi_categorie$/d" $BL_CATEGORIES
|
366 |
$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ossi_categorie" $BL_CATEGORIES
|
366 |
$SED "1i\/etc\/e2guardian\/lists\/blacklists\/$ossi_categorie" $BL_CATEGORIES
|
367 |
ln -sf $DIR_DNS_BL/$ossi_categorie.conf $DIR_DNS_BL_ENABLED/$ossi_categorie
|
367 |
ln -sf $DIR_DNS_BL/$ossi_categorie.conf $DIR_DNS_BL_ENABLED/$ossi_categorie
|
368 |
ln -sf $DIR_IP_BL/$ossi_categorie $DIR_IP_BL_ENABLED/$ossi_categorie
|
368 |
ln -sf $DIR_IP_BL/$ossi_categorie $DIR_IP_BL_ENABLED/$ossi_categorie
|
369 |
fi
|
369 |
fi
|
370 |
fi
|
370 |
fi
|
371 |
done
|
371 |
done
|