Project

General

Profile

Feature #4925 » sqg.sh

Yannick Warnier, 13/07/2012 05:41

 
1
#!/bin/bash
2

    
3
# Variables
4
enabled_blacklist_file=/var/sqg/blacklists
5
blacklist_dir=/var/squidGuard/blacklists
6
squidguard_config_file=/etc/squid/squidGuard.conf
7
tmp_file=/tmp/squidGuard.conf
8
logdir=/var/log/squidGuard
9

    
10
hostname='schoolserver'
11

    
12
# SquidGuard.conf - Blacklists
13
oldIFS=$IFS     # conserva el separador de campo
14
IFS=$'\n'     # nuevo separador de campo, el caracter fin de línea
15
for list in $(cat "$blacklist_file")
16
do
17
	s_blacklist="$s_blacklist!$list "
18
	dest="$dest\ndest $list{\n\tlog\t$list\n"
19
	[ -e "$blacklist_dir/$list/domains" ] && dest="$dest\tdomainlist\t$list/domains\n"
20
	[ -e "$blacklist_dir/$list/urls" ] && dest="$dest\turllist\t$list/urls\n"
21
	dest="$dest}\n"
22
done
23
IFS=$old_IFS
24

    
25
# SquidGuard.conf - Variables
26
cabecera="dbhome $blacklist_dir\nlogdir $logdir\n\n"
27

    
28
# SquidGuard.conf - Reglas
29
ACL="pass $s_blacklist all"
30
s_redirect="redirect     302:http://$hostname/cgi-bin/squidGuard.cgi?clientaddr=%a&clientname=%n&clientident=%i&srcclass=%s&targetgroup=%t&url=%u"
31
s_acl="acl {\n\tdefault {\n\t\t$ACL\n\t\t$s_redirect\n\t}\n}"
32

    
33
# Creacion de archivo squidGuard.conf
34
echo -e "$cabecera" > $tmp_file
35
echo -e "$dest" >> $tmp_file
36
echo -e "$s_acl" >> $tmp_file
37

    
38
# Asegurar permisos
39
chown -R squid:squid $blacklist_dir
40
chown -R squid:squid $logdir
41

    
42
#REINICIA EL SERVICIO
43
cp -f "$tmp_file" "$squidguard_config_file"
44
/sbin/service squid reload
(5-5/6)