2223 |
tom.houday |
1 |
#!/bin/bash
|
1015 |
richard |
2 |
|
63 |
franck |
3 |
# $Id: alcasar-bl.sh 3179 2024-03-03 23:23:58Z rexy $
|
|
|
4 |
|
672 |
richard |
5 |
# alcasar-bl.sh
|
|
|
6 |
# by Franck BOUIJOUX and Richard REY
|
|
|
7 |
# This script is distributed under the Gnu General Public License (GPL)
|
1 |
root |
8 |
|
2688 |
lucas.echa |
9 |
# Gestion de la BL pour le filtrage de domaine (via unbound) et d'URL (via E2guardian)
|
2769 |
rexy |
10 |
# Manage the BL for domain filtering (with unbound) and URL filtering (with E2guardian)
|
672 |
richard |
11 |
|
878 |
richard |
12 |
DIR_CONF="/usr/local/etc"
|
|
|
13 |
CONF_FILE="$DIR_CONF/alcasar.conf"
|
2474 |
tom.houday |
14 |
private_ip_mask=`grep ^PRIVATE_IP= $CONF_FILE|cut -d"=" -f2`
|
854 |
richard |
15 |
private_ip_mask=${private_ip_mask:=192.168.182.1/24}
|
308 |
richard |
16 |
DIR_tmp="/tmp/blacklists"
|
1015 |
richard |
17 |
FILE_tmp="/tmp/filesfilter.txt"
|
|
|
18 |
FILE_ip_tmp="/tmp/filesipfilter.txt"
|
2521 |
armand.ito |
19 |
DIR_DG="/etc/e2guardian/lists"
|
316 |
richard |
20 |
DIR_DG_BL="$DIR_DG/blacklists"
|
2675 |
lucas.echa |
21 |
GLOBAL_USAGE="$DIR_CONF/alcasar-global-usage" # file containing the description of the lists
|
1015 |
richard |
22 |
BL_CATEGORIES="$DIR_CONF/alcasar-bl-categories" # list of names of the BL categories
|
1926 |
richard |
23 |
WL_CATEGORIES="$DIR_CONF/alcasar-wl-categories" # ' ' WL categories
|
1015 |
richard |
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
|
|
|
26 |
DIR_SHARE="/usr/local/share"
|
2688 |
lucas.echa |
27 |
DIR_DNS_BL="$DIR_SHARE/unbound-bl" # all the BL in the Unbound format
|
|
|
28 |
DIR_DNS_WL="$DIR_SHARE/unbound-wl" # all the WL ' ' '
|
2454 |
tom.houday |
29 |
DIR_IP_BL="$DIR_SHARE/iptables-bl" # all the IP addresses of the BL
|
|
|
30 |
DIR_IP_WL="$DIR_SHARE/iptables-wl" # IP ossi disabled WL
|
2688 |
lucas.echa |
31 |
DIR_DNS_BL_ENABLED="$DIR_SHARE/unbound-bl-enabled" # symbolic link to the domains BL (only enabled categories)
|
|
|
32 |
DIR_DNS_WL_ENABLED="$DIR_SHARE/unbound-wl-enabled" # ' ' ' WL ' '
|
1377 |
richard |
33 |
DIR_IP_BL_ENABLED="$DIR_SHARE/iptables-bl-enabled" # ' ' ip BL (only enabled categories)
|
1852 |
raphael.pi |
34 |
DIR_IP_WL_ENABLED="$DIR_SHARE/iptables-wl-enabled" # ' ' ip WL (ossi and ossi-* imported from ACC)
|
2688 |
lucas.echa |
35 |
REHABILITATED_DNS_FILE="/etc/unbound/conf.d/blacklist/rehabilitated.conf"
|
878 |
richard |
36 |
BL_SERVER="dsi.ut-capitole.fr"
|
1 |
root |
37 |
SED="/bin/sed -i"
|
637 |
richard |
38 |
|
1042 |
richard |
39 |
# enable/disable the BL & WL categories
|
308 |
richard |
40 |
function cat_choice (){
|
1931 |
richard |
41 |
mkdir -p $DIR_tmp
|
|
|
42 |
for LIST in $DIR_IP_BL_ENABLED $DIR_DNS_BL_ENABLED $DIR_IP_WL_ENABLED $DIR_DNS_WL_ENABLED
|
1930 |
richard |
43 |
do
|
1938 |
richard |
44 |
if [ ! -e $LIST ] # only on install stage
|
1933 |
richard |
45 |
then
|
|
|
46 |
mkdir $LIST
|
|
|
47 |
else
|
2688 |
lucas.echa |
48 |
rm -rf ${LIST:?}/*
|
1933 |
richard |
49 |
fi
|
|
|
50 |
chown root:apache $LIST
|
|
|
51 |
chmod 770 $LIST
|
1930 |
richard |
52 |
done
|
1870 |
raphael.pi |
53 |
# update categories with rsync
|
|
|
54 |
if [ ! -e $DIR_CONF/update_cat.conf ]
|
|
|
55 |
then
|
|
|
56 |
touch $DIR_CONF/update_cat.conf
|
|
|
57 |
chown root:apache $DIR_CONF/update_cat.conf
|
|
|
58 |
chmod 660 $DIR_CONF/update_cat.conf
|
|
|
59 |
fi
|
1015 |
richard |
60 |
$SED "/\.Include/d" $DIR_DG/bannedsitelist $DIR_DG/bannedurllist # cleaning for DG
|
1042 |
richard |
61 |
$SED "s?^[^#]?#&?g" $BL_CATEGORIES $WL_CATEGORIES # cleaning BL & WL categories file (comment all lines)
|
1912 |
richard |
62 |
|
2454 |
tom.houday |
63 |
# process the file $BL_CATEGORIES with the choice of categories
|
|
|
64 |
for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED`
|
313 |
richard |
65 |
do
|
2454 |
tom.houday |
66 |
$SED "/\/$ENABLE_CATEGORIE$/d" $BL_CATEGORIES
|
2521 |
armand.ito |
67 |
$SED "1i\/etc\/e2guardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $BL_CATEGORIES
|
1395 |
richard |
68 |
ln -sf $DIR_DNS_BL/$ENABLE_CATEGORIE.conf $DIR_DNS_BL_ENABLED/$ENABLE_CATEGORIE
|
|
|
69 |
ln -sf $DIR_IP_BL/$ENABLE_CATEGORIE $DIR_IP_BL_ENABLED/$ENABLE_CATEGORIE
|
2688 |
lucas.echa |
70 |
# echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/domains>" >> $DIR_DG/bannedsitelist # Blacklisted domains are managed by unbound
|
648 |
richard |
71 |
echo ".Include<$DIR_DG_BL/$ENABLE_CATEGORIE/urls>" >> $DIR_DG/bannedurllist
|
313 |
richard |
72 |
done
|
878 |
richard |
73 |
sort +0.0 -0.2 $BL_CATEGORIES -o $FILE_tmp
|
313 |
richard |
74 |
mv $FILE_tmp $BL_CATEGORIES
|
2193 |
richard |
75 |
sort +0.0 -0.2 $BL_CATEGORIES_ENABLED -o $FILE_tmp
|
|
|
76 |
mv $FILE_tmp $BL_CATEGORIES_ENABLED
|
|
|
77 |
chown root:apache $BL_CATEGORIES $BL_CATEGORIES_ENABLED
|
|
|
78 |
chmod 660 $BL_CATEGORIES $BL_CATEGORIES_ENABLED
|
1912 |
richard |
79 |
|
2454 |
tom.houday |
80 |
# process the file $WL_CATEGORIES with the choice of categories
|
|
|
81 |
for ENABLE_CATEGORIE in `cat $WL_CATEGORIES_ENABLED`
|
1042 |
richard |
82 |
do
|
2454 |
tom.houday |
83 |
$SED "/\/$ENABLE_CATEGORIE$/d" $WL_CATEGORIES
|
2521 |
armand.ito |
84 |
$SED "1i\/etc\/e2guardian\/lists\/blacklists\/$ENABLE_CATEGORIE" $WL_CATEGORIES
|
1395 |
richard |
85 |
ln -sf $DIR_DNS_WL/$ENABLE_CATEGORIE.conf $DIR_DNS_WL_ENABLED/$ENABLE_CATEGORIE
|
1042 |
richard |
86 |
done
|
|
|
87 |
sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
|
|
|
88 |
mv $FILE_tmp $WL_CATEGORIES
|
2193 |
richard |
89 |
sort +0.0 -0.2 $WL_CATEGORIES_ENABLED -o $FILE_tmp
|
|
|
90 |
mv $FILE_tmp $WL_CATEGORIES_ENABLED
|
|
|
91 |
chown root:apache $WL_CATEGORIES $WL_CATEGORIES_ENABLED
|
|
|
92 |
chmod 660 $WL_CATEGORIES $WL_CATEGORIES_ENABLED
|
308 |
richard |
93 |
}
|
1482 |
richard |
94 |
|
2192 |
richard |
95 |
# cleaning file and split it ("domains" in $FILE_tmp & "IP" in $FILE_ip_tmp)
|
|
|
96 |
function clean_split (){
|
2919 |
rexy |
97 |
$SED '/^[.#]/d' $FILE_tmp # remove commented lines and lines beginning with a dot
|
2192 |
richard |
98 |
$SED '/^\s*$/d' $FILE_tmp # remove empty lines
|
|
|
99 |
$SED '/[äâëêïîöôüû@,]/d' $FILE_tmp # remove line with "chelou" characters
|
2898 |
rexy |
100 |
# extract ip addresses and ip networks for iptables.
|
2192 |
richard |
101 |
awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}$/{print "add bl_ip_blocked " $0}' $FILE_tmp > $FILE_ip_tmp
|
2898 |
rexy |
102 |
awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}\/[0-9]{1,2}$/{print "add bl_ip_blocked " $0}' $FILE_tmp >> $FILE_ip_tmp
|
2688 |
lucas.echa |
103 |
# extract domain names for unbound.
|
2192 |
richard |
104 |
$SED -n '/^\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/!p' $FILE_tmp
|
|
|
105 |
# Retrieve max Top Level Domain for domain name synthax
|
|
|
106 |
#MAX_TLD=$(curl http://data.iana.org/TLD/tlds-alpha-by-domain.txt | grep -v '-' | grep -v '#' | wc -L)
|
|
|
107 |
#if [ $(echo $MAX_TLD | wc -c) -eq 0 ];then
|
|
|
108 |
# MAX_TLD=18
|
|
|
109 |
#fi
|
|
|
110 |
# search for correction egrep "([a-zA-Z0-9_-.]+\.){1,2}[a-zA-Z]{2,$MAX_TLD}" $ossi_custom_dir/domains > $FILE_tmp
|
|
|
111 |
}
|
|
|
112 |
|
2770 |
rexy |
113 |
usage="Usage: alcasar-bl.sh { -cat_choice or --cat_choice } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload }"
|
1 |
root |
114 |
nb_args=$#
|
|
|
115 |
args=$1
|
|
|
116 |
if [ $nb_args -eq 0 ]
|
|
|
117 |
then
|
2454 |
tom.houday |
118 |
args="-h"
|
1 |
root |
119 |
fi
|
|
|
120 |
case $args in
|
|
|
121 |
-\? | -h* | --h*)
|
|
|
122 |
echo "$usage"
|
|
|
123 |
exit 0
|
|
|
124 |
;;
|
1873 |
richard |
125 |
# Retrieve Toulouse University BL
|
386 |
franck |
126 |
-download | --download)
|
1 |
root |
127 |
rm -rf /tmp/con_ok.html
|
|
|
128 |
`/usr/bin/curl $BL_SERVER -# -o /tmp/con_ok.html`
|
|
|
129 |
if [ ! -e /tmp/con_ok.html ]
|
|
|
130 |
then
|
|
|
131 |
echo "Erreur : le serveur de blacklist ($BL_SERVER) n'est pas joignable"
|
2454 |
tom.houday |
132 |
else
|
878 |
richard |
133 |
rm -rf /tmp/con_ok.html $DIR_tmp
|
|
|
134 |
mkdir $DIR_tmp
|
885 |
richard |
135 |
wget -P $DIR_tmp http://$BL_SERVER/blacklists/download/blacklists.tar.gz
|
878 |
richard |
136 |
md5sum $DIR_tmp/blacklists.tar.gz | cut -d" " -f1 > $DIR_tmp/md5sum
|
885 |
richard |
137 |
chown -R apache:apache $DIR_tmp
|
878 |
richard |
138 |
fi
|
2675 |
lucas.echa |
139 |
;;
|
1488 |
richard |
140 |
# enable/disable categories (used only during the alcasar install process)
|
|
|
141 |
-cat_choice | --cat_choice)
|
|
|
142 |
cat_choice
|
|
|
143 |
;;
|
2688 |
lucas.echa |
144 |
# Adapt Toulouse University BL to ALCASAR architecture (unbound + DG + iptables)
|
878 |
richard |
145 |
-adapt | --adapt)
|
1873 |
richard |
146 |
echo -n "Adaptation process of Toulouse University blackList. Please wait : "
|
1371 |
richard |
147 |
if [ -f $DIR_tmp/blacklists.tar.gz ] # when downloading the last version of the BL
|
878 |
richard |
148 |
then
|
2454 |
tom.houday |
149 |
# keep custom files (ossi)
|
1930 |
richard |
150 |
for x in $(ls -1 $DIR_DG_BL | grep "^ossi-*")
|
|
|
151 |
do
|
|
|
152 |
mv $DIR_DG_BL/$x $DIR_tmp
|
|
|
153 |
done
|
1369 |
richard |
154 |
rm -rf $DIR_DG_BL $DIR_IP_BL
|
|
|
155 |
mkdir $DIR_DG_BL $DIR_IP_BL
|
878 |
richard |
156 |
tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DG/
|
2678 |
lucas.echa |
157 |
# replace the global_usage file of the archive
|
|
|
158 |
cp -f $GLOBAL_USAGE $DIR_DG_BL/global_usage
|
2521 |
armand.ito |
159 |
chown -R e2guardian:apache $DIR_DG
|
1940 |
richard |
160 |
chmod -R 770 $DIR_DG
|
2678 |
lucas.echa |
161 |
# Add the two local categories (ossi-bl & ossi-wl) to the usage file
|
|
|
162 |
# Add the custom categories (ossi-tor_nodes) to the usage file
|
|
|
163 |
cat <<EOF >> $DIR_DG_BL/global_usage
|
|
|
164 |
|
|
|
165 |
NAME: ossi-bl
|
|
|
166 |
DEFAULT_TYPE: black
|
|
|
167 |
SOURCE: ALCASAR Team
|
|
|
168 |
DESC FR: sites blacklistés ajoutés localement
|
|
|
169 |
DESC EN: blacklisted sites add locally
|
|
|
170 |
NAME FR: ossi-bl
|
|
|
171 |
NAME EN: ossi-bl
|
|
|
172 |
|
|
|
173 |
NAME: ossi-wl
|
|
|
174 |
DEFAULT_TYPE: white
|
|
|
175 |
SOURCE: ALCASAR Team
|
|
|
176 |
DESC FR: sites autorisés ajoutés localement
|
|
|
177 |
DESC EN: whitelisted sites add locally
|
|
|
178 |
NAME FR: ossi-wl
|
|
|
179 |
NAME EN: ossi-wl
|
|
|
180 |
|
|
|
181 |
NAME: ossi-bl-tor_nodes
|
|
|
182 |
DEFAULT_TYPE: black
|
|
|
183 |
SOURCE: ALCASAR Team
|
|
|
184 |
DESC FR: Adresses IP des noeuds (routeurs) d'entrée du réseau TOR
|
|
|
185 |
DESC EN: IP addresses of input TOR nodes (routers)
|
|
|
186 |
NAME FR: Noeuds TOR
|
|
|
187 |
NAME EN: TOR nodes
|
2769 |
rexy |
188 |
|
|
|
189 |
NAME: ossi-bl-ultrasurf
|
|
|
190 |
DEFAULT_TYPE: black
|
|
|
191 |
SOURCE: ALCASAR Team
|
|
|
192 |
DESC FR: Adresses IP des point de sortie ULTRASURF
|
|
|
193 |
DESC EN: IP addresses of output points of ULTRASURF
|
|
|
194 |
NAME FR: Points de sortie ULTRASURF
|
|
|
195 |
NAME EN: ULTRASURF output points
|
|
|
196 |
|
|
|
197 |
NAME: ossi-bl-candc
|
|
|
198 |
DEFAULT_TYPE: black
|
|
|
199 |
SOURCE: Bambenek Consulting: https://osint.bambenekconsulting.com
|
|
|
200 |
DESC FR: liste des URLs et IPs des serveurs command & control
|
|
|
201 |
DESC EN: list of URLs and IPs of command & control servers
|
|
|
202 |
NAME FR: Serveurs Command & Control
|
|
|
203 |
NAME EN: Command & Control Server
|
|
|
204 |
|
2678 |
lucas.echa |
205 |
EOF
|
2769 |
rexy |
206 |
# Retrieve custom files (ossi)
|
1930 |
richard |
207 |
for x in $(ls -1 $DIR_tmp | grep "^ossi-*")
|
|
|
208 |
do
|
|
|
209 |
mv $DIR_tmp/$x $DIR_DG_BL
|
|
|
210 |
done
|
|
|
211 |
fi
|
3179 |
rexy |
212 |
rm -f $BL_CATEGORIES $WL_CATEGORIES $WL_CATEGORIES_ENABLED
|
1930 |
richard |
213 |
rm -rf $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
|
2675 |
lucas.echa |
214 |
rm -rf $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED $DIR_IP_WL_ENABLED
|
1930 |
richard |
215 |
touch $BL_CATEGORIES $WL_CATEGORIES
|
|
|
216 |
mkdir $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
|
2675 |
lucas.echa |
217 |
mkdir $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED $DIR_IP_WL_ENABLED
|
1930 |
richard |
218 |
find $DIR_DG_BL/ -type f -name domains > $FILE_tmp # retrieve directory name where a domain file exist
|
|
|
219 |
$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
|
1042 |
richard |
220 |
for dir_categorie in `cat $FILE_tmp` # create the blacklist and the whitelist files
|
878 |
richard |
221 |
do
|
1015 |
richard |
222 |
categorie=`echo $dir_categorie|cut -d "/" -f6`
|
2678 |
lucas.echa |
223 |
categorie_type=`grep -A1 ^NAME:[$' '$'\t']*$categorie\$ $DIR_DG_BL/global_usage | grep ^DEFAULT_TYPE | cut -d":" -f2 | tr -d " \t"`
|
1015 |
richard |
224 |
if [ "$categorie_type" == "white" ]
|
878 |
richard |
225 |
then
|
3179 |
rexy |
226 |
echo "$categorie" >> $WL_CATEGORIES_ENABLED
|
878 |
richard |
227 |
fi
|
3179 |
rexy |
228 |
echo "$dir_categorie" >> $BL_CATEGORIES
|
|
|
229 |
echo "$dir_categorie" >> $WL_CATEGORIES
|
|
|
230 |
done
|
878 |
richard |
231 |
rm -f $FILE_tmp
|
1057 |
richard |
232 |
# Verify that the enabled categories are effectively in the BL (need after an update of the BL)
|
2454 |
tom.houday |
233 |
for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED`
|
1057 |
richard |
234 |
do
|
|
|
235 |
ok=`grep /$ENABLE_CATEGORIE$ $BL_CATEGORIES|wc -l`
|
2454 |
tom.houday |
236 |
if [ $ok != "1" ]
|
1057 |
richard |
237 |
then
|
|
|
238 |
$SED "/^$ENABLE_CATEGORIE$/d" $BL_CATEGORIES_ENABLED
|
|
|
239 |
fi
|
|
|
240 |
done
|
1926 |
richard |
241 |
# Verify that the enabled categories are effectively in the WL (need after an update of the WL)
|
2454 |
tom.houday |
242 |
for ENABLE_CATEGORIE in `cat $WL_CATEGORIES_ENABLED`
|
1926 |
richard |
243 |
do
|
|
|
244 |
ok=`grep /$ENABLE_CATEGORIE$ $WL_CATEGORIES|wc -l`
|
2454 |
tom.houday |
245 |
if [ $ok != "1" ]
|
1926 |
richard |
246 |
then
|
|
|
247 |
$SED "/^$ENABLE_CATEGORIE$/d" $WL_CATEGORIES_ENABLED
|
|
|
248 |
fi
|
|
|
249 |
done
|
2688 |
lucas.echa |
250 |
|
|
|
251 |
# Creation of Unbound and Iptables BL and WL
|
1015 |
richard |
252 |
for LIST in $BL_CATEGORIES $WL_CATEGORIES # for each list (bl and wl)
|
854 |
richard |
253 |
do
|
1015 |
richard |
254 |
for PATH_FILE in `cat $LIST` # for each category
|
|
|
255 |
do
|
1938 |
richard |
256 |
DOMAIN=`basename $PATH_FILE`
|
|
|
257 |
echo -n "$DOMAIN, "
|
2454 |
tom.houday |
258 |
if [ ! -f $PATH_FILE/urls ] # create 'urls' file if it doesn't exist
|
1015 |
richard |
259 |
then
|
|
|
260 |
touch $PATH_FILE/urls
|
2521 |
armand.ito |
261 |
chown e2guardian:apache $PATH_FILE/urls
|
1015 |
richard |
262 |
fi
|
2454 |
tom.houday |
263 |
cp $PATH_FILE/domains $FILE_tmp
|
2688 |
lucas.echa |
264 |
clean_split # clean ossi custom files & split them for unbound and for iptables
|
1015 |
richard |
265 |
if [ "$LIST" == "$BL_CATEGORIES" ]
|
|
|
266 |
then
|
2688 |
lucas.echa |
267 |
# adapt to the unbound syntax for the blacklist
|
|
|
268 |
$SED "s?.*?local-zone: & typetransparent\nlocal-zone-tag: & blacklist?g" $FILE_tmp
|
1938 |
richard |
269 |
mv $FILE_tmp $DIR_DNS_BL/$DOMAIN.conf
|
|
|
270 |
mv $FILE_ip_tmp $DIR_IP_BL/$DOMAIN
|
1015 |
richard |
271 |
else
|
2688 |
lucas.echa |
272 |
# adapt to the unbound syntax for the whitelist
|
|
|
273 |
$SED "s?.*?local-zone: & transparent?g" $FILE_tmp
|
3099 |
rexy |
274 |
$SED "p; s? transparent? ipset?g" $FILE_tmp # duplicate lines to enable ipset module
|
1938 |
richard |
275 |
mv $FILE_tmp $DIR_DNS_WL/$DOMAIN.conf
|
1015 |
richard |
276 |
fi
|
|
|
277 |
done
|
854 |
richard |
278 |
done
|
1940 |
richard |
279 |
echo
|
1953 |
richard |
280 |
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
|
2454 |
tom.houday |
281 |
chmod 770 $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
|
1940 |
richard |
282 |
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/*
|
1015 |
richard |
283 |
rm -f $FILE_tmp $FILE_ip_tmp
|
1339 |
richard |
284 |
rm -rf $DIR_tmp
|
654 |
richard |
285 |
;;
|
1938 |
richard |
286 |
# reload when selected categories are changed or when ossi change his custom files
|
386 |
franck |
287 |
-reload | --reload)
|
2769 |
rexy |
288 |
# for E2Gardian
|
311 |
richard |
289 |
cat_choice
|
2688 |
lucas.echa |
290 |
# for unbound (rehabilitated domain names)
|
|
|
291 |
rm -f $REHABILITATED_DNS_FILE
|
|
|
292 |
if [ "$(wc -w $DIR_DG/exceptionsitelist | cut -d " " -f1)" != "0" ]
|
311 |
richard |
293 |
then
|
2688 |
lucas.echa |
294 |
touch $REHABILITATED_DNS_FILE
|
|
|
295 |
while read -r domain; do
|
|
|
296 |
[ -z "$domain" ] && continue
|
|
|
297 |
echo "local-zone: $domain typetransparent" >> $REHABILITATED_DNS_FILE
|
|
|
298 |
echo "local-zone-tag: $domain \"\"" >> $REHABILITATED_DNS_FILE
|
|
|
299 |
done < $DIR_DG/exceptionsitelist
|
311 |
richard |
300 |
fi
|
1938 |
richard |
301 |
# adapt OSSI BL & WL custom files
|
2675 |
lucas.echa |
302 |
for dir in $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED $DIR_IP_WL_ENABLED $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
|
1938 |
richard |
303 |
do
|
|
|
304 |
rm -f $dir/ossi*
|
|
|
305 |
done
|
1954 |
richard |
306 |
find $DIR_DG_BL/ -type f -name domains | grep ossi- > $FILE_tmp # retrieve ossi directories name where a domain file exist
|
1938 |
richard |
307 |
$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
|
|
|
308 |
for ossi_custom_dir in `cat $FILE_tmp` # create the blacklist and the whitelist files
|
|
|
309 |
do
|
2192 |
richard |
310 |
chown -R root:apache $ossi_custom_dir
|
|
|
311 |
chmod 770 $ossi_custom_dir
|
1938 |
richard |
312 |
ossi_categorie=`echo $ossi_custom_dir|cut -d "/" -f6`
|
1954 |
richard |
313 |
short_categorie=`echo "$ossi_categorie" | cut -d"-" -f2`
|
|
|
314 |
if [ $short_categorie == "bl" ]
|
|
|
315 |
then
|
|
|
316 |
categorie_type="black"
|
|
|
317 |
else
|
|
|
318 |
categorie_type="white"
|
|
|
319 |
fi
|
2192 |
richard |
320 |
$SED "s/\r//" $ossi_custom_dir/domains $ossi_custom_dir/urls # remove Windows <CR> from custom file
|
|
|
321 |
cp $ossi_custom_dir/domains $FILE_tmp
|
2688 |
lucas.echa |
322 |
clean_split # clean ossi custom files & split them for unbound and for iptables
|
1951 |
richard |
323 |
if [ $categorie_type == "white" ]
|
1938 |
richard |
324 |
then
|
2688 |
lucas.echa |
325 |
# adapt the file to the unbound syntax and enable it if needed
|
1951 |
richard |
326 |
# for the WL
|
2688 |
lucas.echa |
327 |
$SED "s?.*?local-zone: & transparent?g" $FILE_tmp
|
3100 |
rexy |
328 |
$SED "p; s? transparent? ipset?g" $FILE_tmp # duplicate lines to enable ipset module
|
1938 |
richard |
329 |
mv $FILE_tmp $DIR_DNS_WL/$ossi_categorie.conf
|
|
|
330 |
mv $FILE_ip_tmp $DIR_IP_WL/$ossi_categorie
|
1951 |
richard |
331 |
enabled=`grep ^$ossi_categorie$ $WL_CATEGORIES_ENABLED | wc -l`
|
|
|
332 |
if [ $enabled == "1" ]
|
|
|
333 |
then
|
2454 |
tom.houday |
334 |
$SED "/\/$ossi_categorie$/d" $WL_CATEGORIES
|
2521 |
armand.ito |
335 |
$SED "1i\/etc\/e2guardian\/lists\/blacklists\/$ossi_categorie" $WL_CATEGORIES
|
1951 |
richard |
336 |
ln -sf $DIR_DNS_WL/$ossi_categorie.conf $DIR_DNS_WL_ENABLED/$ossi_categorie
|
|
|
337 |
ln -sf $DIR_IP_WL/$ossi_categorie $DIR_IP_WL_ENABLED/$ossi_categorie
|
|
|
338 |
fi
|
1938 |
richard |
339 |
else
|
1951 |
richard |
340 |
# for the BL
|
2688 |
lucas.echa |
341 |
$SED "s?.*?local-zone: & typetransparent\nlocal-zone-tag: & blacklist?g" $FILE_tmp
|
1938 |
richard |
342 |
mv $FILE_tmp $DIR_DNS_BL/$ossi_categorie.conf
|
|
|
343 |
mv $FILE_ip_tmp $DIR_IP_BL/$ossi_categorie
|
1951 |
richard |
344 |
enabled=`grep ^$ossi_categorie$ $BL_CATEGORIES_ENABLED | wc -l`
|
|
|
345 |
if [ $enabled == "1" ]
|
|
|
346 |
then
|
2454 |
tom.houday |
347 |
$SED "/\/$ossi_categorie$/d" $BL_CATEGORIES
|
2521 |
armand.ito |
348 |
$SED "1i\/etc\/e2guardian\/lists\/blacklists\/$ossi_categorie" $BL_CATEGORIES
|
1951 |
richard |
349 |
ln -sf $DIR_DNS_BL/$ossi_categorie.conf $DIR_DNS_BL_ENABLED/$ossi_categorie
|
|
|
350 |
ln -sf $DIR_IP_BL/$ossi_categorie $DIR_IP_BL_ENABLED/$ossi_categorie
|
|
|
351 |
fi
|
1938 |
richard |
352 |
fi
|
|
|
353 |
done
|
1958 |
richard |
354 |
for file in $BL_CATEGORIES $BL_CATEGORIES_ENABLED $WL_CATEGORIES $WL_CATEGORIES_ENABLED
|
|
|
355 |
do
|
|
|
356 |
sort +0.0 -0.2 $file -o $FILE_tmp
|
|
|
357 |
mv $FILE_tmp $file
|
|
|
358 |
chown root:apache $file
|
|
|
359 |
chmod 660 $file
|
|
|
360 |
done
|
1969 |
richard |
361 |
chown -R root:apache $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
|
|
|
362 |
chmod 660 $DIR_DNS_BL/* $DIR_DNS_WL/* $DIR_IP_BL/* $DIR_IP_WL/*
|
1957 |
richard |
363 |
if [ "$PARENT_SCRIPT" != "alcasar-conf.sh" ] # don't launch on install stage
|
|
|
364 |
then
|
2688 |
lucas.echa |
365 |
/usr/bin/systemctl restart unbound-blacklist
|
|
|
366 |
/usr/bin/systemctl restart unbound-whitelist
|
2569 |
lucas.echa |
367 |
/usr/bin/systemctl restart e2guardian
|
1957 |
richard |
368 |
/usr/local/bin/alcasar-iptables.sh
|
|
|
369 |
fi
|
503 |
richard |
370 |
;;
|
1 |
root |
371 |
*)
|
|
|
372 |
echo "Argument inconnu :$1";
|
|
|
373 |
echo "$usage"
|
|
|
374 |
exit 1
|
|
|
375 |
;;
|
|
|
376 |
esac
|