Subversion Repositories ALCASAR

Rev

Rev 3195 | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
2223 tom.houday 1
#!/bin/bash
881 richard 2
 
2223 tom.houday 3
# Id: $Id: alcasar-url_filter_bl.sh 3263 2025-03-25 23:14:18Z rexy $
4
 
881 richard 5
# alcasar-url_filter.sh
882 richard 6
# by REXY
881 richard 7
# This script is distributed under the Gnu General Public License (GPL)
8
 
1843 raphael.pi 9
# Active / désactive : safesearch des moteurs de recherche
2454 tom.houday 10
# Enable / disable : search engines safesearch
882 richard 11
# Active / désactive : le filtrage des url contenant une adresse ip à la place d'un nom de domaine
2454 tom.houday 12
# Enable / disable : filter of urls containing ip address instead of domain name
881 richard 13
 
2688 lucas.echa 14
CONF_FILE="/usr/local/etc/alcasar.conf"
3195 rexy 15
DIR_DG_GROUP1="/etc/e2guardian/lists/group1"
881 richard 16
SED="/bin/sed -i"
17
safesearch="Off"
18
pureip="Off"
2688 lucas.echa 19
usage="Usage: alcasar-url_filter_bl.sh { -safesearch_on or -safesearch_off } & { -pureip_on or -pureip_off }"
2648 lucas.echa 20
 
2688 lucas.echa 21
nb_args=$#
22
if [ $nb_args -lt 1 ]
881 richard 23
then
882 richard 24
	echo "$usage"
2688 lucas.echa 25
	exit 1
26
fi
27
 
28
while [ $nb_args -ge 1 ]
29
do
30
	arg=${!nb_args}
31
	case $arg in
32
	-\? | -h* | --h*)
33
		echo "$usage"
34
		exit 0
35
		;;
36
	# Safe search activation
37
	-safesearch_on | --safesearch_on)
38
		safesearch="On"
39
		;;
40
	# Safe search deactivation
41
	-safesearch_off | --safesearch_off)
42
		safesearch="Off"
43
		;;
44
	# pure_ip activation
45
	-pureip_on | --pureip_on)
46
		pureip="On"
47
		;;
48
	# pureip deactivation
49
	-pureip_off | --pureip_off)
50
		pureip="Off"
51
		;;
52
	*)
53
		echo "Argument inconnu :$arg";
54
		echo "$usage"
55
		exit 1
56
		;;
57
	esac
58
nb_args=$(expr $nb_args - 1)
59
done
60
 
61
if [ "$safesearch" == "On" ]
62
then
3263 rexy 63
	$SED "s?^#\"?\"?g" $DIR_DG_GROUP1/urlregexplist # uncomment rules lines
64
	# Before we wrote a special Unbound file with redirection. Ex. for google safesearching
65
	# google_safe_server=`host -ta forcesafesearch.google.com | grep "address" | cut -d" " -f4`	# retrieve google forcesafesearch ip
66
	# echo "server:" > $UNBOUND_BL_DOMAIN_FILTER_CONF
67
	# for domain in "google.com. google.ad. google.ae. google.com.af. google.com.ag. google.com etc."
68
	# do
69
	#	echo -e "\tlocal-zone: \"$domain\" redirect" >> $UNBOUND_BL_DOMAIN_FILTER_CONF
70
	#	echo -e "\tlocal-data: \"$domain A $google_safe_server\"" >> $UNBOUND_BL_DOMAIN_FILTER_CONF
71
	# done
72
	#
73
	# If enable again, add/remove "safe-searching" file in /etc/unbound/conf.d/blacklist (in this file, CNAME is used instead of REDIRECT)
2688 lucas.echa 74
	$SED 's/^BL_SAFESEARCH=.*/BL_SAFESEARCH=on/g' $CONF_FILE
75
elif [ "$safesearch" == "Off" ]
76
then
3263 rexy 77
	$SED "s?^[^#]?#&?g" $DIR_DG_GROUP1/urlregexplist # comment rules lines
2688 lucas.echa 78
 
79
	$SED 's/^BL_SAFESEARCH=.*/BL_SAFESEARCH=off/g' $CONF_FILE
80
fi
81
 
82
if [ "$pureip" == "On" ]
83
then
3195 rexy 84
	$SED "s/^\#\*ip$/*ip/g" $DIR_DG_GROUP1/bannedsitelist
85
	$SED "s/^\#\*ips$/*ips/g" $DIR_DG_GROUP1/bannedsitelist
2688 lucas.echa 86
 
87
	$SED 's/^BL_PUREIP=.*/BL_PUREIP=on/g' $CONF_FILE
88
elif [ "$pureip" == "Off" ]
89
then
3195 rexy 90
	$SED "s/^\*ip$/#*ip/g" $DIR_DG_GROUP1/bannedsitelist
91
	$SED "s/^\*ips$/#*ips/g" $DIR_DG_GROUP1/bannedsitelist
2688 lucas.echa 92
 
93
	$SED 's/^BL_PUREIP=.*/BL_PUREIP=off/g' $CONF_FILE
94
fi
2521 armand.ito 95
systemctl restart e2guardian
2688 lucas.echa 96
systemctl restart unbound-blacklist