Subversion Repositories ALCASAR

Rev

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

Rev 1867 Rev 1870
Line 1... Line 1...
1
#/bin/bash
1
#/bin/bash
2
 
2
 
3
# $Id: alcasar-bl.sh 1867 2016-05-04 12:22:08Z raphael.pion $
3
# $Id: alcasar-bl.sh 1870 2016-05-04 14:55:06Z raphael.pion $
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 102... Line 102...
102
		touch $DIR_DNS_WL/ossi.conf
102
		touch $DIR_DNS_WL/ossi.conf
103
		chown apache $DIR_DNS_WL/ossi.conf
103
		chown apache $DIR_DNS_WL/ossi.conf
104
		ln -s $DIR_DNS_WL/ossi.conf $DIR_DNS_WL_ENABLED/ossi
104
		ln -s $DIR_DNS_WL/ossi.conf $DIR_DNS_WL_ENABLED/ossi
105
	fi
105
	fi
106
 
106
 
-
 
107
	# update categories with rsync
-
 
108
	if [ ! -e $DIR_CONF/update_cat.conf ]
-
 
109
	then
-
 
110
		touch $DIR_CONF/update_cat.conf
-
 
111
		chown root:apache $DIR_CONF/update_cat.conf
-
 
112
		chmod 660 $DIR_CONF/update_cat.conf
107
	
113
	fi
108
	
114
	
109
	$SED "/\.Include/d" $DIR_DG/bannedsitelist $DIR_DG/bannedurllist # cleaning for DG
115
	$SED "/\.Include/d" $DIR_DG/bannedsitelist $DIR_DG/bannedurllist # cleaning for DG
110
	$SED "s?^[^#]?#&?g" $BL_CATEGORIES $WL_CATEGORIES # cleaning BL & WL categories file (comment all lines)
116
	$SED "s?^[^#]?#&?g" $BL_CATEGORIES $WL_CATEGORIES # cleaning BL & WL categories file (comment all lines)
111
	# process the file $BL_CATEGORIES with the choice of categories 
117
	# process the file $BL_CATEGORIES with the choice of categories 
112
	for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED` 
118
	for ENABLE_CATEGORIE in `cat $BL_CATEGORIES_ENABLED` 
Line 135... Line 141...
135
	chown apache $DIR_IP_BL/ossi
141
	chown apache $DIR_IP_BL/ossi
136
	rm -rf $DIR_tmp
142
	rm -rf $DIR_tmp
137
	
143
	
138
}
144
}
139
 
145
 
140
usage="Usage: alcasar-bl.sh { -cat_choice or --cat_choice } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload } | { -update_cat or --update_cat } & categorie & url_rsync"
146
usage="Usage: alcasar-bl.sh { -cat_choice or --cat_choice } | { -download or --download } | { -adapt or --adapt } | { -reload or --reload } | { -update_cat or --update_cat }"
141
nb_args=$#
147
nb_args=$#
142
args=$1
148
args=$1
143
if [ $nb_args -eq 0 ]
149
if [ $nb_args -eq 0 ]
144
then
150
then
145
	  args="-h"
151
	  args="-h"
Line 250... Line 256...
250
		echo
256
		echo
251
		;;
257
		;;
252
		#mise a jour d'une categorie avec rsync
258
		#mise a jour d'une categorie avec rsync
253
		-update_cat | --update_cat)
259
		-update_cat | --update_cat)
254
		
260
		
255
		if [ $# -ge 3 ]
261
		echo -n "Updating categories in /usr/local/etc/update_cat.conf ..."
-
 
262
 
256
		then
263
		
257
		echo -n "Updating $2 category ..."
264
		for LIGNE_RSYNC in $(cat /usr/local/etc/update_cat.conf)
-
 
265
		do
258
 
266
 
-
 
267
		$CATEGORIE=$(echo $LIGNE_RSYNC | cut -d' ' -f0)
-
 
268
		$URL=$(echo $LIGNE_RSYNC | cut -d' ' -f1)
-
 
269
	
259
		PATH_FILE=$(find $DIR_DG_BL/ -type d -name $2) # retrieve directory name of the category
270
		PATH_FILE=$(find $DIR_DG_BL/ -type d -name $CATEGORIE) # retrieve directory name of the category
260
		rsync -rv $3 $(dirname $PATH_FILE ) #rsync inside of the blacklist directory
271
		echo "rsync -rv $URL $(dirname $PATH_FILE )" #rsync inside of the blacklist directory
-
 
272
		echo $PATH_FILE
261
		
273
		
262
		# Creation of DNSMASQ and Iptables BL and WL
274
		# Creation of DNSMASQ and Iptables BL and WL
263
		DOMAINE=$(basename $PATH_FILE)
275
		DOMAINE=$(basename $PATH_FILE)
264
		
276
		
265
		$SED "s/\.\{2,10\}/\./g" $PATH_FILE/domains $PATH_FILE/urls # correct some syntax errors
277
		$SED "s/\.\{2,10\}/\./g" $PATH_FILE/domains $PATH_FILE/urls # correct some syntax errors
Line 275... Line 287...
275
		then
287
		then
276
			# adapt to the dnsmasq syntax for the blacklist
288
			# adapt to the dnsmasq syntax for the blacklist
277
			$SED "s?.*?address=/&/$PRIVATE_IP?g" $FILE_tmp 
289
			$SED "s?.*?address=/&/$PRIVATE_IP?g" $FILE_tmp 
278
			mv $FILE_tmp $DIR_DNS_BL/$DOMAINE.conf
290
			mv $FILE_tmp $DIR_DNS_BL/$DOMAINE.conf
279
			mv $FILE_ip_tmp $DIR_IP_BL/$DOMAINE
291
			mv $FILE_ip_tmp $DIR_IP_BL/$DOMAINE
280
			/usr/bin/systemctl restart dnsmasq-blacklist
-
 
281
		else
292
		else
282
			# adapt to the dnsmasq syntax for the whitelist
293
			# adapt to the dnsmasq syntax for the whitelist
283
			$SED "s?.*?server=/&/$DNS1?g" $FILE_tmp 
294
			$SED "s?.*?server=/&/$DNS1?g" $FILE_tmp 
284
			mv $FILE_tmp $DIR_DNS_WL/$DOMAINE.conf
295
			mv $FILE_tmp $DIR_DNS_WL/$DOMAINE.conf
285
			/usr/bin/systemctl restart dnsmasq-whitelist
-
 
286
		fi
296
		fi
287
 
-
 
288
		rm -f $FILE_tmp $FILE_ip_tmp
297
		rm -f $FILE_tmp $FILE_ip_tmp
-
 
298
 
-
 
299
		done
-
 
300
		
-
 
301
		/usr/bin/systemctl restart dnsmasq-whitelist
-
 
302
		/usr/bin/systemctl restart dnsmasq-blacklist
289
		/usr/bin/systemctl restart dansguardian
303
		/usr/bin/systemctl restart dansguardian
290
		/usr/local/bin/alcasar-iptables.sh
304
		/usr/local/bin/alcasar-iptables.sh
291
		
305
		
292
		echo "MAJ RSYNC réussie"
306
		echo "MAJ RSYNC réussie"
293
	
307
	
294
		else
-
 
295
			echo "$usage"
-
 
296
		fi
-
 
297
		;;
308
		;;
298
	# reload when categories are changed 
309
	# reload when categories are changed 
299
	-reload | --reload)
310
	-reload | --reload)
300
		# for DG
311
		# for DG
301
		chown -R dansguardian:apache $DIR_DG_BL/ossi
312
		chown -R dansguardian:apache $DIR_DG_BL/ossi