Line 1... |
Line 1... |
1 |
#/bin/bash
|
1 |
#/bin/bash
|
2 |
|
2 |
|
3 |
# $Id: alcasar-bl.sh 1938 2016-06-12 15:12:06Z richard $
|
3 |
# $Id: alcasar-bl.sh 1940 2016-06-12 22:09:49Z 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 69... |
Line 69... |
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
|
74 |
# add ossi categories
|
- |
|
75 |
for OSSI_CATEGORIE in `ls $DIR_DNS_BL | grep ossi`
|
- |
|
76 |
do
|
- |
|
77 |
OSSI_CATEGORIE_SHORT=`echo $OSSI_CATEGORIE|cut -d"." -f1`
|
- |
|
78 |
ln -sf $DIR_DNS_BL/$OSSI_CATEGORIE $DIR_DNS_BL_ENABLED/$OSSI_CATEGORIE_SHORT
|
- |
|
79 |
done
|
- |
|
80 |
for OSSI_CATEGORIE in `ls $DIR_IP_BL | grep ossi`
|
- |
|
81 |
do
|
- |
|
82 |
ln -sf $DIR_IP_BL/$OSSI_CATEGORIE $DIR_IP_BL_ENABLED/$OSSI_CATEGORIE
|
- |
|
83 |
done
|
- |
|
84 |
|
- |
|
85 |
sort +0.0 -0.2 $BL_CATEGORIES -o $FILE_tmp
|
74 |
sort +0.0 -0.2 $BL_CATEGORIES -o $FILE_tmp
|
86 |
mv $FILE_tmp $BL_CATEGORIES
|
75 |
mv $FILE_tmp $BL_CATEGORIES
|
87 |
|
76 |
|
88 |
# process the file $WL_CATEGORIES with the choice of categories
|
77 |
# process the file $WL_CATEGORIES with the choice of categories
|
89 |
for ENABLE_CATEGORIE in `cat $WL_CATEGORIES_ENABLED`
|
78 |
for ENABLE_CATEGORIE in `cat $WL_CATEGORIES_ENABLED`
|
90 |
do
|
79 |
do
|
91 |
$SED "/\/$ENABLE_CATEGORIE$/d" $WL_CATEGORIES
|
80 |
$SED "/\/$ENABLE_CATEGORIE$/d" $WL_CATEGORIES
|
92 |
$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $WL_CATEGORIES
|
81 |
$SED "1i\/etc\/dansguardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $WL_CATEGORIES
|
93 |
ln -sf $DIR_DNS_WL/$ENABLE_CATEGORIE.conf $DIR_DNS_WL_ENABLED/$ENABLE_CATEGORIE
|
82 |
ln -sf $DIR_DNS_WL/$ENABLE_CATEGORIE.conf $DIR_DNS_WL_ENABLED/$ENABLE_CATEGORIE
|
94 |
done
|
83 |
done
|
95 |
# add ossi categories
|
- |
|
96 |
for OSSI_CATEGORIE in `ls $DIR_DNS_WL | grep ossi`
|
- |
|
97 |
do
|
- |
|
98 |
OSSI_CATEGORIE_SHORT=`echo $OSSI_CATEGORIE|cut -d"." -f1`
|
- |
|
99 |
ln -sf $DIR_DNS_WL/$OSSI_CATEGORIE $DIR_DNS_WL_ENABLED/$OSSI_CATEGORIE_SHORT
|
- |
|
100 |
done
|
- |
|
101 |
for OSSI_CATEGORIE in `ls $DIR_IP_WL | grep ossi`
|
- |
|
102 |
do
|
- |
|
103 |
ln -sf $DIR_IP_WL/$OSSI_CATEGORIE $DIR_IP_WL_ENABLED/$OSSI_CATEGORIE
|
- |
|
104 |
done
|
- |
|
105 |
sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
|
84 |
sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
|
106 |
mv $FILE_tmp $WL_CATEGORIES
|
85 |
mv $FILE_tmp $WL_CATEGORIES
|
107 |
}
|
86 |
}
|
108 |
|
87 |
|
109 |
usage="Usage: alcasar-bl.sh { -cat_choice or --cat_choice } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload } | { -update_cat or --update_cat }"
|
88 |
usage="Usage: alcasar-bl.sh { -cat_choice or --cat_choice } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload } | { -update_cat or --update_cat }"
|
Line 148... |
Line 127... |
148 |
mv $DIR_DG_BL/$x $DIR_tmp
|
127 |
mv $DIR_DG_BL/$x $DIR_tmp
|
149 |
done
|
128 |
done
|
150 |
rm -rf $DIR_DG_BL $DIR_IP_BL
|
129 |
rm -rf $DIR_DG_BL $DIR_IP_BL
|
151 |
mkdir $DIR_DG_BL $DIR_IP_BL
|
130 |
mkdir $DIR_DG_BL $DIR_IP_BL
|
152 |
tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DG/
|
131 |
tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DG/
|
- |
|
132 |
chown -R root:apache $DIR_DG
|
- |
|
133 |
chmod -R 770 $DIR_DG
|
153 |
# Add the two local categories (ossi-bl & ossi-wl) to the usage file
|
134 |
# Add the two local categories (ossi-bl & ossi-wl) to the usage file
|
154 |
# Add the custom categories (ossi-tor_nodes) to the usage file
|
135 |
# Add the custom categories (ossi-tor_nodes) to the usage file
|
155 |
cat << EOF >> $DIR_DG_BL/global_usage
|
136 |
cat << EOF >> $DIR_DG_BL/global_usage
|
156 |
|
137 |
|
157 |
NAME: ossi-bl
|
138 |
NAME: ossi-bl
|
Line 188... |
Line 169... |
188 |
rm -rf $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
|
169 |
rm -rf $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
|
189 |
rm -rf $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED $DIR_IP_WL_ENBALED
|
170 |
rm -rf $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED $DIR_IP_WL_ENBALED
|
190 |
touch $BL_CATEGORIES $WL_CATEGORIES
|
171 |
touch $BL_CATEGORIES $WL_CATEGORIES
|
191 |
mkdir $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
|
172 |
mkdir $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
|
192 |
mkdir $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED $DIR_IP_WL_ENBALED
|
173 |
mkdir $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED $DIR_IP_WL_ENBALED
|
193 |
chown -R root: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
|
- |
|
194 |
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
|
- |
|
195 |
find $DIR_DG_BL/ -type f -name domains > $FILE_tmp # retrieve directory name where a domain file exist
|
174 |
find $DIR_DG_BL/ -type f -name domains > $FILE_tmp # retrieve directory name where a domain file exist
|
196 |
$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
|
175 |
$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
|
197 |
for dir_categorie in `cat $FILE_tmp` # create the blacklist and the whitelist files
|
176 |
for dir_categorie in `cat $FILE_tmp` # create the blacklist and the whitelist files
|
198 |
do
|
177 |
do
|
199 |
categorie=`echo $dir_categorie|cut -d "/" -f6`
|
178 |
categorie=`echo $dir_categorie|cut -d "/" -f6`
|
Line 254... |
Line 233... |
254 |
$SED "s?.*?server=/&/$DNS1?g" $FILE_tmp
|
233 |
$SED "s?.*?server=/&/$DNS1?g" $FILE_tmp
|
255 |
mv $FILE_tmp $DIR_DNS_WL/$DOMAIN.conf
|
234 |
mv $FILE_tmp $DIR_DNS_WL/$DOMAIN.conf
|
256 |
fi
|
235 |
fi
|
257 |
done
|
236 |
done
|
258 |
done
|
237 |
done
|
- |
|
238 |
echo
|
- |
|
239 |
chown -R root:apache $BL_CATEGORIES $WL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES_ENABLED $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED $DIR_IP_WL_ENABLED
|
- |
|
240 |
chmod 770 $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
|
- |
|
241 |
chmod -f 660 $BL_CATEGORIES $WL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES_ENABLED $DIR_DNS_BL/* $DIR_DNS_WL/* $DIR_IP_BL/* $DIR_IP_WL/*
|
259 |
rm -f $FILE_tmp $FILE_ip_tmp
|
242 |
rm -f $FILE_tmp $FILE_ip_tmp
|
260 |
rm -rf $DIR_tmp
|
243 |
rm -rf $DIR_tmp
|
261 |
;;
|
244 |
;;
|
262 |
# update the categories which are written in "/usr/local/etc/update_cat.conf" with rsync
|
245 |
# update the categories which are written in "/usr/local/etc/update_cat.conf" with rsync
|
263 |
-update_cat | --update_cat)
|
246 |
-update_cat | --update_cat)
|
Line 363... |
Line 346... |
363 |
echo "$usage"
|
346 |
echo "$usage"
|
364 |
exit 1
|
347 |
exit 1
|
365 |
;;
|
348 |
;;
|
366 |
esac
|
349 |
esac
|
367 |
|
350 |
|
368 |
|
- |
|
369 |
|
- |
|
370 |
|
- |
|