Subversion Repositories ALCASAR

Rev

Rev 1927 | Rev 1931 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 1927 Rev 1930
Line 1... Line 1...
1
#/bin/bash
1
#/bin/bash
2
 
2
 
3
# $Id: alcasar-bl.sh 1927 2016-06-05 21:36:32Z richard $
3
# $Id: alcasar-bl.sh 1930 2016-06-08 22:00:48Z 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 44... Line 44...
44
SED="/bin/sed -i"
44
SED="/bin/sed -i"
45
 
45
 
46
# enable/disable the BL & WL categories
46
# enable/disable the BL & WL categories
47
function cat_choice (){
47
function cat_choice (){
48
	mkdir $DIR_tmp
48
	mkdir $DIR_tmp
49
	#ip BL ENABLE
-
 
50
	if [ -d $DIR_IP_BL_ENABLED ]
-
 
51
	then
-
 
52
		for file in `ls -1 $DIR_IP_BL_ENABLED | grep -v "^ossi-*"`
-
 
53
		do
-
 
54
			rm -f $DIR_IP_BL_ENABLED/$file
-
 
55
		done
-
 
56
	else
-
 
57
		mkdir $DIR_IP_BL_ENABLED
-
 
58
		chown root:apache $DIR_IP_BL_ENABLED
-
 
59
		chmod 770 $DIR_IP_BL_ENABLED
-
 
60
	fi
-
 
61
 
-
 
62
	#dns BL ENABLED
-
 
63
	if [ -d $DIR_DNS_BL_ENABLED ]
-
 
64
	then
-
 
65
		for file in `ls -1 $DIR_DNS_BL_ENABLED | grep -v "^ossi-*"`
49
	for dir_bl in $DIR_IP_BL_ENABLED $DIR_DNS_BL_ENABLED $DIR_IP_WL_ENABLED $DIR_DNS_WL_ENABLED 
66
		do
50
	do
67
			rm -f $DIR_DNS_BL_ENABLED/$file
-
 
68
		done
-
 
69
	else
-
 
70
		mkdir $DIR_DNS_BL_ENABLED
-
 
71
		chown root:apache $DIR_DNS_BL_ENABLED
-
 
72
		chmod 770 $DIR_DNS_BL_ENABLED
-
 
73
	fi
-
 
74
	#dns BL ossi.conf 
51
		rm -f $dir_bl/*
75
	if [ ! -e $DIR_DNS_BL/ossi.conf ]
-
 
76
	then
-
 
77
		touch $DIR_DNS_BL/ossi.conf
-
 
78
		chown root:apache $DIR_DNS_BL/ossi.conf
-
 
79
		chmod g+w $DIR_DNS_BL/ossi.conf
-
 
80
		if [ ! -e $DIR_DNS_BL_ENABLED/ossi ]
-
 
81
		then
-
 
82
			ln -s $DIR_DNS_BL/ossi.conf $DIR_DNS_BL_ENABLED/ossi
-
 
83
		fi
-
 
84
	fi
-
 
85
 
-
 
86
	#ip WL ENABLE
-
 
87
	if [ -d $DIR_IP_WL_ENABLED ]
-
 
88
	then
-
 
89
		for file in `ls -1 $DIR_IP_WL_ENABLED | grep -v "^ossi*"`
-
 
90
		do
-
 
91
			rm -f $DIR_IP_WL_ENABLED/$file
-
 
92
		done
-
 
93
	else
-
 
94
		mkdir $DIR_IP_WL_ENABLED
-
 
95
		touch $DIR_IP_WL_ENABLED/ossi
-
 
96
		chown -R root:apache $DIR_IP_WL_ENABLED
-
 
97
		chmod 770 $DIR_IP_WL_ENABLED
-
 
98
		chmod g+w $DIR_IP_WL_ENABLED/ossi
-
 
99
	fi
-
 
100
 
-
 
101
	#dns WL ENABLED
-
 
102
	if [ -d $DIR_DNS_WL_ENABLED ]
-
 
103
	then
-
 
104
		for file in `ls -1 $DIR_DNS_WL_ENABLED | grep -v "^ossi-*"`
-
 
105
		do
-
 
106
			rm -f $DIR_DNS_WL_ENABLED/$file
-
 
107
		done
52
	done
108
	else
-
 
109
		mkdir $DIR_DNS_WL_ENABLED
-
 
110
		chown root:apache $DIR_DNS_WL_ENABLED
-
 
111
		chmod 770 $DIR_DNS_WL_ENABLED
-
 
112
	fi
-
 
113
	#dns WL ossi.conf 
-
 
114
	if [ ! -e $DIR_DNS_WL/ossi.conf ]
-
 
115
	then
-
 
116
		touch $DIR_DNS_WL/ossi.conf
-
 
117
		chown root:apache $DIR_DNS_WL/ossi.conf
-
 
118
		chmod g+w $DIR_DNS_WL/ossi.conf
-
 
119
		if [ ! -e $DIR_DNS_WL_ENABLED/ossi ]
-
 
120
		then
-
 
121
			ln -s $DIR_DNS_WL/ossi.conf $DIR_DNS_WL_ENABLED/ossi
-
 
122
		fi
-
 
123
	fi
-
 
124
 
-
 
125
	# update categories with rsync
53
	# update categories with rsync
126
	if [ ! -e $DIR_CONF/update_cat.conf ]
54
	if [ ! -e $DIR_CONF/update_cat.conf ]
127
	then
55
	then
128
		touch $DIR_CONF/update_cat.conf
56
		touch $DIR_CONF/update_cat.conf
129
		chown root:apache $DIR_CONF/update_cat.conf
57
		chown root:apache $DIR_CONF/update_cat.conf
Line 188... Line 116...
188
		cat_choice
116
		cat_choice
189
		;;
117
		;;
190
	# Adapt Toulouse University BL to ALCASAR architecture (dnsmasq + DG + iptables)
118
	# Adapt Toulouse University BL to ALCASAR architecture (dnsmasq + DG + iptables)
191
	-adapt | --adapt)
119
	-adapt | --adapt)
192
		echo -n "Adaptation process of Toulouse University blackList. Please wait : "
120
		echo -n "Adaptation process of Toulouse University blackList. Please wait : "
193
		# keep custom files (ossi) 
-
 
194
		for x in $(ls -1 $DIR_DG_BL | grep "^ossi-*")
-
 
195
		do
-
 
196
			mv $DIR_DG_BL/$x $DIR_tmp
-
 
197
		done
-
 
198
		if [ -f $DIR_tmp/blacklists.tar.gz ] # when downloading the last version of the BL
121
		if [ -f $DIR_tmp/blacklists.tar.gz ] # when downloading the last version of the BL
199
		then
122
		then
-
 
123
			# keep custom files (ossi) 
-
 
124
			for x in $(ls -1 $DIR_DG_BL | grep "^ossi-*")
-
 
125
			do
-
 
126
				mv $DIR_DG_BL/$x $DIR_tmp
-
 
127
			done
200
			rm -rf $DIR_DG_BL $DIR_IP_BL
128
			rm -rf $DIR_DG_BL $DIR_IP_BL
201
			mkdir $DIR_DG_BL $DIR_IP_BL
129
			mkdir $DIR_DG_BL $DIR_IP_BL
202
			tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DG/
130
			tar zxf $DIR_tmp/blacklists.tar.gz --directory=$DIR_DG/
203
		fi
-
 
204
		# Retrieve custom files (ossi)
-
 
205
		for x in $(ls -1 $DIR_tmp | grep "^ossi-*")
-
 
206
		do
-
 
207
			mv $DIR_tmp/$x $DIR_DG_BL
-
 
208
		done
-
 
209
		rm -f $BL_CATEGORIES $WL_CATEGORIES
-
 
210
		rm -rf $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
-
 
211
		touch $BL_CATEGORIES $WL_CATEGORIES
-
 
212
		mkdir $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
-
 
213
		chown -R dansguardian: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
-
 
214
		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
-
 
215
		find $DIR_DG_BL/ -type f -name domains > $FILE_tmp # retrieve directory name where a domain file exist
-
 
216
		$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
-
 
217
		# Add the two local categories (ossi-bl & ossi-wl) to the usage file
131
			# Add the two local categories (ossi-bl & ossi-wl) to the usage file
218
		cat << EOF >> $DIR_DG_BL/global_usage 
132
			cat << EOF >> $DIR_DG_BL/global_usage 
219
 
133
 
220
NAME: ossi-bl
134
NAME: ossi-bl
221
DEFAULT_TYPE: black
135
DEFAULT_TYPE: black
222
SOURCE: ALCASAR Team
136
SOURCE: ALCASAR Team
223
DESC FR: sites blacklistés ajoutés localement
137
DESC FR: sites blacklistés ajoutés localement
Line 239... Line 153...
239
NAME IT: ossi-wl
153
NAME IT: ossi-wl
240
NAME NL: ossi-wl
154
NAME NL: ossi-wl
241
NAME DE: ossi-wl
155
NAME DE: ossi-wl
242
NAME ES: ossi-wl
156
NAME ES: ossi-wl
243
EOF
157
EOF
-
 
158
			# Retrieve custom files (ossi)
-
 
159
			for x in $(ls -1 $DIR_tmp | grep "^ossi-*")
-
 
160
			do
-
 
161
				mv $DIR_tmp/$x $DIR_DG_BL
-
 
162
			done
-
 
163
		fi
-
 
164
		rm -f $BL_CATEGORIES $WL_CATEGORIES
-
 
165
		rm -rf $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
-
 
166
		touch $BL_CATEGORIES $WL_CATEGORIES
-
 
167
		mkdir $DIR_DNS_BL $DIR_DNS_WL $DIR_IP_BL $DIR_IP_WL
-
 
168
		chown -R dansguardian: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
-
 
169
		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
-
 
170
		find $DIR_DG_BL/ -type f -name domains > $FILE_tmp # retrieve directory name where a domain file exist
-
 
171
		$SED "s?\/domains??g" $FILE_tmp # remove "/domains" suffix
244
		for dir_categorie in `cat $FILE_tmp` # create the blacklist and the whitelist files
172
		for dir_categorie in `cat $FILE_tmp` # create the blacklist and the whitelist files
245
		do
173
		do
246
			categorie=`echo $dir_categorie|cut -d "/" -f6`
174
			categorie=`echo $dir_categorie|cut -d "/" -f6`
247
			categorie_type=`grep -A1 ^NAME:[$' '$'\t']*$categorie $DIR_DG_BL/global_usage | grep ^DEFAULT_TYPE | cut -d":" -f2 | tr -d " \t"`
175
			categorie_type=`grep -A1 ^NAME:[$' '$'\t']*$categorie $DIR_DG_BL/global_usage | grep ^DEFAULT_TYPE | cut -d":" -f2 | tr -d " \t"`
248
			if [ "$categorie_type" == "white" ]
176
			if [ "$categorie_type" == "white" ]
249
			then
177
			then
250
				echo "$dir_categorie" >> $WL_CATEGORIES 
178
				echo "$dir_categorie" >> $WL_CATEGORIES 
-
 
179
			else
-
 
180
				echo "$dir_categorie" >> $BL_CATEGORIES
251
			fi
181
			fi
252
			echo "$dir_categorie" >> $BL_CATEGORIES
-
 
253
		done
182
		done
254
		rm -f $FILE_tmp
183
		rm -f $FILE_tmp
255
		# Verify that the enabled categories are effectively in the BL (need after an update of the BL)
184
		# Verify that the enabled categories are effectively in the BL (need after an update of the BL)
256
		for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED` 
185
		for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED` 
257
		do
186
		do