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