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