Subversion Repositories ALCASAR

Rev

Rev 3193 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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