Subversion Repositories ALCASAR

Rev

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

Rev 1383 Rev 1386
Line 1... Line 1...
1
#/bin/bash
1
#/bin/bash
2
 
2
 
3
# $Id: alcasar-bl.sh 1383 2014-06-11 22:30:51Z richard $
3
# $Id: alcasar-bl.sh 1386 2014-06-12 14:53:07Z 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 41... Line 41...
41
 
41
 
42
# enable/disable the BL & WL categories
42
# enable/disable the BL & WL categories
43
function cat_choice (){
43
function cat_choice (){
44
	# saving ip files and ossi category
44
	# saving ip files and ossi category
45
	mkdir $DIR_tmp
45
	mkdir $DIR_tmp
-
 
46
	if [ $(find $DIR_IP_BL_ENABLED -name "ossi-*" | wc -l) -ne 0 ]
-
 
47
	then
46
	cp $DIR_IP_BL_ENABLED/ossi-* $DIR_tmp
48
		cp $DIR_IP_BL_ENABLED/ossi-* $DIR_tmp
-
 
49
	fi
47
	cp $DIR_IP_BL/ossi $DIR_tmp
50
	cp $DIR_IP_BL/ossi $DIR_tmp
48
	rm -rf $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED $DIR_IP_WL_ENABLED # cleaning for dnsmasq and iptables
51
	rm -rf $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED $DIR_IP_WL_ENABLED # cleaning for dnsmasq and iptables
49
	$SED "/\.Include/d" $DIR_DG/bannedsitelist $DIR_DG/bannedurllist # cleaning for DG
52
	$SED "/\.Include/d" $DIR_DG/bannedsitelist $DIR_DG/bannedurllist # cleaning for DG
50
	$SED "s?^[^#]?#&?g" $BL_CATEGORIES $WL_CATEGORIES # cleaning BL & WL categories file (comment all lines)
53
	$SED "s?^[^#]?#&?g" $BL_CATEGORIES $WL_CATEGORIES # cleaning BL & WL categories file (comment all lines)
51
	mkdir $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED $DIR_IP_WL_ENABLED
54
	mkdir $DIR_DNS_BL_ENABLED $DIR_DNS_WL_ENABLED $DIR_IP_BL_ENABLED $DIR_IP_WL_ENABLED
Line 73... Line 76...
73
	sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
76
	sort +0.0 -0.2 $WL_CATEGORIES -o $FILE_tmp
74
	mv $FILE_tmp $WL_CATEGORIES
77
	mv $FILE_tmp $WL_CATEGORIES
75
	# restoring ip files and ossi category
78
	# restoring ip files and ossi category
76
	mv $DIR_tmp/ossi $DIR_IP_BL
79
	mv $DIR_tmp/ossi $DIR_IP_BL
77
	chown apache $DIR_IP_BL/ossi
80
	chown apache $DIR_IP_BL/ossi
-
 
81
	if [ $(find $DIR_tmp -name "ossi-*" | wc -l) -ne 0 ]
-
 
82
	then
78
	mv $DIR_tmp/ossi-* $DIR_IP_BL_ENABLED
83
		mv $DIR_tmp/ossi-* $DIR_IP_BL_ENABLED
-
 
84
	fi
79
	rm -rf $DIR_tmp
85
	rm -rf $DIR_tmp
80
}
86
}
81
function bl_enable (){
87
function bl_enable (){
82
	$SED "s/^reportinglevel =.*/reportinglevel = 3/g" /etc/dansguardian/dansguardian.conf
88
	$SED "s/^reportinglevel =.*/reportinglevel = 3/g" /etc/dansguardian/dansguardian.conf
83
	if [ "$PARENT_SCRIPT" != "alcasar-conf.sh" ] # don't launch on install stage
89
	if [ "$PARENT_SCRIPT" != "alcasar-conf.sh" ] # don't launch on install stage
Line 108... Line 114...
108
	# retrieving IPs of all domain names for the whitelist
114
	# retrieving IPs of all domain names for the whitelist
109
	index=0
115
	index=0
110
	if [ ! -d $DIR_IP_WL ]
116
	if [ ! -d $DIR_IP_WL ]
111
	then
117
	then
112
		mkdir $DIR_IP_WL
118
		mkdir $DIR_IP_WL
-
 
119
		touch $DIR_IP_WL/ossi
-
 
120
		chown apache $DIR_IP_WL/ossi
113
	else
121
	else
-
 
122
		# delete old IPs
-
 
123
		mkdir $DIR_tmp
-
 
124
		cp $DIR_IP_WL/ossi $DIR_tmp
114
		rm -rf $DIR_IP_WL/*
125
		rm -rf $DIR_IP_WL/*
-
 
126
		cp $DIR_tmp/ossi $DIR_IP_WL
-
 
127
		rm -rf $DIR_tmp
115
	fi
128
	fi
116
	echo "Retrieving IPs :"
129
	echo "Retrieving IPs :"
117
	cd $DIR_DNS_WL
130
	cd $DIR_DNS_WL
118
	for category in `ls | cut -d '.' -f 1`
131
	for category in `ls | cut -d '.' -f 1`
119
	do
132
	do
Line 129... Line 142...
129
				sleep 1
142
				sleep 1
130
			fi
143
			fi
131
		done
144
		done
132
	done
145
	done
133
	echo "done"
146
	echo "done"
134
	sleep 2
147
	sleep 5
135
	cd $DIR_IP_WL
148
	cd $DIR_IP_WL
136
	for category in `ls`
149
	for category in `ls`
137
	do
150
	do
138
		# one IP per line
151
		# one IP per line
139
		$SED 's/ /\n/g' $category
152
		$SED 's/ /\n/g' $category
Line 153... Line 166...
153
	> $OSSI_WL_IP
166
	> $OSSI_WL_IP
154
	for domain in `cat $OSSI_DOMAINS_WL`
167
	for domain in `cat $OSSI_DOMAINS_WL`
155
	do
168
	do
156
		echo `host $domain | grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}'` >> $OSSI_WL_IP &
169
		echo `host $domain | grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}'` >> $OSSI_WL_IP &
157
	done
170
	done
158
	sleep 2
171
	sleep 5
159
	# one IP per line
172
	# one IP per line
160
	$SED 's/ /\n/g' $OSSI_WL_IP
173
	$SED 's/ /\n/g' $OSSI_WL_IP
161
	# add SET syntax
174
	# add SET syntax
162
	$SED 's/^/add whitelist_ip_allowed /g' $OSSI_WL_IP
175
	$SED 's/^/add whitelist_ip_allowed /g' $OSSI_WL_IP
163
	# delete empty lines
176
	# delete empty lines