-
Notifications
You must be signed in to change notification settings - Fork 1
/
squidguard_conf.pm
executable file
·759 lines (707 loc) · 26.2 KB
/
squidguard_conf.pm
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
#
# $Id: squidguard_conf.pm,v 2.7 2007/01/27 17:30:48 pv Exp $
#
package squidguard_conf;
use strict;
use vars qw(@ISA);
use subs qw(exit);
use Config::IniFiles;
use locale;
# You can get some additional Messages in STDERR (the apache error-logfile)
# if you set $DEBUG to 1.
my $DEBUG=0; # 0=off; 1=on
# We have to set some "hardcoded variables" for our configuration files:
my $blacklist_server_file = "/etc/squid/blacklist_servers";
my $squidguard_conf = "/etc/squid/squidguard.conf";
if ($DEBUG){ use Data::Dumper; }
sub ReadSquidGuardConf{
my $sg_config = shift;
open(CONF, $sg_config);
my @c=<CONF>;
close(CONF);
my @config=();
for (my $i=0; $i < @c ; $i++) {
next if (!$c[$i] );
#|| ($c[$i] =~ /^#/));
if ($c[$i] =~ /^dbhome\s+(\S+)/) {
# find dbhome
my %section;
$section{'sectype'}='dbhome';
$section{'dbhome'}=$1;
$section{'line'}=$i;
push(@config, \%section);
}
elsif ($c[$i] =~ /^logdir\s+(\S+)/)
{
# find logdir
my %section;
$section{'sectype'}='logdir';
$section{'logdir'}=$1;
$section{'line'}=$i;
push(@config, \%section);
}
# elsif ($c[$i] =~ /^\#\s+(dest|destination)\s+([-_.a-zA-Z0-9]+)(\s+(within|outside)\s+([-_.a-zA-Z0-9]+))?\s+\{\s*$/)
elsif( $c[$i] =~ /^\#\s*(dest|destination)\s+([-_.a-zA-Z0-9]+)(\s+(within|outside)\s+([-_.a-zA-Z0-9]+))?\s+\{\s*$/)
{
# destination is disabled
my %section;
$section{'sectype'}='disabled_dest';
$section{'secname'}=$2;
$section{'line'}=$i;
while(($i <= scalar(@c)) && ($c[$i] !~ /^\#\s*\}/))
{
while ($c[$i] !~ /\}$/) {
if ($c[$i] =~ /^\#\s+domainlist\s+(\S+)/)
{
$section{'disabled_domainlist'}=$1;
$section{'disabled_domainlist_line'} = $i;
}
elsif ($c[$i] =~ /\#\s+urllist\s+(\S+)/)
{
$section{'disabled_urllist'}=$1;
$section{'disabled_urllist_line'} = $i;
}
elsif ($c[$i] =~ /\#\s+expressionlist\s+(\S+)/)
{
$section{'disabled_exprlist'}=$1;
$section{'disabled_exprlist_line'} = $i;
}
elsif ($c[$i] =~ /\#\s+log\s+(\S+)/)
{
$section{'disabled_log'}=$1;
$section{'disabled_log_line'} = $i;
}
$i++;
}
push(@config, \%section);
} # end while
} # end if disabled_dest
elsif ($c[$i] =~ /^(dest|destination)\s+([-_.a-zA-Z0-9]+)(\s+(within|outside)\s+([-_.a-zA-Z0-9]+))?\s+\{\s*$/)
{
# find destination group
my %section;
$section{'sectype'}='dest';
$section{'secname'}=$2;
$section{'line'}=$i;
while(($i <= scalar(@c)) && ($c[$i] !~ /^\s*\}/))
{
while ($c[$i] !~ /\}/) {
if ($c[$i] =~ /^\s+domainlist\s+(\S+)/)
{
$section{'domainlist'}=$1;
$section{'domainlist_line'} = $i;
}
elsif ($c[$i] =~ /^\s+urllist\s+(\S+)/)
{
$section{'urllist'}=$1;
$section{'urllist_line'} = $i;
}
elsif ($c[$i] =~ /^\s+expressionlist\s+(\S+)/)
{
$section{'exprlist'}=$1;
$section{'exprlist_line'} = $i;
}
elsif ($c[$i] =~ /^\s+log\s+(\S+)/)
{
$section{'log'}=$1;
$section{'log_line'} = $i;
}
$i++;
}
push(@config, \%section);
} # end while
} # endif destgroup
} # endfor
print STDERR "ReadSquidGuardConf: \n".Data::Dumper->Dump([@config]) if ($DEBUG);
return wantarray ? @config : \@config;
}
sub ReadBlacklistServers{
my $this = shift;
my %dests;
my @dests;
my $i = 1;
my $ini = new Config::IniFiles( -file => "$blacklist_server_file",
-allowcontinue =>1);
# usefull data? if not, display an error message
if( ! $ini )
{
exit 1;
}
foreach my $section ( $ini->Sections())
{
my $serverurl = $ini->val($section, 'url');
foreach my $line ($ini->val($section,'dests'))
{
my ($external,$local)=split /=>/,$line,2;
my %section;
$section{'sectype'}='bl_dest';
$section{'local'}=$local;
$section{'extern'}=$external;
$section{'number'}=$i;
push(@dests, \%section);
$i++;
}
if ($DEBUG)
{
print STDERR "My Section: ".$section."\n";
print STDERR "\nDestinations:\n".Data::Dumper->Dump([@dests]);
}
}
return $ini;
}
sub writeBlacklistServer{
use File::Temp qw(tempfile);
my $this = shift;
my $edit = shift;
my $servername = shift;
my $old_servername = shift;
my $serverurl = shift;
my $serveractive = shift || 'no';
my $serverdests = shift || '';
my $filename = $blacklist_server_file;
my $ini = new Config::IniFiles( -file => '/etc/squid/blacklist_servers',
-allowcontinue =>1 );
# usefull data? if not, display error message
if( ! $ini )
{
exit 1;
}
if ( ($serveractive eq '1') || ($serveractive eq 'yes'))
{
$serveractive = 'yes';
}
else
{
$serveractive = 'no';
}
if ($DEBUG)
{
print STDERR "\n\nHere is writeBlacklistServer...\n";
print STDERR "Edit: $edit\n";
print STDERR "Servername: $servername\n";
print STDERR "Serverurl : $serverurl\n";
print STDERR "Serverdests: $serverdests\n";
print STDERR "Active : $serveractive\n";
}
my $err='';
# add a new entry or edit an existing one?
if ( $edit eq "new")
{
$ini->AddSection($servername);
$err .= $ini->newval($servername, 'url', $serverurl);
$err .= $ini->newval($servername, 'dests', $serverdests);
$err .= $ini->newval($servername, 'active', $serveractive);
}
elsif ( $edit eq "delete")
{
$ini->DeleteSection($servername);
$err = 'delete';
}
else
{
if ($old_servername ne $servername)
{
$ini->AddSection($servername);
$ini->DeleteSection($old_servername);
$err .= $ini->newval($servername, 'url', $serverurl);
$err .= $ini->newval($servername, 'dests', $serverdests);
$err .= $ini->newval($servername, 'active', $serveractive);
}
else
{
$err .= $ini->setval($servername, 'url', $serverurl);
$err .= $ini->setval($servername, 'dests', $serverdests);
$err .= $ini->setval($servername, 'active', $serveractive);
}
}
# define error-message
if ( $err eq '111')
{
$err = "successful";
}
elsif ( $edit eq 'delete' )
{
$err = "successful";
}
else
{
$err = "failed";
}
# save new config to a temporary file
my ($fh, $file) = tempfile(DIR => "/tmp/");
if(! $ini->WriteConfig( $file ))
{
$err= "bl_unable_to_save";
exit 1;
}
close $fh;
# write contents of the tempfile to $blacklist_servers
my $saved .= "save_bl_server :";
if( ! open $fh, $file)
{
$err="bl_unable_to_save";
exit 1;
}
my @file = <$fh>;
chomp(@file);
## FIXME: do some magic to avoid use of suad here
## my $msg = $session->save_read2session($filename, $filename);
## if( $msg->code() ne "OK" ) {
## if( $msg->code() eq "MD5SUM" )
## {
## $err = "<font color=\"green\">".$message->{'successful'}."</font>";
## exit;
## } else
## {
## $err = "<font color=\"red\">".$message->{'failed'}."</font>";
## exit;
## }
## }
## my $ret = $session->suad_save(\@file, $filename);
## if( $ret->code() ne "OK" )
## {
## $err = "<font color=\"red\">".$message->{'failed'}."</font>";
## exit;
## }
unlink($file);
close $fh;
my $status = "";
$saved .= "";
## display message
exit;
}
sub recompileBlacklist{
my $this = shift;
my $file = shift || "all";
my $ERRORS = '';
my @sgconfig = &ReadSquidGuardConf("$squidguard_conf");
my $sec = &find_section( 'config' => \@sgconfig,
'sectype' => 'dbhome' );
my $dbpath = $sec->{'dbhome'};
## my $ret = $session->suad_stdout_exec("chown -R squid.nogroup $dbpath");
## $ret = $session->suad_stdout_exec("find $dbpath -type f -exec chmod 640 {} \;");
## $ret = $session->suad_stdout_exec("find $dbpath -type d -exec chmod 750 {} \;");
## $ret = $session->suad_stdout_exec("/usr/sbin/squidGuard -c $squidguard_conf -C $file");
## $ret = $session->suad_stdout_exec("chown -R squid.nogroup $dbpath");
# display message
## if ($ret->code() =~/^OK/)
## { $ERRORS .= "<tr><td>".$message->{'recompiling'}." $file</td><td>".$message->{'successful'}."</td></tr>\n"; }
## else
## { $ERRORS .= "<tr><td>".$message->{'recompiling'}." $file</td><td>".$message->{'failed'}."<br>$2</td></tr>\n"; }
return $ERRORS;
}
sub UpdateBlacklist{
my $this = shift;
my $bl_serv_ref = shift;
my $servers = $this->ReadBlacklistServers();
my ($ERROR,$urls);
my @bl_serv;
# check for other processes
if (-f "/var/run/get_blacklist.pid")
{
print STDERR "another_process_is_running";
exit 1;
}
# give the user a message
# first probe if we should update from all servers
if ( ! defined($bl_serv_ref) || $bl_serv_ref eq '')
{
print STDERR "\nHere is UpdateBlacklist : I've to update ALL active servers!\n" if ($DEBUG);
foreach my $section ( $servers->Sections()) { push @bl_serv,$section; }
}
else
{
foreach my $l (@$bl_serv_ref)
{
push @bl_serv,$l;
}
}
# now do the work...
foreach my $server (@bl_serv)
{
$urls .= $servers->val($server, 'url')." ";
}
# fork in the background
my $kind = fork();
if ($kind)
{ return 0; }
else
{
## my $ret = $session->suad_stdout_exec("/usr/sbin/get_blacklist $urls &");
return;
}
# return 0; #$ret;
}
sub saveDomains{
use File::Basename;
my $this = shift;
my $file = shift;
my $content = shift;
my $ERRORS = '';
my (@domains,@urls);
my $tp;
# get the language-specific messages
my @temp = split "\n",$content;
foreach my $l ( @temp )
{
$l =~ s/\r//mg;
$l =~ s/\n\s+\n/\n/mg;
$l =~ s/\n\n/\n/mg; # trim double endlines
$l =~ s/^\s+//; # trim whitespaces from the start
$l =~ s/\s+$//; # trim whitespaces from the end
chomp $l; # not really necessary - only security ;-)
next if ( $l eq '' ); # skip empty lines
if ( $l =~ /:/ ){ # remove protocoll information
$l = (split /:\/\//,$l)[1];
}
if ( $l =~ /\// ) { # => it's an url
push @urls, $l;
} else { # => it's a domain
push @domains, $l;
}
}
# first do some checks to avoid errors
## open()
## my $ret = $session->suad_read($file);
## if(!($ret->code() =~ /^OK/))
# { # something is bad - perhaps the file or directory doesn't exist?
# check the directory:
my @paths=split(/\//,$file);
pop @paths;
$tp=$paths[0];
for (my $i=1; $i<@paths; $i++)
{
if( ! opendir(DIR, "$tp/$paths[$i]") )
{
# $ret = $session->suad_mkdir("$tp/$paths[$i]",775);
# $ret = $session->suad_chown("$tp/$paths[$i]", 'squid', 'nogroup');
print STDERR "$tp/$paths[$i] do not exist!\n";
exit 1;
}
closedir(DIR);
$tp .= "/".$paths[$i];
} # endfor
# } # endif
$tp=dirname($file);
# save files
# domains
sort @domains;
## $ret = $session->suad_save(\@domains, $file);
## $ret = $session->suad_chown($file, 'squid', 'nogroup');
## $ret = $session->suad_chmod($file, '750');
if ( 1 )
{ $ERRORS .= "saving $file successful\n"; }
else
{ $ERRORS .= "saving $file failed\n"; }
# urls
sort @urls;
# $ret = $session->suad_save(\@urls, "$tp/urls");
# $ret = $session->suad_chown("$tp/urls", 'squid', 'nogroup');
# $ret = $session->suad_chmod("$tp/urls", '750');
if ( 1 )
{ $ERRORS .= "saving $tp/urls successful\n"; }
else
{ $ERRORS .= "saving $tp/urls failed\n"; }
return $ERRORS;
}
sub ConfigBlacklist{
my $this = shift;
my $q = $this->{'cgi'};
my $save_blserver = $q->param('new_serversave');
my $new_servername = $q->param('new_servername');
my $old_servername = $q->param('old_servername');
my $new_active = lc($q->param('serveractive'));
my $new_serverurl = $q->param('new_serverurl');
my $new_dests = $q->param('new_dests');
my $bl_add = $q->param('bl_add');
my $bl_delete = $q->param('bl_delete');
my $edit = $q->param('edit');
my @bl_servers = $q->param('bl_servers');
my $bl_update = $q->param('bl_update');
my $bl_config = $q->param('bl_config');
my $bl_reload_list = $q->param('bl_reload_list');
my $conf_server = $bl_servers[0];
my $editserver = '';
my @blacklist_server= ();
my @localdests =($message->{'ignore_list'});
my %dests;
# Make an Blacklist update from the given servers
if (defined $bl_update && $bl_update ne '' && defined @bl_servers)
{ $this->UpdateBlacklist(\@bl_servers); }
# Get Blacklist-Servers from file
my $ini = new Config::IniFiles( -file => "$blacklist_server_file",
-allowcontinue =>1 );
# usefull data? if not, display an error message
if( ! $ini )
{
$this->display_error($message->{'bl_unable_to_open'},
$confParam->{cgi_path}."/squidguard_conf.pl?sessionID=$sessionID\&tab=$tab\&stab=$stab");
exit;
}
foreach my $section ( $ini->Sections())
{
next if ("$section" eq "global");
push @blacklist_server, $section;
}
# Get domainlist from SquidGuards configuration
my @sgconfig = &ReadSquidGuardConf("$squidguard_conf");
foreach my $sec (@sgconfig)
{
if ( ($sec->{'sectype'} eq "dest") && (($sec->{'secname'} ne 'bad') && ($sec->{'secname'} ne 'good')))
{ push @localdests,$sec->{'secname'}; }
}
# Save entries?
if ((defined($save_blserver) && $save_blserver ne '') || (defined($bl_delete) && $bl_delete ne ''))
{
my $ERROR='';
if ($new_active eq ''){ $new_active='no'; }
else { $new_active='yes'; }
# check required fields
if ($new_servername eq '') { $ERROR .= '<tr><td>'.$message->{'no_servername'}.'</td></tr>'; }
if ($new_serverurl eq '') { $ERROR .= '<tr><td>'.$message->{'no_serverurl'}.'</td></tr>'; }
elsif ( $new_serverurl !~ /(ftp|http):\/\//i ) { $ERROR .= "<tr><td>".$message->{'no_url'}."</td></tr>"; }
# Add a new entry?
if ( defined($edit) && $edit eq 'new')
{
foreach my $server ( $ini->Sections())
{
if ( $server eq $new_servername )
{ $ERROR .= '<tr><td>'.$message->{'servername_exists'}.$new_servername.'</td></tr>'; }
}
}
# display errors or save server
unless (defined($old_servername) && $old_servername ne ''){ $old_servername = ''; }
if ( $ERROR eq '')
{
# should we delete a server?
if ($bl_delete ne '') { $edit = 'delete' };
# Let's do it...
$this->writeBlacklistServer($edit,$new_servername, $old_servername, $new_serverurl,$new_active,$new_dests);
}
else
{
$this->display_head();
print $q->start_table({width=>'100%'}).$q->start_Tr().$q->start_td();
print "<H1>$message->{reload}</H1>";
print $q->end_td().$q->end_Tr().$q->end_table()."\n";
print $q->start_table({width=>'100%'})."\n";
print $ERROR;
print $q->end_table()."\n";
$this->display_footer("$confParam->{cgi_path}/squidguard_conf.pl?sessionID=$sessionID\&tab=$tab\&stab=$stab");
exit 1;
}
}
# configure blacklist server?
if (( defined($conf_server) && $conf_server ne '' ) || (defined($bl_add) && $bl_add ne '')){
my ($servername, $old_servername, $serverurl, $serverdests, $dests) = '';
my (@serverdests);
my $serveractive = '1';
if ($bl_add eq '') {
foreach my $server ( $ini->Sections()) {
next if ("$server" eq "global");
if ( $server eq $conf_server ) {
$servername = $conf_server;
$old_servername = $conf_server;
$serverurl = $ini->val($server,'url');
$serveractive = $ini->val($server,'active');
if (( $serveractive eq 'yes') || ( $serveractive eq 'Yes') || ( $serveractive eq 'YES')) { $serveractive='1';}
else { $serveractive='0'; }
# read destinations
foreach my $value ($ini->val($server,'dests'))
{
my ($external,$local)=split /=>/,$value,2;
if ( defined($bl_reload_list) && $bl_reload_list ne '')
{
my $ret = $session->suad_stdout_exec("/usr/sbin/get_blacklist -g $serverurl");
my $result = $ret->code();
$result =~ s/^OK: 0\s+//mg;
$result =~ tr/ //s;
chomp($result);
@serverdests = split(/ /,$result);
}
else
{ push @serverdests, $external; }
$dests{$external}=$local;
} # end foreach
} # endif
} # end foreach
$editserver .= $q->hidden(-name=>'edit', -value=>'edit');
$editserver .= $q->hidden(-name=>'old_servername', -value=>$old_servername);
} # end edit existing server
else
{ # get a new server
$editserver .= $q->hidden(-name=>'edit', -value=>'new');
}
# html output
$editserver .= $q->Tr( $q->td({-align=>"center",-colspan=>3},'<hr noshade size="2">'));
$editserver .= $q->Tr( $q->td({-align=>"right"}, $message->{bl_server}.":"),
$q->td({-align=>"left"}, $q->textfield(-name=>'new_servername',
-default=>$servername,
-size=>75,
-maxlength=>120,
-override=>1)));
$editserver .= $q->Tr( $q->td({-align=>"right"}, $message->{bl_server_url}.":"),
$q->td({-align=>"left"}, $q->textfield(-name=>'new_serverurl',
-default=>$serverurl,
-size=>75,
-maxlength=>250,
-override=>1)));
$editserver .= $q->start_Tr();
$editserver .= $q->td({-align=>"right"}, $message->{bl_dests}.":");
$editserver .= $q->start_td();
$editserver .= $q->start_table({-width=>"100%"});
$editserver .= $q->Tr($q->td({-align=>"left"}, $message->{'ext_list'}." :"),
$q->td({-align=>"center"}, " "),
$q->td({-align=>"left"}, $message->{'local_list'}." :"));
foreach my $line (@serverdests)
{
my $default='';
foreach my $l (@localdests)
{
if ($dests{$line} eq $l){ $default = $l; }
}
$editserver .= $q->Tr($q->td({align=>"left"}, $line),
$q->td({-align=>"center"}, " => "),
$q->td({-align=>"left"}, $q->popup_menu( -name=>"localdests.$line.$default",
-values=>\@localdests,
-default=>$default,
-labels=>\%dests,
-override=>1)));
}
$editserver .= $q->end_table();
$editserver .= $q->end_td();
$editserver .= $q->end_Tr();
$editserver .= $q->Tr( $q->td(" "),$q->td({-align=>"left"},
$q->submit(-class=>"button",-name=>'bl_reload_list', -value=>$message->{'bl_reload_list'})));
$editserver .= $q->Tr( $q->td({-align=>"right"}, $message->{bl_server_active}),
$q->td({-align=>"left"}, $q->checkbox( -name=>'serveractive',
-checked=>$serveractive,
-value=>$serveractive,
-label=>'')));
$editserver .= $q->Tr( $q->td(" "),$q->td({-align=>"right"},
$q->submit(-class=>"button",-name=>'bl_delete', -value=>$message->{'delete'}),
$q->submit(-class=>"button",-name=>'new_serversave', -value=>$message->{'save'})));
$editserver .= $q->Tr( $q->td({-align=>"center",-colspan=>3},'<hr noshade size="2">'));
} # end if (edit bl_server or new_bl_server)
# Let's start the HTML-Output
my $html= $q->start_table({-class=>'AdminBorder', -cellspacing=>2, -cellpadding=>0, -width=>'100%'});
$html .= $q->start_Tr();
$html .= $q->start_td();
$html .= $q->start_table({-cellspacing=>0, -cellpadding=>3, -width=>'100%'});
$html .= $q->Tr( [ $this->help_th(2, $message->{squidguard_conf},'SQUIDGUARD'),
$q->td({-class=>'AdminSubHeader',-colspan=>'2'}, $message->{bl_server})
]);
$html .= $q->start_multipart_form(-action=>$confParam->{cgi_path}.'/squidguard_conf.pl').
$q->hidden(-name=>'sessionID', -value=>"$sessionID").
$q->hidden(-name=>'tab', -value=>"$tab").
$q->hidden(-name=>'stab', -value=>"$stab");
# get a view of configured blacklist servers:
$html .= $q->start_Tr();
# $html .= $q->start_td();
# $html .= $q->start_table({-cellspacing=>0, -cellpadding=>3, -width=>'100%'});
# $html .= $q->start_Tr();
$html .= $q->td({-align=>'right'}, $message->{active_bl_servers});
$html .= $q->td({-align=>'left'}, $q->scrolling_list( -name=>'bl_servers',
-multiple=>'true',
-value=>\@blacklist_server,
-size=>7 ));
# $html .= $q->end_Tr();
# $html .= $q->end_table();
# $html .= $q->end_td();
# $html .= $q->end_Tr();
# $html .= $q->end_table();
# $html .= $q->end_td();
$html .= $q->end_Tr();
# insert fields for editing or adding a blacklist server, if exists
$html .= $editserver;
# bottom buttons
$html .= $q->Tr( $q->td({-align=>'center', -colspan=>'3'},
$q->submit(-class=>"button",-name=>'squidguard',-value=>$message->{back}),
# $html .= $q->start_td({-align=>'left', -colspan=>'3'});
# $html .= $q->start_table({-cellspacing=>0, -cellpadding=>3, -width=>'100%'});
# $html .= $q->Tr( $q->td({-align=>'left'},
$q->submit(-class=>"button",-name=>'bl_update', -value=>$message->{bl_update}),
# $html .= $q->Tr( $q->td({-align=>'left'},
$q->submit(-class=>"button",-name=>'bl_config', -value=>$message->{bl_config}),
# $html .= $q->Tr( $q->td({-align=>'left'},
$q->submit(-class=>"button",-name=>'bl_add', -value=>$message->{bl_add})));
# $html .= $q->end_table();
# $html .= $q->end_td();
# $html .= $q->end_table();
# $html .= $q->end_td();
$html .= $q->end_Tr();
$html .= $q->end_table();
$html .= $q->end_form();
$this->SUPER::display($html);
}
sub reload{
my $this = shift;
my @gooddom_content = $q->param('gooddom_content');
my @baddom_content = $q->param('baddom_content');
my @sgconfig = &ReadSquidGuardConf("$squidguard_conf");
my $sec = &find_section( 'config' => \@sgconfig,
'sectype' => 'dbhome' );
my $dbpath = $sec->{'dbhome'};
my $gooddom = &find_section( 'config' => \@sgconfig,
'sectype' => 'dest',
'secname' => 'good' );
my $baddom = &find_section( 'config' => \@sgconfig,
'sectype' => 'dest',
'secname' => 'bad' );
my $ERRORS=$this->saveDomains($dbpath.'/'.$gooddom->{'domainlist'}, 'gooddom_content');
print $ERRORS;
$ERRORS=$this->saveDomains($dbpath.'/'.$baddom->{'domainlist'}, 'baddom_content');
print $ERRORS;
# recompile squidGuards blacklists
$ERRORS=$this->recompileBlacklist($dbpath.'/'.$gooddom->{'domainlist'});
print $ERRORS;
$ERRORS=$this->recompileBlacklist($dbpath.'/'.$baddom->{'domainlist'});
print $ERRORS;
$ERRORS=$this->recompileBlacklist($dbpath.'/'.$gooddom->{'urllist'});
print $ERRORS;
$ERRORS=$this->recompileBlacklist($dbpath.'/'.$baddom->{'urllist'});
print $ERRORS;
# reload squid
## my $ret = $session->suad_service_exec('squid', 'reload');
## $ret->code() =~ /OK:\s(\d+?)\s(.*)/ms;
## if( $1 != 0 ){
$ERRORS="reload_squid failed\n";
# } else {
$ERRORS="reload_squid successful\n";
# }
print $ERRORS;
}
sub find_section {
my %args=@_;
my $c;
foreach $c (@{$args{'config'}}) {
my $ok=1;
for (keys %args) {
next if ($_ eq 'config');
if ($c->{$_} !~ /^$args{$_}$/) {
$ok=0;
last;
}
}
return $c if ($ok);
}
return undef;
}
sub check_and_create {
my $this = shift;
my $file = shift;
# my $ret = $session->suad_read($file);
# if($ret->code() !~ /^OK/) {
print STDERR "$file not found - creating\n" if ( $DEBUG );
my @foo = ('');
# $session->suad_save(\@foo,$file);
# $session->suad_chmod($file, '750' );
# $ret = $session->suad_chown($file, 'squid', 'nogroup');
# }
# if ( $ret->code() =~ /^OK/) {
# return 0;
# } else {
# return 1;
# }
}
1;