Line 1... |
Line 1... |
1 |
#/bin/bash
|
1 |
#/bin/bash
|
2 |
|
2 |
|
3 |
# $Id: alcasar-bl.sh 1827 2016-04-19 09:47:29Z raphael.pion $
|
3 |
# $Id: alcasar-bl.sh 1852 2016-05-01 18:46:46Z raphael.pion $
|
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 13... |
Line 13... |
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 |
FILE_tmp="/tmp/filesfilter.txt"
|
19 |
FILE_tmp="/tmp/filesfilter.txt"
|
19 |
FILE_ip_tmp="/tmp/filesipfilter.txt"
|
20 |
FILE_ip_tmp="/tmp/filesipfilter.txt"
|
20 |
DIR_DG="/etc/dansguardian/lists"
|
21 |
DIR_DG="/etc/dansguardian/lists"
|
21 |
DIR_DG_BL="$DIR_DG/blacklists"
|
22 |
DIR_DG_BL="$DIR_DG/blacklists"
|
22 |
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
|
Line 29... |
Line 30... |
29 |
DIR_DNS_WL="$DIR_SHARE/dnsmasq-wl" # all the WL ' ' '
|
30 |
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
|
31 |
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)
|
32 |
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 ' ' '
|
33 |
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)
|
34 |
DIR_IP_BL_ENABLED="$DIR_SHARE/iptables-bl-enabled" # ' ' ip BL (only enabled categories)
|
- |
|
35 |
DIR_IP_WL_ENABLED="$DIR_SHARE/iptables-wl-enabled" # ' ' ip WL (ossi and ossi-* imported from ACC)
|
- |
|
36 |
DIR_IP_WL="$DIR_SHARE/iptables-wl-enabled" # ' ' ip WL (ossi and ossi-* imported from ACC)
|
34 |
DNSMASQ_BL_CONF="/etc/dnsmasq-blacklist.conf" # conf file of dnsmasq-blacklist
|
37 |
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)
|
38 |
DNS1=`grep "DNS1" $CONF_FILE | cut -d '=' -f 2` # server DNS1 (for WL domain names)
|
36 |
BL_SERVER="dsi.ut-capitole.fr"
|
39 |
BL_SERVER="dsi.ut-capitole.fr"
|
37 |
SED="/bin/sed -i"
|
40 |
SED="/bin/sed -i"
|
38 |
|
41 |
|
39 |
# enable/disable the BL & WL categories
|
42 |
# enable/disable the BL & WL categories
|
40 |
function cat_choice (){
|
43 |
function cat_choice (){
|
41 |
# saving ossi category
|
44 |
# saving ossi category
|
42 |
mkdir $DIR_tmp
|
45 |
mkdir $DIR_tmp
|
43 |
cp $DIR_IP_BL/ossi $DIR_tmp
|
46 |
cp $DIR_IP_BL/ossi $DIR_tmp
|
- |
|
47 |
|
44 |
if [ -d $DIR_IP_BL_ENABLED ]
|
48 |
if [ -d $DIR_IP_BL_ENABLED ]
|
45 |
then
|
49 |
then
|
46 |
for file in `ls -1 $DIR_IP_BL_ENABLED | grep -v "^ossi-*"`
|
50 |
for file in `ls -1 $DIR_IP_BL_ENABLED | grep -v "^ossi-*"`
|
47 |
do
|
51 |
do
|
48 |
rm -f $DIR_IP_BL_ENABLED/$file
|
52 |
rm -f $DIR_IP_BL_ENABLED/$file
|
49 |
done
|
53 |
done
|
50 |
else
|
54 |
else
|
51 |
mkdir $DIR_IP_BL_ENABLED
|
55 |
mkdir $DIR_IP_BL_ENABLED
|
52 |
chown apache $DIR_IP_BL_ENABLED
|
56 |
chown apache $DIR_IP_BL_ENABLED
|
53 |
fi
|
57 |
fi
|
- |
|
58 |
|
- |
|
59 |
if [ -d $DIR_IP_WL_ENABLED ]
|
- |
|
60 |
then
|
- |
|
61 |
for file in `ls -1 $DIR_IP_WL_ENABLED | grep -v "^ossi-*"`
|
- |
|
62 |
do
|
- |
|
63 |
rm -f $DIR_IP_WL_ENABLED/$file
|
- |
|
64 |
done
|
- |
|
65 |
else
|
- |
|
66 |
mkdir $DIR_IP_WL_ENABLED
|
- |
|
67 |
chown apache $DIR_IP_WL_ENABLED
|
- |
|
68 |
fi
|
- |
|
69 |
|
54 |
if [ -d $DIR_DNS_BL_ENABLED ]
|
70 |
if [ -d $DIR_DNS_BL_ENABLED ]
|
55 |
then
|
71 |
then
|
56 |
for file in `ls -1 $DIR_DNS_BL_ENABLED | grep -v "^ossi-*"`
|
72 |
for file in `ls -1 $DIR_DNS_BL_ENABLED | grep -v "^ossi-*"`
|
57 |
do
|
73 |
do
|
58 |
rm -f $DIR_DNS_BL_ENABLED/$file
|
74 |
rm -f $DIR_DNS_BL_ENABLED/$file
|
59 |
done
|
75 |
done
|
60 |
else
|
76 |
else
|
61 |
mkdir $DIR_DNS_BL_ENABLED
|
77 |
mkdir $DIR_DNS_BL_ENABLED
|
62 |
chown apache $DIR_DNS_BL_ENABLED
|
78 |
chown apache $DIR_DNS_BL_ENABLED
|
63 |
fi
|
79 |
fi
|
- |
|
80 |
if [ -d $DIR_DNS_WL_ENABLED ]
|
- |
|
81 |
then
|
- |
|
82 |
for file in `ls -1 $DIR_DNS_WL_ENABLED | grep -v "^ossi-*"`
|
- |
|
83 |
do
|
64 |
rm -rf $DIR_DNS_WL_ENABLED # cleaning for dnsmasq and iptables
|
84 |
rm -f $DIR_DNS_WL_ENABLED/$file
|
- |
|
85 |
done
|
- |
|
86 |
else
|
- |
|
87 |
mkdir $DIR_DNS_WL_ENABLED
|
- |
|
88 |
chown apache $DIR_DNS_WL_ENABLED
|
- |
|
89 |
fi
|
65 |
$SED "/\.Include/d" $DIR_DG/bannedsitelist $DIR_DG/bannedurllist # cleaning for DG
|
90 |
$SED "/\.Include/d" $DIR_DG/bannedsitelist $DIR_DG/bannedurllist # cleaning for DG
|
66 |
$SED "s?^[^#]?#&?g" $BL_CATEGORIES $WL_CATEGORIES # cleaning BL & WL categories file (comment all lines)
|
91 |
$SED "s?^[^#]?#&?g" $BL_CATEGORIES $WL_CATEGORIES # cleaning BL & WL categories file (comment all lines)
|
67 |
mkdir $DIR_DNS_WL_ENABLED
|
- |
|
68 |
# process the file $BL_CATEGORIES with the choice of categories
|
92 |
# process the file $BL_CATEGORIES with the choice of categories
|
69 |
for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED`
|
93 |
for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED`
|
70 |
do
|
94 |
do
|
71 |
$SED "/\/$ENABLE_CATEGORIE$/d" $BL_CATEGORIES
|
95 |
$SED "/\/$ENABLE_CATEGORIE$/d" $BL_CATEGORIES
|
72 |
$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $BL_CATEGORIES
|
96 |
$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $BL_CATEGORIES
|
Line 84... |
Line 108... |
84 |
$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $WL_CATEGORIES
|
108 |
$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $WL_CATEGORIES
|
85 |
ln -sf $DIR_DNS_WL/$ENABLE_CATEGORIE.conf $DIR_DNS_WL_ENABLED/$ENABLE_CATEGORIE
|
109 |
ln -sf $DIR_DNS_WL/$ENABLE_CATEGORIE.conf $DIR_DNS_WL_ENABLED/$ENABLE_CATEGORIE
|
86 |
done
|
110 |
done
|
87 |
sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
|
111 |
sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
|
88 |
mv $FILE_tmp $WL_CATEGORIES
|
112 |
mv $FILE_tmp $WL_CATEGORIES
|
- |
|
113 |
|
89 |
# restoring ip files and ossi category
|
114 |
# restoring ip files and ossi category BL/WL
|
90 |
mv $DIR_tmp/ossi $DIR_IP_BL
|
115 |
mv $DIR_tmp/ossi $DIR_IP_BL
|
91 |
chown apache $DIR_IP_BL/ossi
|
116 |
chown apache $DIR_IP_BL/ossi
|
92 |
rm -rf $DIR_tmp
|
117 |
rm -rf $DIR_tmp
|
- |
|
118 |
|
93 |
}
|
119 |
}
|
94 |
|
120 |
|
95 |
usage="Usage: alcasar-bl.sh { -cat_choice or --cat_choice } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload }"
|
121 |
usage="Usage: alcasar-bl.sh { -cat_choice or --cat_choice } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload }"
|
96 |
nb_args=$#
|
122 |
nb_args=$#
|
97 |
args=$1
|
123 |
args=$1
|
Line 124... |
Line 150... |
124 |
cat_choice
|
150 |
cat_choice
|
125 |
;;
|
151 |
;;
|
126 |
# Adapt Toulouse BL to ALCASAR architecture (dnsmasq + DG + iptables)
|
152 |
# Adapt Toulouse BL to ALCASAR architecture (dnsmasq + DG + iptables)
|
127 |
-adapt | --adapt)
|
153 |
-adapt | --adapt)
|
128 |
echo -n "Toulouse BlackList migration process. Please wait : "
|
154 |
echo -n "Toulouse BlackList migration process. Please wait : "
|
129 |
if [ ! -e $DIR_SHARE/ossi-ip-wl ]
|
155 |
if [ ! -e $DIR_IP_WL_ENABLED/ossi ]
|
130 |
then
|
156 |
then
|
131 |
touch $DIR_SHARE/ossi-ip-wl
|
157 |
touch $DIR_IP_WL_ENABLED/ossi
|
132 |
chown apache $DIR_SHARE/ossi-ip-wl
|
158 |
chown apache $DIR_IP_WL_ENABLED/ossi
|
133 |
fi
|
159 |
fi
|
134 |
if [ -f $DIR_tmp/blacklists.tar.gz ] # when downloading the last version of the BL
|
160 |
if [ -f $DIR_tmp/blacklists.tar.gz ] # when downloading the last version of the BL
|
135 |
then
|
161 |
then
|
136 |
[ -d $DIR_DG_BL/ossi ] && mv $DIR_DG_BL/ossi $DIR_tmp
|
162 |
[ -d $DIR_DG_BL/ossi ] && mv $DIR_DG_BL/ossi $DIR_tmp
|
137 |
[ -e $DIR_IP_BL/ossi ] && mv $DIR_IP_BL/ossi $DIR_tmp/ossi-ip-bl
|
163 |
[ -e $DIR_IP_BL/ossi ] && mv $DIR_IP_BL/ossi $DIR_tmp/ossi-ip-bl
|