1 |
#/bin/bash
|
1 |
#/bin/bash
|
2 |
|
2 |
|
3 |
# $Id: alcasar-bl.sh 1071 2013-04-14 19:58:17Z richard $
|
3 |
# $Id: alcasar-bl.sh 1293 2014-01-12 21:08:59Z 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 |
|
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 Dansguardian)
|
10 |
# Manage the BL for DnsBlackHole (dnsmasq) and URL filtering (Dansguardian)
|
10 |
# Manage the BL for DnsBlackHole (dnsmasq) and URL filtering (Dansguardian)
|
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 |
FILE_tmp="/tmp/filesfilter.txt"
|
18 |
FILE_tmp="/tmp/filesfilter.txt"
|
19 |
FILE_ip_tmp="/tmp/filesipfilter.txt"
|
19 |
FILE_ip_tmp="/tmp/filesipfilter.txt"
|
20 |
DIR_DG="/etc/dansguardian/lists"
|
20 |
DIR_DG="/etc/dansguardian/lists"
|
21 |
DIR_DG_BL="$DIR_DG/blacklists"
|
21 |
DIR_DG_BL="$DIR_DG/blacklists"
|
22 |
BL_CATEGORIES="$DIR_CONF/alcasar-bl-categories" # list of names of the BL categories
|
22 |
BL_CATEGORIES="$DIR_CONF/alcasar-bl-categories" # list of names of the BL categories
|
23 |
WL_CATEGORIES="$DIR_CONF/alcasar-wl-categories" #' ' WL '
|
23 |
WL_CATEGORIES="$DIR_CONF/alcasar-wl-categories" #' ' WL '
|
24 |
BL_CATEGORIES_ENABLED="$DIR_CONF/alcasar-bl-categories-enabled" # ' ' BL enabled categories
|
24 |
BL_CATEGORIES_ENABLED="$DIR_CONF/alcasar-bl-categories-enabled" # ' ' BL enabled categories
|
25 |
WL_CATEGORIES_ENABLED="$DIR_CONF/alcasar-wl-categories-enabled" # ' ' WL enabled categories
|
25 |
WL_CATEGORIES_ENABLED="$DIR_CONF/alcasar-wl-categories-enabled" # ' ' WL enabled categories
|
26 |
DIR_SHARE="/usr/local/share"
|
26 |
DIR_SHARE="/usr/local/share"
|
27 |
DIR_DNS_BL="$DIR_SHARE/dnsmasq-bl" # all the BL in the DNSMASQ format
|
27 |
DIR_DNS_BL="$DIR_SHARE/dnsmasq-bl" # all the BL in the DNSMASQ format
|
28 |
DIR_DNS_WL="$DIR_SHARE/dnsmasq-wl" # all the WL ' ' '
|
28 |
DIR_DNS_WL="$DIR_SHARE/dnsmasq-wl" # all the WL ' ' '
|
29 |
DIR_IP_BL="$DIR_SHARE/iptables-bl" # all the IP addresses of the BL
|
29 |
DIR_IP_BL="$DIR_SHARE/iptables-bl" # all the IP addresses of the BL
|
30 |
DIR_DNS_BL_ENABLED="$DIR_SHARE/dnsmasq-bl-enabled" # symbolic link to the dnsmasq BL (only enabled categories)
|
30 |
DIR_DNS_BL_ENABLED="$DIR_SHARE/dnsmasq-bl-enabled" # symbolic link to the dnsmasq BL (only enabled categories)
|
31 |
DIR_DNS_WL_ENABLED="$DIR_SHARE/dnsmasq-wl-enabled" # ' ' ' WL ' ' '
|
31 |
DIR_DNS_WL_ENABLED="$DIR_SHARE/dnsmasq-wl-enabled" # ' ' ' WL ' ' '
|
32 |
DIR_IP_BL_ENABLED="$DIR_SHARE/iptables-bl-enabled" # ' ' ip BL (only enabled categories)
|
32 |
DIR_IP_BL_ENABLED="$DIR_SHARE/iptables-bl-enabled" # ' ' ip BL (only enabled categories)
|
33 |
DNSMASQ_BL_CONF="/etc/dnsmasq-blackhole.conf" # conf file of dnsmasq-blackhole
|
33 |
DNSMASQ_BL_CONF="/etc/dnsmasq-blackhole.conf" # conf file of dnsmasq-blackhole
|
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 |
rm -rf $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED # cleaning for dnsmasq and iptables
|
39 |
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
|
40 |
$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)
|
41 |
$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
|
42 |
mkdir $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED
|
43 |
# process the file $BL_CATEGORIES with the choice of categories
|
43 |
# process the file $BL_CATEGORIES with the choice of categories
|
44 |
for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED`
|
44 |
for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED`
|
45 |
do
|
45 |
do
|
46 |
$SED "/\/$ENABLE_CATEGORIE$/d" $BL_CATEGORIES
|
46 |
$SED "/\/$ENABLE_CATEGORIE$/d" $BL_CATEGORIES
|
47 |
$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $BL_CATEGORIES
|
47 |
$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $BL_CATEGORIES
|
48 |
ln -s $DIR_DNS_BL/$ENABLE_CATEGORIE.conf $DIR_DNS_BL_ENABLED/$ENABLE_CATEGORIE
|
48 |
ln -s $DIR_DNS_BL/$ENABLE_CATEGORIE.conf $DIR_DNS_BL_ENABLED/$ENABLE_CATEGORIE
|
49 |
ln -s $DIR_IP_BL/$ENABLE_CATEGORIE $DIR_IP_BL_ENABLED/$ENABLE_CATEGORIE
|
49 |
ln -s $DIR_IP_BL/$ENABLE_CATEGORIE $DIR_IP_BL_ENABLED/$ENABLE_CATEGORIE
|
50 |
echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/domains>" >> $DIR_DG/bannedsitelist # we let DG filters domain in order to prevent bypass by proxy http vpn ;-)
|
50 |
# echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/domains>" >> $DIR_DG/bannedsitelist # Blacklisted domains are managed by dnsmasq
|
51 |
echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/urls>" >> $DIR_DG/bannedurllist
|
51 |
echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/urls>" >> $DIR_DG/bannedurllist
|
52 |
done
|
52 |
done
|
53 |
sort +0.0 -0.2 $BL_CATEGORIES -o $FILE_tmp
|
53 |
sort +0.0 -0.2 $BL_CATEGORIES -o $FILE_tmp
|
54 |
mv $FILE_tmp $BL_CATEGORIES
|
54 |
mv $FILE_tmp $BL_CATEGORIES
|
55 |
# process the file $WL_CATEGORIES with the choice of categories
|
55 |
# process the file $WL_CATEGORIES with the choice of categories
|
56 |
for ENABLE_CATEGORIE in `cat $WL_CATEGORIES_ENABLED`
|
56 |
for ENABLE_CATEGORIE in `cat $WL_CATEGORIES_ENABLED`
|
57 |
do
|
57 |
do
|
58 |
$SED "/\/$ENABLE_CATEGORIE$/d" $WL_CATEGORIES
|
58 |
$SED "/\/$ENABLE_CATEGORIE$/d" $WL_CATEGORIES
|
59 |
$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $WL_CATEGORIES
|
59 |
$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
|
60 |
ln -s $DIR_DNS_WL/$ENABLE_CATEGORIE.conf $DIR_DNS_WL_ENABLED/$ENABLE_CATEGORIE
|
61 |
done
|
61 |
done
|
62 |
sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
|
62 |
sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
|
63 |
mv $FILE_tmp $WL_CATEGORIES
|
63 |
mv $FILE_tmp $WL_CATEGORIES
|
64 |
}
|
64 |
}
|
65 |
function bl_enable (){
|
65 |
function bl_enable (){
|
66 |
$SED "s/^reportinglevel =.*/reportinglevel = 3/g" /etc/dansguardian/dansguardian.conf
|
66 |
$SED "s/^reportinglevel =.*/reportinglevel = 3/g" /etc/dansguardian/dansguardian.conf
|
67 |
if [ "$PARENT_SCRIPT" != "alcasar-conf.sh" ] # don't launch on install stage
|
67 |
if [ "$PARENT_SCRIPT" != "alcasar-conf.sh" ] # don't launch on install stage
|
68 |
then
|
68 |
then
|
69 |
service dansguardian restart
|
69 |
service dansguardian restart
|
70 |
service dnsmasq restart
|
70 |
service dnsmasq restart
|
71 |
/usr/local/bin/alcasar-iptables.sh
|
71 |
/usr/local/bin/alcasar-iptables.sh
|
72 |
fi
|
72 |
fi
|
73 |
}
|
73 |
}
|
74 |
function bl_disable (){
|
74 |
function bl_disable (){
|
75 |
rm -rf $DIR_DNS_BL_ENABLED/*
|
75 |
rm -rf $DIR_DNS_BL_ENABLED/*
|
76 |
$SED "s/^reportinglevel =.*/reportinglevel = -1/g" /etc/dansguardian/dansguardian.conf
|
76 |
$SED "s/^reportinglevel =.*/reportinglevel = -1/g" /etc/dansguardian/dansguardian.conf
|
77 |
$SED "/google/d" $DNSMASQ_BL_CONF # remove nosslsearch server
|
77 |
$SED "/google/d" $DNSMASQ_BL_CONF # remove nosslsearch server
|
78 |
$SED "s?^[^#]?#&?g" $DIR_DG/urlregexplist # remove safe searching
|
78 |
$SED "s?^[^#]?#&?g" $DIR_DG/urlregexplist # remove safe searching
|
79 |
$SED "s/^\*ip$/#*ip/g" $DIR_DG/bannedsitelist # remove pureip browsing
|
79 |
$SED "s/^\*ip$/#*ip/g" $DIR_DG/bannedsitelist # remove pureip browsing
|
80 |
if [ "$PARENT_SCRIPT" != "alcasar-conf.sh" ] # don't launch on install stage
|
80 |
if [ "$PARENT_SCRIPT" != "alcasar-conf.sh" ] # don't launch on install stage
|
81 |
then
|
81 |
then
|
82 |
service dansguardian restart
|
82 |
service dansguardian restart
|
83 |
service dnsmasq restart
|
83 |
service dnsmasq restart
|
84 |
/usr/local/bin/alcasar-iptables.sh
|
84 |
/usr/local/bin/alcasar-iptables.sh
|
85 |
fi
|
85 |
fi
|
86 |
}
|
86 |
}
|
87 |
usage="Usage: alcasar-bl.sh { -on or --on } | { -off or --off } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload }"
|
87 |
usage="Usage: alcasar-bl.sh { -on or --on } | { -off or --off } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload }"
|
88 |
nb_args=$#
|
88 |
nb_args=$#
|
89 |
args=$1
|
89 |
args=$1
|
90 |
if [ $nb_args -eq 0 ]
|
90 |
if [ $nb_args -eq 0 ]
|
91 |
then
|
91 |
then
|
92 |
DNS_FILTERING=`grep DNS_FILTERING $CONF_FILE|cut -d"=" -f2` # DNS and URLs filter (on/off)
|
92 |
DNS_FILTERING=`grep DNS_FILTERING $CONF_FILE|cut -d"=" -f2` # DNS and URLs filter (on/off)
|
93 |
DNS_FILTERING=${DNS_FILTERING:=off}
|
93 |
DNS_FILTERING=${DNS_FILTERING:=off}
|
94 |
echo "Set BlackList Filtering to $DNS_FILTERING"
|
94 |
echo "Set BlackList Filtering to $DNS_FILTERING"
|
95 |
if [ $DNS_FILTERING = on ]; then
|
95 |
if [ $DNS_FILTERING = on ]; then
|
96 |
cat_choice
|
96 |
cat_choice
|
97 |
bl_enable
|
97 |
bl_enable
|
98 |
else
|
98 |
else
|
99 |
bl_disable
|
99 |
bl_disable
|
100 |
fi
|
100 |
fi
|
101 |
exit 0
|
101 |
exit 0
|
102 |
fi
|
102 |
fi
|
103 |
case $args in
|
103 |
case $args in
|
104 |
-\? | -h* | --h*)
|
104 |
-\? | -h* | --h*)
|
105 |
echo "$usage"
|
105 |
echo "$usage"
|
106 |
exit 0
|
106 |
exit 0
|
107 |
;;
|
107 |
;;
|
108 |
# enable the filtering
|
108 |
# enable the filtering
|
109 |
-on | --on)
|
109 |
-on | --on)
|
110 |
cat_choice
|
110 |
cat_choice
|
111 |
$SED "s?^DNS_FILTERING.*?DNS_FILTERING=on?g" $CONF_FILE
|
111 |
$SED "s?^DNS_FILTERING.*?DNS_FILTERING=on?g" $CONF_FILE
|
112 |
bl_enable
|
112 |
bl_enable
|
113 |
;;
|
113 |
;;
|
114 |
# disable the filtering
|
114 |
# disable the filtering
|
115 |
-off | --off)
|
115 |
-off | --off)
|
116 |
$SED "s?^DNS_FILTERING.*?DNS_FILTERING=off?g" $CONF_FILE
|
116 |
$SED "s?^DNS_FILTERING.*?DNS_FILTERING=off?g" $CONF_FILE
|
117 |
bl_disable
|
117 |
bl_disable
|
118 |
;;
|
118 |
;;
|
119 |
# Retrieve Toulouse BL
|
119 |
# Retrieve Toulouse BL
|
120 |
-download | --download)
|
120 |
-download | --download)
|
121 |
rm -rf /tmp/con_ok.html
|
121 |
rm -rf /tmp/con_ok.html
|
122 |
`/usr/bin/curl $BL_SERVER -# -o /tmp/con_ok.html`
|
122 |
`/usr/bin/curl $BL_SERVER -# -o /tmp/con_ok.html`
|
123 |
if [ ! -e /tmp/con_ok.html ]
|
123 |
if [ ! -e /tmp/con_ok.html ]
|
124 |
then
|
124 |
then
|
125 |
echo "Erreur : le serveur de blacklist ($BL_SERVER) n'est pas joignable"
|
125 |
echo "Erreur : le serveur de blacklist ($BL_SERVER) n'est pas joignable"
|
126 |
else
|
126 |
else
|
127 |
rm -rf /tmp/con_ok.html $DIR_tmp
|
127 |
rm -rf /tmp/con_ok.html $DIR_tmp
|
128 |
mkdir $DIR_tmp
|
128 |
mkdir $DIR_tmp
|
129 |
wget -P $DIR_tmp http://$BL_SERVER/blacklists/download/blacklists.tar.gz
|
129 |
wget -P $DIR_tmp http://$BL_SERVER/blacklists/download/blacklists.tar.gz
|
130 |
md5sum $DIR_tmp/blacklists.tar.gz | cut -d" " -f1 > $DIR_tmp/md5sum
|
130 |
md5sum $DIR_tmp/blacklists.tar.gz | cut -d" " -f1 > $DIR_tmp/md5sum
|
131 |
chown -R apache:apache $DIR_tmp
|
131 |
chown -R apache:apache $DIR_tmp
|
132 |
fi
|
132 |
fi
|
133 |
;;
|
133 |
;;
|
134 |
# Adapt Toulouse BL to our structure (dnsmasq + DG)
|
134 |
# Adapt Toulouse BL to ALCASAR architecture (dnsmasq + DG + iptables)
|
135 |
-adapt | --adapt)
|
135 |
-adapt | --adapt)
|
136 |
echo -n "Toulouse BlackList migration process. Please wait : "
|
136 |
echo -n "Toulouse BlackList migration process. Please wait : "
|
137 |
if [ -f $DIR_tmp/blacklists.tar.gz ]
|
137 |
if [ -f $DIR_tmp/blacklists.tar.gz ]
|
138 |
then
|
138 |
then
|
139 |
[ -d $DIR_DG_BL/ossi ] && mv -f $DIR_DG_BL/ossi $DIR_tmp
|
139 |
[ -d $DIR_DG_BL/ossi ] && mv -f $DIR_DG_BL/ossi $DIR_tmp
|
140 |
rm -rf $DIR_DG_BL
|
140 |
rm -rf $DIR_DG_BL
|
141 |
mkdir $DIR_DG_BL
|
141 |
mkdir $DIR_DG_BL
|
142 |
tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DG/
|
142 |
tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DG/
|
143 |
[ -d $DIR_tmp/ossi ] && mv -f $DIR_tmp/ossi $DIR_DG_BL/
|
143 |
[ -d $DIR_tmp/ossi ] && mv -f $DIR_tmp/ossi $DIR_DG_BL/
|
144 |
rm -rf $DIR_tmp
|
144 |
rm -rf $DIR_tmp
|
145 |
fi
|
145 |
fi
|
146 |
rm -f $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
|
146 |
rm -f $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
|
147 |
rm -rf $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL
|
147 |
rm -rf $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL
|
148 |
touch $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
|
148 |
touch $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
|
149 |
mkdir $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL
|
149 |
mkdir $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL
|
150 |
chown -R dansguardian:apache $DIR_DG $BL_CATEGORIES $WL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES_ENABLED
|
150 |
chown -R dansguardian:apache $DIR_DG $BL_CATEGORIES $WL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES_ENABLED
|
151 |
chmod -R g+w $DIR_DG $BL_CATEGORIES $WL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES_ENABLED
|
151 |
chmod -R g+w $DIR_DG $BL_CATEGORIES $WL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES_ENABLED
|
152 |
find $DIR_DG_BL/ -type f -name domains > $FILE_tmp # retrieve directory name where a domain file exist
|
152 |
find $DIR_DG_BL/ -type f -name domains > $FILE_tmp # retrieve directory name where a domain file exist
|
153 |
$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
|
153 |
$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
|
154 |
for dir_categorie in `cat $FILE_tmp` # create the blacklist and the whitelist files
|
154 |
for dir_categorie in `cat $FILE_tmp` # create the blacklist and the whitelist files
|
155 |
do
|
155 |
do
|
156 |
categorie=`echo $dir_categorie|cut -d "/" -f6`
|
156 |
categorie=`echo $dir_categorie|cut -d "/" -f6`
|
157 |
categorie_type=`grep -A1 ^NAME:[$' '$'\t']*$categorie $DIR_DG_BL/global_usage | grep ^DEFAULT_TYPE | cut -d":" -f2 | tr -d " \t"`
|
157 |
categorie_type=`grep -A1 ^NAME:[$' '$'\t']*$categorie $DIR_DG_BL/global_usage | grep ^DEFAULT_TYPE | cut -d":" -f2 | tr -d " \t"`
|
158 |
if [ "$categorie_type" == "white" ]
|
158 |
if [ "$categorie_type" == "white" ]
|
159 |
then
|
159 |
then
|
160 |
echo "$dir_categorie" >> $WL_CATEGORIES
|
160 |
echo "$dir_categorie" >> $WL_CATEGORIES
|
161 |
echo `basename $dir_categorie` >> $WL_CATEGORIES_ENABLED # by default all WL are enabled
|
161 |
echo `basename $dir_categorie` >> $WL_CATEGORIES_ENABLED # by default all WL are enabled
|
162 |
else
|
162 |
else
|
163 |
echo "$dir_categorie" >> $BL_CATEGORIES
|
163 |
echo "$dir_categorie" >> $BL_CATEGORIES
|
164 |
fi
|
164 |
fi
|
165 |
done
|
165 |
done
|
166 |
rm -f $FILE_tmp
|
166 |
rm -f $FILE_tmp
|
167 |
# Verify that the enabled categories are effectively in the BL (need after an update of the BL)
|
167 |
# Verify that the enabled categories are effectively in the BL (need after an update of the BL)
|
168 |
for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED`
|
168 |
for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED`
|
169 |
do
|
169 |
do
|
170 |
ok=`grep /$ENABLE_CATEGORIE$ $BL_CATEGORIES|wc -l`
|
170 |
ok=`grep /$ENABLE_CATEGORIE$ $BL_CATEGORIES|wc -l`
|
171 |
if [ $ok != "1" ]
|
171 |
if [ $ok != "1" ]
|
172 |
then
|
172 |
then
|
173 |
$SED "/^$ENABLE_CATEGORIE$/d" $BL_CATEGORIES_ENABLED
|
173 |
$SED "/^$ENABLE_CATEGORIE$/d" $BL_CATEGORIES_ENABLED
|
174 |
fi
|
174 |
fi
|
175 |
done
|
175 |
done
|
176 |
# Creation of DNSMASQ BL and WL
|
176 |
# Creation of DNSMASQ and Iptables BL and WL
|
177 |
for LIST in $BL_CATEGORIES $WL_CATEGORIES # for each list (bl and wl)
|
177 |
for LIST in $BL_CATEGORIES $WL_CATEGORIES # for each list (bl and wl)
|
178 |
do
|
178 |
do
|
179 |
for PATH_FILE in `cat $LIST` # for each category
|
179 |
for PATH_FILE in `cat $LIST` # for each category
|
180 |
do
|
180 |
do
|
181 |
DOMAINE=`basename $PATH_FILE`
|
181 |
DOMAINE=`basename $PATH_FILE`
|
182 |
echo -n "$DOMAINE, "
|
182 |
echo -n "$DOMAINE, "
|
183 |
if [ ! -f $PATH_FILE/urls ] # create 'urls' file if it doesn't exist
|
183 |
if [ ! -f $PATH_FILE/urls ] # create 'urls' file if it doesn't exist
|
184 |
then
|
184 |
then
|
185 |
touch $PATH_FILE/urls
|
185 |
touch $PATH_FILE/urls
|
186 |
chown dansguardian:apache $PATH_FILE/urls
|
186 |
chown dansguardian:apache $PATH_FILE/urls
|
187 |
fi
|
187 |
fi
|
188 |
$SED "s/\.\{2,10\}/\./g" $PATH_FILE/domains $PATH_FILE/urls # correct some syntax errors
|
188 |
$SED "s/\.\{2,10\}/\./g" $PATH_FILE/domains $PATH_FILE/urls # correct some syntax errors
|
189 |
# retrieve the ip addresses for iptables
|
189 |
# retrieve the ip addresses for iptables
|
190 |
egrep "([0-9]{1,3}\.){3}[0-9]{1,3}" $PATH_FILE/domains > $FILE_ip_tmp
|
190 |
egrep "^([0-9]{1,3}\.){3}[0-9]{1,3}$" $PATH_FILE/domains > $FILE_ip_tmp
|
191 |
# for dnsmask, remove IP addesses, accented characters and commented lines.
|
191 |
# for dnsmask, remove IP addesses, accented characters and commented lines.
|
192 |
egrep -v "([0-9]{1,3}\.){3}[0-9]{1,3}" $PATH_FILE/domains > $FILE_tmp
|
192 |
egrep -v "^([0-9]{1,3}\.){3}[0-9]{1,3}$" $PATH_FILE/domains > $FILE_tmp
|
193 |
$SED "/[äâëêïîöôüû]/d" $FILE_tmp
|
193 |
$SED "/[äâëêïîöôüû]/d" $FILE_tmp
|
194 |
$SED "/^#.*/d" $FILE_tmp
|
194 |
$SED "/^#.*/d" $FILE_tmp
|
195 |
# adapt to the dnsmasq syntax
|
195 |
# adapt to the dnsmasq syntax
|
196 |
$SED "s?.*?address=/&/$PRIVATE_IP?g" $FILE_tmp
|
196 |
$SED "s?.*?address=/&/$PRIVATE_IP?g" $FILE_tmp
|
197 |
if [ "$LIST" == "$BL_CATEGORIES" ]
|
197 |
if [ "$LIST" == "$BL_CATEGORIES" ]
|
198 |
then
|
198 |
then
|
199 |
mv $FILE_tmp $DIR_DNS_BL/$DOMAINE.conf
|
199 |
mv $FILE_tmp $DIR_DNS_BL/$DOMAINE.conf
|
200 |
mv $FILE_ip_tmp $DIR_IP_BL/$DOMAINE
|
200 |
mv $FILE_ip_tmp $DIR_IP_BL/$DOMAINE
|
201 |
else
|
201 |
else
|
202 |
mv $FILE_tmp $DIR_DNS_WL/$DOMAINE.conf
|
202 |
mv $FILE_tmp $DIR_DNS_WL/$DOMAINE.conf
|
203 |
fi
|
203 |
fi
|
204 |
done
|
204 |
done
|
205 |
done
|
205 |
done
|
206 |
rm -f $FILE_tmp $FILE_ip_tmp
|
206 |
rm -f $FILE_tmp $FILE_ip_tmp
|
207 |
echo
|
207 |
echo
|
208 |
;;
|
208 |
;;
|
209 |
# reload when categories are changed
|
209 |
# reload when categories are changed
|
210 |
-reload | --reload)
|
210 |
-reload | --reload)
|
211 |
# for DG
|
211 |
# for DG
|
212 |
chown -R dansguardian:apache $DIR_DG_BL/ossi
|
212 |
chown -R dansguardian:apache $DIR_DG_BL/ossi
|
213 |
chmod -R g+w $DIR_DG_BL/ossi
|
213 |
chmod -R g+w $DIR_DG_BL/ossi
|
214 |
cat_choice
|
214 |
cat_choice
|
215 |
# for dnsmasq (rehabited domain names)
|
215 |
# for dnsmasq (rehabited domain names)
|
216 |
if [ `wc -w $DIR_DG/exceptionsitelist|cut -d " " -f1` != "0" ]
|
216 |
if [ `wc -w $DIR_DG/exceptionsitelist|cut -d " " -f1` != "0" ]
|
217 |
then
|
217 |
then
|
218 |
for i in `cat $DIR_DG/exceptionsitelist`
|
218 |
for i in `cat $DIR_DG/exceptionsitelist`
|
219 |
do
|
219 |
do
|
220 |
$SED "/$i/d" $DIR_DNS_BL/*
|
220 |
$SED "/$i/d" $DIR_DNS_BL/*
|
221 |
done
|
221 |
done
|
222 |
fi
|
222 |
fi
|
223 |
cp -f $DIR_DG_BL/ossi/domains $DIR_DNS_BL/ossi.conf
|
223 |
cp -f $DIR_DG_BL/ossi/domains $DIR_DNS_BL/ossi.conf
|
224 |
$SED "s?.*?address=/&/$PRIVATE_IP?g" $DIR_DNS_BL/ossi.conf
|
224 |
$SED "s?.*?address=/&/$PRIVATE_IP?g" $DIR_DNS_BL/ossi.conf
|
225 |
cp -f $DIR_DG_BL/ossi/domains_wl $DIR_DNS_WL/ossi.conf
|
225 |
cp -f $DIR_DG_BL/ossi/domains_wl $DIR_DNS_WL/ossi.conf
|
226 |
DNS_FILTERING=`grep DNS_FILTERING $CONF_FILE|cut -d"=" -f2` # DNS and URLs filter (on/off)
|
226 |
DNS_FILTERING=`grep DNS_FILTERING $CONF_FILE|cut -d"=" -f2` # DNS and URLs filter (on/off)
|
227 |
DNS_FILTERING=${DNS_FILTERING:=off}
|
227 |
DNS_FILTERING=${DNS_FILTERING:=off}
|
228 |
if [ $DNS_FILTERING = on ]; then
|
228 |
if [ $DNS_FILTERING = on ]; then
|
229 |
bl_enable
|
229 |
bl_enable
|
230 |
else
|
230 |
else
|
231 |
bl_disable
|
231 |
bl_disable
|
232 |
fi
|
232 |
fi
|
233 |
;;
|
233 |
;;
|
234 |
*)
|
234 |
*)
|
235 |
echo "Argument inconnu :$1";
|
235 |
echo "Argument inconnu :$1";
|
236 |
echo "$usage"
|
236 |
echo "$usage"
|
237 |
exit 1
|
237 |
exit 1
|
238 |
;;
|
238 |
;;
|
239 |
esac
|
239 |
esac
|
240 |
|
240 |
|
241 |
|
241 |
|