/
nethserver-squidguard-update-custom-list
executable file
·58 lines (52 loc) · 1.95 KB
/
nethserver-squidguard-update-custom-list
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/perl
#
# Copyright (C) 2014 Nethesis S.r.l.
# http://www.nethesis.it - support@nethesis.it
#
# This script is part of NethServer.
#
# NethServer is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License,
# or any later version.
#
# NethServer is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NethServer. If not, see .
#
use File::Path;
use esmith::ConfigDB;
my $db = esmith::ConfigDB->open_ro('contentfilter');
my $dir = '/var/squidGuard/blacklists/custom/';
my $event = shift;
# clean up directory
rmtree($dir);
mkdir $dir;
foreach ($db->get_all_by_prop(type => 'category')) {
my $urls = $_->prop('URLs') || '';
my $domains = $_->prop('Domains') || '';
my $name = $_->key;
$urls =~ s/,/\n/g;
$domains =~ s/,/\n/g;
mkdir "$dir/$name";
open (FILE, ">$dir/$name/urls");
print FILE $urls;
close (FILE);
open (FILE, ">$dir/$name/domains");
print FILE $domains;
close (FILE);
}
mkdir "/var/squidGuard/blacklists/custom/whitelist";
mkdir "/var/squidGuard/blacklists/custom/files";
mkdir "/var/squidGuard/blacklists/custom/blacklist";
system("/sbin/e-smith/expand-template /var/squidGuard/blacklists/custom/whitelist/domains");
system("/sbin/e-smith/expand-template /var/squidGuard/blacklists/custom/files/expressions");
system("/sbin/e-smith/expand-template /var/squidGuard/blacklists/custom/blacklist/domains");
system("/sbin/e-smith/expand-template /etc/ufdbguard/ufdbGuard.conf");
system("/usr/sbin/ufdbConvertDB /var/squidGuard/blacklists/custom/ >/dev/null 2>&1");
system("chown -R squid:squid /var/squidGuard/blacklists/custom/");
exit 0