HinzugefĆ¼gt:
authorms <ms@ea5c0bd1-69bd-2848-81d8-4f18e57aeed8>
Fri, 30 Jun 2006 14:25:35 +0000 (14:25 +0000)
committerms <ms@ea5c0bd1-69bd-2848-81d8-4f18e57aeed8>
Fri, 30 Jun 2006 14:25:35 +0000 (14:25 +0000)
  * URL-Filter

git-svn-id: http://svn.ipfire.org/svn/ipfire/trunk@185 ea5c0bd1-69bd-2848-81d8-4f18e57aeed8

23 files changed:
config/cron/crontab
config/etc/logrotate.conf
config/httpd/httpd.conf
config/urlfilter/autoupdate.pl [new file with mode: 0644]
config/urlfilter/autoupdate.urls [new file with mode: 0644]
config/urlfilter/blacklists.tar.gz [new file with mode: 0644]
config/urlfilter/makeconf.pl [new file with mode: 0644]
config/urlfilter/prebuild.pl [new file with mode: 0644]
config/urlfilter/squidGuard.conf [new file with mode: 0644]
html/cgi-bin/logs.cgi/urlfilter.dat [new file with mode: 0644]
html/cgi-bin/proxy.cgi
html/cgi-bin/redirect.cgi [new file with mode: 0644]
html/cgi-bin/urlfilter.cgi [new file with mode: 0644]
html/html/images/urlfilter/1x1.gif [new file with mode: 0644]
html/html/images/urlfilter/background.jpg [new file with mode: 0644]
html/html/images/urlfilter/led-green.gif [new file with mode: 0644]
html/html/images/urlfilter/led-red.gif [new file with mode: 0644]
langs/de/cgi-bin/de.pl
langs/en/cgi-bin/en.pl
lfs/configroot
lfs/linux
lfs/squid
lfs/squidguard

index 9b08f06..2b74778 100644 (file)
@@ -33,4 +33,9 @@ HOME=/
                find /var/log/logwatch/ -ctime +${LOGWATCH_KEEP=56} -exec rm -f '{}' ';'
 
 # hddshutdown
-00 * * * *     /usr/local/bin/hddshutdown >/dev/null
\ No newline at end of file
+00 * * * *     /usr/local/bin/hddshutdown >/dev/null
+
+# URL Filter
+%nightly * 3-5   /var/ipfire/urlfilter/autoupdate/cron.daily
+%weekly  * 3-5   /var/ipfire/urlfilter/autoupdate/cron.weekly
+%monthly * 3-5 * /var/ipfire/urlfilter/autoupdate/cron.monthly
index d420936..3b29695 100644 (file)
@@ -73,3 +73,12 @@ compress
        /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
     endscript
 }
+
+/var/log/squidGuard/*.log {
+    weekly
+    rotate 4
+    copytruncate
+    compress
+    notifempty
+    missingok
+}
index b5ba5db..9ce0e71 100644 (file)
@@ -18,7 +18,8 @@ MaxSpareServers 2
 StartServers 2
 MaxClients 10
 MaxRequestsPerChild 100
-Port 444
+Port 81
+Listen 81
 Listen 444
 User nobody
 Group nobody
@@ -44,7 +45,7 @@ RewriteRule .* - [F]
     AuthName "Restricted"
     AuthType Basic
     AuthUserFile /var/ipfire/auth/users
-    require user admin
+    Require user admin
 </DirectoryMatch>
 ScriptAlias /cgi-bin/ /home/httpd/cgi-bin/
 <Directory /home/httpd/cgi-bin>
diff --git a/config/urlfilter/autoupdate.pl b/config/urlfilter/autoupdate.pl
new file mode 100644 (file)
index 0000000..9e61b44
--- /dev/null
@@ -0,0 +1,522 @@
+#!/usr/bin/perl
+
+#
+# $Id: autoupdate.pl,v 1.0 2005/06/15 00:00:00 marco Exp $
+#
+use strict;
+
+my $make_clean = 1;
+
+my $swroot = "/var/ipfire";
+my $target = "$swroot/urlfilter/download";
+my $dbdir  = "$swroot/urlfilter/blacklists";
+
+my $sourceurlfile = "$swroot/urlfilter/autoupdate/autoupdate.urls";
+my $updconffile = "$swroot/urlfilter/autoupdate/autoupdate.conf";
+my $updflagfile = "$swroot/urlfilter/blacklists/.autoupdate.last";
+
+my %cgiparams;
+my %updatesettings;
+my $blacklist_url;
+my $blacklist_src;
+my $source_url;
+my $source_name;
+my @source_urllist;
+
+my $blacklist;
+my $category;
+
+my $exitcode = 1;
+
+if (-e "$sourceurlfile")
+{
+       open(FILE, $sourceurlfile);
+       @source_urllist = <FILE>;
+       close(FILE);
+}
+
+if (-e "$updconffile") { &readhash("$updconffile", \%updatesettings); }
+
+if (@ARGV[0] =~ m@^(f|h)tt?ps?://@) { $updatesettings{'UPDATE_SOURCE'} = @ARGV[0]; }
+
+if ($updatesettings{'UPDATE_SOURCE'} eq 'custom')
+{
+       $blacklist_url=$updatesettings{'CUSTOM_UPDATE_URL'};
+} else {
+       $blacklist_url=$updatesettings{'UPDATE_SOURCE'};
+       foreach (@source_urllist)
+       {
+               chomp;
+               $source_name = substr($_,0,rindex($_,","));
+               $source_url = substr($_,index($_,",")+1);
+               if ($blacklist_url eq $source_url) { $blacklist_src=$source_name; }
+       }
+}
+
+if ($blacklist_src eq '') { $blacklist_src="custom source URL"; }
+
+$blacklist_url =~ s/\&/\\\&/;
+
+$blacklist=substr($blacklist_url,rindex($blacklist_url,"/")+1);
+if (($blacklist =~ /\?/) || (!($blacklist =~ /\.t(ar\.)?gz$/))) { $blacklist = 'blacklist.tar.gz'; }
+$blacklist=$target.'/'.$blacklist;
+
+unless ($blacklist_url eq '')
+{
+
+       if (-d $target) { system("rm -rf $target"); }
+       system("mkdir $target");
+
+       system("/usr/bin/wget -o $target/wget.log -O $blacklist $blacklist_url");
+
+       if (-e $blacklist)
+       {
+               system("/bin/tar --no-same-owner -xzf $blacklist -C $target");
+               if (-d "$target/blacklists")
+               {
+                       open(FILE, ">$target/update.conf");
+                       flock FILE, 2;
+                       print FILE "logdir $target\n";
+                       print FILE "dbhome $target/blacklists\n\n";
+
+                       foreach (<$target/blacklists/*>)
+                       {
+                               if ((-d $_) && ((-s "$_/domains") || (-s "$_/urls")))
+                               {
+                                       $category=substr($_,rindex($_,"/")+1);
+                                       print FILE "dest $category {\n";
+                                       if (-s "$_/domains") { print FILE "    domainlist  $category/domains\n"; }
+                                       if (-s "$_/urls")    { print FILE "    urllist     $category/urls\n"; }
+                                       print FILE "}\n\n";
+                               }
+                       }
+                       print FILE "acl {\n";
+                       print FILE "    default {\n";
+                       print FILE "        pass none\n";
+                       print FILE "    }\n";
+                       print FILE "}\n";
+                       close FILE;
+
+                       system("/usr/sbin/squidGuard -d -c $target/update.conf -C all");
+
+                       system("cp -r $target/blacklists/* $dbdir");
+
+                       system("chown -R nobody.nobody $dbdir");
+
+                       foreach $category (<$dbdir/*>)
+                       {
+                               if (-d $category)
+                               {
+                                       system("chmod 755 $category &> /dev/null");
+                                       foreach $blacklist (<$category/*>)
+                                       {
+                                               if (-f $blacklist){ system("chmod 644 $blacklist &> /dev/null"); }
+                                               if (-d $blacklist){ system("chmod 755 $blacklist &> /dev/null"); }
+                                       }
+                                       system("chmod 666 $category/*.db &> /dev/null");
+                               }
+                       }
+
+                       system("touch $updflagfile");
+                       system("chown nobody.nobody $updflagfile");
+
+                       system("/usr/local/bin/restartsquid");
+
+                       system("logger -t installpackage[urlfilter] \"URL filter blacklist - Update from $blacklist_src completed\"");
+
+                       $exitcode = 0;
+
+               } else {
+                       system("logger -t installpackage[urlfilter] \"URL filter blacklist - ERROR: Not a valid URL filter blacklist\"");
+               }
+       } else {
+               system("logger -t installpackage[urlfilter] \"URL filter blacklist - ERROR: Unable to retrieve blacklist from $blacklist_src\"");
+       }
+
+} else {
+       system("logger -t installpackage[urlfilter] \"URL filter blacklist - ERROR: No update source defined\"");
+}
+
+if ((-d $target) && ($make_clean)) { system("rm -rf $target"); }
+
+exit $exitcode;
+
+# -------------------------------------------------------------------
+
+sub readhash
+{
+       my $filename = $_[0];
+       my $hash = $_[1];
+       my ($var, $val);
+
+       if (-e $filename)
+       {
+               open(FILE, $filename) or die "Unable to read file $filename";
+               while (<FILE>)
+               {
+                       chop;
+                       ($var, $val) = split /=/, $_, 2;
+                       if ($var)
+                       {
+                               $val =~ s/^\'//g;
+                               $val =~ s/\'$//g;
+       
+                               # Untaint variables read from hash
+                               $var =~ /([A-Za-z0-9_-]*)/;        $var = $1;
+                               $val =~ /([\w\W]*)/; $val = $1;
+                               $hash->{$var} = $val;
+                       }
+               }
+               close FILE;
+       }
+}
+
+# -------------------------------------------------------------------
+#!/usr/bin/perl
+
+#
+# $Id: autoupdate.pl,v 1.0 2005/06/15 00:00:00 marco Exp $
+#
+use strict;
+
+my $make_clean = 1;
+
+my $swroot = "/var/ipfire";
+my $target = "$swroot/urlfilter/download";
+my $dbdir  = "$swroot/urlfilter/blacklists";
+
+my $sourceurlfile = "$swroot/urlfilter/autoupdate/autoupdate.urls";
+my $updconffile = "$swroot/urlfilter/autoupdate/autoupdate.conf";
+my $updflagfile = "$swroot/urlfilter/blacklists/.autoupdate.last";
+
+my %cgiparams;
+my %updatesettings;
+my $blacklist_url;
+my $blacklist_src;
+my $source_url;
+my $source_name;
+my @source_urllist;
+
+my $blacklist;
+my $category;
+
+my $exitcode = 1;
+
+if (-e "$sourceurlfile")
+{
+       open(FILE, $sourceurlfile);
+       @source_urllist = <FILE>;
+       close(FILE);
+}
+
+if (-e "$updconffile") { &readhash("$updconffile", \%updatesettings); }
+
+if (@ARGV[0] =~ m@^(f|h)tt?ps?://@) { $updatesettings{'UPDATE_SOURCE'} = @ARGV[0]; }
+
+if ($updatesettings{'UPDATE_SOURCE'} eq 'custom')
+{
+       $blacklist_url=$updatesettings{'CUSTOM_UPDATE_URL'};
+} else {
+       $blacklist_url=$updatesettings{'UPDATE_SOURCE'};
+       foreach (@source_urllist)
+       {
+               chomp;
+               $source_name = substr($_,0,rindex($_,","));
+               $source_url = substr($_,index($_,",")+1);
+               if ($blacklist_url eq $source_url) { $blacklist_src=$source_name; }
+       }
+}
+
+if ($blacklist_src eq '') { $blacklist_src="custom source URL"; }
+
+$blacklist_url =~ s/\&/\\\&/;
+
+$blacklist=substr($blacklist_url,rindex($blacklist_url,"/")+1);
+if (($blacklist =~ /\?/) || (!($blacklist =~ /\.t(ar\.)?gz$/))) { $blacklist = 'blacklist.tar.gz'; }
+$blacklist=$target.'/'.$blacklist;
+
+unless ($blacklist_url eq '')
+{
+
+       if (-d $target) { system("rm -rf $target"); }
+       system("mkdir $target");
+
+       system("/usr/bin/wget -o $target/wget.log -O $blacklist $blacklist_url");
+
+       if (-e $blacklist)
+       {
+               system("/bin/tar --no-same-owner -xzf $blacklist -C $target");
+               if (-d "$target/blacklists")
+               {
+                       open(FILE, ">$target/update.conf");
+                       flock FILE, 2;
+                       print FILE "logdir $target\n";
+                       print FILE "dbhome $target/blacklists\n\n";
+
+                       foreach (<$target/blacklists/*>)
+                       {
+                               if ((-d $_) && ((-s "$_/domains") || (-s "$_/urls")))
+                               {
+                                       $category=substr($_,rindex($_,"/")+1);
+                                       print FILE "dest $category {\n";
+                                       if (-s "$_/domains") { print FILE "    domainlist  $category/domains\n"; }
+                                       if (-s "$_/urls")    { print FILE "    urllist     $category/urls\n"; }
+                                       print FILE "}\n\n";
+                               }
+                       }
+                       print FILE "acl {\n";
+                       print FILE "    default {\n";
+                       print FILE "        pass none\n";
+                       print FILE "    }\n";
+                       print FILE "}\n";
+                       close FILE;
+
+                       system("/usr/sbin/squidGuard -d -c $target/update.conf -C all");
+
+                       system("cp -r $target/blacklists/* $dbdir");
+
+                       system("chown -R nobody.nobody $dbdir");
+
+                       foreach $category (<$dbdir/*>)
+                       {
+                               if (-d $category)
+                               {
+                                       system("chmod 755 $category &> /dev/null");
+                                       foreach $blacklist (<$category/*>)
+                                       {
+                                               if (-f $blacklist){ system("chmod 644 $blacklist &> /dev/null"); }
+                                               if (-d $blacklist){ system("chmod 755 $blacklist &> /dev/null"); }
+                                       }
+                                       system("chmod 666 $category/*.db &> /dev/null");
+                               }
+                       }
+
+                       system("touch $updflagfile");
+                       system("chown nobody.nobody $updflagfile");
+
+                       system("/usr/local/bin/restartsquid");
+
+                       system("logger -t installpackage[urlfilter] \"URL filter blacklist - Update from $blacklist_src completed\"");
+
+                       $exitcode = 0;
+
+               } else {
+                       system("logger -t installpackage[urlfilter] \"URL filter blacklist - ERROR: Not a valid URL filter blacklist\"");
+               }
+       } else {
+               system("logger -t installpackage[urlfilter] \"URL filter blacklist - ERROR: Unable to retrieve blacklist from $blacklist_src\"");
+       }
+
+} else {
+       system("logger -t installpackage[urlfilter] \"URL filter blacklist - ERROR: No update source defined\"");
+}
+
+if ((-d $target) && ($make_clean)) { system("rm -rf $target"); }
+
+exit $exitcode;
+
+# -------------------------------------------------------------------
+
+sub readhash
+{
+       my $filename = $_[0];
+       my $hash = $_[1];
+       my ($var, $val);
+
+       if (-e $filename)
+       {
+               open(FILE, $filename) or die "Unable to read file $filename";
+               while (<FILE>)
+               {
+                       chop;
+                       ($var, $val) = split /=/, $_, 2;
+                       if ($var)
+                       {
+                               $val =~ s/^\'//g;
+                               $val =~ s/\'$//g;
+       
+                               # Untaint variables read from hash
+                               $var =~ /([A-Za-z0-9_-]*)/;        $var = $1;
+                               $val =~ /([\w\W]*)/; $val = $1;
+                               $hash->{$var} = $val;
+                       }
+               }
+               close FILE;
+       }
+}
+
+# -------------------------------------------------------------------
+#!/usr/bin/perl
+
+#
+# $Id: autoupdate.pl,v 1.0 2005/06/15 00:00:00 marco Exp $
+#
+use strict;
+
+my $make_clean = 1;
+
+my $swroot = "/var/ipfire";
+my $target = "$swroot/urlfilter/download";
+my $dbdir  = "$swroot/urlfilter/blacklists";
+
+my $sourceurlfile = "$swroot/urlfilter/autoupdate/autoupdate.urls";
+my $updconffile = "$swroot/urlfilter/autoupdate/autoupdate.conf";
+my $updflagfile = "$swroot/urlfilter/blacklists/.autoupdate.last";
+
+my %cgiparams;
+my %updatesettings;
+my $blacklist_url;
+my $blacklist_src;
+my $source_url;
+my $source_name;
+my @source_urllist;
+
+my $blacklist;
+my $category;
+
+my $exitcode = 1;
+
+if (-e "$sourceurlfile")
+{
+       open(FILE, $sourceurlfile);
+       @source_urllist = <FILE>;
+       close(FILE);
+}
+
+if (-e "$updconffile") { &readhash("$updconffile", \%updatesettings); }
+
+if (@ARGV[0] =~ m@^(f|h)tt?ps?://@) { $updatesettings{'UPDATE_SOURCE'} = @ARGV[0]; }
+
+if ($updatesettings{'UPDATE_SOURCE'} eq 'custom')
+{
+       $blacklist_url=$updatesettings{'CUSTOM_UPDATE_URL'};
+} else {
+       $blacklist_url=$updatesettings{'UPDATE_SOURCE'};
+       foreach (@source_urllist)
+       {
+               chomp;
+               $source_name = substr($_,0,rindex($_,","));
+               $source_url = substr($_,index($_,",")+1);
+               if ($blacklist_url eq $source_url) { $blacklist_src=$source_name; }
+       }
+}
+
+if ($blacklist_src eq '') { $blacklist_src="custom source URL"; }
+
+$blacklist_url =~ s/\&/\\\&/;
+
+$blacklist=substr($blacklist_url,rindex($blacklist_url,"/")+1);
+if (($blacklist =~ /\?/) || (!($blacklist =~ /\.t(ar\.)?gz$/))) { $blacklist = 'blacklist.tar.gz'; }
+$blacklist=$target.'/'.$blacklist;
+
+unless ($blacklist_url eq '')
+{
+
+       if (-d $target) { system("rm -rf $target"); }
+       system("mkdir $target");
+
+       system("/usr/bin/wget -o $target/wget.log -O $blacklist $blacklist_url");
+
+       if (-e $blacklist)
+       {
+               system("/bin/tar --no-same-owner -xzf $blacklist -C $target");
+               if (-d "$target/blacklists")
+               {
+                       open(FILE, ">$target/update.conf");
+                       flock FILE, 2;
+                       print FILE "logdir $target\n";
+                       print FILE "dbhome $target/blacklists\n\n";
+
+                       foreach (<$target/blacklists/*>)
+                       {
+                               if ((-d $_) && ((-s "$_/domains") || (-s "$_/urls")))
+                               {
+                                       $category=substr($_,rindex($_,"/")+1);
+                                       print FILE "dest $category {\n";
+                                       if (-s "$_/domains") { print FILE "    domainlist  $category/domains\n"; }
+                                       if (-s "$_/urls")    { print FILE "    urllist     $category/urls\n"; }
+                                       print FILE "}\n\n";
+                               }
+                       }
+                       print FILE "acl {\n";
+                       print FILE "    default {\n";
+                       print FILE "        pass none\n";
+                       print FILE "    }\n";
+                       print FILE "}\n";
+                       close FILE;
+
+                       system("/usr/sbin/squidGuard -d -c $target/update.conf -C all");
+
+                       system("cp -r $target/blacklists/* $dbdir");
+
+                       system("chown -R nobody.nobody $dbdir");
+
+                       foreach $category (<$dbdir/*>)
+                       {
+                               if (-d $category)
+                               {
+                                       system("chmod 755 $category &> /dev/null");
+                                       foreach $blacklist (<$category/*>)
+                                       {
+                                               if (-f $blacklist){ system("chmod 644 $blacklist &> /dev/null"); }
+                                               if (-d $blacklist){ system("chmod 755 $blacklist &> /dev/null"); }
+                                       }
+                                       system("chmod 666 $category/*.db &> /dev/null");
+                               }
+                       }
+
+                       system("touch $updflagfile");
+                       system("chown nobody.nobody $updflagfile");
+
+                       system("/usr/local/bin/restartsquid");
+
+                       system("logger -t installpackage[urlfilter] \"URL filter blacklist - Update from $blacklist_src completed\"");
+
+                       $exitcode = 0;
+
+               } else {
+                       system("logger -t installpackage[urlfilter] \"URL filter blacklist - ERROR: Not a valid URL filter blacklist\"");
+               }
+       } else {
+               system("logger -t installpackage[urlfilter] \"URL filter blacklist - ERROR: Unable to retrieve blacklist from $blacklist_src\"");
+       }
+
+} else {
+       system("logger -t installpackage[urlfilter] \"URL filter blacklist - ERROR: No update source defined\"");
+}
+
+if ((-d $target) && ($make_clean)) { system("rm -rf $target"); }
+
+exit $exitcode;
+
+# -------------------------------------------------------------------
+
+sub readhash
+{
+       my $filename = $_[0];
+       my $hash = $_[1];
+       my ($var, $val);
+
+       if (-e $filename)
+       {
+               open(FILE, $filename) or die "Unable to read file $filename";
+               while (<FILE>)
+               {
+                       chop;
+                       ($var, $val) = split /=/, $_, 2;
+                       if ($var)
+                       {
+                               $val =~ s/^\'//g;
+                               $val =~ s/\'$//g;
+       
+                               # Untaint variables read from hash
+                               $var =~ /([A-Za-z0-9_-]*)/;        $var = $1;
+                               $val =~ /([\w\W]*)/; $val = $1;
+                               $hash->{$var} = $val;
+                       }
+               }
+               close FILE;
+       }
+}
+
+# -------------------------------------------------------------------
diff --git a/config/urlfilter/autoupdate.urls b/config/urlfilter/autoupdate.urls
new file mode 100644 (file)
index 0000000..9254659
--- /dev/null
@@ -0,0 +1,9 @@
+squidGuard,http://ftp.teledanmark.no/pub/www/proxy/squidGuard/contrib/blacklists.tar.gz
+MESD,http://squidguard.mesd.k12.or.us/blacklists.tgz
+Univ. Toulouse,ftp://ftp.univ-tlse1.fr/pub/reseau/cache/squidguard_contrib/blacklists.tar.gz
+squidGuard,http://ftp.teledanmark.no/pub/www/proxy/squidGuard/contrib/blacklists.tar.gz
+MESD,http://squidguard.mesd.k12.or.us/blacklists.tgz
+Univ. Toulouse,ftp://ftp.univ-tlse1.fr/pub/reseau/cache/squidguard_contrib/blacklists.tar.gz
+squidGuard,http://ftp.teledanmark.no/pub/www/proxy/squidGuard/contrib/blacklists.tar.gz
+MESD,http://squidguard.mesd.k12.or.us/blacklists.tgz
+Univ. Toulouse,ftp://ftp.univ-tlse1.fr/pub/reseau/cache/squidguard_contrib/blacklists.tar.gz
diff --git a/config/urlfilter/blacklists.tar.gz b/config/urlfilter/blacklists.tar.gz
new file mode 100644 (file)
index 0000000..dc21990
Binary files /dev/null and b/config/urlfilter/blacklists.tar.gz differ
diff --git a/config/urlfilter/makeconf.pl b/config/urlfilter/makeconf.pl
new file mode 100644 (file)
index 0000000..8a2e542
--- /dev/null
@@ -0,0 +1,159 @@
+#!/usr/bin/perl
+
+$swroot="/var/ipfire";
+$logdir="/var/log/squidGuard";
+$dbdir="/var/ipfire/urlfilter/blacklists";
+
+print "Creating configuration file ";
+foreach $blacklist (<$dbdir/*>)
+{
+       if (-d $blacklist)
+       {
+               $lastslashpos = rindex($blacklist,"/");
+               $section = substr($blacklist,$lastslashpos+1);
+               push(@categories,$section);
+       }
+}
+open(FILE, ">$swroot/urlfilter/squidGuard.conf");
+print FILE "logdir $logdir\n";
+print FILE "dbhome $dbdir\n\n";
+foreach $category (@categories)
+{
+       print FILE "dest $category {\n";
+       if (-e "$dbdir/$category/domains") {
+               print FILE "    domainlist     $category\/domains\n";
+       }
+       if (-e "$dbdir/$category/urls") {
+               print FILE "    urllist        $category\/urls\n";
+       }
+       print FILE "}\n\n";
+}
+print FILE "acl {\n";
+print FILE "    default {\n";
+print FILE "        pass all\n";
+print FILE "    }\n";
+print FILE "}\n";
+close FILE;
+print "\n";
+
+print "Building blacklist databases ";
+system("$swroot/urlfilter/bin/prebuild.pl");
+print "\n";
+
+print "Creating custom directories ";
+mkdir("$dbdir/custom");
+mkdir("$dbdir/custom/allowed");
+mkdir("$dbdir/custom/blocked");
+system("touch $dbdir/custom/allowed/domains");
+system("touch $dbdir/custom/allowed/urls");
+system("touch $dbdir/custom/blocked/domains");
+system("touch $dbdir/custom/blocked/urls");
+print "\n";
+
+exit
+#!/usr/bin/perl
+
+$swroot="/var/ipfire";
+$logdir="/var/log/squidGuard";
+$dbdir="/var/ipfire/urlfilter/blacklists";
+
+print "Creating configuration file ";
+foreach $blacklist (<$dbdir/*>)
+{
+       if (-d $blacklist)
+       {
+               $lastslashpos = rindex($blacklist,"/");
+               $section = substr($blacklist,$lastslashpos+1);
+               push(@categories,$section);
+       }
+}
+open(FILE, ">$swroot/urlfilter/squidGuard.conf");
+print FILE "logdir $logdir\n";
+print FILE "dbhome $dbdir\n\n";
+foreach $category (@categories)
+{
+       print FILE "dest $category {\n";
+       if (-e "$dbdir/$category/domains") {
+               print FILE "    domainlist     $category\/domains\n";
+       }
+       if (-e "$dbdir/$category/urls") {
+               print FILE "    urllist        $category\/urls\n";
+       }
+       print FILE "}\n\n";
+}
+print FILE "acl {\n";
+print FILE "    default {\n";
+print FILE "        pass all\n";
+print FILE "    }\n";
+print FILE "}\n";
+close FILE;
+print "\n";
+
+print "Building blacklist databases ";
+system("$swroot/urlfilter/bin/prebuild.pl");
+print "\n";
+
+print "Creating custom directories ";
+mkdir("$dbdir/custom");
+mkdir("$dbdir/custom/allowed");
+mkdir("$dbdir/custom/blocked");
+system("touch $dbdir/custom/allowed/domains");
+system("touch $dbdir/custom/allowed/urls");
+system("touch $dbdir/custom/blocked/domains");
+system("touch $dbdir/custom/blocked/urls");
+print "\n";
+
+exit
+#!/usr/bin/perl
+
+$swroot="/var/ipfire";
+$logdir="/var/log/squidGuard";
+$dbdir="/var/ipfire/urlfilter/blacklists";
+
+print "Creating configuration file ";
+foreach $blacklist (<$dbdir/*>)
+{
+       if (-d $blacklist)
+       {
+               $lastslashpos = rindex($blacklist,"/");
+               $section = substr($blacklist,$lastslashpos+1);
+               push(@categories,$section);
+       }
+}
+open(FILE, ">$swroot/urlfilter/squidGuard.conf");
+print FILE "logdir $logdir\n";
+print FILE "dbhome $dbdir\n\n";
+foreach $category (@categories)
+{
+       print FILE "dest $category {\n";
+       if (-e "$dbdir/$category/domains") {
+               print FILE "    domainlist     $category\/domains\n";
+       }
+       if (-e "$dbdir/$category/urls") {
+               print FILE "    urllist        $category\/urls\n";
+       }
+       print FILE "}\n\n";
+}
+print FILE "acl {\n";
+print FILE "    default {\n";
+print FILE "        pass all\n";
+print FILE "    }\n";
+print FILE "}\n";
+close FILE;
+print "\n";
+
+print "Building blacklist databases ";
+system("$swroot/urlfilter/bin/prebuild.pl");
+print "\n";
+
+print "Creating custom directories ";
+mkdir("$dbdir/custom");
+mkdir("$dbdir/custom/allowed");
+mkdir("$dbdir/custom/blocked");
+system("touch $dbdir/custom/allowed/domains");
+system("touch $dbdir/custom/allowed/urls");
+system("touch $dbdir/custom/blocked/domains");
+system("touch $dbdir/custom/blocked/urls");
+print "\n";
+
+exit
diff --git a/config/urlfilter/prebuild.pl b/config/urlfilter/prebuild.pl
new file mode 100644 (file)
index 0000000..87b9e72
--- /dev/null
@@ -0,0 +1,96 @@
+#!/usr/bin/perl
+#
+# This code is distributed under the terms of the GPL
+#
+# (c) written from scratch
+#
+# $Id: prebuild.pl,v 0.3 2005/04/16 00:00:00 marco Exp $
+#
+
+$dbdir="/var/ipfire/urlfilter/blacklists";
+
+system("/usr/bin/squidGuard -C all");
+
+if (-e "$dbdir/custom/allowed/domains.db") { unlink("$dbdir/custom/allowed/domains.db"); }
+if (-e "$dbdir/custom/allowed/urls.db")    { unlink("$dbdir/custom/allowed/urls.db"); }
+if (-e "$dbdir/custom/blocked/domains.db") { unlink("$dbdir/custom/blocked/domains.db"); }
+if (-e "$dbdir/custom/blocked/urls.db")    { unlink("$dbdir/custom/blocked/urls.db"); }
+
+system("chown -R nobody.nobody $dbdir");
+
+foreach $category (<$dbdir/*>)
+{
+         if (-d $category){
+               system("chmod 755 $category &> /dev/null");
+               foreach $blacklist (<$category/*>)
+               {
+                       if (-f $blacklist){ system("chmod 644 $blacklist &> /dev/null"); }
+                       if (-d $blacklist){ system("chmod 755 $blacklist &> /dev/null"); }
+               }
+               system("chmod 666 $category/*.db &> /dev/null");
+        }
+}
+#!/usr/bin/perl
+#
+# This code is distributed under the terms of the GPL
+#
+# (c) written from scratch
+#
+# $Id: prebuild.pl,v 0.3 2005/04/16 00:00:00 marco Exp $
+#
+
+$dbdir="/var/ipfire/urlfilter/blacklists";
+
+system("/usr/bin/squidGuard -C all");
+
+if (-e "$dbdir/custom/allowed/domains.db") { unlink("$dbdir/custom/allowed/domains.db"); }
+if (-e "$dbdir/custom/allowed/urls.db")    { unlink("$dbdir/custom/allowed/urls.db"); }
+if (-e "$dbdir/custom/blocked/domains.db") { unlink("$dbdir/custom/blocked/domains.db"); }
+if (-e "$dbdir/custom/blocked/urls.db")    { unlink("$dbdir/custom/blocked/urls.db"); }
+
+system("chown -R nobody.nobody $dbdir");
+
+foreach $category (<$dbdir/*>)
+{
+         if (-d $category){
+               system("chmod 755 $category &> /dev/null");
+               foreach $blacklist (<$category/*>)
+               {
+                       if (-f $blacklist){ system("chmod 644 $blacklist &> /dev/null"); }
+                       if (-d $blacklist){ system("chmod 755 $blacklist &> /dev/null"); }
+               }
+               system("chmod 666 $category/*.db &> /dev/null");
+        }
+}
+#!/usr/bin/perl
+#
+# This code is distributed under the terms of the GPL
+#
+# (c) written from scratch
+#
+# $Id: prebuild.pl,v 0.3 2005/04/16 00:00:00 marco Exp $
+#
+
+$dbdir="/var/ipfire/urlfilter/blacklists";
+
+system("/usr/bin/squidGuard -C all");
+
+if (-e "$dbdir/custom/allowed/domains.db") { unlink("$dbdir/custom/allowed/domains.db"); }
+if (-e "$dbdir/custom/allowed/urls.db")    { unlink("$dbdir/custom/allowed/urls.db"); }
+if (-e "$dbdir/custom/blocked/domains.db") { unlink("$dbdir/custom/blocked/domains.db"); }
+if (-e "$dbdir/custom/blocked/urls.db")    { unlink("$dbdir/custom/blocked/urls.db"); }
+
+system("chown -R nobody.nobody $dbdir");
+
+foreach $category (<$dbdir/*>)
+{
+         if (-d $category){
+               system("chmod 755 $category &> /dev/null");
+               foreach $blacklist (<$category/*>)
+               {
+                       if (-f $blacklist){ system("chmod 644 $blacklist &> /dev/null"); }
+                       if (-d $blacklist){ system("chmod 755 $blacklist &> /dev/null"); }
+               }
+               system("chmod 666 $category/*.db &> /dev/null");
+        }
+}
diff --git a/config/urlfilter/squidGuard.conf b/config/urlfilter/squidGuard.conf
new file mode 100644 (file)
index 0000000..22454f5
--- /dev/null
@@ -0,0 +1,24 @@
+logdir /var/log/squidGuard\r
+dbhome /var/ipfire/urlfilter/blacklists\r
+\r
+acl {\r
+    default {\r
+        pass all\r
+    }\r
+}\r
+logdir /var/log/squidGuard\r
+dbhome /var/ipfire/urlfilter/blacklists\r
+\r
+acl {\r
+    default {\r
+        pass all\r
+    }\r
+}\r
+logdir /var/log/squidGuard\r
+dbhome /var/ipfire/urlfilter/blacklists\r
+\r
+acl {\r
+    default {\r
+        pass all\r
+    }\r
+}\r
diff --git a/html/cgi-bin/logs.cgi/urlfilter.dat b/html/cgi-bin/logs.cgi/urlfilter.dat
new file mode 100644 (file)
index 0000000..94d150c
--- /dev/null
@@ -0,0 +1,1353 @@
+#!/usr/bin/perl
+#
+# SmoothWall CGIs
+#
+# This code is distributed under the terms of the GPL
+#
+# (c) The SmoothWall Team
+#
+# $Id: urlfilter.dat,v 1.4 2005/05/15 00:00:00 marco Exp $
+#
+
+use strict;
+
+# enable only the following on debugging purpose
+#use warnings;
+#use CGI::Carp 'fatalsToBrowser';
+
+use POSIX();
+
+require '/var/ipfire/general-functions.pl';
+require "${General::swroot}/lang.pl";
+require "${General::swroot}/header.pl";
+
+my $dbdir = "${General::swroot}/urlfilter/blacklists";
+my $logdir = "/var/log/squidGuard";
+
+my %cgiparams=();
+my %logsettings=();
+my %filtersettings=();
+my %selected=();
+
+my $errormessage='';
+
+my @log=();
+my $logarch='';
+my $date='';
+my $time='';
+my $pid='';
+my @loginfo=();
+my @ip=();
+my @category=();
+my $dsturl='';
+my $site='';
+my $attr1='';
+my $attr2='';
+
+my $start=0;
+my $prev=0;
+my $next=0;
+my $lines=0;
+my @slice=();
+
+my @then=();
+my @temp=();
+my @temp_then=();
+my @temp_now=();
+my $lastleap='';
+
+my $day='';
+my $daystr='';
+my $month='';
+my $monthstr='';
+my $longmonthstr='';
+my $year='';
+
+my $logday='';
+my $logmonth='';
+my $logyear='';
+
+my @shortmonths = ( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
+       'Sep', 'Oct', 'Nov', 'Dec' );
+my @longmonths = ( $Lang::tr{'january'}, $Lang::tr{'february'}, $Lang::tr{'march'},
+       $Lang::tr{'april'}, $Lang::tr{'may'}, $Lang::tr{'june'}, $Lang::tr{'july'}, $Lang::tr{'august'},
+       $Lang::tr{'september'}, $Lang::tr{'october'}, $Lang::tr{'november'},
+       $Lang::tr{'december'} );
+
+my @now = localtime(time);
+my $doy = $now[7];
+my $tdoy = $now[7];
+my $year = $now[5]+1900;
+
+$cgiparams{'DAY'} = $now[3];
+$cgiparams{'MONTH'} = $now[4];
+$cgiparams{'LOGTYPE'} = 'urlfilter';
+
+&Header::getcgihash(\%cgiparams);
+$logsettings{'LOGVIEW_REVERSE'} = 'off';
+&General::readhash("${General::swroot}/logging/settings", \%logsettings);
+if (-e "${General::swroot}/urlfilter/settings")
+{
+       &General::readhash("${General::swroot}/urlfilter/settings", \%filtersettings);
+}
+
+$now[4] = $cgiparams{'MONTH'}+1;
+if($now[4] < 10) {
+        $now[4] = "0$now[4]"; }
+
+$start = -1;
+
+if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr{'update'})
+{
+       @temp = split(',',$ ENV{'QUERY_STRING'});
+       $start = $temp[0];
+       $cgiparams{'MONTH'} = $temp[1];
+       $cgiparams{'DAY'} = $temp[2];  
+       $cgiparams{'LOGTYPE'} = $temp[3];  
+}
+
+if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
+        !($cgiparams{'DAY'} =~ /^(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)$/))
+{
+        $cgiparams{'DAY'} = $now[3];
+        $cgiparams{'MONTH'} = $now[4];
+}
+elsif($cgiparams{'ACTION'} eq '>>')
+{
+        @temp_now = localtime(time);
+        $temp_now[4] = $cgiparams{'MONTH'};
+        $temp_now[3] = $cgiparams{'DAY'};
+        @temp_then = localtime(POSIX::mktime(@temp_now) + 86400);
+           ## Retrieve the same time on the next day -
+           ## 86400 seconds in a day
+        $cgiparams{'MONTH'} = $temp_then[4];
+        $cgiparams{'DAY'} = $temp_then[3];
+}
+elsif($cgiparams{'ACTION'} eq '<<')
+{
+        @temp_now = localtime(time);
+        $temp_now[4] = $cgiparams{'MONTH'};
+        $temp_now[3] = $cgiparams{'DAY'};
+        @temp_then = localtime(POSIX::mktime(@temp_now) - 86400);
+           ## Retrieve the same time on the previous day -
+           ## 86400 seconds in a day
+        $cgiparams{'MONTH'} = $temp_then[4];
+        $cgiparams{'DAY'} = $temp_then[3];
+}
+
+$monthstr = $shortmonths[$cgiparams{'MONTH'}];
+$longmonthstr = $longmonths[$cgiparams{'MONTH'}];
+
+if (($cgiparams{'DAY'} ne $now[3]) || ($cgiparams{'MONTH'} ne $now[4]))
+{
+       @then = ();
+       if ( (  $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
+                       ( $cgiparams{'MONTH'} > $now[4] ) ) {
+               @then = localtime(POSIX::mktime( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 ));
+       } else {
+               @then = localtime(POSIX::mktime( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 ));
+       }
+       $tdoy = $then[7];
+       $lastleap=($year-1)%4; 
+        if ($tdoy>$doy) {
+               if ($lastleap == 0 && $tdoy < 60) {
+                       $doy=$tdoy+366;
+               } else {
+                       $doy=$doy+365;
+               }
+       }
+}
+
+$day = $cgiparams{'DAY'};
+if ($day <= 9) {
+       $daystr = " $day";
+} else {
+       $daystr = $day;
+}
+if ($day < 10) {
+        $day = "0$day";
+}
+
+&processevent;
+
+if ($cgiparams{'ACTION'} eq $Lang::tr{'export'})
+{
+       print "Content-type: text/plain\n\n";
+       print "IPCop URL filter log\r\n";
+       print "Section: $cgiparams{'LOGTYPE'}\r\n";
+       print "Date: $daystr $longmonthstr\r\n"; 
+       print "\r\n";
+
+       if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
+
+       foreach (@log)
+        {
+               ($date,$time,$pid,@loginfo) = split(/ /);
+               @ip = split(/\//,$loginfo[2]);
+               @category = split(/\//,$loginfo[0]);
+               $dsturl = $loginfo[1];
+               $loginfo[3] =~ s/\%5c/\\/;
+               print "$date ";
+               print "$time ";
+                if ($cgiparams{'LOGTYPE'} eq 'squidGuard')
+               {
+                       print "$pid ";
+                       print "@loginfo";
+               } else {
+                       print "$category[1] ";
+                       print "$ip[0] ";
+                       if ($filtersettings{'ENABLE_USERNAME_LOG'} eq 'on') { print "$loginfo[3] "; }
+                       print "$dsturl";
+                       print "\n";
+               }
+        }
+
+       exit;
+}
+
+&Header::showhttpheaders();
+
+&Header::openpage($Lang::tr{'urlfilter log viewer'}, 1, '');
+
+&Header::openbigbox('100%', 'left', '', $errormessage);
+
+if ($errormessage) {
+       &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
+       print "<font class='base'>$errormessage&nbsp;</font>\n";
+       &Header::closebox();
+}
+
+&Header::openbox('100%', 'left', "$Lang::tr{'settings'}:");
+
+$selected{'LOGTYPE'}{$cgiparams{'LOGTYPE'}} = "selected='selected'";
+
+print <<END
+<form method='post' action="$ENV{'SCRIPT_NAME'}">
+<table width='100%'>
+<tr>
+       <td width='8%' class='base'>$Lang::tr{'section'}</td>
+       <td width='15%' class='base'>
+       <select name='LOGTYPE' size='1'>
+       <option value='urlfilter' $selected{'LOGTYPE'}{'urlfilter'} = "selected='selected'">$Lang::tr{'urlfilter url filter'}</option>
+       <option value='squidGuard' $selected{'LOGTYPE'}{'squidGuard'} = "selected='selected'">squidGuard</option>
+       </select>
+       </td>
+
+       <td width='8%' class='base'>$Lang::tr{'month'}:</td>
+       <td width='15%'>
+       <select name='MONTH'>
+END
+;
+for ($month = 0; $month < 12; $month++)
+{
+       print "\t<option ";
+       if ($month == $cgiparams{'MONTH'}) {
+               print 'selected="selected" '; }
+       print "value='$month'>$longmonths[$month]</option>\n";
+}
+print <<END
+       </select>
+       </td>
+       <td width='8%' class='base'>$Lang::tr{'day'}:</td>
+       <td width='15%'>
+       <select name='DAY'>
+END
+;
+for ($day = 1; $day <= 31; $day++) 
+{
+       print "\t<option ";
+       if ($day == $cgiparams{'DAY'}) {
+               print 'selected="selected" '; }
+       print "value='$day'>$day</option>\n";
+}
+print <<END
+       </select>
+       </td>
+       <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='&lt;&lt;' /></td>
+        <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='&gt;&gt;' /></td>
+       <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
+       <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td>
+</tr>
+</table>
+</form>
+END
+;
+
+&Header::closebox();
+
+&Header::openbox('100%', 'left', $Lang::tr{'log'});
+
+$lines = @log;
+
+if ($start == -1) { $start = $lines - $Header::viewsize; }
+if ($start >= $lines - $Header::viewsize) { $start = $lines - $Header::viewsize; };
+if ($start < 0) { $start = 0; }
+
+$prev = $start - $Header::viewsize;
+$next = $start + $Header::viewsize;
+
+if ($prev < 0) { $prev = 0; }
+if ($next >= $lines) { $next = -1 }
+if ($start == 0) { $prev = -1; }
+
+if ($cgiparams{'LOGTYPE'} eq 'urlfilter')
+{
+       print "<b>$Lang::tr{'urlfilter log summary'} $longmonthstr $daystr: $lines</b><p>\n";
+}
+
+@slice = splice(@log, $start, $Header::viewsize);
+
+if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @slice = reverse @slice; }
+
+if ($lines)
+{
+
+       $lines = 0;
+
+       print "<table width='100%'>\n";
+       unless ($cgiparams{'LOGTYPE'} eq 'squidGuard')
+       {
+               print "<tr>\n";
+               print "<td align='center'><b>$Lang::tr{'urlfilter time'}</b></td>\n";
+               print "<td align='center'><b>$Lang::tr{'urlfilter category'}</b></td>\n";
+               print "<td align='center'><b>$Lang::tr{'urlfilter client'}</b></td>\n";
+               if ($filtersettings{'ENABLE_USERNAME_LOG'} eq 'on') { print "<td align='center'><b>$Lang::tr{'urlfilter username'}</b></td>\n"; }
+               print "<td align='center'><b>$Lang::tr{'urlfilter dst'}</b></td>\n";
+               print "</tr>\n";
+       }
+
+       foreach (@slice)
+       {
+               undef $attr1; undef $attr2;
+               $lines++;
+               ($date,$time,$pid,@loginfo) = split(/ /);
+               @ip = split(/\//,$loginfo[2]);
+               @category = split(/\//,$loginfo[0]);
+               $dsturl = $loginfo[1];
+               $loginfo[3] =~ s/\%5c/\\/;
+               if ($cgiparams{'LOGTYPE'} eq 'squidGuard') {
+                       if (@loginfo[0] =~ /squidGuard/) { $attr1 .= "<b>"; $attr2 .= "</b>"; }
+                       if (@loginfo[1] =~ /ready/) { $attr1 .= "<b><font color='$Header::colourgreen'>"; $attr2 .= "</font></b>"; }
+                       if (@loginfo[2] =~ /emergency/) { $attr1 .= "<b><font color='$Header::colourerr'>"; $attr2 .= "</font></b>"; }
+                       print "<tr>\n";
+               } else {
+                       if ($lines % 2) { print "<tr bgcolor='$Header::table1colour'>\n"; } else { print "<tr bgcolor='$Header::table2colour'>\n"; } 
+               }
+               if ($cgiparams{'LOGTYPE'} eq 'squidGuard') {
+                       print "<td nowrap>$time &nbsp; $pid &nbsp; $attr1@loginfo$attr2</td>\n";
+               } else {
+                       print "<td width='10%' align='center' nowrap>$time</td>\n";
+                       print "<td width='11%' align='center' nowrap>$category[1]</td>\n";
+                       print "<td width='15%' align='center' nowrap>$ip[0]</td>\n";
+                       if ($filtersettings{'ENABLE_USERNAME_LOG'} eq 'on')
+                       {
+                               print "<td width='12%' align='center' nowrap>$loginfo[3]</td>\n";
+                               $site = substr($dsturl,0,55);
+                               if (length($dsturl) > 55) { $site .= "..."; }
+                       } else {
+                               $site = substr($dsturl,0,69);
+                               if (length($dsturl) > 69) { $site .= "..."; }
+                       }
+                       #print "<td>$site</td>\n";
+                       print "<td><a href='$dsturl' title='$dsturl' target='_blank'>$site</a></td>\n";
+               }
+               print "</tr>\n";
+       }
+
+       print "</table><br>\n";
+
+}
+
+&oldernewer();
+
+&Header::closebox();
+
+&Header::closebigbox();
+
+&Header::closepage();
+
+# -------------------------------------------------------------------
+
+sub processevent
+{
+       my $filestr='';
+
+       undef @log;
+       if ($cgiparams{'LOGTYPE'} eq 'squidGuard')
+       {
+               $filestr = "$logdir/squidGuard.log";
+               foreach $logarch (<$filestr.*.gz>)
+               {
+                       open (LOG,"gzip -dc $logarch |");
+                       foreach (<LOG>) {
+                               ($date,$time,$pid,@loginfo) = split(/ /);
+                               ($logyear,$logmonth,$logday) = split(/-/,$date);
+                               if (($logyear == $year) && ($logmonth == $cgiparams{'MONTH'}+1) && ($logday == $day)) { push(@log,$_) }
+                       }
+                       close(LOG);
+               }
+               open (LOG,$filestr);
+               foreach (<LOG>) {
+                       ($date,$time,$pid,@loginfo) = split(/ /);
+                       ($logyear,$logmonth,$logday) = split(/-/,$date);
+                       if (($logyear == $year) && ($logmonth == $cgiparams{'MONTH'}+1) && ($logday == $day)) { push(@log,$_) }
+               }
+               close(LOG);
+       } else {
+               foreach $logarch (<$logdir/*.gz>)
+               {
+                       if ($logarch !~ /squidGuard\.log/) {
+                               open (LOG,"gzip -dc $logarch |");
+                               foreach (<LOG>) {
+                                       ($date,$time,$pid,@loginfo) = split(/ /);
+                                       ($logyear,$logmonth,$logday) = split(/-/,$date);
+                                       if (($logyear == $year) && ($logmonth == $cgiparams{'MONTH'}+1) && ($logday == $day)) { push(@log,$_) }
+                               }
+                               close(LOG);
+                       }
+               }
+               foreach $filestr (<$logdir/*.log>)
+               {
+                       if ($filestr !~ /squidGuard\.log/) {
+                               open (LOG,$filestr);
+                               foreach (<LOG>) {
+                                       ($date,$time,$pid,@loginfo) = split(/ /);
+                                       ($logyear,$logmonth,$logday) = split(/-/,$date);
+                                       if (($logyear == $year) && ($logmonth == $cgiparams{'MONTH'}+1) && ($logday == $day)) { push(@log,$_) }
+                               }
+                               close(LOG);
+                       }
+               }
+               @log = sort { substr($a,11,8) cmp substr($b,11,8) } @log; 
+
+       }
+}
+
+# -------------------------------------------------------------------
+
+sub oldernewer
+{
+       print "<table width='100%'>";
+       print "<tr>";
+
+       print "<td align='center' width='50%'>";
+       if ($prev != -1) {
+               print "<a href='$ENV{'SCRIPT_NAME'}?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'LOGTYPE'}'>$Lang::tr{'older'}</a>"; }
+       else {
+               print "$Lang::tr{'older'}"; }
+       print "</td>\n";
+
+       print "<td align='center' width='50%'>";
+       if ($next != -1) {
+               print "<a href='$ENV{'SCRIPT_NAME'}?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'LOGTYPE'}'>$Lang::tr{'newer'}</a>"; }
+       else {
+               print "$Lang::tr{'newer'}"; }
+       print "</td>\n";
+
+       print "</tr>";
+       print "</table>";
+}
+
+# -------------------------------------------------------------------
+#!/usr/bin/perl
+#
+# SmoothWall CGIs
+#
+# This code is distributed under the terms of the GPL
+#
+# (c) The SmoothWall Team
+#
+# $Id: urlfilter.dat,v 1.4 2005/05/15 00:00:00 marco Exp $
+#
+
+use strict;
+
+# enable only the following on debugging purpose
+#use warnings;
+#use CGI::Carp 'fatalsToBrowser';
+
+use POSIX();
+
+require '/var/ipfire/general-functions.pl';
+require "${General::swroot}/lang.pl";
+require "${General::swroot}/header.pl";
+
+my $dbdir = "${General::swroot}/urlfilter/blacklists";
+my $logdir = "/var/log/squidGuard";
+
+my %cgiparams=();
+my %logsettings=();
+my %filtersettings=();
+my %selected=();
+
+my $errormessage='';
+
+my @log=();
+my $logarch='';
+my $date='';
+my $time='';
+my $pid='';
+my @loginfo=();
+my @ip=();
+my @category=();
+my $dsturl='';
+my $site='';
+my $attr1='';
+my $attr2='';
+
+my $start=0;
+my $prev=0;
+my $next=0;
+my $lines=0;
+my @slice=();
+
+my @then=();
+my @temp=();
+my @temp_then=();
+my @temp_now=();
+my $lastleap='';
+
+my $day='';
+my $daystr='';
+my $month='';
+my $monthstr='';
+my $longmonthstr='';
+my $year='';
+
+my $logday='';
+my $logmonth='';
+my $logyear='';
+
+my @shortmonths = ( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
+       'Sep', 'Oct', 'Nov', 'Dec' );
+my @longmonths = ( $Lang::tr{'january'}, $Lang::tr{'february'}, $Lang::tr{'march'},
+       $Lang::tr{'april'}, $Lang::tr{'may'}, $Lang::tr{'june'}, $Lang::tr{'july'}, $Lang::tr{'august'},
+       $Lang::tr{'september'}, $Lang::tr{'october'}, $Lang::tr{'november'},
+       $Lang::tr{'december'} );
+
+my @now = localtime(time);
+my $doy = $now[7];
+my $tdoy = $now[7];
+my $year = $now[5]+1900;
+
+$cgiparams{'DAY'} = $now[3];
+$cgiparams{'MONTH'} = $now[4];
+$cgiparams{'LOGTYPE'} = 'urlfilter';
+
+&Header::getcgihash(\%cgiparams);
+$logsettings{'LOGVIEW_REVERSE'} = 'off';
+&General::readhash("${General::swroot}/logging/settings", \%logsettings);
+if (-e "${General::swroot}/urlfilter/settings")
+{
+       &General::readhash("${General::swroot}/urlfilter/settings", \%filtersettings);
+}
+
+$now[4] = $cgiparams{'MONTH'}+1;
+if($now[4] < 10) {
+        $now[4] = "0$now[4]"; }
+
+$start = -1;
+
+if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr{'update'})
+{
+       @temp = split(',',$ ENV{'QUERY_STRING'});
+       $start = $temp[0];
+       $cgiparams{'MONTH'} = $temp[1];
+       $cgiparams{'DAY'} = $temp[2];  
+       $cgiparams{'LOGTYPE'} = $temp[3];  
+}
+
+if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
+        !($cgiparams{'DAY'} =~ /^(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)$/))
+{
+        $cgiparams{'DAY'} = $now[3];
+        $cgiparams{'MONTH'} = $now[4];
+}
+elsif($cgiparams{'ACTION'} eq '>>')
+{
+        @temp_now = localtime(time);
+        $temp_now[4] = $cgiparams{'MONTH'};
+        $temp_now[3] = $cgiparams{'DAY'};
+        @temp_then = localtime(POSIX::mktime(@temp_now) + 86400);
+           ## Retrieve the same time on the next day -
+           ## 86400 seconds in a day
+        $cgiparams{'MONTH'} = $temp_then[4];
+        $cgiparams{'DAY'} = $temp_then[3];
+}
+elsif($cgiparams{'ACTION'} eq '<<')
+{
+        @temp_now = localtime(time);
+        $temp_now[4] = $cgiparams{'MONTH'};
+        $temp_now[3] = $cgiparams{'DAY'};
+        @temp_then = localtime(POSIX::mktime(@temp_now) - 86400);
+           ## Retrieve the same time on the previous day -
+           ## 86400 seconds in a day
+        $cgiparams{'MONTH'} = $temp_then[4];
+        $cgiparams{'DAY'} = $temp_then[3];
+}
+
+$monthstr = $shortmonths[$cgiparams{'MONTH'}];
+$longmonthstr = $longmonths[$cgiparams{'MONTH'}];
+
+if (($cgiparams{'DAY'} ne $now[3]) || ($cgiparams{'MONTH'} ne $now[4]))
+{
+       @then = ();
+       if ( (  $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
+                       ( $cgiparams{'MONTH'} > $now[4] ) ) {
+               @then = localtime(POSIX::mktime( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 ));
+       } else {
+               @then = localtime(POSIX::mktime( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 ));
+       }
+       $tdoy = $then[7];
+       $lastleap=($year-1)%4; 
+        if ($tdoy>$doy) {
+               if ($lastleap == 0 && $tdoy < 60) {
+                       $doy=$tdoy+366;
+               } else {
+                       $doy=$doy+365;
+               }
+       }
+}
+
+$day = $cgiparams{'DAY'};
+if ($day <= 9) {
+       $daystr = " $day";
+} else {
+       $daystr = $day;
+}
+if ($day < 10) {
+        $day = "0$day";
+}
+
+&processevent;
+
+if ($cgiparams{'ACTION'} eq $Lang::tr{'export'})
+{
+       print "Content-type: text/plain\n\n";
+       print "IPCop URL filter log\r\n";
+       print "Section: $cgiparams{'LOGTYPE'}\r\n";
+       print "Date: $daystr $longmonthstr\r\n"; 
+       print "\r\n";
+
+       if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
+
+       foreach (@log)
+        {
+               ($date,$time,$pid,@loginfo) = split(/ /);
+               @ip = split(/\//,$loginfo[2]);
+               @category = split(/\//,$loginfo[0]);
+               $dsturl = $loginfo[1];
+               $loginfo[3] =~ s/\%5c/\\/;
+               print "$date ";
+               print "$time ";
+                if ($cgiparams{'LOGTYPE'} eq 'squidGuard')
+               {
+                       print "$pid ";
+                       print "@loginfo";
+               } else {
+                       print "$category[1] ";
+                       print "$ip[0] ";
+                       if ($filtersettings{'ENABLE_USERNAME_LOG'} eq 'on') { print "$loginfo[3] "; }
+                       print "$dsturl";
+                       print "\n";
+               }
+        }
+
+       exit;
+}
+
+&Header::showhttpheaders();
+
+&Header::openpage($Lang::tr{'urlfilter log viewer'}, 1, '');
+
+&Header::openbigbox('100%', 'left', '', $errormessage);
+
+if ($errormessage) {
+       &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
+       print "<font class='base'>$errormessage&nbsp;</font>\n";
+       &Header::closebox();
+}
+
+&Header::openbox('100%', 'left', "$Lang::tr{'settings'}:");
+
+$selected{'LOGTYPE'}{$cgiparams{'LOGTYPE'}} = "selected='selected'";
+
+print <<END
+<form method='post' action="$ENV{'SCRIPT_NAME'}">
+<table width='100%'>
+<tr>
+       <td width='8%' class='base'>$Lang::tr{'section'}</td>
+       <td width='15%' class='base'>
+       <select name='LOGTYPE' size='1'>
+       <option value='urlfilter' $selected{'LOGTYPE'}{'urlfilter'} = "selected='selected'">$Lang::tr{'urlfilter url filter'}</option>
+       <option value='squidGuard' $selected{'LOGTYPE'}{'squidGuard'} = "selected='selected'">squidGuard</option>
+       </select>
+       </td>
+
+       <td width='8%' class='base'>$Lang::tr{'month'}:</td>
+       <td width='15%'>
+       <select name='MONTH'>
+END
+;
+for ($month = 0; $month < 12; $month++)
+{
+       print "\t<option ";
+       if ($month == $cgiparams{'MONTH'}) {
+               print 'selected="selected" '; }
+       print "value='$month'>$longmonths[$month]</option>\n";
+}
+print <<END
+       </select>
+       </td>
+       <td width='8%' class='base'>$Lang::tr{'day'}:</td>
+       <td width='15%'>
+       <select name='DAY'>
+END
+;
+for ($day = 1; $day <= 31; $day++) 
+{
+       print "\t<option ";
+       if ($day == $cgiparams{'DAY'}) {
+               print 'selected="selected" '; }
+       print "value='$day'>$day</option>\n";
+}
+print <<END
+       </select>
+       </td>
+       <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='&lt;&lt;' /></td>
+        <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='&gt;&gt;' /></td>
+       <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
+       <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td>
+</tr>
+</table>
+</form>
+END
+;
+
+&Header::closebox();
+
+&Header::openbox('100%', 'left', $Lang::tr{'log'});
+
+$lines = @log;
+
+if ($start == -1) { $start = $lines - $Header::viewsize; }
+if ($start >= $lines - $Header::viewsize) { $start = $lines - $Header::viewsize; };
+if ($start < 0) { $start = 0; }
+
+$prev = $start - $Header::viewsize;
+$next = $start + $Header::viewsize;
+
+if ($prev < 0) { $prev = 0; }
+if ($next >= $lines) { $next = -1 }
+if ($start == 0) { $prev = -1; }
+
+if ($cgiparams{'LOGTYPE'} eq 'urlfilter')
+{
+       print "<b>$Lang::tr{'urlfilter log summary'} $longmonthstr $daystr: $lines</b><p>\n";
+}
+
+@slice = splice(@log, $start, $Header::viewsize);
+
+if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @slice = reverse @slice; }
+
+if ($lines)
+{
+
+       $lines = 0;
+
+       print "<table width='100%'>\n";
+       unless ($cgiparams{'LOGTYPE'} eq 'squidGuard')
+       {
+               print "<tr>\n";
+               print "<td align='center'><b>$Lang::tr{'urlfilter time'}</b></td>\n";
+               print "<td align='center'><b>$Lang::tr{'urlfilter category'}</b></td>\n";
+               print "<td align='center'><b>$Lang::tr{'urlfilter client'}</b></td>\n";
+               if ($filtersettings{'ENABLE_USERNAME_LOG'} eq 'on') { print "<td align='center'><b>$Lang::tr{'urlfilter username'}</b></td>\n"; }
+               print "<td align='center'><b>$Lang::tr{'urlfilter dst'}</b></td>\n";
+               print "</tr>\n";
+       }
+
+       foreach (@slice)
+       {
+               undef $attr1; undef $attr2;
+               $lines++;
+               ($date,$time,$pid,@loginfo) = split(/ /);
+               @ip = split(/\//,$loginfo[2]);
+               @category = split(/\//,$loginfo[0]);
+               $dsturl = $loginfo[1];
+               $loginfo[3] =~ s/\%5c/\\/;
+               if ($cgiparams{'LOGTYPE'} eq 'squidGuard') {
+                       if (@loginfo[0] =~ /squidGuard/) { $attr1 .= "<b>"; $attr2 .= "</b>"; }
+                       if (@loginfo[1] =~ /ready/) { $attr1 .= "<b><font color='$Header::colourgreen'>"; $attr2 .= "</font></b>"; }
+                       if (@loginfo[2] =~ /emergency/) { $attr1 .= "<b><font color='$Header::colourerr'>"; $attr2 .= "</font></b>"; }
+                       print "<tr>\n";
+               } else {
+                       if ($lines % 2) { print "<tr bgcolor='$Header::table1colour'>\n"; } else { print "<tr bgcolor='$Header::table2colour'>\n"; } 
+               }
+               if ($cgiparams{'LOGTYPE'} eq 'squidGuard') {
+                       print "<td nowrap>$time &nbsp; $pid &nbsp; $attr1@loginfo$attr2</td>\n";
+               } else {
+                       print "<td width='10%' align='center' nowrap>$time</td>\n";
+                       print "<td width='11%' align='center' nowrap>$category[1]</td>\n";
+                       print "<td width='15%' align='center' nowrap>$ip[0]</td>\n";
+                       if ($filtersettings{'ENABLE_USERNAME_LOG'} eq 'on')
+                       {
+                               print "<td width='12%' align='center' nowrap>$loginfo[3]</td>\n";
+                               $site = substr($dsturl,0,55);
+                               if (length($dsturl) > 55) { $site .= "..."; }
+                       } else {
+                               $site = substr($dsturl,0,69);
+                               if (length($dsturl) > 69) { $site .= "..."; }
+                       }
+                       #print "<td>$site</td>\n";
+                       print "<td><a href='$dsturl' title='$dsturl' target='_blank'>$site</a></td>\n";
+               }
+               print "</tr>\n";
+       }
+
+       print "</table><br>\n";
+
+}
+
+&oldernewer();
+
+&Header::closebox();
+
+&Header::closebigbox();
+
+&Header::closepage();
+
+# -------------------------------------------------------------------
+
+sub processevent
+{
+       my $filestr='';
+
+       undef @log;
+       if ($cgiparams{'LOGTYPE'} eq 'squidGuard')
+       {
+               $filestr = "$logdir/squidGuard.log";
+               foreach $logarch (<$filestr.*.gz>)
+               {
+                       open (LOG,"gzip -dc $logarch |");
+                       foreach (<LOG>) {
+                               ($date,$time,$pid,@loginfo) = split(/ /);
+                               ($logyear,$logmonth,$logday) = split(/-/,$date);
+                               if (($logyear == $year) && ($logmonth == $cgiparams{'MONTH'}+1) && ($logday == $day)) { push(@log,$_) }
+                       }
+                       close(LOG);
+               }
+               open (LOG,$filestr);
+               foreach (<LOG>) {
+                       ($date,$time,$pid,@loginfo) = split(/ /);
+                       ($logyear,$logmonth,$logday) = split(/-/,$date);
+                       if (($logyear == $year) && ($logmonth == $cgiparams{'MONTH'}+1) && ($logday == $day)) { push(@log,$_) }
+               }
+               close(LOG);
+       } else {
+               foreach $logarch (<$logdir/*.gz>)
+               {
+                       if ($logarch !~ /squidGuard\.log/) {
+                               open (LOG,"gzip -dc $logarch |");
+                               foreach (<LOG>) {
+                                       ($date,$time,$pid,@loginfo) = split(/ /);
+                                       ($logyear,$logmonth,$logday) = split(/-/,$date);
+                                       if (($logyear == $year) && ($logmonth == $cgiparams{'MONTH'}+1) && ($logday == $day)) { push(@log,$_) }
+                               }
+                               close(LOG);
+                       }
+               }
+               foreach $filestr (<$logdir/*.log>)
+               {
+                       if ($filestr !~ /squidGuard\.log/) {
+                               open (LOG,$filestr);
+                               foreach (<LOG>) {
+                                       ($date,$time,$pid,@loginfo) = split(/ /);
+                                       ($logyear,$logmonth,$logday) = split(/-/,$date);
+                                       if (($logyear == $year) && ($logmonth == $cgiparams{'MONTH'}+1) && ($logday == $day)) { push(@log,$_) }
+                               }
+                               close(LOG);
+                       }
+               }
+               @log = sort { substr($a,11,8) cmp substr($b,11,8) } @log; 
+
+       }
+}
+
+# -------------------------------------------------------------------
+
+sub oldernewer
+{
+       print "<table width='100%'>";
+       print "<tr>";
+
+       print "<td align='center' width='50%'>";
+       if ($prev != -1) {
+               print "<a href='$ENV{'SCRIPT_NAME'}?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'LOGTYPE'}'>$Lang::tr{'older'}</a>"; }
+       else {
+               print "$Lang::tr{'older'}"; }
+       print "</td>\n";
+
+       print "<td align='center' width='50%'>";
+       if ($next != -1) {
+               print "<a href='$ENV{'SCRIPT_NAME'}?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'LOGTYPE'}'>$Lang::tr{'newer'}</a>"; }
+       else {
+               print "$Lang::tr{'newer'}"; }
+       print "</td>\n";
+
+       print "</tr>";
+       print "</table>";
+}
+
+# -------------------------------------------------------------------
+#!/usr/bin/perl
+#
+# SmoothWall CGIs
+#
+# This code is distributed under the terms of the GPL
+#
+# (c) The SmoothWall Team
+#
+# $Id: urlfilter.dat,v 1.4 2005/05/15 00:00:00 marco Exp $
+#
+
+use strict;
+
+# enable only the following on debugging purpose
+#use warnings;
+#use CGI::Carp 'fatalsToBrowser';
+
+use POSIX();
+
+require '/var/ipfire/general-functions.pl';
+require "${General::swroot}/lang.pl";
+require "${General::swroot}/header.pl";
+
+my $dbdir = "${General::swroot}/urlfilter/blacklists";
+my $logdir = "/var/log/squidGuard";
+
+my %cgiparams=();
+my %logsettings=();
+my %filtersettings=();
+my %selected=();
+
+my $errormessage='';
+
+my @log=();
+my $logarch='';
+my $date='';
+my $time='';
+my $pid='';
+my @loginfo=();
+my @ip=();
+my @category=();
+my $dsturl='';
+my $site='';
+my $attr1='';
+my $attr2='';
+
+my $start=0;
+my $prev=0;
+my $next=0;
+my $lines=0;
+my @slice=();
+
+my @then=();
+my @temp=();
+my @temp_then=();
+my @temp_now=();
+my $lastleap='';
+
+my $day='';
+my $daystr='';
+my $month='';
+my $monthstr='';
+my $longmonthstr='';
+my $year='';
+
+my $logday='';
+my $logmonth='';
+my $logyear='';
+
+my @shortmonths = ( 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',
+       'Sep', 'Oct', 'Nov', 'Dec' );
+my @longmonths = ( $Lang::tr{'january'}, $Lang::tr{'february'}, $Lang::tr{'march'},
+       $Lang::tr{'april'}, $Lang::tr{'may'}, $Lang::tr{'june'}, $Lang::tr{'july'}, $Lang::tr{'august'},
+       $Lang::tr{'september'}, $Lang::tr{'october'}, $Lang::tr{'november'},
+       $Lang::tr{'december'} );
+
+my @now = localtime(time);
+my $doy = $now[7];
+my $tdoy = $now[7];
+my $year = $now[5]+1900;
+
+$cgiparams{'DAY'} = $now[3];
+$cgiparams{'MONTH'} = $now[4];
+$cgiparams{'LOGTYPE'} = 'urlfilter';
+
+&Header::getcgihash(\%cgiparams);
+$logsettings{'LOGVIEW_REVERSE'} = 'off';
+&General::readhash("${General::swroot}/logging/settings", \%logsettings);
+if (-e "${General::swroot}/urlfilter/settings")
+{
+       &General::readhash("${General::swroot}/urlfilter/settings", \%filtersettings);
+}
+
+$now[4] = $cgiparams{'MONTH'}+1;
+if($now[4] < 10) {
+        $now[4] = "0$now[4]"; }
+
+$start = -1;
+
+if ($ENV{'QUERY_STRING'} && $cgiparams{'ACTION'} ne $Lang::tr{'update'})
+{
+       @temp = split(',',$ ENV{'QUERY_STRING'});
+       $start = $temp[0];
+       $cgiparams{'MONTH'} = $temp[1];
+       $cgiparams{'DAY'} = $temp[2];  
+       $cgiparams{'LOGTYPE'} = $temp[3];  
+}
+
+if (!($cgiparams{'MONTH'} =~ /^(0|1|2|3|4|5|6|7|8|9|10|11)$/) ||
+        !($cgiparams{'DAY'} =~ /^(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)$/))
+{
+        $cgiparams{'DAY'} = $now[3];
+        $cgiparams{'MONTH'} = $now[4];
+}
+elsif($cgiparams{'ACTION'} eq '>>')
+{
+        @temp_now = localtime(time);
+        $temp_now[4] = $cgiparams{'MONTH'};
+        $temp_now[3] = $cgiparams{'DAY'};
+        @temp_then = localtime(POSIX::mktime(@temp_now) + 86400);
+           ## Retrieve the same time on the next day -
+           ## 86400 seconds in a day
+        $cgiparams{'MONTH'} = $temp_then[4];
+        $cgiparams{'DAY'} = $temp_then[3];
+}
+elsif($cgiparams{'ACTION'} eq '<<')
+{
+        @temp_now = localtime(time);
+        $temp_now[4] = $cgiparams{'MONTH'};
+        $temp_now[3] = $cgiparams{'DAY'};
+        @temp_then = localtime(POSIX::mktime(@temp_now) - 86400);
+           ## Retrieve the same time on the previous day -
+           ## 86400 seconds in a day
+        $cgiparams{'MONTH'} = $temp_then[4];
+        $cgiparams{'DAY'} = $temp_then[3];
+}
+
+$monthstr = $shortmonths[$cgiparams{'MONTH'}];
+$longmonthstr = $longmonths[$cgiparams{'MONTH'}];
+
+if (($cgiparams{'DAY'} ne $now[3]) || ($cgiparams{'MONTH'} ne $now[4]))
+{
+       @then = ();
+       if ( (  $cgiparams{'MONTH'} eq $now[4]) && ($cgiparams{'DAY'} > $now[3]) ||
+                       ( $cgiparams{'MONTH'} > $now[4] ) ) {
+               @then = localtime(POSIX::mktime( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1901 ));
+       } else {
+               @then = localtime(POSIX::mktime( 0, 0, 0, $cgiparams{'DAY'}, $cgiparams{'MONTH'}, $year - 1900 ));
+       }
+       $tdoy = $then[7];
+       $lastleap=($year-1)%4; 
+        if ($tdoy>$doy) {
+               if ($lastleap == 0 && $tdoy < 60) {
+                       $doy=$tdoy+366;
+               } else {
+                       $doy=$doy+365;
+               }
+       }
+}
+
+$day = $cgiparams{'DAY'};
+if ($day <= 9) {
+       $daystr = " $day";
+} else {
+       $daystr = $day;
+}
+if ($day < 10) {
+        $day = "0$day";
+}
+
+&processevent;
+
+if ($cgiparams{'ACTION'} eq $Lang::tr{'export'})
+{
+       print "Content-type: text/plain\n\n";
+       print "IPCop URL filter log\r\n";
+       print "Section: $cgiparams{'LOGTYPE'}\r\n";
+       print "Date: $daystr $longmonthstr\r\n"; 
+       print "\r\n";
+
+       if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @log = reverse @log; }
+
+       foreach (@log)
+        {
+               ($date,$time,$pid,@loginfo) = split(/ /);
+               @ip = split(/\//,$loginfo[2]);
+               @category = split(/\//,$loginfo[0]);
+               $dsturl = $loginfo[1];
+               $loginfo[3] =~ s/\%5c/\\/;
+               print "$date ";
+               print "$time ";
+                if ($cgiparams{'LOGTYPE'} eq 'squidGuard')
+               {
+                       print "$pid ";
+                       print "@loginfo";
+               } else {
+                       print "$category[1] ";
+                       print "$ip[0] ";
+                       if ($filtersettings{'ENABLE_USERNAME_LOG'} eq 'on') { print "$loginfo[3] "; }
+                       print "$dsturl";
+                       print "\n";
+               }
+        }
+
+       exit;
+}
+
+&Header::showhttpheaders();
+
+&Header::openpage($Lang::tr{'urlfilter log viewer'}, 1, '');
+
+&Header::openbigbox('100%', 'left', '', $errormessage);
+
+if ($errormessage) {
+       &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
+       print "<font class='base'>$errormessage&nbsp;</font>\n";
+       &Header::closebox();
+}
+
+&Header::openbox('100%', 'left', "$Lang::tr{'settings'}:");
+
+$selected{'LOGTYPE'}{$cgiparams{'LOGTYPE'}} = "selected='selected'";
+
+print <<END
+<form method='post' action="$ENV{'SCRIPT_NAME'}">
+<table width='100%'>
+<tr>
+       <td width='8%' class='base'>$Lang::tr{'section'}</td>
+       <td width='15%' class='base'>
+       <select name='LOGTYPE' size='1'>
+       <option value='urlfilter' $selected{'LOGTYPE'}{'urlfilter'} = "selected='selected'">$Lang::tr{'urlfilter url filter'}</option>
+       <option value='squidGuard' $selected{'LOGTYPE'}{'squidGuard'} = "selected='selected'">squidGuard</option>
+       </select>
+       </td>
+
+       <td width='8%' class='base'>$Lang::tr{'month'}:</td>
+       <td width='15%'>
+       <select name='MONTH'>
+END
+;
+for ($month = 0; $month < 12; $month++)
+{
+       print "\t<option ";
+       if ($month == $cgiparams{'MONTH'}) {
+               print 'selected="selected" '; }
+       print "value='$month'>$longmonths[$month]</option>\n";
+}
+print <<END
+       </select>
+       </td>
+       <td width='8%' class='base'>$Lang::tr{'day'}:</td>
+       <td width='15%'>
+       <select name='DAY'>
+END
+;
+for ($day = 1; $day <= 31; $day++) 
+{
+       print "\t<option ";
+       if ($day == $cgiparams{'DAY'}) {
+               print 'selected="selected" '; }
+       print "value='$day'>$day</option>\n";
+}
+print <<END
+       </select>
+       </td>
+       <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day before'}' value='&lt;&lt;' /></td>
+        <td width='5%' align='center'><input type='submit' name='ACTION' title='$Lang::tr{'day after'}' value='&gt;&gt;' /></td>
+       <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'update'}' /></td>
+       <td width='10%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'export'}' /></td>
+</tr>
+</table>
+</form>
+END
+;
+
+&Header::closebox();
+
+&Header::openbox('100%', 'left', $Lang::tr{'log'});
+
+$lines = @log;
+
+if ($start == -1) { $start = $lines - $Header::viewsize; }
+if ($start >= $lines - $Header::viewsize) { $start = $lines - $Header::viewsize; };
+if ($start < 0) { $start = 0; }
+
+$prev = $start - $Header::viewsize;
+$next = $start + $Header::viewsize;
+
+if ($prev < 0) { $prev = 0; }
+if ($next >= $lines) { $next = -1 }
+if ($start == 0) { $prev = -1; }
+
+if ($cgiparams{'LOGTYPE'} eq 'urlfilter')
+{
+       print "<b>$Lang::tr{'urlfilter log summary'} $longmonthstr $daystr: $lines</b><p>\n";
+}
+
+@slice = splice(@log, $start, $Header::viewsize);
+
+if ($logsettings{'LOGVIEW_REVERSE'} eq 'on') { @slice = reverse @slice; }
+
+if ($lines)
+{
+
+       $lines = 0;
+
+       print "<table width='100%'>\n";
+       unless ($cgiparams{'LOGTYPE'} eq 'squidGuard')
+       {
+               print "<tr>\n";
+               print "<td align='center'><b>$Lang::tr{'urlfilter time'}</b></td>\n";
+               print "<td align='center'><b>$Lang::tr{'urlfilter category'}</b></td>\n";
+               print "<td align='center'><b>$Lang::tr{'urlfilter client'}</b></td>\n";
+               if ($filtersettings{'ENABLE_USERNAME_LOG'} eq 'on') { print "<td align='center'><b>$Lang::tr{'urlfilter username'}</b></td>\n"; }
+               print "<td align='center'><b>$Lang::tr{'urlfilter dst'}</b></td>\n";
+               print "</tr>\n";
+       }
+
+       foreach (@slice)
+       {
+               undef $attr1; undef $attr2;
+               $lines++;
+               ($date,$time,$pid,@loginfo) = split(/ /);
+               @ip = split(/\//,$loginfo[2]);
+               @category = split(/\//,$loginfo[0]);
+               $dsturl = $loginfo[1];
+               $loginfo[3] =~ s/\%5c/\\/;
+               if ($cgiparams{'LOGTYPE'} eq 'squidGuard') {
+                       if (@loginfo[0] =~ /squidGuard/) { $attr1 .= "<b>"; $attr2 .= "</b>"; }
+                       if (@loginfo[1] =~ /ready/) { $attr1 .= "<b><font color='$Header::colourgreen'>"; $attr2 .= "</font></b>"; }
+                       if (@loginfo[2] =~ /emergency/) { $attr1 .= "<b><font color='$Header::colourerr'>"; $attr2 .= "</font></b>"; }
+                       print "<tr>\n";
+               } else {
+                       if ($lines % 2) { print "<tr bgcolor='$Header::table1colour'>\n"; } else { print "<tr bgcolor='$Header::table2colour'>\n"; } 
+               }
+               if ($cgiparams{'LOGTYPE'} eq 'squidGuard') {
+                       print "<td nowrap>$time &nbsp; $pid &nbsp; $attr1@loginfo$attr2</td>\n";
+               } else {
+                       print "<td width='10%' align='center' nowrap>$time</td>\n";
+                       print "<td width='11%' align='center' nowrap>$category[1]</td>\n";
+                       print "<td width='15%' align='center' nowrap>$ip[0]</td>\n";
+                       if ($filtersettings{'ENABLE_USERNAME_LOG'} eq 'on')
+                       {
+                               print "<td width='12%' align='center' nowrap>$loginfo[3]</td>\n";
+                               $site = substr($dsturl,0,55);
+                               if (length($dsturl) > 55) { $site .= "..."; }
+                       } else {
+                               $site = substr($dsturl,0,69);
+                               if (length($dsturl) > 69) { $site .= "..."; }
+                       }
+                       #print "<td>$site</td>\n";
+                       print "<td><a href='$dsturl' title='$dsturl' target='_blank'>$site</a></td>\n";
+               }
+               print "</tr>\n";
+       }
+
+       print "</table><br>\n";
+
+}
+
+&oldernewer();
+
+&Header::closebox();
+
+&Header::closebigbox();
+
+&Header::closepage();
+
+# -------------------------------------------------------------------
+
+sub processevent
+{
+       my $filestr='';
+
+       undef @log;
+       if ($cgiparams{'LOGTYPE'} eq 'squidGuard')
+       {
+               $filestr = "$logdir/squidGuard.log";
+               foreach $logarch (<$filestr.*.gz>)
+               {
+                       open (LOG,"gzip -dc $logarch |");
+                       foreach (<LOG>) {
+                               ($date,$time,$pid,@loginfo) = split(/ /);
+                               ($logyear,$logmonth,$logday) = split(/-/,$date);
+                               if (($logyear == $year) && ($logmonth == $cgiparams{'MONTH'}+1) && ($logday == $day)) { push(@log,$_) }
+                       }
+                       close(LOG);
+               }
+               open (LOG,$filestr);
+               foreach (<LOG>) {
+                       ($date,$time,$pid,@loginfo) = split(/ /);
+                       ($logyear,$logmonth,$logday) = split(/-/,$date);
+                       if (($logyear == $year) && ($logmonth == $cgiparams{'MONTH'}+1) && ($logday == $day)) { push(@log,$_) }
+               }
+               close(LOG);
+       } else {
+               foreach $logarch (<$logdir/*.gz>)
+               {
+                       if ($logarch !~ /squidGuard\.log/) {
+                               open (LOG,"gzip -dc $logarch |");
+                               foreach (<LOG>) {
+                                       ($date,$time,$pid,@loginfo) = split(/ /);
+                                       ($logyear,$logmonth,$logday) = split(/-/,$date);
+                                       if (($logyear == $year) && ($logmonth == $cgiparams{'MONTH'}+1) && ($logday == $day)) { push(@log,$_) }
+                               }
+                               close(LOG);
+                       }
+               }
+               foreach $filestr (<$logdir/*.log>)
+               {
+                       if ($filestr !~ /squidGuard\.log/) {
+                               open (LOG,$filestr);
+                               foreach (<LOG>) {
+                                       ($date,$time,$pid,@loginfo) = split(/ /);
+                                       ($logyear,$logmonth,$logday) = split(/-/,$date);
+                                       if (($logyear == $year) && ($logmonth == $cgiparams{'MONTH'}+1) && ($logday == $day)) { push(@log,$_) }
+                               }
+                               close(LOG);
+                       }
+               }
+               @log = sort { substr($a,11,8) cmp substr($b,11,8) } @log; 
+
+       }
+}
+
+# -------------------------------------------------------------------
+
+sub oldernewer
+{
+       print "<table width='100%'>";
+       print "<tr>";
+
+       print "<td align='center' width='50%'>";
+       if ($prev != -1) {
+               print "<a href='$ENV{'SCRIPT_NAME'}?$prev,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'LOGTYPE'}'>$Lang::tr{'older'}</a>"; }
+       else {
+               print "$Lang::tr{'older'}"; }
+       print "</td>\n";
+
+       print "<td align='center' width='50%'>";
+       if ($next != -1) {
+               print "<a href='$ENV{'SCRIPT_NAME'}?$next,$cgiparams{'MONTH'},$cgiparams{'DAY'},$cgiparams{'LOGTYPE'}'>$Lang::tr{'newer'}</a>"; }
+       else {
+               print "$Lang::tr{'newer'}"; }
+       print "</td>\n";
+
+       print "</tr>";
+       print "</table>";
+}
+
+# -------------------------------------------------------------------
index c921ef5..192c982 100644 (file)
@@ -130,6 +130,12 @@ open FILE, $browserdb;
 @useragentlist = sort { reverse(substr(reverse(substr($a,index($a,',')+1)),index(reverse(substr($a,index($a,','))),',')+1)) cmp reverse(substr(reverse(substr($b,index($b,',')+1)),index(reverse(substr($b,index($b,','))),',')+1))} grep !/(^$)|(^\s*#)/,<FILE>;
 close(FILE);
 
+my %filtersettings=();
+$filtersettings{'CHILDREN'} = '5';
+if (-e "${General::swroot}/urlfilter/settings") {
+       &General::readhash("${General::swroot}/urlfilter/settings", \%filtersettings);
+}
+
 &General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
 &General::readhash("${General::swroot}/main/settings", \%mainsettings);
 
@@ -152,6 +158,7 @@ if ($updacclrtr_addon) {
 
 &Header::showhttpheaders();
 
+$proxysettings{'ENABLE_FILTER'} = 'off';
 $proxysettings{'ACTION'} = '';
 $proxysettings{'VALID'} = '';
 
@@ -338,6 +345,15 @@ if (($proxysettings{'ACTION'} eq $Lang::tr{'save'}) || ($proxysettings{'ACTION'}
                $errormessage = $Lang::tr{'invalid maximum outgoing size'};
                goto ERROR;
        }
+       if ($proxysettings{'ENABLE_FILTER'} eq 'on')
+       {
+               print FILE <<END
+redirect_program /usr/bin/squidGuard
+redirect_children $filtersettings{'CHILDREN'}
+
+END
+               ;
+       }
        if (!($proxysettings{'TIME_TO_HOUR'}.$proxysettings{'TIME_TO_MINUTE'} gt $proxysettings{'TIME_FROM_HOUR'}.$proxysettings{'TIME_FROM_MINUTE'}))
        {
                $errormessage = $Lang::tr{'advproxy errmsg time restriction'};
@@ -715,6 +731,10 @@ $checked{'ENABLE_BROWSER_CHECK'}{'off'} = '';
 $checked{'ENABLE_BROWSER_CHECK'}{'on'} = '';
 $checked{'ENABLE_BROWSER_CHECK'}{$proxysettings{'ENABLE_BROWSER_CHECK'}} = "checked='checked'";
 
+$checked{'ENABLE_FILTER'}{'off'} = '';
+$checked{'ENABLE_FILTER'}{'on'} = '';
+$checked{'ENABLE_FILTER'}{$proxysettings{'ENABLE_FILTER'}} = "checked='checked'";
+
 foreach (@useragentlist) {
        @useragent = split(/,/);
        $checked{'UA_'.@useragent[0]}{'off'} = '';
@@ -865,6 +885,14 @@ print <<END
        </select>
        </td>
 </tr>
+<tr>
+       <td colspan='4'><hr /><b>$Lang::tr{'urlfilter url filter'}</b></td>
+</tr>
+<tr>
+       <td width='25%' class='base'>$Lang::tr{'urlfilter enabled'}</td>
+       <td><input type='checkbox' name='ENABLE_FILTER' $checked{'ENABLE_FILTER'}{'on'} /></td>
+       <td colspan='2'>&nbsp;</td>
+</tr>
 </table>
 <hr size='1'>
 <table width='100%'>
@@ -3414,7 +3442,7 @@ END
                if ($proxysettings{'ENABLE_FILTER'} eq 'on')
                {
                        print FILE <<END
-redirect_program /usr/sbin/squidGuard
+redirect_program /usr/bin/squidGuard
 redirect_children $filtersettings{'CHILDREN'}
 
 END
diff --git a/html/cgi-bin/redirect.cgi b/html/cgi-bin/redirect.cgi
new file mode 100644 (file)
index 0000000..40087d1
--- /dev/null
@@ -0,0 +1,498 @@
+#!/usr/bin/perl
+
+#
+# $Id: redirect.cgi,v 0.1 2004/09/26 00:00:00 marco Exp $
+#
+
+use CGI qw(param);
+
+$swroot="/var/ipfire";
+
+my %netsettings;
+my %filtersettings;
+
+&readhash("$swroot/ethernet/settings", \%netsettings);
+&readhash("$swroot/urlfilter/settings", \%filtersettings);
+
+$category=param("category");
+$url=param("url");
+$ip=param("ip");
+
+if ($filtersettings{'MSG_TEXT_1'} eq '') {
+       $msgtext1 = "A C C E S S &nbsp;&nbsp; D E N I E D";
+} else { $msgtext1 = $filtersettings{'MSG_TEXT_1'}; }
+if ($filtersettings{'MSG_TEXT_2'} eq '') {
+       $msgtext2 = "Access to the requested page has been denied";
+} else { $msgtext2 = $filtersettings{'MSG_TEXT_2'}; }
+if ($filtersettings{'MSG_TEXT_3'} eq '') {
+       $msgtext3 = "Please contact the Network Administrator if you think there has been an error";
+} else { $msgtext3 = $filtersettings{'MSG_TEXT_3'}; }
+
+if ($category eq '') { $category = '&nbsp;'; } else { $category = '['.$category.']'; }
+
+print "Pragma: no-cache\n";
+print "Cache-control: no-cache\n";
+print "Connection: close\n";
+print "Content-type: text/html\n\n";
+
+print <<END
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
+<title></title>
+</head>
+
+END
+;
+
+if (($filtersettings{'ENABLE_JPEG'} eq 'on') && (-e "/home/httpd/html/images/urlfilter/background.jpg"))
+{
+print <<END
+<body background="http://$netsettings{'GREEN_ADDRESS'}:81//images/urlfilter/background.jpg" bgcolor="#FFFFFF">
+END
+;
+} else {
+print <<END
+<body bgcolor="#FFFFFF">
+END
+;
+}
+
+print <<END
+
+<center>
+
+<table width="80%" cellspacing="10" cellpadding="5" border="0">
+
+<tr>
+       <td bgcolor="#C0C0C0" align="right">
+               <font face="verdana, arial, sans serif" color="#000000" size="1">
+               <b>$category</b>
+               </font>
+       </td>
+</tr>
+<tr>
+       <td bgcolor="#F4F4F4" align="center">
+               <table width="100%" cellspacing="20" cellpadding="20" border="0">
+                       <tr>
+                               <td nowrap bgcolor="#FF0000" align="center">
+                                       <font face="verdana, arial, sans serif" color="#FFFFFF" size="6">
+                                       <b>$msgtext1</b>
+                                       </font>
+                               </td>
+                       </tr>
+                       <tr>
+                               <td bgcolor="#E2E2E2" align="center">
+                                       <font face="verdana, arial, sans serif" color="#000000" size="4">
+                                       <b>$msgtext2</b>
+                                       </font>
+                                       <font face="verdana,arial,sans serif" color="#000000" size="2">
+END
+;
+
+if (!($url eq ""))
+{
+print <<END
+                                       <p>URL: <a href="$url">$url</a>
+END
+;
+}
+
+if (!($ip eq ""))
+{
+print <<END
+                                       <p>Client IP address: <i>$ip</i>
+END
+;
+}
+
+print <<END
+                                       <br><p>$msgtext3
+                                       </font>
+                               </td>
+                       </tr>
+       </td>
+</tr>
+</table>
+
+<tr>
+       <td bgcolor="#C0C0C0" align="right">
+               <font face="verdana,arial,sans serif" color="#FFFFFF" size="1">Web Filtering by
+               </font>
+               <a href="http://www.ipcop.org" target="_blank"><b>
+               <font face="verdana,arial,sans serif" color="#FFFFFF" size="1">IPCop</b></a> and
+               <a href="http://www.squidguard.org" target="_blank"><b>
+               <font face="verdana,arial,sans serif" color="#FFFFFF" size="1">SquidGuard
+               </font></b></a>
+       </td>
+</tr>
+
+</table>
+
+</center>
+
+</body>
+
+</html>
+END
+;
+
+sub readhash
+{
+       my $filename = $_[0];
+       my $hash = $_[1];
+       my ($var, $val);
+
+       if (-e $filename)
+       {
+               open(FILE, $filename) or die "Unable to read file $filename";
+               while (<FILE>)
+               {
+                       chop;
+                       ($var, $val) = split /=/, $_, 2;
+                       if ($var)
+                       {
+                               $val =~ s/^\'//g;
+                               $val =~ s/\'$//g;
+       
+                               # Untaint variables read from hash
+                               $var =~ /([A-Za-z0-9_-]*)/;        $var = $1;
+                               $val =~ /([\w\W]*)/; $val = $1;
+                               $hash->{$var} = $val;
+                       }
+               }
+               close FILE;
+       }
+}
+#!/usr/bin/perl
+
+#
+# $Id: redirect.cgi,v 0.1 2004/09/26 00:00:00 marco Exp $
+#
+
+use CGI qw(param);
+
+$swroot="/var/ipfire";
+
+my %netsettings;
+my %filtersettings;
+
+&readhash("$swroot/ethernet/settings", \%netsettings);
+&readhash("$swroot/urlfilter/settings", \%filtersettings);
+
+$category=param("category");
+$url=param("url");
+$ip=param("ip");
+
+if ($filtersettings{'MSG_TEXT_1'} eq '') {
+       $msgtext1 = "A C C E S S &nbsp;&nbsp; D E N I E D";
+} else { $msgtext1 = $filtersettings{'MSG_TEXT_1'}; }
+if ($filtersettings{'MSG_TEXT_2'} eq '') {
+       $msgtext2 = "Access to the requested page has been denied";
+} else { $msgtext2 = $filtersettings{'MSG_TEXT_2'}; }
+if ($filtersettings{'MSG_TEXT_3'} eq '') {
+       $msgtext3 = "Please contact the Network Administrator if you think there has been an error";
+} else { $msgtext3 = $filtersettings{'MSG_TEXT_3'}; }
+
+if ($category eq '') { $category = '&nbsp;'; } else { $category = '['.$category.']'; }
+
+print "Pragma: no-cache\n";
+print "Cache-control: no-cache\n";
+print "Connection: close\n";
+print "Content-type: text/html\n\n";
+
+print <<END
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
+<title></title>
+</head>
+
+END
+;
+
+if (($filtersettings{'ENABLE_JPEG'} eq 'on') && (-e "/home/httpd/html/images/urlfilter/background.jpg"))
+{
+print <<END
+<body background="http://$netsettings{'GREEN_ADDRESS'}:81//images/urlfilter/background.jpg" bgcolor="#FFFFFF">
+END
+;
+} else {
+print <<END
+<body bgcolor="#FFFFFF">
+END
+;
+}
+
+print <<END
+
+<center>
+
+<table width="80%" cellspacing="10" cellpadding="5" border="0">
+
+<tr>
+       <td bgcolor="#C0C0C0" align="right">
+               <font face="verdana, arial, sans serif" color="#000000" size="1">
+               <b>$category</b>
+               </font>
+       </td>
+</tr>
+<tr>
+       <td bgcolor="#F4F4F4" align="center">
+               <table width="100%" cellspacing="20" cellpadding="20" border="0">
+                       <tr>
+                               <td nowrap bgcolor="#FF0000" align="center">
+                                       <font face="verdana, arial, sans serif" color="#FFFFFF" size="6">
+                                       <b>$msgtext1</b>
+                                       </font>
+                               </td>
+                       </tr>
+                       <tr>
+                               <td bgcolor="#E2E2E2" align="center">
+                                       <font face="verdana, arial, sans serif" color="#000000" size="4">
+                                       <b>$msgtext2</b>
+                                       </font>
+                                       <font face="verdana,arial,sans serif" color="#000000" size="2">
+END
+;
+
+if (!($url eq ""))
+{
+print <<END
+                                       <p>URL: <a href="$url">$url</a>
+END
+;
+}
+
+if (!($ip eq ""))
+{
+print <<END
+                                       <p>Client IP address: <i>$ip</i>
+END
+;
+}
+
+print <<END
+                                       <br><p>$msgtext3
+                                       </font>
+                               </td>
+                       </tr>
+       </td>
+</tr>
+</table>
+
+<tr>
+       <td bgcolor="#C0C0C0" align="right">
+               <font face="verdana,arial,sans serif" color="#FFFFFF" size="1">Web Filtering by
+               </font>
+               <a href="http://www.ipcop.org" target="_blank"><b>
+               <font face="verdana,arial,sans serif" color="#FFFFFF" size="1">IPCop</b></a> and
+               <a href="http://www.squidguard.org" target="_blank"><b>
+               <font face="verdana,arial,sans serif" color="#FFFFFF" size="1">SquidGuard
+               </font></b></a>
+       </td>
+</tr>
+
+</table>
+
+</center>
+
+</body>
+
+</html>
+END
+;
+
+sub readhash
+{
+       my $filename = $_[0];
+       my $hash = $_[1];
+       my ($var, $val);
+
+       if (-e $filename)
+       {
+               open(FILE, $filename) or die "Unable to read file $filename";
+               while (<FILE>)
+               {
+                       chop;
+                       ($var, $val) = split /=/, $_, 2;
+                       if ($var)
+                       {
+                               $val =~ s/^\'//g;
+                               $val =~ s/\'$//g;
+       
+                               # Untaint variables read from hash
+                               $var =~ /([A-Za-z0-9_-]*)/;        $var = $1;
+                               $val =~ /([\w\W]*)/; $val = $1;
+                               $hash->{$var} = $val;
+                       }
+               }
+               close FILE;
+       }
+}
+#!/usr/bin/perl
+
+#
+# $Id: redirect.cgi,v 0.1 2004/09/26 00:00:00 marco Exp $
+#
+
+use CGI qw(param);
+
+$swroot="/var/ipfire";
+
+my %netsettings;
+my %filtersettings;
+
+&readhash("$swroot/ethernet/settings", \%netsettings);
+&readhash("$swroot/urlfilter/settings", \%filtersettings);
+
+$category=param("category");
+$url=param("url");
+$ip=param("ip");
+
+if ($filtersettings{'MSG_TEXT_1'} eq '') {
+       $msgtext1 = "A C C E S S &nbsp;&nbsp; D E N I E D";
+} else { $msgtext1 = $filtersettings{'MSG_TEXT_1'}; }
+if ($filtersettings{'MSG_TEXT_2'} eq '') {
+       $msgtext2 = "Access to the requested page has been denied";
+} else { $msgtext2 = $filtersettings{'MSG_TEXT_2'}; }
+if ($filtersettings{'MSG_TEXT_3'} eq '') {
+       $msgtext3 = "Please contact the Network Administrator if you think there has been an error";
+} else { $msgtext3 = $filtersettings{'MSG_TEXT_3'}; }
+
+if ($category eq '') { $category = '&nbsp;'; } else { $category = '['.$category.']'; }
+
+print "Pragma: no-cache\n";
+print "Cache-control: no-cache\n";
+print "Connection: close\n";
+print "Content-type: text/html\n\n";
+
+print <<END
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
+<title></title>
+</head>
+
+END
+;
+
+if (($filtersettings{'ENABLE_JPEG'} eq 'on') && (-e "/home/httpd/html/images/urlfilter/background.jpg"))
+{
+print <<END
+<body background="http://$netsettings{'GREEN_ADDRESS'}:81//images/urlfilter/background.jpg" bgcolor="#FFFFFF">
+END
+;
+} else {
+print <<END
+<body bgcolor="#FFFFFF">
+END
+;
+}
+
+print <<END
+
+<center>
+
+<table width="80%" cellspacing="10" cellpadding="5" border="0">
+
+<tr>
+       <td bgcolor="#C0C0C0" align="right">
+               <font face="verdana, arial, sans serif" color="#000000" size="1">
+               <b>$category</b>
+               </font>
+       </td>
+</tr>
+<tr>
+       <td bgcolor="#F4F4F4" align="center">
+               <table width="100%" cellspacing="20" cellpadding="20" border="0">
+                       <tr>
+                               <td nowrap bgcolor="#FF0000" align="center">
+                                       <font face="verdana, arial, sans serif" color="#FFFFFF" size="6">
+                                       <b>$msgtext1</b>
+                                       </font>
+                               </td>
+                       </tr>
+                       <tr>
+                               <td bgcolor="#E2E2E2" align="center">
+                                       <font face="verdana, arial, sans serif" color="#000000" size="4">
+                                       <b>$msgtext2</b>
+                                       </font>
+                                       <font face="verdana,arial,sans serif" color="#000000" size="2">
+END
+;
+
+if (!($url eq ""))
+{
+print <<END
+                                       <p>URL: <a href="$url">$url</a>
+END
+;
+}
+
+if (!($ip eq ""))
+{
+print <<END
+                                       <p>Client IP address: <i>$ip</i>
+END
+;
+}
+
+print <<END
+                                       <br><p>$msgtext3
+                                       </font>
+                               </td>
+                       </tr>
+       </td>
+</tr>
+</table>
+
+<tr>
+       <td bgcolor="#C0C0C0" align="right">
+               <font face="verdana,arial,sans serif" color="#FFFFFF" size="1">Web Filtering by
+               </font>
+               <a href="http://www.ipcop.org" target="_blank"><b>
+               <font face="verdana,arial,sans serif" color="#FFFFFF" size="1">IPCop</b></a> and
+               <a href="http://www.squidguard.org" target="_blank"><b>
+               <font face="verdana,arial,sans serif" color="#FFFFFF" size="1">SquidGuard
+               </font></b></a>
+       </td>
+</tr>
+
+</table>
+
+</center>
+
+</body>
+
+</html>
+END
+;
+
+sub readhash
+{
+       my $filename = $_[0];
+       my $hash = $_[1];
+       my ($var, $val);
+
+       if (-e $filename)
+       {
+               open(FILE, $filename) or die "Unable to read file $filename";
+               while (<FILE>)
+               {
+                       chop;
+                       ($var, $val) = split /=/, $_, 2;
+                       if ($var)
+                       {
+                               $val =~ s/^\'//g;
+                               $val =~ s/\'$//g;
+       
+                               # Untaint variables read from hash
+                               $var =~ /([A-Za-z0-9_-]*)/;        $var = $1;
+                               $val =~ /([\w\W]*)/; $val = $1;
+                               $hash->{$var} = $val;
+                       }
+               }
+               close FILE;
+       }
+}
diff --git a/html/cgi-bin/urlfilter.cgi b/html/cgi-bin/urlfilter.cgi
new file mode 100644 (file)
index 0000000..4da98f9
--- /dev/null
@@ -0,0 +1,9012 @@
+#!/usr/bin/perl
+#
+# SmoothWall CGIs
+#
+# This code is distributed under the terms of the GPL
+#
+# (c) written from scratch
+#
+# $Id: urlfilter.cgi,v 1.7 2006/05/08 00:00:00 marco Exp $
+#
+
+use strict;
+
+# enable only the following on debugging purpose
+#use warnings;
+#use CGI::Carp 'fatalsToBrowser';
+
+use File::Copy;
+use IO::Socket;
+
+require '/var/ipfire/general-functions.pl';
+require "${General::swroot}/lang.pl";
+require "${General::swroot}/header.pl";
+
+my %netsettings=();
+my %mainsettings=();
+my %proxysettings=();
+my %filtersettings=();
+my %tcsettings=();
+my %uqsettings=();
+my %besettings=();
+my %updatesettings=();
+my %checked=();
+my %selected=();
+my $id=0;
+my $line='';
+my $i=0;
+my $n=0;
+my $time='';
+my $filesize;
+my $category='';
+my $section='';
+my $blacklist='';
+my $blistbackup='';
+
+my $changed = 'no';
+my $tcfile = "${General::swroot}/urlfilter/timeconst";
+my $uqfile = "${General::swroot}/urlfilter/userquota";
+my $dbdir = "${General::swroot}/urlfilter/blacklists";
+my $editdir = "${General::swroot}/urlfilter/editor";
+my $repository = "/home/httpd/html/repository";
+my $hintcolour = '#FFFFCC';
+
+my $sourceurlfile = "${General::swroot}/urlfilter/autoupdate/autoupdate.urls";
+my $updconffile = "${General::swroot}/urlfilter/autoupdate/autoupdate.conf";
+my $updflagfile = "${General::swroot}/urlfilter/blacklists/.autoupdate.last";
+my $upd_cron_dly = "${General::swroot}/urlfilter/autoupdate/cron.daily";
+my $upd_cron_wly = "${General::swroot}/urlfilter/autoupdate/cron.weekly";
+my $upd_cron_mly = "${General::swroot}/urlfilter/autoupdate/cron.monthly";
+
+my $errormessage='';
+my $updatemessage='';
+my $restoremessage='';
+my $buttontext='';
+my $source_name='';
+my $source_url='';
+my $blacklistage=0;
+
+my @repositorylist=();
+my @repositoryfiles=();
+my @categories=();
+my @selectedcategories=();
+my @filtergroups=();
+my @tclist=();
+my @uqlist=();
+my @source_urllist=();
+my @temp=();
+
+my $lastslashpos=0;
+
+my $toggle='';
+my $gif='';
+my $led='';
+my $ldesc='';
+my $gdesc='';
+
+if (! -d $dbdir) { mkdir("$dbdir"); }
+if (! -e $tcfile) { system("touch $tcfile"); }
+if (! -e $uqfile) { system("touch $uqfile"); }
+if (! -e $sourceurlfile) { system("touch $sourceurlfile"); }
+
+&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
+&General::readhash("${General::swroot}/main/settings", \%mainsettings);
+&General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
+
+&readblockcategories;
+
+open(FILE, $tcfile);
+@tclist = <FILE>;
+close(FILE);
+open(FILE, $uqfile);
+@uqlist = <FILE>;
+close(FILE);
+open(FILE, $sourceurlfile);
+@source_urllist = <FILE>;
+close(FILE);
+
+$filtersettings{'ENABLE_CUSTOM_BLACKLIST'} = 'off';
+$filtersettings{'ENABLE_CUSTOM_WHITELIST'} = 'off';
+$filtersettings{'ENABLE_CUSTOM_EXPRESSIONS'} = 'off';
+$filtersettings{'BLOCK_EXECUTABLES'} = 'off';
+$filtersettings{'BLOCK_AUDIO-VIDEO'} = 'off';
+$filtersettings{'BLOCK_ARCHIVES'} = 'off';
+$filtersettings{'ENABLE_REWRITE'} = 'off';
+$filtersettings{'UNFILTERED_CLIENTS'} = '';
+$filtersettings{'BANNED_CLIENTS'} = '';
+$filtersettings{'SHOW_CATEGORY'} = 'off';
+$filtersettings{'SHOW_URL'} = 'off';
+$filtersettings{'SHOW_IP'} = 'off';
+$filtersettings{'ENABLE_DNSERROR'} = 'off';
+$filtersettings{'ENABLE_JPEG'} = 'off';
+$filtersettings{'REDIRECT_PAGE'} = '';
+$filtersettings{'MSG_TEXT_1'} = '';
+$filtersettings{'MSG_TEXT_2'} = '';
+$filtersettings{'MSG_TEXT_3'} = '';
+$filtersettings{'ENABLE_EXPR_LISTS'} = 'off';
+$filtersettings{'BLOCK_IP_ADDR'} = 'off';
+$filtersettings{'BLOCK_ALL'} = 'off';
+$filtersettings{'ENABLE_EMPTY_ADS'} = 'off';
+$filtersettings{'ENABLE_GLOBAL_WHITELIST'} = 'off';
+$filtersettings{'ENABLE_SAFESEARCH'} = 'off';
+$filtersettings{'ENABLE_LOG'} = 'off';
+$filtersettings{'ENABLE_USERNAME_LOG'} = 'off';
+$filtersettings{'ENABLE_CATEGORY_LOG'} = 'off';
+$filtersettings{'CHILDREN'} = '5';
+$filtersettings{'ENABLE_AUTOUPDATE'} = 'off';
+
+$filtersettings{'ACTION'} = '';
+$filtersettings{'VALID'} = '';
+
+&Header::getcgihash(\%filtersettings);
+&Header::getcgihash(\%tcsettings);
+&Header::getcgihash(\%uqsettings);
+&Header::getcgihash(\%besettings);
+
+if (($filtersettings{'ACTION'} eq $Lang::tr{'save'}) ||
+    ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter save and restart'}) ||
+    ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter upload file'}) ||
+    ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter remove file'}) ||
+    ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter upload background'}) ||
+    ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter upload blacklist'}) ||
+    ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter backup'}) ||
+    ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter restore'}))
+{ 
+       if (!($filtersettings{'CHILDREN'} =~ /^\d+$/) || ($filtersettings{'CHILDREN'} < 1))
+       {
+               $errormessage = $Lang::tr{'urlfilter invalid num of children'};
+               goto ERROR;
+       }
+
+       if ((!($filtersettings{'REDIRECT_PAGE'} eq '')) && (!($filtersettings{'REDIRECT_PAGE'} =~ /^https?:\/\//)))
+       {
+               $filtersettings{'REDIRECT_PAGE'} = "http://".$filtersettings{'REDIRECT_PAGE'};
+       }
+
+       if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter remove file'})
+       {
+               if (-e "$repository/$filtersettings{'ID'}") { unlink("$repository/$filtersettings{'ID'}"); }
+               $filtersettings{'ACTION'} = $Lang::tr{'urlfilter manage repository'};
+       }
+
+       if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter upload file'})
+       {
+               &Header::getcgihash(\%filtersettings, {'wantfile' => 1, 'filevar' => 'UPLOADFILE'});
+
+               $filtersettings{'ACTION'} = $Lang::tr{'urlfilter manage repository'};
+               $_ = $filtersettings{'UPLOADFILE'};
+               tr/\\/\//;
+               $_ = substr($_,rindex($_,"/")+1);
+               if ($_) {
+                       if (copy($filtersettings{'UPLOADFILE'}, "$repository/$_") != 1)
+                       {
+                               $errormessage = $!;
+                               goto ERROR;
+                       }
+               }
+
+       }
+       
+       if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter upload background'})
+       {
+               &Header::getcgihash(\%filtersettings, {'wantfile' => 1, 'filevar' => 'BACKGROUND'});
+
+               if (copy($filtersettings{'BACKGROUND'}, "/home/httpd/html/images/urlfilter/background.jpg") != 1)
+               {
+                       $errormessage = $!;
+                       goto ERROR;
+               }
+       }
+       
+       if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter upload blacklist'})
+       {
+               &Header::getcgihash(\%filtersettings, {'wantfile' => 1, 'filevar' => 'UPDATEFILE'});
+
+               if (!($filtersettings{'UPDATEFILE'} =~ /.tar.gz$/))
+               {
+                       $errormessage = $Lang::tr{'urlfilter wrong filetype'};
+                       goto ERROR;
+               }
+
+               if (copy($filtersettings{'UPDATEFILE'}, "${General::swroot}/urlfilter/blacklists.tar.gz") != 1)
+               {
+                       $errormessage = $!;
+                       goto ERROR;
+               }
+               
+               if (!(-d "${General::swroot}/urlfilter/update")) { mkdir("${General::swroot}/urlfilter/update"); }
+
+               my $exitcode = system("/bin/tar --no-same-owner -xzf ${General::swroot}/urlfilter/blacklists.tar.gz -C ${General::swroot}/urlfilter/update");
+               
+               if ($exitcode > 0)
+               {
+                       $errormessage = $Lang::tr{'urlfilter tar error'};
+               } else {
+
+                       if (-d "${General::swroot}/urlfilter/update/category")
+                       {
+                               system("mv ${General::swroot}/urlfilter/update/category ${General::swroot}/urlfilter/update/blacklists");
+                       }
+
+                       if (!(-d "${General::swroot}/urlfilter/update/blacklists"))
+                       {
+                               $errormessage = $Lang::tr{'urlfilter invalid content'};
+                       } else {
+                               system("cp -r ${General::swroot}/urlfilter/update/blacklists/* $dbdir");
+
+                               &readblockcategories;
+                               &readcustomlists;
+
+                               &writeconfigfile;
+
+                               $updatemessage = $Lang::tr{'urlfilter upload success'};
+                               system("${General::swroot}/urlfilter/bin/prebuild.pl &");
+                               system("logger -t installpackage[urlfilter] \"URL filter blacklist - Blacklist update from local source completed\"");
+                       }
+               }
+               if (-d "${General::swroot}/urlfilter/update") { system("rm -rf ${General::swroot}/urlfilter/update"); }
+               if (-e "${General::swroot}/urlfilter/blacklists.tar.gz") { unlink("${General::swroot}/urlfilter/blacklists.tar.gz"); }
+               if ($errormessage) { goto ERROR; }
+       }
+
+       if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter backup'})
+       {
+               $blistbackup = ($filtersettings{'ENABLE_FULLBACKUP'} eq 'on') ? "blacklists" : "blacklists/custom";
+               if (system("/bin/tar -C ${General::swroot}/urlfilter -czf ${General::swroot}/urlfilter/backup.tar.gz settings timeconst userquota autoupdate $blistbackup"))
+               {
+                       $errormessage = $Lang::tr{'urlfilter backup error'};
+                       goto ERROR;
+               }
+               else
+               {
+                       print "Content-type: application/gzip\n";
+                       print "Content-length: ";
+                       print (-s "${General::swroot}/urlfilter/backup.tar.gz");
+                       print "\n";
+                       print "Content-disposition: attachment; filename=urlfilter-backup.tar.gz\n\n";
+
+                       open (FILE, "${General::swroot}/urlfilter/backup.tar.gz");
+                       while (<FILE>) { print; }
+                       close (FILE);
+
+                       if (-e "${General::swroot}/urlfilter/backup.tar.gz") { unlink("${General::swroot}/urlfilter/backup.tar.gz"); }
+                       exit;
+               }
+       }
+
+       if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter restore'})
+       {
+               &Header::getcgihash(\%filtersettings, {'wantfile' => 1, 'filevar' => 'UPDATEFILE'});
+
+               if (!($filtersettings{'UPDATEFILE'} =~ /.tar.gz$/))
+               {
+                       $errormessage = $Lang::tr{'urlfilter wrong filetype'};
+                       goto ERROR;
+               }
+
+               if (!(-d "${General::swroot}/urlfilter/restore")) { mkdir("${General::swroot}/urlfilter/restore"); }
+
+               if (copy($filtersettings{'UPDATEFILE'}, "${General::swroot}/urlfilter/backup.tar.gz") != 1)
+               {
+                       $errormessage = $!;
+               }
+               
+               my $exitcode = system("/bin/tar --no-same-owner --preserve-permissions -xzf ${General::swroot}/urlfilter/backup.tar.gz -C ${General::swroot}/urlfilter/restore");
+               if ($exitcode > 0)
+               {
+                       $errormessage = $Lang::tr{'urlfilter tar error'};
+               } else {
+                       if (!(-e "${General::swroot}/urlfilter/restore/settings"))
+                       {
+                               $errormessage = $Lang::tr{'urlfilter invalid restore file'};
+                       } else {
+                               system("cp -rp ${General::swroot}/urlfilter/restore/* ${General::swroot}/urlfilter/");
+                               &readblockcategories;
+                               &readcustomlists;
+                               &writeconfigfile;
+
+                               $restoremessage = $Lang::tr{'urlfilter restore success'};
+                       }
+               }
+
+               if (-e "${General::swroot}/urlfilter/backup.tar.gz") { unlink("${General::swroot}/urlfilter/backup.tar.gz"); }
+               if (-d "${General::swroot}/urlfilter/restore") { system("rm -rf ${General::swroot}/urlfilter/restore"); }
+               if ($errormessage) { goto ERROR; }
+       }
+
+       if ($filtersettings{'ACTION'} eq $Lang::tr{'save'})
+       {
+               $filtersettings{'VALID'} = 'yes';
+               &savesettings;
+       }
+
+       if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter save and restart'})
+       {
+               if (!(-e "${General::swroot}/proxy/enable"))
+               {
+                       $errormessage = $Lang::tr{'urlfilter web proxy service required'};
+                       goto ERROR;
+               }
+               if (!($proxysettings{'ENABLE_FILTER'} eq 'on'))
+               {
+                       $errormessage = $Lang::tr{'urlfilter not enabled'};
+                       goto ERROR;
+               }
+
+               $filtersettings{'VALID'} = 'yes';
+               &savesettings;
+
+               system("chown -R nobody.nobody $dbdir");
+
+               if (-e "$dbdir/custom/allowed/domains.db") { unlink("$dbdir/custom/allowed/domains.db"); }
+               if (-e "$dbdir/custom/allowed/urls.db")    { unlink("$dbdir/custom/allowed/urls.db"); }
+               if (-e "$dbdir/custom/blocked/domains.db") { unlink("$dbdir/custom/blocked/domains.db"); }
+               if (-e "$dbdir/custom/blocked/urls.db")    { unlink("$dbdir/custom/blocked/urls.db"); }
+
+               foreach (<$dbdir/*>)
+               {
+                       if (-d $_){ system("chmod 644 $_/*"); }
+                       if (-d $_){ system("chmod 666 $_/*.db"); }
+               }
+               if (-d "$dbdir/custom/allowed")
+               {
+                       system("chmod 755 $dbdir/custom/allowed");
+                       system("chmod 644 $dbdir/custom/allowed/*");
+               }
+               if (-d "$dbdir/custom/blocked")
+               {
+                       system("chmod 755 $dbdir/custom/blocked");
+                       system("chmod 644 $dbdir/custom/blocked/*");
+               }
+
+               system('/usr/local/bin/restartsquid');
+       }
+
+ERROR:
+
+       if ($errormessage) { $filtersettings{'VALID'} = 'no'; }
+
+}
+
+if ($tcsettings{'ACTION'} eq $Lang::tr{'urlfilter set time constraints'}) { $tcsettings{'TCMODE'} = 'on'}
+
+if (($tcsettings{'MODE'} eq 'TIMECONSTRAINT') && ($tcsettings{'ACTION'} eq $Lang::tr{'add'}))
+{
+       $tcsettings{'TCMODE'}='on';
+
+       if (!$tcsettings{'DST'})
+       {
+               $errormessage=$Lang::tr{'urlfilter dst error'};
+       }
+
+       if (!$tcsettings{'SRC'})
+       {
+               $errormessage=$Lang::tr{'urlfilter src error'};
+       }
+
+       if (!($tcsettings{'TO_HOUR'}.$tcsettings{'TO_MINUTE'} gt $tcsettings{'FROM_HOUR'}.$tcsettings{'FROM_MINUTE'}))
+       {
+               $errormessage=$Lang::tr{'urlfilter timespace error'};
+       }
+
+       if (!(($tcsettings{'MON'} eq 'on') || ($tcsettings{'TUE'} eq 'on') || ($tcsettings{'WED'} eq 'on') || ($tcsettings{'THU'} eq 'on') || ($tcsettings{'FRI'} eq 'on') || ($tcsettings{'SAT'} eq 'on') || ($tcsettings{'SUN'} eq 'on')))
+       {
+               $errormessage=$Lang::tr{'urlfilter weekday error'};
+       }
+
+       if (!$errormessage)
+       {
+               if ($tcsettings{'DST'} =~ /^any/) { $tcsettings{'DST'} = 'any'; }
+               if ($tcsettings{'ENABLERULE'} eq 'on') { $tcsettings{'ACTIVE'} = $tcsettings{'ENABLERULE'}; } else { $tcsettings{'ACTIVE'} = 'off'}
+
+               $tcsettings{'ENABLERULE'} = 'on';
+               if($tcsettings{'EDITING'} eq 'no') {
+                       open(FILE,">>$tcfile");
+                       flock FILE, 2;
+                       print FILE "$tcsettings{'DEFINITION'},$tcsettings{'MON'},$tcsettings{'TUE'},$tcsettings{'WED'},$tcsettings{'THU'},$tcsettings{'FRI'},$tcsettings{'SAT'},$tcsettings{'SUN'},$tcsettings{'FROM_HOUR'},$tcsettings{'FROM_MINUTE'},$tcsettings{'TO_HOUR'},$tcsettings{'TO_MINUTE'},$tcsettings{'SRC'},$tcsettings{'DST'},$tcsettings{'ACCESS'},$tcsettings{'ACTIVE'},$tcsettings{'COMMENT'}\n";
+               } else {
+                       open(FILE, ">$tcfile");
+                       flock FILE, 2;
+                       $id = 0;
+                       foreach $line (@tclist)
+                       {
+                               $id++;
+                               if ($tcsettings{'EDITING'} eq $id) {
+                                       print FILE "$tcsettings{'DEFINITION'},$tcsettings{'MON'},$tcsettings{'TUE'},$tcsettings{'WED'},$tcsettings{'THU'},$tcsettings{'FRI'},$tcsettings{'SAT'},$tcsettings{'SUN'},$tcsettings{'FROM_HOUR'},$tcsettings{'FROM_MINUTE'},$tcsettings{'TO_HOUR'},$tcsettings{'TO_MINUTE'},$tcsettings{'SRC'},$tcsettings{'DST'},$tcsettings{'ACCESS'},$tcsettings{'ACTIVE'},$tcsettings{'COMMENT'}\n";
+                               } else { print FILE "$line"; }
+                       }
+               }
+               close(FILE);
+               undef %tcsettings;
+               $tcsettings{'CHANGED'}='yes';
+               $tcsettings{'TCMODE'}='on';
+               $changed = 'yes';
+       } else {
+               if ($tcsettings{'EDITING'} ne 'no')
+               {
+                       $tcsettings{'ACTION'} = $Lang::tr{'edit'};
+                       $tcsettings{'ID'} = $tcsettings{'EDITING'};
+               }
+       }
+}
+
+if (($tcsettings{'MODE'} eq 'TIMECONSTRAINT') && ($tcsettings{'ACTION'} eq $Lang::tr{'remove'}))
+{
+       $id = 0;
+       open(FILE, ">$tcfile");
+       flock FILE, 2;
+       foreach $line (@tclist)
+       {
+               $id++;
+               unless ($tcsettings{'ID'} eq $id) { print FILE "$line"; }
+       }
+       close(FILE);
+       $tcsettings{'CHANGED'}='yes';
+       $tcsettings{'TCMODE'}='on';
+}
+
+if (($tcsettings{'MODE'} eq 'TIMECONSTRAINT') && ($tcsettings{'ACTION'} eq $Lang::tr{'urlfilter restart'}))
+{
+       if (!($proxysettings{'ENABLE_FILTER'} eq 'on'))
+       {
+               $errormessage = $Lang::tr{'urlfilter not enabled'};
+       }
+       if (!(-e "${General::swroot}/proxy/enable"))
+       {
+               $errormessage = $Lang::tr{'urlfilter web proxy service required'};
+       }
+
+       if (!$errormessage) { system('/usr/local/bin/restartsquid'); }
+       $tcsettings{'TCMODE'}='on';
+}
+
+if (($tcsettings{'MODE'} eq 'TIMECONSTRAINT') && ($tcsettings{'ACTION'} eq $Lang::tr{'toggle enable disable'}))
+{
+       open(FILE, ">$tcfile");
+       flock FILE, 2;
+       $id = 0;
+       foreach $line (@tclist)
+       {
+               $id++;
+               unless ($tcsettings{'ID'} eq $id) { print FILE "$line"; }
+               else
+               {
+                       chomp($line);
+                       @temp = split(/\,/,$line);
+                       if ($temp[15] eq 'on') { $temp[15] = 'off'; } else { $temp[15] = 'on' }
+                       print FILE "$temp[0],$temp[1],$temp[2],$temp[3],$temp[4],$temp[5],$temp[6],$temp[7],$temp[8],$temp[9],$temp[10],$temp[11],$temp[12],$temp[13],$temp[14],$temp[15],$temp[16]\n";
+               }
+       }
+       close(FILE);
+       $tcsettings{'CHANGED'}='yes';
+       $tcsettings{'TCMODE'}='on';
+}
+
+if (!$errormessage) {
+       $tcsettings{'ENABLERULE'}='on';
+       $tcsettings{'TO_HOUR'}='24';
+}
+
+if (($tcsettings{'MODE'} eq 'TIMECONSTRAINT') && ($tcsettings{'ACTION'} eq $Lang::tr{'edit'}) && (!$errormessage))
+{
+       $id = 0;
+       foreach $line (@tclist)
+       {
+               $id++;
+               if ($tcsettings{'ID'} eq $id)
+               {
+                       chomp($line);
+                       @temp = split(/\,/,$line);
+                       $tcsettings{'DEFINITION'} = $temp[0];
+                       $tcsettings{'MON'} = $temp[1];
+                       $tcsettings{'TUE'} = $temp[2];
+                       $tcsettings{'WED'} = $temp[3];
+                       $tcsettings{'THU'} = $temp[4];
+                       $tcsettings{'FRI'} = $temp[5];
+                       $tcsettings{'SAT'} = $temp[6];
+                       $tcsettings{'SUN'} = $temp[7];
+                       $tcsettings{'FROM_HOUR'} = $temp[8];
+                       $tcsettings{'FROM_MINUTE'} = $temp[9];
+                       $tcsettings{'TO_HOUR'} = $temp[10];
+                       $tcsettings{'TO_MINUTE'} = $temp[11];
+                       $tcsettings{'SRC'} = $temp[12];
+                       $tcsettings{'DST'} = $temp[13];
+                       $tcsettings{'ACCESS'} = $temp[14];
+                       $tcsettings{'ENABLERULE'} = $temp[15];
+                       $tcsettings{'COMMENT'} = $temp[16];
+               }
+       }
+       $tcsettings{'TCMODE'}='on';
+}
+
+if ($uqsettings{'ACTION'} eq $Lang::tr{'urlfilter set user quota'}) { $uqsettings{'UQMODE'} = 'on'}
+
+if (($uqsettings{'MODE'} eq 'USERQUOTA') && ($uqsettings{'ACTION'} eq $Lang::tr{'add'}))
+{
+       $uqsettings{'UQMODE'}='on';
+
+       if ((!($uqsettings{'TIME_QUOTA'} =~ /^\d+/)) || ($uqsettings{'TIME_QUOTA'} < '1'))
+       {
+               $errormessage=$Lang::tr{'urlfilter quota time error'};
+       }
+
+       @temp = split(/\n/,$uqsettings{'QUOTA_USERS'});
+       undef $uqsettings{'QUOTA_USERS'};
+       foreach (@temp)
+       {
+               s/^\s+//g; s/\s+$//g;
+               if ($_) { $uqsettings{'QUOTA_USERS'} .= $_."\n"; }
+       }
+
+       if ($uqsettings{'QUOTA_USERS'} eq '')
+       {
+               $errormessage=$Lang::tr{'urlfilter quota user error'};
+       }
+
+       $_  = $uqsettings{'QUOTA_USERS'};
+       chomp; s/\n/|/g;
+       my $quota_users = $_;
+
+       if ($uqsettings{'QUOTA_USERS'} =~ /\\/)
+       {
+               $errormessage=$Lang::tr{'urlfilter invalid user error'};
+       }
+
+       if (!$errormessage) {
+               if ($uqsettings{'ENABLEQUOTA'} eq 'on') { $uqsettings{'ACTIVE'} = $uqsettings{'ENABLEQUOTA'}; } else { $uqsettings{'ACTIVE'} = 'off'}
+
+               $uqsettings{'ENABLERULE'} = 'on';
+               if($uqsettings{'EDITING'} eq 'no') {
+                       open(FILE,">>$uqfile");
+                       flock FILE, 2;
+                       print FILE "$uqsettings{'TIME_QUOTA'},$uqsettings{'SPORADIC'},$uqsettings{'RENEWAL'},$quota_users,$uqsettings{'ACTIVE'}\n";
+               } else {
+                       open(FILE, ">$uqfile");
+                       flock FILE, 2;
+                       $id = 0;
+                       foreach $line (@uqlist)
+                       {
+                               $id++;
+                               if ($uqsettings{'EDITING'} eq $id) {
+                                       print FILE "$uqsettings{'TIME_QUOTA'},$uqsettings{'SPORADIC'},$uqsettings{'RENEWAL'},$quota_users,$uqsettings{'ACTIVE'}\n";
+                               } else { print FILE "$line"; }
+                       }
+               }
+               close(FILE);
+               undef %uqsettings;
+               $uqsettings{'CHANGED'}='yes';
+               $uqsettings{'MODE'}='USERQUOTA';
+               $uqsettings{'UQMODE'}='on';
+               $changed = 'yes';
+       } else {
+               if ($uqsettings{'EDITING'} ne 'no')
+               {
+                       $uqsettings{'ACTION'} = $Lang::tr{'edit'};
+                       $uqsettings{'ID'} = $uqsettings{'EDITING'};
+               }
+       }
+}
+
+if (($uqsettings{'MODE'} eq 'USERQUOTA') && ($uqsettings{'ACTION'} eq $Lang::tr{'remove'}))
+{
+       $id = 0;
+       open(FILE, ">$uqfile");
+       flock FILE, 2;
+       foreach $line (@uqlist)
+       {
+               $id++;
+               unless ($uqsettings{'ID'} eq $id) { print FILE "$line"; }
+       }
+       close(FILE);
+       $uqsettings{'CHANGED'}='yes';
+       $uqsettings{'UQMODE'}='on';
+}
+
+if (!$errormessage) {
+       $uqsettings{'ENABLEQUOTA'}='on';
+}
+
+if (($uqsettings{'MODE'} eq 'USERQUOTA') && ($uqsettings{'ACTION'} eq $Lang::tr{'edit'}) && (!$errormessage))
+{
+       $id = 0;
+       foreach $line (@uqlist)
+       {
+               $id++;
+               if ($uqsettings{'ID'} eq $id)
+               {
+                       chomp($line);
+                       @temp = split(/\,/,$line);
+                       $uqsettings{'TIME_QUOTA'} = $temp[0];
+                       $uqsettings{'SPORADIC'} = $temp[1];
+                       $uqsettings{'RENEWAL'} = $temp[2];
+                       $uqsettings{'QUOTA_USERS'} = $temp[3];
+                       $uqsettings{'ENABLEQUOTA'} = $temp[4];
+               }
+       }
+       $uqsettings{'UQMODE'}='on';
+}
+
+if (($uqsettings{'MODE'} eq 'USERQUOTA') && ($uqsettings{'ACTION'} eq $Lang::tr{'toggle enable disable'}))
+{
+       open(FILE, ">$uqfile");
+       flock FILE, 2;
+       $id = 0;
+       foreach $line (@uqlist)
+       {
+               $id++;
+               unless ($uqsettings{'ID'} eq $id) { print FILE "$line"; }
+               else
+               {
+                       chomp($line);
+                       @temp = split(/\,/,$line);
+                       if ($temp[4] eq 'on') { $temp[4] = 'off'; } else { $temp[4] = 'on' }
+                       print FILE "$temp[0],$temp[1],$temp[2],$temp[3],$temp[4]\n";
+               }
+       }
+       close(FILE);
+       $uqsettings{'CHANGED'}='yes';
+       $uqsettings{'UQMODE'}='on';
+}
+
+if (($uqsettings{'MODE'} eq 'USERQUOTA') && ($uqsettings{'ACTION'} eq $Lang::tr{'urlfilter restart'}))
+{
+       if (!($proxysettings{'ENABLE_FILTER'} eq 'on'))
+       {
+               $errormessage = $Lang::tr{'urlfilter not enabled'};
+       }
+       if (!(-e "${General::swroot}/proxy/enable"))
+       {
+               $errormessage = $Lang::tr{'urlfilter web proxy service required'};
+       }
+
+       if (!$errormessage) { system('/usr/local/bin/restartsquid'); }
+       $uqsettings{'UQMODE'}='on';
+}
+
+if ($besettings{'ACTION'} eq $Lang::tr{'urlfilter blacklist editor'}) { $besettings{'BEMODE'} = 'on'; }
+
+if ($besettings{'MODE'} eq 'BLACKLIST_EDITOR')
+{
+       @temp = split(/\n/,$besettings{'BE_DOMAINS'});
+        undef $besettings{'BE_DOMAINS'};
+        foreach (@temp)
+        {
+                s/^\s+//g; s/\s+$//g;
+                if ($_) { $besettings{'BE_DOMAINS'} .= $_."\n"; }
+        }
+       chomp($besettings{'BE_DOMAINS'});
+       @temp = split(/\n/,$besettings{'BE_URLS'});
+        undef $besettings{'BE_URLS'};
+        foreach (@temp)
+        {
+                s/^\s+//g; s/\s+$//g;
+                if ($_) { $besettings{'BE_URLS'} .= $_."\n"; }
+        }
+       chomp($besettings{'BE_URLS'});
+       @temp = split(/\n/,$besettings{'BE_EXPRESSIONS'});
+        undef $besettings{'BE_EXPRESSIONS'};
+        foreach (@temp)
+        {
+                s/^\s+//g; s/\s+$//g;
+                if ($_) { $besettings{'BE_EXPRESSIONS'} .= $_."\n"; }
+        }
+       chomp($besettings{'BE_EXPRESSIONS'});
+}
+
+if (($besettings{'ACTION'} eq $Lang::tr{'urlfilter load blacklist'}) && ($besettings{'MODE'} = 'BLACKLIST_EDITOR'))
+{
+       $besettings{'BEMODE'} = 'on';
+
+       $besettings{'BE_NAME'} = $besettings{'BE_BLACKLIST'};
+
+       delete $besettings{'BE_DOMAINS'};
+       delete $besettings{'BE_URLS'};
+       delete $besettings{'BE_EXPRESSIONS'};
+
+       if (-e "$dbdir/$besettings{'BE_NAME'}/domains")
+       {
+               open(FILE, "$dbdir/$besettings{'BE_NAME'}/domains");
+               while (<FILE>) { unless ($_ eq '\n') { $besettings{'BE_DOMAINS'} .= $_ } };
+               close FILE;
+               chomp($besettings{'BE_DOMAINS'});
+       }
+       if (-e "$dbdir/$besettings{'BE_NAME'}/urls")
+       {
+               open(FILE, "$dbdir/$besettings{'BE_NAME'}/urls");
+               while (<FILE>) { unless ($_ eq '\n') { $besettings{'BE_URLS'} .= $_ } };
+               close FILE;
+               chomp($besettings{'BE_URLS'});
+       }
+       if (-e "$dbdir/$besettings{'BE_NAME'}/expressions")
+       {
+               open(FILE, "$dbdir/$besettings{'BE_NAME'}/expressions");
+               while (<FILE>) { unless ($_ eq '\n') { $besettings{'BE_EXPRESSIONS'} .= $_ } };
+               close FILE;
+               chomp($besettings{'BE_EXPRESSIONS'});
+       }
+}
+
+if (($besettings{'ACTION'} eq $Lang::tr{'urlfilter import blacklist'}) && ($besettings{'MODE'} = 'BLACKLIST_EDITOR'))
+{
+       $besettings{'BEMODE'} = 'on';
+
+       &Header::getcgihash(\%besettings, {'wantfile' => 1, 'filevar' => 'IMPORTFILE'});
+
+       if (!($besettings{'IMPORTFILE'} =~ /.tar.gz$/))
+       {
+               $errormessage = $Lang::tr{'urlfilter wrong filetype'};
+       } else {
+               if (!-d "$editdir") { mkdir("$editdir"); }
+
+               if (copy($besettings{'IMPORTFILE'}, "$editdir/blacklist.tar.gz") != 1)
+               {
+                       $errormessage = $!;
+               } else {
+               
+                       my $exitcode = system("/bin/tar --no-same-owner --preserve-permissions -xzf $editdir/blacklist.tar.gz -C $editdir");
+                       if ($exitcode > 0)
+                       {
+                               $errormessage = $Lang::tr{'urlfilter tar error'};
+                       } else {
+                               $i = 0;
+                               foreach (<$editdir/blacklists/*>)
+                               {
+                                       if (-d)
+                                       {
+                                               $i++;
+                                               $besettings{'BE_NAME'} = substr($_, rindex($_,"/")+1);
+                                       }
+                               }
+
+                               if (!($i == 1))
+                               {
+                                       $errormessage = $Lang::tr{'urlfilter invalid import file'};
+                               } else {
+                                       delete $besettings{'BE_DOMAINS'};
+                                       delete $besettings{'BE_URLS'};
+                                       delete $besettings{'BE_EXPRESSIONS'};
+
+                                       if (-e "$editdir/blacklists/$besettings{'BE_NAME'}/domains")
+                                       {
+                                               open(FILE, "$editdir/blacklists/$besettings{'BE_NAME'}/domains");
+                                               while (<FILE>) { unless ($_ eq '\n') { $besettings{'BE_DOMAINS'} .= $_ } };
+                                               close FILE;
+                                               chomp($besettings{'BE_DOMAINS'});
+                                       }
+                                       if (-e "$editdir/blacklists/$besettings{'BE_NAME'}/urls")
+                                       {
+                                               open(FILE, "$editdir/blacklists/$besettings{'BE_NAME'}/urls");
+                                               while (<FILE>) { unless ($_ eq '\n') { $besettings{'BE_URLS'} .= $_ } };
+                                               close FILE;
+                                               chomp($besettings{'BE_URLS'});
+                                       }
+                                       if (-e "$editdir/blacklists/$besettings{'BE_NAME'}/expressions")
+                                       {
+                                               open(FILE, "$editdir/blacklists/$besettings{'BE_NAME'}/expressions");
+                                               while (<FILE>) { unless ($_ eq '\n') { $besettings{'BE_EXPRESSIONS'} .= $_ } };
+                                               close FILE;
+                                               chomp($besettings{'BE_EXPRESSIONS'});
+                                       }
+                               }
+                       }
+
+               if (-d $editdir) { system("rm -rf $editdir"); }
+
+               }
+       }
+}
+
+if (($besettings{'ACTION'} eq $Lang::tr{'urlfilter export blacklist'}) && ($besettings{'MODE'} = 'BLACKLIST_EDITOR'))
+{
+       $besettings{'BEMODE'} = 'on';
+
+       if ($besettings{'BE_NAME'} eq '')
+       {
+               $errormessage = $Lang::tr{'urlfilter category name error'};
+       } elsif ($besettings{'BE_DOMAINS'} || $besettings{'BE_URLS'} || $besettings{'BE_EXPRESSIONS'}) {
+
+               $_ = $besettings{'BE_NAME'}; tr/A-Z/a-z/; $besettings{'BE_NAME'} = $_;
+
+               if (!(-d "$editdir")) { mkdir("$editdir"); }
+               if (!(-d "$editdir/blacklists")) { mkdir("$editdir/blacklists"); }
+               if (!(-d "$editdir/blacklists/$besettings{'BE_NAME'}")) { mkdir("$editdir/blacklists/$besettings{'BE_NAME'}"); }
+
+               open(FILE, ">$editdir/blacklists/$besettings{'BE_NAME'}/domains");
+               flock FILE, 2;
+               print FILE "$besettings{'BE_DOMAINS'}\n";
+               close FILE;
+               open(FILE, ">$editdir/blacklists/$besettings{'BE_NAME'}/urls");
+               flock FILE, 2;
+               print FILE "$besettings{'BE_URLS'}\n";
+               close FILE;
+               open(FILE, ">$editdir/blacklists/$besettings{'BE_NAME'}/expressions");
+               flock FILE, 2;
+               print FILE "$besettings{'BE_EXPRESSIONS'}\n";
+               close FILE;
+
+               if (system("/bin/tar -C $editdir -czf $editdir/$besettings{'BE_NAME'}.tar.gz blacklists"))
+               {
+                       $errormessage = $Lang::tr{'urlfilter export error'};
+               }
+               else
+               {
+                       print "Content-type: application/gzip\n";
+                       print "Content-length: ";
+                       print (-s "$editdir/$besettings{'BE_NAME'}.tar.gz");
+                       print "\n";
+                       print "Content-disposition: attachment; filename=$besettings{'BE_NAME'}.tar.gz\n\n";
+
+                       open (FILE, "$editdir/$besettings{'BE_NAME'}.tar.gz");
+                       while (<FILE>) { print; }
+                       close (FILE);
+
+                       if (-d $editdir) { system("rm -rf $editdir"); }
+                       exit;
+               }
+       } else {
+               $errormessage = $Lang::tr{'urlfilter category data error'};
+       }
+}
+
+if (($besettings{'ACTION'} eq $Lang::tr{'urlfilter install blacklist'}) && ($besettings{'MODE'} = 'BLACKLIST_EDITOR'))
+{
+       $besettings{'BEMODE'} = 'on';
+
+       if ($besettings{'BE_NAME'} eq '')
+       {
+               $errormessage = $Lang::tr{'urlfilter category name error'};
+       } elsif ($besettings{'BE_DOMAINS'} || $besettings{'BE_URLS'} || $besettings{'BE_EXPRESSIONS'}) {
+
+               $_ = $besettings{'BE_NAME'}; tr/A-Z/a-z/; $besettings{'BE_NAME'} = $_;
+
+               if (!-d "$editdir") { mkdir("$editdir"); }
+
+               if (!-d "$dbdir/$besettings{'BE_NAME'}") { mkdir("$dbdir/$besettings{'BE_NAME'}"); }
+
+               if (-e "$dbdir/$besettings{'BE_NAME'}/domains") { unlink("$dbdir/$besettings{'BE_NAME'}/domains"); }
+               if ($besettings{'BE_DOMAINS'})
+               {
+                       open(FILE, ">$dbdir/$besettings{'BE_NAME'}/domains");
+                       flock FILE, 2;
+                       print FILE "$besettings{'BE_DOMAINS'}\n";
+                       close FILE;
+               }
+               if (-e "$dbdir/$besettings{'BE_NAME'}/urls") { unlink("$dbdir/$besettings{'BE_NAME'}/urls"); }
+               if ($besettings{'BE_URLS'})
+               {
+                       open(FILE, ">$dbdir/$besettings{'BE_NAME'}/urls");
+                       flock FILE, 2;
+                       print FILE "$besettings{'BE_URLS'}\n";
+                       close FILE;
+               }
+               if (-e "$dbdir/$besettings{'BE_NAME'}/expressions") { unlink("$dbdir/$besettings{'BE_NAME'}/expressions"); }
+               if ($besettings{'BE_EXPRESSIONS'})
+               {
+                       open(FILE, ">$dbdir/$besettings{'BE_NAME'}/expressions");
+                       flock FILE, 2;
+                       print FILE "$besettings{'BE_EXPRESSIONS'}\n";
+                       close FILE;
+               }
+
+               open(FILE, ">$editdir/install.conf");
+               flock FILE, 2;
+               print FILE "logdir /var/log/squidGuard\n";
+               print FILE "dbhome $dbdir/$besettings{'BE_NAME'}\n\n";
+               print FILE "dest $besettings{'BE_NAME'} {\n";
+               if ($besettings{'BE_DOMAINS'})     { print FILE "    domainlist  domains\n"; }
+               if ($besettings{'BE_URLS'})        { print FILE "    urllist     urls\n"; }
+               if ($besettings{'BE_EXPRESSIONS'}) { print FILE "    expressions expressions\n"; }
+               print FILE "}\n\n";
+               print FILE "acl {\n";
+               print FILE "    default {\n";
+               print FILE "        pass none\n";
+               print FILE "    }\n";
+               print FILE "}\n";
+               close FILE;
+
+               system("rm -f $dbdir/$besettings{'BE_NAME'}/*.db");
+               system("/usr/sbin/squidGuard -c $editdir/install.conf -C all");
+               system("chmod a+w $dbdir/$besettings{'BE_NAME'}/*.db");
+
+               &readblockcategories;
+               &readcustomlists;
+
+               &writeconfigfile;
+
+               system('/usr/local/bin/restartsquid') unless ($besettings{'NORESTART'} eq 'on');
+
+               if (-d $editdir) { system("rm -rf $editdir"); }
+       } else {
+               $errormessage = $Lang::tr{'urlfilter category data error'};
+       }
+}
+
+if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter save schedule'})
+{
+       if (($filtersettings{'UPDATE_SOURCE'} eq 'custom') && ($filtersettings{'CUSTOM_UPDATE_URL'} eq ''))
+       {
+               $errormessage = $Lang::tr{'urlfilter custom url required'};
+       } else {
+               open (FILE, ">$updconffile");
+               print FILE "ENABLE_AUTOUPDATE=$filtersettings{'ENABLE_AUTOUPDATE'}\n";
+               print FILE "UPDATE_SCHEDULE=$filtersettings{'UPDATE_SCHEDULE'}\n";
+               print FILE "UPDATE_SOURCE=$filtersettings{'UPDATE_SOURCE'}\n";
+               print FILE "CUSTOM_UPDATE_URL=$filtersettings{'CUSTOM_UPDATE_URL'}\n";
+               close FILE;
+
+               if (-e $upd_cron_dly) { unlink($upd_cron_dly); }
+               if (-e $upd_cron_wly) { unlink($upd_cron_wly); }
+               if (-e $upd_cron_mly) { unlink($upd_cron_mly); }
+
+               if (($filtersettings{'ENABLE_AUTOUPDATE'} eq 'on') && ($filtersettings{'UPDATE_SCHEDULE'} eq 'daily'))
+               {
+                       symlink("../bin/autoupdate.pl",$upd_cron_dly)
+               } else {
+                       symlink("/bin/false",$upd_cron_dly)
+               }
+
+               if (($filtersettings{'ENABLE_AUTOUPDATE'} eq 'on') && ($filtersettings{'UPDATE_SCHEDULE'} eq 'weekly'))
+               {
+                       symlink("../bin/autoupdate.pl",$upd_cron_wly)
+               } else {
+                       symlink("/bin/false",$upd_cron_wly)
+               }
+
+               if (($filtersettings{'ENABLE_AUTOUPDATE'} eq 'on') && ($filtersettings{'UPDATE_SCHEDULE'} eq 'monthly'))
+               {
+                       symlink("../bin/autoupdate.pl",$upd_cron_mly)
+               } else {
+                       symlink("/bin/false",$upd_cron_mly)
+               }
+       }
+}
+
+if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter update now'})
+{
+       if ($filtersettings{'UPDATE_SOURCE'} eq 'custom')
+       {
+               if ($filtersettings{'CUSTOM_UPDATE_URL'} eq '')
+               {
+                       $errormessage = $Lang::tr{'urlfilter custom url required'};
+               } else {
+                       system("${General::swroot}/urlfilter/bin/autoupdate.pl $filtersettings{'CUSTOM_UPDATE_URL'} &");
+               }
+       } else {
+               system("${General::swroot}/urlfilter/bin/autoupdate.pl $filtersettings{'UPDATE_SOURCE'} &");
+       }
+}
+
+
+if (-e "${General::swroot}/urlfilter/settings") { &General::readhash("${General::swroot}/urlfilter/settings", \%filtersettings); }
+
+&readcustomlists;
+
+$checked{'ENABLE_CUSTOM_BLACKLIST'}{'off'} = '';
+$checked{'ENABLE_CUSTOM_BLACKLIST'}{'on'} = '';
+$checked{'ENABLE_CUSTOM_BLACKLIST'}{$filtersettings{'ENABLE_CUSTOM_BLACKLIST'}} = "checked='checked'";
+$checked{'ENABLE_CUSTOM_WHITELIST'}{'off'} = '';
+$checked{'ENABLE_CUSTOM_WHITELIST'}{'on'} = '';
+$checked{'ENABLE_CUSTOM_WHITELIST'}{$filtersettings{'ENABLE_CUSTOM_WHITELIST'}} = "checked='checked'";
+$checked{'ENABLE_CUSTOM_EXPRESSIONS'}{'off'} = '';
+$checked{'ENABLE_CUSTOM_EXPRESSIONS'}{'on'} = '';
+$checked{'ENABLE_CUSTOM_EXPRESSIONS'}{$filtersettings{'ENABLE_CUSTOM_EXPRESSIONS'}} = "checked='checked'";
+$checked{'BLOCK_EXECUTABLES'}{'off'} = '';
+$checked{'BLOCK_EXECUTABLES'}{'on'} = '';
+$checked{'BLOCK_EXECUTABLES'}{$filtersettings{'BLOCK_EXECUTABLES'}} = "checked='checked'";
+$checked{'BLOCK_AUDIO-VIDEO'}{'off'} = '';
+$checked{'BLOCK_AUDIO-VIDEO'}{'on'} = '';
+$checked{'BLOCK_AUDIO-VIDEO'}{$filtersettings{'BLOCK_AUDIO-VIDEO'}} = "checked='checked'";
+$checked{'BLOCK_ARCHIVES'}{'off'} = '';
+$checked{'BLOCK_ARCHIVES'}{'on'} = '';
+$checked{'BLOCK_ARCHIVES'}{$filtersettings{'BLOCK_ARCHIVES'}} = "checked='checked'";
+$checked{'ENABLE_REWRITE'}{'off'} = '';
+$checked{'ENABLE_REWRITE'}{'on'} = '';
+$checked{'ENABLE_REWRITE'}{$filtersettings{'ENABLE_REWRITE'}} = "checked='checked'";
+$checked{'SHOW_CATEGORY'}{'off'} = '';
+$checked{'SHOW_CATEGORY'}{'on'} = '';
+$checked{'SHOW_CATEGORY'}{$filtersettings{'SHOW_CATEGORY'}} = "checked='checked'";
+$checked{'SHOW_URL'}{'off'} = '';
+$checked{'SHOW_URL'}{'on'} = '';
+$checked{'SHOW_URL'}{$filtersettings{'SHOW_URL'}} = "checked='checked'";
+$checked{'SHOW_IP'}{'off'} = '';
+$checked{'SHOW_IP'}{'on'} = '';
+$checked{'SHOW_IP'}{$filtersettings{'SHOW_IP'}} = "checked='checked'";
+$checked{'ENABLE_DNSERROR'}{'off'} = '';
+$checked{'ENABLE_DNSERROR'}{'on'} = '';
+$checked{'ENABLE_DNSERROR'}{$filtersettings{'ENABLE_DNSERROR'}} = "checked='checked'";
+$checked{'ENABLE_JPEG'}{'off'} = '';
+$checked{'ENABLE_JPEG'}{'on'} = '';
+$checked{'ENABLE_JPEG'}{$filtersettings{'ENABLE_JPEG'}} = "checked='checked'";
+$checked{'ENABLE_EXPR_LISTS'}{'off'} = '';
+$checked{'ENABLE_EXPR_LISTS'}{'on'} = '';
+$checked{'ENABLE_EXPR_LISTS'}{$filtersettings{'ENABLE_EXPR_LISTS'}} = "checked='checked'";
+$checked{'BLOCK_IP_ADDR'}{'off'} = '';
+$checked{'BLOCK_IP_ADDR'}{'on'} = '';
+$checked{'BLOCK_IP_ADDR'}{$filtersettings{'BLOCK_IP_ADDR'}} = "checked='checked'";
+$checked{'BLOCK_ALL'}{'off'} = '';
+$checked{'BLOCK_ALL'}{'on'} = '';
+$checked{'BLOCK_ALL'}{$filtersettings{'BLOCK_ALL'}} = "checked='checked'";
+$checked{'ENABLE_EMPTY_ADS'}{'off'} = '';
+$checked{'ENABLE_EMPTY_ADS'}{'on'} = '';
+$checked{'ENABLE_EMPTY_ADS'}{$filtersettings{'ENABLE_EMPTY_ADS'}} = "checked='checked'";
+$checked{'ENABLE_GLOBAL_WHITELIST'}{'off'} = '';
+$checked{'ENABLE_GLOBAL_WHITELIST'}{'on'} = '';
+$checked{'ENABLE_GLOBAL_WHITELIST'}{$filtersettings{'ENABLE_GLOBAL_WHITELIST'}} = "checked='checked'";
+$checked{'ENABLE_SAFESEARCH'}{'off'} = '';
+$checked{'ENABLE_SAFESEARCH'}{'on'} = '';
+$checked{'ENABLE_SAFESEARCH'}{$filtersettings{'ENABLE_SAFESEARCH'}} = "checked='checked'";
+$checked{'ENABLE_LOG'}{'off'} = '';
+$checked{'ENABLE_LOG'}{'on'} = '';
+$checked{'ENABLE_LOG'}{$filtersettings{'ENABLE_LOG'}} = "checked='checked'";
+$checked{'ENABLE_USERNAME_LOG'}{'off'} = '';
+$checked{'ENABLE_USERNAME_LOG'}{'on'} = '';
+$checked{'ENABLE_USERNAME_LOG'}{$filtersettings{'ENABLE_USERNAME_LOG'}} = "checked='checked'";
+$checked{'ENABLE_CATEGORY_LOG'}{'off'} = '';
+$checked{'ENABLE_CATEGORY_LOG'}{'on'} = '';
+$checked{'ENABLE_CATEGORY_LOG'}{$filtersettings{'ENABLE_CATEGORY_LOG'}} = "checked='checked'";
+
+foreach $category (@filtergroups) {
+       $checked{$category}{'off'} = '';
+       $checked{$category}{'on'} = '';
+       $checked{$category}{$filtersettings{$category}} = "checked='checked'";
+}
+
+$selected{'DEFINITION'}{$tcsettings{'DEFINITION'}} = "selected='selected'";
+$selected{'FROM_HOUR'}{$tcsettings{'FROM_HOUR'}} = "selected='selected'";
+$selected{'FROM_MINUTE'}{$tcsettings{'FROM_MINUTE'}} = "selected='selected'";
+$selected{'TO_HOUR'}{$tcsettings{'TO_HOUR'}} = "selected='selected'";
+$selected{'TO_MINUTE'}{$tcsettings{'TO_MINUTE'}} = "selected='selected'";
+
+@selectedcategories = split(/\|/,$tcsettings{'DST'});
+foreach (@selectedcategories)
+{
+        $selected{'DST'}{$_} = "selected='selected'";
+}
+
+$selected{'ACCESS'}{$tcsettings{'ACCESS'}} = "selected='selected'";
+
+$checked{'ENABLERULE'}{'off'} = '';
+$checked{'ENABLERULE'}{'on'} = '';
+$checked{'ENABLERULE'}{$tcsettings{'ENABLERULE'}} = "checked='checked'";
+$checked{'MON'}{'off'} = '';
+$checked{'MON'}{'on'} = '';
+$checked{'MON'}{$tcsettings{'MON'}} = "checked='checked'";
+$checked{'TUE'}{'off'} = '';
+$checked{'TUE'}{'on'} = '';
+$checked{'TUE'}{$tcsettings{'TUE'}} = "checked='checked'";
+$checked{'WED'}{'off'} = '';
+$checked{'WED'}{'on'} = '';
+$checked{'WED'}{$tcsettings{'WED'}} = "checked='checked'";
+$checked{'THU'}{'off'} = '';
+$checked{'THU'}{'on'} = '';
+$checked{'THU'}{$tcsettings{'THU'}} = "checked='checked'";
+$checked{'FRI'}{'off'} = '';
+$checked{'FRI'}{'on'} = '';
+$checked{'FRI'}{$tcsettings{'FRI'}} = "checked='checked'";
+$checked{'SAT'}{'off'} = '';
+$checked{'SAT'}{'on'} = '';
+$checked{'SAT'}{$tcsettings{'SAT'}} = "checked='checked'";
+$checked{'SUN'}{'off'} = '';
+$checked{'SUN'}{'on'} = '';
+$checked{'SUN'}{$tcsettings{'SUN'}} = "checked='checked'";
+
+$selected{'SPORADIC'}{$uqsettings{'SPORADIC'}} = "selected='selected'";
+$selected{'RENEWAL'} {$uqsettings{'RENEWAL'}}  = "selected='selected'";
+
+$checked{'ENABLEQUOTA'}{'off'} = '';
+$checked{'ENABLEQUOTA'}{'on'} = '';
+$checked{'ENABLEQUOTA'}{$uqsettings{'ENABLEQUOTA'}} = "checked='checked'";
+
+$selected{'BE_BLACKLIST'}{$besettings{'BE_BLACKLIST'}} = "selected='selected'";
+
+
+&Header::showhttpheaders();
+
+&Header::openpage($Lang::tr{'urlfilter configuration'}, 1, '');
+
+&Header::openbigbox('100%', 'left', '', $errormessage);
+
+if ($errormessage) {
+       &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
+       print "<font class='base'>$errormessage&nbsp;</font>\n";
+       &Header::closebox();
+} elsif (($tcsettings{'CHANGED'} eq 'yes') || ($uqsettings{'CHANGED'} eq 'yes') ) {
+       &writeconfigfile;
+       print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
+       &Header::openbox('100%', 'left', "$Lang::tr{'urlfilter restart notification'}:");
+       print "<class name='base'>$Lang::tr{'urlfilter restart message'}\n";
+       if ($uqsettings{'MODE'} eq 'USERQUOTA') { print "<p><class name='base'>$Lang::tr{'urlfilter quota restart message'}\n"; }
+       print "</class>\n";
+       print "<p><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter restart'}' />";
+       if ($tcsettings{'MODE'} eq 'TIMECONSTRAINT') { print "<input type='hidden' name='MODE' value='TIMECONSTRAINT' />"; }
+       if ($uqsettings{'MODE'} eq 'USERQUOTA') { print "<input type='hidden' name='MODE' value='USERQUOTA' />"; }
+       &Header::closebox();
+       print "</form>\n";
+}
+
+if ($restoremessage) {
+       &Header::openbox('100%', 'left', "$Lang::tr{'urlfilter restore results'}:");
+       print "<class name='base'>$restoremessage\n";
+        print "&nbsp;</class>\n";
+       &Header::closebox();
+}
+
+if ((!$tcsettings{'TCMODE'}) && (!$uqsettings{'UQMODE'}) && (!$besettings{'BEMODE'})) {
+
+if (!($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter manage repository'})) {
+
+#==========================================================
+#
+# Section: Main Configuration
+#
+#==========================================================
+
+print "<form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>\n";
+
+&Header::openbox('100%', 'left', "$Lang::tr{'urlfilter filter settings'}:");
+print <<END
+<table width='100%'>
+<tr>
+        <td colspan='4'><b>$Lang::tr{'urlfilter block categories'}</b></td>
+</tr>
+END
+;
+
+if (@categories == 0) {
+print <<END
+<tr>
+        <td><i>$Lang::tr{'urlfilter no categories'}</i></td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+</tr>
+
+END
+;
+}
+
+for ($n=0; $n<=@categories; $n = $n + $i) {
+       for ($i=0; $i<=3; $i++) {
+               if ($i eq 0) { print "<tr>\n"; }
+               if (($n+$i) < @categories) {
+                       print "<td width='15%'>@categories[$n+$i]:<\/td>\n";
+                       print "<td width='10%'><input type='checkbox' name=@filtergroups[$n+$i] $checked{@filtergroups[$n+$i]}{'on'} /></td>\n";
+               }
+               if ($i eq 3) { print "<\/tr>\n"; }
+       }
+}
+
+print <<END
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+        <td><b>$Lang::tr{'urlfilter custom blacklist'}</b></td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+</tr>
+<tr>
+       <td colspan='2'>$Lang::tr{'urlfilter blocked domains'}&nbsp;<img src='/blob.gif' alt='*' /></td>
+       <td colspan='2'>$Lang::tr{'urlfilter blocked urls'}&nbsp;<img src='/blob.gif' alt='*' /></td>
+</tr>
+<tr>
+       <td colspan='2' width='50%'><textarea name='CUSTOM_BLACK_DOMAINS' cols='32' rows='6' wrap='off'>
+END
+;
+
+print $filtersettings{'CUSTOM_BLACK_DOMAINS'};
+
+print <<END
+</textarea></td>
+       <td colspan='2' width='50%'><textarea name='CUSTOM_BLACK_URLS' cols='32' rows='6' wrap='off'>
+END
+;
+
+print $filtersettings{'CUSTOM_BLACK_URLS'};
+
+print <<END
+</textarea></td>
+</tr>
+</table>
+<table width='100%'>
+<tr>
+        <td class='base' width='25%'>$Lang::tr{'urlfilter enable custom blacklist'}:</td>
+        <td><input type='checkbox' name='ENABLE_CUSTOM_BLACKLIST' $checked{'ENABLE_CUSTOM_BLACKLIST'}{'on'} /></td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+</tr>
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+        <td><b>$Lang::tr{'urlfilter custom whitelist'}</b></td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+</tr>
+<tr>
+       <td colspan='2'>$Lang::tr{'urlfilter allowed domains'}&nbsp;<img src='/blob.gif' alt='*' /></td>
+       <td colspan='2'>$Lang::tr{'urlfilter allowed urls'}&nbsp;<img src='/blob.gif' alt='*' /></td>
+</tr>
+<tr>
+       <td colspan='2' width='50%'><textarea name='CUSTOM_WHITE_DOMAINS' cols='32' rows='6' wrap='off'>
+END
+;
+
+print $filtersettings{'CUSTOM_WHITE_DOMAINS'};
+
+print <<END
+</textarea></td>
+       <td colspan='2' width='50%'><textarea name='CUSTOM_WHITE_URLS' cols='32' rows='6' wrap='off'>
+END
+;
+
+print $filtersettings{'CUSTOM_WHITE_URLS'};
+
+print <<END
+</textarea></td>
+</tr>
+</table>
+<table width='100%'>
+<tr>
+        <td class='base' width='25%'>$Lang::tr{'urlfilter enable custom whitelist'}:</td>
+        <td><input type='checkbox' name='ENABLE_CUSTOM_WHITELIST' $checked{'ENABLE_CUSTOM_WHITELIST'}{'on'} /></td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+</tr>
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+        <td colspan='4'><b>$Lang::tr{'urlfilter custom expression list'}</b></td>
+</tr>
+<tr>
+       <td colspan='4'>$Lang::tr{'urlfilter blocked expressions'}&nbsp;<img src='/blob.gif' alt='*' /></td>
+</tr>
+<tr>
+       <td colspan='4'><textarea name='CUSTOM_EXPRESSIONS' cols='70' rows='3' wrap='off'>
+END
+;
+
+print $filtersettings{'CUSTOM_EXPRESSIONS'};
+
+print <<END
+</textarea></td>
+</tr>
+<tr>
+        <td class='base' width='25%'>$Lang::tr{'urlfilter enable custom expression list'}:</td>
+        <td><input type='checkbox' name='ENABLE_CUSTOM_EXPRESSIONS' $checked{'ENABLE_CUSTOM_EXPRESSIONS'}{'on'} /></td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+</tr>
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+        <td colspan='4'><b>$Lang::tr{'urlfilter file ext block'}</b></td>
+</tr>
+<tr>
+        <td width='25%' class='base'>$Lang::tr{'urlfilter block executables'}:</td>
+        <td width='12%'><input type='checkbox' name='BLOCK_EXECUTABLES' $checked{'BLOCK_EXECUTABLES'}{'on'} /></td>
+        <td width='25%'  class='base'>$Lang::tr{'urlfilter block audio-video'}:</td>
+        <td><input type='checkbox' name='BLOCK_AUDIO-VIDEO' $checked{'BLOCK_AUDIO-VIDEO'}{'on'} /></td>
+</tr>
+<tr>
+        <td class='base'>$Lang::tr{'urlfilter block archives'}:</td>
+        <td><input type='checkbox' name='BLOCK_ARCHIVES' $checked{'BLOCK_ARCHIVES'}{'on'} /></td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+</tr>
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+        <td colspan='4'><b>$Lang::tr{'urlfilter local file redirection'}</b></td>
+</tr>
+<tr>
+       <td width='25%' class='base'>$Lang::tr{'urlfilter enable rewrite rules'}:</td>
+       <td width='12%'><input type='checkbox' name='ENABLE_REWRITE' $checked{'ENABLE_REWRITE'}{'on'} /></td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+</tr>
+<tr>
+       <td><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter manage repository'}'></td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+</tr>
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+        <td colspan='2'><b>$Lang::tr{'urlfilter network access control'}</b></td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+</tr>
+<tr>
+        <td class='base'>$Lang::tr{'urlfilter unfiltered clients'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
+        <td><input type='text' name='UNFILTERED_CLIENTS' value='$filtersettings{'UNFILTERED_CLIENTS'}' size='30' /></td>
+        <td class='base'>$Lang::tr{'urlfilter banned clients'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
+        <td><input type='text' name='BANNED_CLIENTS' value='$filtersettings{'BANNED_CLIENTS'}' size='30' /></td>
+</tr>
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+        <td colspan='4'><b>$Lang::tr{'urlfilter timebased access control'}</b></td>
+</tr>
+<tr>
+       <td width='25%'><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter set time constraints'}'></td>
+       <td width='25%'><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter set user quota'}'></td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+</tr>
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+        <td colspan='4'><b>$Lang::tr{'urlfilter block settings'}</b></td>
+</tr>
+<tr>
+       <td width='25%' class='base'>$Lang::tr{'urlfilter show category'}:</td>
+       <td width='12%'><input type='checkbox' name='SHOW_CATEGORY' $checked{'SHOW_CATEGORY'}{'on'} /></td>
+       <td width='25%' class='base'>$Lang::tr{'urlfilter redirectpage'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
+       <td><input type='text' name='REDIRECT_PAGE' value='$filtersettings{'REDIRECT_PAGE'}' size='40' /></td>
+</tr>
+<tr>
+       <td class='base'>$Lang::tr{'urlfilter show url'}:</td>
+       <td><input type='checkbox' name='SHOW_URL' $checked{'SHOW_URL'}{'on'} /></td>
+       <td class='base'>$Lang::tr{'urlfilter msg text 1'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
+       <td><input type='text' name='MSG_TEXT_1' value='$filtersettings{'MSG_TEXT_1'}' size='40' /></td>
+</tr>
+<tr>
+       <td class='base'>$Lang::tr{'urlfilter show ip'}:</td>
+       <td><input type='checkbox' name='SHOW_IP' $checked{'SHOW_IP'}{'on'} /></td>
+       <td class='base'>$Lang::tr{'urlfilter msg text 2'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
+       <td><input type='text' name='MSG_TEXT_2' value='$filtersettings{'MSG_TEXT_2'}' size='40' /></td>
+</tr>
+<tr>
+       <td class='base'>$Lang::tr{'urlfilter show dnserror'}:</td>
+       <td><input type='checkbox' name='ENABLE_DNSERROR' $checked{'ENABLE_DNSERROR'}{'on'} /></td>
+       <td class='base'>$Lang::tr{'urlfilter msg text 3'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
+       <td><input type='text' name='MSG_TEXT_3' value='$filtersettings{'MSG_TEXT_3'}' size='40' /></td>
+</tr>
+<tr>
+       <td class='base'>$Lang::tr{'urlfilter enable jpeg'}:</td>
+       <td><input type='checkbox' name='ENABLE_JPEG' $checked{'ENABLE_JPEG'}{'on'} /></td>
+       <td>&nbsp;</td>
+       <td>&nbsp;</td>
+</tr>
+</table>
+<table width='100%'>
+<tr>
+       <td class='base'><b>$Lang::tr{'urlfilter background image'}</b></td>
+</tr>
+<tr>
+       <td><br>$Lang::tr{'urlfilter background text'}:</td>
+</tr>
+<tr>
+       <td><input type='file' name='BACKGROUND' size='40' /> &nbsp; <input type='submit' name='ACTION' value='$Lang::tr{'urlfilter upload background'}' /></td>
+</tr>
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+       <td colspan='4'><b>$Lang::tr{'urlfilter advanced settings'}</b></td>
+</tr>
+<tr>
+       <td width='25%' class='base'>$Lang::tr{'urlfilter enable expression lists'}:</td>
+       <td width='12%'><input type='checkbox' name='ENABLE_EXPR_LISTS' $checked{'ENABLE_EXPR_LISTS'}{'on'} /></td>
+       <td width='25%' class='base'>$Lang::tr{'urlfilter enable log'}:</td>
+       <td><input type='checkbox' name='ENABLE_LOG' $checked{'ENABLE_LOG'}{'on'} /></td>
+</tr>
+<tr>
+       <td class='base'>$Lang::tr{'urlfilter safesearch'}:</td>
+       <td><input type='checkbox' name='ENABLE_SAFESEARCH' $checked{'ENABLE_SAFESEARCH'}{'on'} /></td>
+       <td class='base'>$Lang::tr{'urlfilter username log'}:</td>
+       <td><input type='checkbox' name='ENABLE_USERNAME_LOG' $checked{'ENABLE_USERNAME_LOG'}{'on'} /></td>
+</tr>
+<tr>
+       <td class='base'>$Lang::tr{'urlfilter empty ads'}:</td>
+       <td><input type='checkbox' name='ENABLE_EMPTY_ADS' $checked{'ENABLE_EMPTY_ADS'}{'on'} /></td>
+       <td class='base'>$Lang::tr{'urlfilter category log'}:</td>
+       <td><input type='checkbox' name='ENABLE_CATEGORY_LOG' $checked{'ENABLE_CATEGORY_LOG'}{'on'} /></td>
+</tr>
+<tr>
+       <td class='base'>$Lang::tr{'urlfilter block ip'}:</td>
+       <td><input type='checkbox' name='BLOCK_IP_ADDR' $checked{'BLOCK_IP_ADDR'}{'on'} /></td>
+       <td class='base'>$Lang::tr{'urlfilter children'}:</td>
+       <td><input type='text' name='CHILDREN' value='$filtersettings{'CHILDREN'}' size='5' /></td>
+</tr>
+<tr>
+       <td class='base'>$Lang::tr{'urlfilter block all'}:</td>
+       <td><input type='checkbox' name='BLOCK_ALL' $checked{'BLOCK_ALL'}{'on'} /></td>
+       <td class='base'>$Lang::tr{'urlfilter whitelist always allowed'}:</td>
+       <td><input type='checkbox' name='ENABLE_GLOBAL_WHITELIST' $checked{'ENABLE_GLOBAL_WHITELIST'}{'on'} /></td>
+</tr>
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+       <td>
+       <img src='/blob.gif' align='top' alt='*' />&nbsp;
+       <font class='base'>$Lang::tr{'this field may be blank'}</font>
+       </td>
+       <td align='right'>
+<sup><small><a href='http://www.urlfilter.net' target='_blank'>URL filter</a></small></sup>
+</td>
+</tr>
+</table>
+<table width='100%'>
+<tr>
+<td>&nbsp;</td>
+<td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
+<td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter save and restart'}' /></td>
+<td>&nbsp;</td>
+</tr>
+</table>
+END
+;
+
+&Header::closebox();
+
+print "</form>\n";
+
+print "<form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>\n";
+
+&Header::openbox('100%', 'left', "$Lang::tr{'urlfilter maintenance'}:");
+
+print <<END
+<table width='100%'>
+<tr>
+<td class='base'><b>$Lang::tr{'urlfilter blacklist update'}</b></td>
+</tr>
+<tr>
+<td>$Lang::tr{'urlfilter upload information'}<p>$Lang::tr{'urlfilter upload text'}:</td>
+</tr>
+<tr>
+<td><input type='file' name='UPDATEFILE' size='40' /> &nbsp; <input type='submit' name='ACTION' value='$Lang::tr{'urlfilter upload blacklist'}' /></td>
+</tr>
+</table>
+
+<hr size='1'>
+
+<table width='100%'>
+<tr>
+       <td colspan='2' class='base'><b>$Lang::tr{'urlfilter automatic blacklist update'}</b>
+END
+;
+if (-e "$updflagfile")
+{
+$blacklistage = int(-M "$updflagfile");
+print "&nbsp; <b>[</b> <small><i>$Lang::tr{'urlfilter blacklist age 1'} <b>$blacklistage</b> $Lang::tr{'urlfilter blacklist age 2'}</i></small> <b>]</b>";
+}
+
+$updatesettings{'UPDATE_SCHEDULE'} = 'monthly';
+$updatesettings{'CUSTOM_UPDATE_URL'} = '';
+
+if (-e "$updconffile") { &General::readhash("$updconffile", \%updatesettings); }
+
+$checked{'ENABLE_AUTOUPDATE'}{'off'} = '';
+$checked{'ENABLE_AUTOUPDATE'}{'on'} = '';
+$checked{'ENABLE_AUTOUPDATE'}{$updatesettings{'ENABLE_AUTOUPDATE'}} = "checked='checked'";
+
+$selected{'UPDATE_SCHEDULE'}{$updatesettings{'UPDATE_SCHEDULE'}} = "selected='selected'";
+
+$selected{'UPDATE_SOURCE'}{$updatesettings{'UPDATE_SOURCE'}} = "selected='selected'";
+
+print <<END
+       </td>
+</tr>
+<tr>
+       <td width='25%' class='base'>$Lang::tr{'urlfilter enable automatic blacklist update'}:</td>
+        <td width='75%' class='base'><input type='checkbox' name='ENABLE_AUTOUPDATE' $checked{'ENABLE_AUTOUPDATE'}{'on'} /></td>
+</tr>
+<tr>
+       <td class='base'>$Lang::tr{'urlfilter automatic update schedule'}:</td>
+       <td class='base'>
+       <select name='UPDATE_SCHEDULE'>
+       <option value='daily' $selected{'UPDATE_SCHEDULE'}{'daily'}>$Lang::tr{'urlfilter daily'}</option>
+       <option value='weekly' $selected{'UPDATE_SCHEDULE'}{'weekly'}>$Lang::tr{'urlfilter weekly'}</option>
+       <option value='monthly' $selected{'UPDATE_SCHEDULE'}{'monthly'}>$Lang::tr{'urlfilter monthly'}</option>
+       </select>
+       </td>
+</tr>
+<tr>
+       <td class='base'>$Lang::tr{'urlfilter select source'}:</td>
+       <td class='base' colspan='2'>
+       <select name='UPDATE_SOURCE'>
+END
+;
+
+foreach (@source_urllist) {
+       chomp;
+       $source_name = substr($_,0,rindex($_,","));
+       $source_url = substr($_,index($_,",")+1);
+       print "\t<option value='$source_url' $selected{'UPDATE_SOURCE'}{$source_url}>$source_name</option>\n";
+}
+
+print <<END
+       <option value='custom' $selected{'UPDATE_SOURCE'}{'custom'}>$Lang::tr{'urlfilter custom url'}</option>
+       </select>
+       </td>
+</tr>
+<tr>
+       <td>$Lang::tr{'urlfilter custom url'}:</td>
+       <td><input type='text' name='CUSTOM_UPDATE_URL' value='$updatesettings{'CUSTOM_UPDATE_URL'}' size='72' /></td>
+</tr>
+</table>
+<table width='100%'>
+<tr>
+       <td width='25%'><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter save schedule'}'>&nbsp;&nbsp;&nbsp;<input type='submit' name='ACTION' value='$Lang::tr{'urlfilter update now'}'></td>
+</tr>
+</table>
+
+<hr size='1'>
+
+<table width='100%'>
+<tr>
+       <td class='base'><b>$Lang::tr{'urlfilter blacklist editor'}</b></td>
+</tr>
+<tr>
+       <td>$Lang::tr{'urlfilter blacklist editor info'}</td>
+</tr>
+<tr>
+       <td><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter blacklist editor'}' /></td>
+</tr>
+</table>
+
+<hr size='1'>
+
+<table width='100%'>
+<tr>
+       <td colspan='4' class='base'><b>$Lang::tr{'urlfilter backup settings'}</b></td>
+</tr>
+<tr>
+       <td width='25%' class='base'>$Lang::tr{'urlfilter enable full backup'}:</td>
+        <td width='12%' class='base'><input type='checkbox' name='ENABLE_FULLBACKUP' $checked{'ENABLE_FULLBACKUP'}{'on'} /></td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+</tr>
+<tr>
+       <td colspan='4' class='base'><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter backup'}' /></td>
+</tr>
+</table>
+
+<hr size='1'>
+
+<table width='100%'>
+<tr>
+       <td class='base'><b>$Lang::tr{'urlfilter restore settings'}</b></td>
+</tr>
+<tr>
+       <td>$Lang::tr{'urlfilter restore text'}:</td>
+</tr>
+<tr>
+       <td><input type='file' name='UPDATEFILE' size='40' /> &nbsp; <input type='submit' name='ACTION' value='$Lang::tr{'urlfilter restore'}' /></td>
+</tr>
+</table>
+</form>
+END
+;
+
+&Header::closebox();
+
+} else {
+
+#==========================================================
+#
+# Section: Manage Repository
+#
+#==========================================================
+
+print "<form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>\n";
+
+&Header::openbox('100%', 'left', "$Lang::tr{'urlfilter manage local file repository'}:");
+print <<END
+<table width='100%'>
+<tr>
+       <td>$Lang::tr{'urlfilter repository information'}<br><br></td>
+</tr>
+<tr>
+       <td>$Lang::tr{'urlfilter upload file text'}:</td>
+</tr>
+<tr>
+       <td><input type='file' name='UPLOADFILE' size='50' /> &nbsp; <input type='submit' name='ACTION' value='$Lang::tr{'urlfilter upload file'}' /></td>
+</tr>
+<tr>
+       <td><br><b>$Lang::tr{'urlfilter upload file information 1'}:</b> $Lang::tr{'urlfilter upload file information 2'}</td>
+</tr>
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+       <td><input type='button' name='return2main' value='$Lang::tr{'urlfilter back to main page'}' onClick='self.location.href="$ENV{'SCRIPT_NAME'}"'></td>
+</tr>
+</table>
+</form>
+END
+;
+
+&Header::closebox();
+
+&Header::openbox('100%', 'left', "$Lang::tr{'urlfilter current files'}: </b>[$repository]");
+
+@repositorylist = <$repository/*>;
+
+undef @repositoryfiles;
+foreach (@repositorylist)
+{
+       if (!-d) { push(@repositoryfiles,substr($_,rindex($_,"/")+1));  }
+}
+
+if (@repositoryfiles)
+{
+       print <<END
+<table width='100%'>
+<tr>
+       <td align='center'><b>$Lang::tr{'urlfilter filename'}</b></td>
+       <td width='15%' align='center'><b>$Lang::tr{'urlfilter filesize'}</b></td>
+       <td width='10%'></td>
+</tr>
+END
+;
+       $id = 0;
+       foreach $line (@repositoryfiles)
+       {
+               $id++;
+               if ($id % 2) {
+                       print "<tr bgcolor='$Header::table1colour'>\n"; }
+               else {
+                       print "<tr bgcolor='$Header::table2colour'>\n"; }
+               $filesize = (-s "$repository/$line");
+               1 while $filesize =~ s/^(-?\d+)(\d{3})/$1.$2/;
+
+print <<END
+               <td>&nbsp; &nbsp;$line</td>
+               <td align='right'>$filesize&nbsp; &nbsp;</td>
+
+               <td align='center'>
+               <form method='post' name='frma$id' action='$ENV{'SCRIPT_NAME'}'>
+               <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' title='$Lang::tr{'remove'}' alt='$Lang::tr{'remove'}' />
+               <input type='hidden' name='ID' value='$line' />
+               <input type='hidden' name='ACTION' value='$Lang::tr{'urlfilter remove file'}' />
+               </form>
+               </td>
+
+       </tr>
+END
+;
+       }
+
+print <<END
+</table>
+<table>
+       <tr>
+       </tr>
+</table>
+<table>
+       <tr>
+               <td class='boldbase'>&nbsp; <b>$Lang::tr{'legend'}:</b></td>
+               <td>&nbsp; &nbsp; <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
+               <td class='base'>$Lang::tr{'remove'}</td>
+       </tr>
+</table>
+END
+;
+} else {
+
+       print "<i>$Lang::tr{'urlfilter empty repository'}</i>\n";
+}
+
+&Header::closebox();
+
+}
+
+} elsif ($tcsettings{'TCMODE'}) {
+
+#==========================================================
+#
+# Section: Set Time Constraints
+#
+#==========================================================
+
+print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
+
+$buttontext = $Lang::tr{'urlfilter add rule'};
+if ($tcsettings{'ACTION'} eq $Lang::tr{'edit'}) {
+&Header::openbox('100%', 'left', $Lang::tr{'urlfilter edit time constraint rule'}.':');
+$buttontext = $Lang::tr{'urlfilter update rule'};
+} else {
+&Header::openbox('100%', 'left', $Lang::tr{'urlfilter add new time constraint rule'}.':');
+}
+print <<END
+
+<table width='100%'>
+<tr>
+       <td width='2%'>$Lang::tr{'urlfilter constraint definition'}</td>
+       <td width='1%'>&nbsp;&nbsp;</td>
+       <td width='2%' align='center'>$Lang::tr{'urlfilter monday'}</td>
+       <td width='2%' align='center'>$Lang::tr{'urlfilter tuesday'}</td>
+       <td width='2%' align='center'>$Lang::tr{'urlfilter wednesday'}</td>
+       <td width='2%' align='center'>$Lang::tr{'urlfilter thursday'}</td>
+       <td width='2%' align='center'>$Lang::tr{'urlfilter friday'}</td>
+       <td width='2%' align='center'>$Lang::tr{'urlfilter saturday'}</td>
+       <td width='2%' align='center'>$Lang::tr{'urlfilter sunday'}</td>
+       <td width='1%'>&nbsp;&nbsp;</td>
+       <td width='7%' colspan=3>$Lang::tr{'urlfilter from'}</td>
+       <td width='1%'>&nbsp;</td>
+       <td width='7%' colspan=3>$Lang::tr{'urlfilter to'}</td>
+       <td>&nbsp;</td>
+</tr>
+<tr>
+       <td class='base'>
+       <select name='DEFINITION'>
+       <option value='within' $selected{'DEFINITION'}{'within'}>$Lang::tr{'urlfilter constraint within'}</option>
+       <option value='outside' $selected{'DEFINITION'}{'outside'}>$Lang::tr{'urlfilter constraint outside'}</option>
+       </select>
+       </td>
+       <td>&nbsp;</td>
+       <td class='base'><input type='checkbox' name='MON' $checked{'MON'}{'on'} /></td>
+       <td class='base'><input type='checkbox' name='TUE' $checked{'TUE'}{'on'} /></td>
+       <td class='base'><input type='checkbox' name='WED' $checked{'WED'}{'on'} /></td>
+       <td class='base'><input type='checkbox' name='THU' $checked{'THU'}{'on'} /></td>
+       <td class='base'><input type='checkbox' name='FRI' $checked{'FRI'}{'on'} /></td>
+       <td class='base'><input type='checkbox' name='SAT' $checked{'SAT'}{'on'} /></td>
+       <td class='base'><input type='checkbox' name='SUN' $checked{'SUN'}{'on'} /></td>
+       <td>&nbsp;</td>
+       <td class='base'>
+       <select name='FROM_HOUR'>
+END
+;
+for ($i=0;$i<=24;$i++) {
+$_ = sprintf("%02s",$i);
+print "<option $selected{'FROM_HOUR'}{$_}>$_</option>\n";
+}
+print <<END
+       </select>
+       </td>
+       <td>:</td>
+       <td class='base'>
+       <select name='FROM_MINUTE'>
+END
+;
+for ($i=0;$i<=45;$i+=15) {
+$_ = sprintf("%02s",$i);
+print "<option $selected{'FROM_MINUTE'}{$_}>$_</option>\n";
+}
+print <<END
+       </select>
+       <td> - </td>
+       </td>
+       <td class='base'>
+       <select name='TO_HOUR'>
+END
+;
+for ($i=0;$i<=24;$i++) {
+$_ = sprintf("%02s",$i);
+print "<option $selected{'TO_HOUR'}{$_}>$_</option>\n";
+}
+print <<END
+       </select>
+       </td>
+       <td>:</td>
+       <td class='base'>
+       <select name='TO_MINUTE'>
+END
+;
+for ($i=0;$i<=45;$i+=15) {
+$_ = sprintf("%02s",$i);
+print "<option $selected{'TO_MINUTE'}{$_}>$_</option>\n";
+}
+print <<END
+       </select>
+       </td>
+       <td>&nbsp;</td>
+</tr>
+</table>
+
+<br>
+
+<table width='100%'>
+       <tr>
+               <td width='5%'>$Lang::tr{'urlfilter source'}</td>
+               <td width='1%'>&nbsp;&nbsp;</td>
+               <td width='5%'>$Lang::tr{'urlfilter dst'}&nbsp;<img src='/blob.gif' alt='*'><img src='/blob.gif' alt='*'></td>
+               <td width='1%'>&nbsp;&nbsp;</td>
+               <td width='5%'>$Lang::tr{'urlfilter access'}</td>
+               <td>&nbsp;</td>
+       </tr>
+       <tr>
+               <td valign='top'><input type='text' name='SRC' value='$tcsettings{'SRC'}' size='32' /></td>
+               <td>&nbsp;</td>
+               <td class='base' rowspan='3' valign='top'>
+               <select name='DST' size='4' multiple>
+               <option value='any' $selected{'DST'}{'any'} = "selected='selected'">$Lang::tr{'urlfilter category all'}</option>
+               <option value='in-addr' $selected{'DST'}{'in-addr'} = "selected='selected'">in-addr</option>
+END
+;
+
+&readblockcategories;
+foreach (@categories)
+{
+       print "<option value='$_' $selected{'DST'}{$_}>$_</option>\n";
+}
+
+print <<END
+               <option value='files' $selected{'DST'}{'files'} = "selected='selected'">files</option>
+               <option value='custom-blocked' $selected{'DST'}{'custom-blocked'} = "selected='selected'">custom-blocked</option>
+               <option value='custom-expressions' $selected{'DST'}{'custom-expressions'} = "selected='selected'">custom-expressions</option>
+               </select>
+               </td>
+               <td>&nbsp;</td>
+               <td class='base' valign='top'>
+               <select name='ACCESS'>
+               <option value='block' $selected{'ACCESS'}{'block'}>$Lang::tr{'urlfilter mode block'}</option>
+               <option value='allow' $selected{'ACCESS'}{'allow'}>$Lang::tr{'urlfilter mode allow'}</option>
+               </select>
+               </td>
+               <td>&nbsp;</td>
+       </tr>
+       <tr>
+               <td>$Lang::tr{'remark'}&nbsp;<img src='/blob.gif' alt='*'></td>
+               <td>&nbsp;</td>
+               <td>&nbsp;</td>
+               <td>&nbsp;</td>
+               <td>&nbsp;</td>
+       </tr>
+       <tr>
+               <td><input type='text' name='COMMENT' value='$tcsettings{'COMMENT'}' size='32' /></td>
+               <td>&nbsp;</td>
+               <td>&nbsp;</td>
+               <td>&nbsp;</td>
+               <td>&nbsp;</td>
+       </tr>
+</table>
+
+<table width='100%'>
+       <tr>
+               <td class='base'>$Lang::tr{'urlfilter enabled'}<input type='checkbox' name='ENABLERULE' $checked{'ENABLERULE'}{'on'} /></td>
+       </tr>
+</table>
+
+<p>
+
+<table width='50%'>
+       <tr>
+               <td><input type='hidden' name='ACTION' value='$Lang::tr{'add'}' /></td>
+               <td><input type='hidden' name='MODE' value='TIMECONSTRAINT' /></td>
+               <td><input type='submit' name='SUBMIT' value='$buttontext' /></td>
+               <td><input type='reset' name='ACTION' value='$Lang::tr{'urlfilter reset'}' /></td>
+               <td>&nbsp;</td>
+               <td><input type='button' name='return2main' value='$Lang::tr{'urlfilter back to main page'}' onClick='self.location.href="$ENV{'SCRIPT_NAME'}"'></td>
+       </tr>
+</table>
+<p>
+<table width='100%'>
+       <tr>
+               <td width='1%' align='right'> <img src='/blob.gif' align='top' alt='*' />&nbsp;</td>
+               <td><font class='base'>$Lang::tr{'this field may be blank'}</font></td>
+       </tr>
+       <tr>
+               <td width='1%' align='right'><img src='/blob.gif' align='top' alt='*' /><img src='/blob.gif' align='top' alt='*' />&nbsp;</td>
+               <td><font class='base'>$Lang::tr{'urlfilter select multi'}</font></td>
+       </tr>
+</table>
+END
+;
+
+if ($tcsettings{'ACTION'} eq $Lang::tr{'edit'}) {
+       print "<input type='hidden' name='EDITING' value='$tcsettings{'ID'}' />\n";
+} else {
+       print "<input type='hidden' name='EDITING' value='no' />\n";
+}
+
+&Header::closebox();
+print "</form>\n";
+
+&Header::openbox('100%', 'left', $Lang::tr{'current rules'});
+print <<END
+<table width='100%'>
+       <tr>
+               <td width='5%' class='boldbase' align='center'><b>$Lang::tr{'urlfilter constraint definition'}</b></td>
+               <td width='10%' class='boldbase' align='center'><b>$Lang::tr{'urlfilter time space'}</b></td>
+               <td width='15%' class='boldbase' align='center'><b>$Lang::tr{'urlfilter src'}</b></td>
+               <td width='5%' class='boldbase' align='center'><b>$Lang::tr{'urlfilter dst'}</b></td>
+               <td width='10%' class='boldbase' colspan='4' align='center'>&nbsp;</td>
+       </tr>
+END
+;
+
+if ($tcsettings{'ACTION'} ne '' or $changed ne 'no')
+{
+       open(FILE, $tcfile);
+       @tclist = <FILE>;
+       close(FILE);
+}
+
+$id = 0;
+foreach $line (@tclist)
+{
+       $id++;
+       chomp($line);
+       @temp = split(/\,/,$line);
+       if($tcsettings{'ACTION'} eq $Lang::tr{'edit'} && $tcsettings{'ID'} eq $id) {
+               print "<tr bgcolor='$Header::colouryellow'>\n"; }
+       elsif ($id % 2) {
+               print "<tr bgcolor='$Header::table1colour'>\n"; }
+       else {
+               print "<tr bgcolor='$Header::table2colour'>\n"; }
+       if ($temp[0] eq 'within') { $temp[0]=$Lang::tr{'urlfilter constraint within'}; } else { $temp[0]=$Lang::tr{'urlfilter constraint outside'}; }
+       if ($temp[13] eq 'any') { $temp[13]=$Lang::tr{'urlfilter category all'}; }
+       if ($temp[15] eq 'on') { $gif='on.gif'; $toggle='off'; $gdesc=$Lang::tr{'click to disable'};}
+       else { $gif='off.gif'; $toggle='on'; $gdesc=$Lang::tr{'click to enable'}; }
+       if ($temp[14] eq 'block') { $led='led-red.gif'; $ldesc=$Lang::tr{'urlfilter block access'};}
+       else { $led='led-green.gif'; $ldesc=$Lang::tr{'urlfilter allow access'}; }
+
+       undef $time;
+       if ($temp[1] eq 'on') { $time.=$Lang::tr{'urlfilter mon'}; } else { $time.='='; }
+       if ($temp[2] eq 'on') { $time.=$Lang::tr{'urlfilter tue'}; } else { $time.='='; }
+       if ($temp[3] eq 'on') { $time.=$Lang::tr{'urlfilter wed'}; } else { $time.='='; }
+       if ($temp[4] eq 'on') { $time.=$Lang::tr{'urlfilter thu'}; } else { $time.='='; }
+       if ($temp[5] eq 'on') { $time.=$Lang::tr{'urlfilter fri'}; } else { $time.='='; }
+       if ($temp[6] eq 'on') { $time.=$Lang::tr{'urlfilter sat'}; } else { $time.='='; }
+       if ($temp[7] eq 'on') { $time.=$Lang::tr{'urlfilter sun'}; } else { $time.='='; }
+       $time=$time.' &nbsp; '.$temp[8].':'.$temp[9].' to '.$temp[10].':'.$temp[11];
+
+print <<END
+               <td align='center'>$temp[0]</td>
+               <td align='center' nowrap>$time</td>
+               <td align='center'>$temp[12]</td>
+               <td align='center'>$temp[13]</td>
+               <td align='center'><image src='/images/urlfilter/$led' alt='$ldesc'></td>
+
+               <td align='center'>
+               <form method='post' name='frma$id' action='$ENV{'SCRIPT_NAME'}'>
+               <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' title='$gdesc' alt='$gdesc' />
+               <input type='hidden' name='MODE' value='TIMECONSTRAINT' />
+               <input type='hidden' name='ID' value='$id' />
+               <input type='hidden' name='ACTIVE' value='$toggle' />
+               <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
+               </form>
+               </td>
+
+               <td align='center'>
+               <form method='post' name='frmb$id' action='$ENV{'SCRIPT_NAME'}'>
+               <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' title='$Lang::tr{'edit'}' alt='$Lang::tr{'edit'}' />
+               <input type='hidden' name='MODE' value='TIMECONSTRAINT' />
+               <input type='hidden' name='ID' value='$id' />
+               <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
+               </form>
+               </td>
+
+               <td align='center'>
+               <form method='post' name='frmc$id' action='$ENV{'SCRIPT_NAME'}'>
+               <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' title='$Lang::tr{'remove'}' alt='$Lang::tr{'remove'}' />
+               <input type='hidden' name='MODE' value='TIMECONSTRAINT' />
+               <input type='hidden' name='ID' value='$id' />
+               <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' />
+               </form>
+               </td>
+
+       </tr>
+END
+;
+       if($tcsettings{'ACTION'} eq $Lang::tr{'edit'} && $tcsettings{'ID'} eq $id) {
+               print "<tr bgcolor='$Header::colouryellow'>\n"; }
+       elsif ($id % 2) {
+               print "<tr bgcolor='$Header::table1colour'>\n"; }
+       else {
+               print "<tr bgcolor='$Header::table2colour'>\n"; }
+print <<END
+               <td align='center' colspan='4'>$temp[16]
+               </td>
+               <td align='center' colspan='4'>
+               </td>
+       </tr>
+END
+;
+}
+
+print "</table>\n";
+
+# If the time constraint file contains entries, print entries and action icons
+if (! -z "$tcfile") {
+print <<END
+
+<table>
+       <tr>
+               <td class='boldbase'>&nbsp; <b>$Lang::tr{'legend'}:</b></td>
+               <td>&nbsp; &nbsp; <img src='/images/urlfilter/led-green.gif' alt='$Lang::tr{'urlfilter allow access'}' /></td>
+               <td class='base'>$Lang::tr{'urlfilter allow'}</td>
+               <td>&nbsp; &nbsp; <img src='/images/urlfilter/led-red.gif' alt='$Lang::tr{'urlfilter block access'}' /></td>
+               <td class='base'>$Lang::tr{'urlfilter block'}</td>
+               <td>&nbsp; <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
+               <td class='base'>$Lang::tr{'click to disable'}</td>
+               <td>&nbsp; &nbsp; <img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
+               <td class='base'>$Lang::tr{'click to enable'}</td>
+               <td>&nbsp; &nbsp; <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
+               <td class='base'>$Lang::tr{'edit'}</td>
+               <td>&nbsp; &nbsp; <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
+               <td class='base'>$Lang::tr{'remove'}</td>
+       </tr>
+</table>
+END
+;
+}
+
+&Header::closebox();
+
+} elsif ($uqsettings{'UQMODE'}) {
+
+#==========================================================
+#
+# Section: Set User Quota
+#
+#==========================================================
+
+print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
+
+$buttontext = $Lang::tr{'urlfilter add rule'};
+if ($uqsettings{'ACTION'} eq $Lang::tr{'edit'}) {
+&Header::openbox('100%', 'left', $Lang::tr{'urlfilter edit user quota rule'}.':');
+$buttontext = $Lang::tr{'urlfilter update rule'};
+} else {
+&Header::openbox('100%', 'left', $Lang::tr{'urlfilter add new user quota rule'}.':');
+}
+print <<END
+
+<table width='100%'>
+<tr>
+       <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td>
+</tr>
+<tr>
+        <td class='base'>$Lang::tr{'urlfilter user time quota'}:</td>
+        <td><input type='text' name='TIME_QUOTA' value='$uqsettings{'TIME_QUOTA'}' size='5' /></td>
+       <td colspan='2' rowspan= '5' valign='top' class='base'>
+               <table cellpadding='0' cellspacing='0'>
+                       <tr>
+                               <!-- intentionally left empty -->
+                       </tr>
+                       <tr>
+                       <td>$Lang::tr{'urlfilter assigned quota users'}:</td>
+                       </tr>
+                       <tr>
+                               <!-- intentionally left empty -->
+                       </tr>
+                       <tr>
+                               <!-- intentionally left empty -->
+                       </tr>
+                       <tr>
+                       <td><textarea name='QUOTA_USERS' cols='32' rows='6' wrap='off'>
+END
+;
+
+$uqsettings{'QUOTA_USERS'} =~ s/\|/\n/g;
+print $uqsettings{'QUOTA_USERS'};
+
+print <<END
+</textarea></td>
+               </tr>
+               </table>
+       </td>
+</tr>
+<tr>
+        <td class='base'>$Lang::tr{'urlfilter activity detection'}:</td>
+        <td class='base'><select name='SPORADIC'>
+                <option value='0'   $selected{'SPORADIC'}{'0'}>$Lang::tr{'urlfilter disabled'}</option>
+                <option value='300' $selected{'SPORADIC'}{'300'}>5 $Lang::tr{'urlfilter minutes'}</option>
+                <option value='900' $selected{'SPORADIC'}{'900'}>15 $Lang::tr{'urlfilter minutes'}</option>
+        </select></td>
+</tr>
+<tr>
+        <td class='base'>$Lang::tr{'urlfilter renewal period'}:</td>
+        <td class='base'><select name='RENEWAL'>
+                <option value='hourly' $selected{'RENEWAL'}{'hourly'}>$Lang::tr{'urlfilter hourly'}</option>
+                <option value='daily'  $selected{'RENEWAL'}{'daily'}>$Lang::tr{'urlfilter daily'}</option>
+                <option value='weekly' $selected{'RENEWAL'}{'weekly'}>$Lang::tr{'urlfilter weekly'}</option>
+        </select></td>
+</tr>
+<tr>
+       <td colspan='2'>&nbsp;</td>
+</tr>
+<tr>
+       <td class='base'>$Lang::tr{'urlfilter enabled'}</td>
+       <td class='base'><input type='checkbox' name='ENABLEQUOTA' $checked{'ENABLEQUOTA'}{'on'} /></td>
+</tr>
+
+</table>
+<p>
+
+<table width='50%'>
+       <tr>
+               <td><input type='hidden' name='ACTION' value='$Lang::tr{'add'}' /></td>
+               <td><input type='hidden' name='MODE' value='USERQUOTA' /></td>
+               <td><input type='submit' name='SUBMIT' value='$buttontext' /></td>
+               <td><input type='reset'  name='ACTION' value='$Lang::tr{'urlfilter reset'}' /></td>
+               <td>&nbsp;</td>
+               <td><input type='button' name='return2main' value='$Lang::tr{'urlfilter back to main page'}' onClick='self.location.href="$ENV{'SCRIPT_NAME'}"'></td>
+       </tr>
+</table>
+
+<p>
+END
+;
+
+if ($uqsettings{'ACTION'} eq $Lang::tr{'edit'}) {
+       print "<input type='hidden' name='EDITING' value='$uqsettings{'ID'}' />\n";
+} else {
+       print "<input type='hidden' name='EDITING' value='no' />\n";
+}
+
+&Header::closebox();
+print "</form>\n";
+
+&Header::openbox('100%', 'left', $Lang::tr{'current rules'});
+print <<END
+<table width='100%'>
+       <tr>
+               <td width='15%' class='boldbase' align='center'><b><nobr>$Lang::tr{'urlfilter time quota'}</nobr></b></td>
+               <td width='15%' class='boldbase' align='center'><b><nobr>$Lang::tr{'urlfilter activity detection'}</nobr></b></td>
+               <td width='10%' class='boldbase' align='center'><b>$Lang::tr{'urlfilter renewal'}</b></td>
+               <td class='boldbase' align='center'><b>$Lang::tr{'urlfilter assigned users'}</b></td>
+               <td width='20%' class='boldbase' colspan='4' align='center'>&nbsp;</td>
+       </tr>
+END
+;
+
+if ($uqsettings{'ACTION'} ne '' or $changed ne 'no')
+{
+       open(FILE, $uqfile);
+       @uqlist = <FILE>;
+       close(FILE);
+}
+
+$id = 0;
+foreach $line (@uqlist)
+{
+       $id++;
+       chomp($line);
+       @temp = split(/\,/,$line);
+       if($uqsettings{'ACTION'} eq $Lang::tr{'edit'} && $uqsettings{'ID'} eq $id) {
+               print "<tr bgcolor='$Header::colouryellow'>\n"; }
+       elsif ($id % 2) {
+               print "<tr bgcolor='$Header::table1colour'>\n"; }
+       else {
+               print "<tr bgcolor='$Header::table2colour'>\n"; }
+       if ($temp[4] eq 'on') { $gif='on.gif'; $toggle='off'; $gdesc=$Lang::tr{'click to disable'};}
+       else { $gif='off.gif'; $toggle='on'; $gdesc=$Lang::tr{'click to enable'}; }
+
+       $temp[5] = $temp[1];
+       if ($temp[1] eq '0') { $temp[5] = $Lang::tr{'urlfilter disabled'} } else { $temp[5] = ($temp[5]/60).' '.$Lang::tr{'urlfilter minutes'} }
+       $_ = $temp[3]; s/\|/, /g; $temp[6] = $_;
+
+print <<END
+               <td align='center'>$temp[0] $Lang::tr{'urlfilter minutes'}</td>
+               <td align='center'>$temp[5]</td>
+               <td align='center'>$Lang::tr{'urlfilter '.$temp[2]}</td>
+               <td align='center'>$temp[6]</td>
+
+               <td align='center'>
+               <form method='post' name='frma$id' action='$ENV{'SCRIPT_NAME'}'>
+               <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' title='$gdesc' alt='$gdesc' />
+               <input type='hidden' name='MODE' value='USERQUOTA' />
+               <input type='hidden' name='ID' value='$id' />
+               <input type='hidden' name='ACTIVE' value='$toggle' />
+               <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
+               </form>
+               </td>
+
+               <td align='center'>
+               <form method='post' name='frmb$id' action='$ENV{'SCRIPT_NAME'}'>
+               <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' title='$Lang::tr{'edit'}' alt='$Lang::tr{'edit'}' />
+               <input type='hidden' name='MODE' value='USERQUOTA' />
+               <input type='hidden' name='ID' value='$id' />
+               <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
+               </form>
+               </td>
+
+               <td align='center'>
+               <form method='post' name='frmc$id' action='$ENV{'SCRIPT_NAME'}'>
+               <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' title='$Lang::tr{'remove'}' alt='$Lang::tr{'remove'}' />
+               <input type='hidden' name='MODE' value='USERQUOTA' />
+               <input type='hidden' name='ID' value='$id' />
+               <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' />
+               </form>
+               </td>
+
+       </tr>
+END
+;
+}
+
+print "</table>\n";
+
+# If the user quota file contains entries, print entries and action icons
+if (! -z "$uqfile") {
+print <<END
+
+<table>
+       <tr>
+               <td class='boldbase'>&nbsp; <b>$Lang::tr{'legend'}:</b></td>
+               <td>&nbsp; <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
+               <td class='base'>$Lang::tr{'click to disable'}</td>
+               <td>&nbsp; &nbsp; <img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
+               <td class='base'>$Lang::tr{'click to enable'}</td>
+               <td>&nbsp; &nbsp; <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
+               <td class='base'>$Lang::tr{'edit'}</td>
+               <td>&nbsp; &nbsp; <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
+               <td class='base'>$Lang::tr{'remove'}</td>
+       </tr>
+</table>
+END
+;
+}
+
+&Header::closebox();
+
+} else {
+
+#==========================================================
+#
+# Section: Blacklist editor
+#
+#==========================================================
+
+print "<form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>\n";
+
+&Header::openbox('100%', 'left', $Lang::tr{'urlfilter urlfilter blacklist editor'}.':');
+
+print <<END
+
+<table width='100%'>
+<tr>
+       <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td>
+</tr>
+<tr>
+               <td class='base'><b>$Lang::tr{'urlfilter blacklist name'}</b></td>
+</tr>
+<tr>
+               <td class='base'>$Lang::tr{'urlfilter blacklist category name'}:</td>
+       <td><input type='text' name='BE_NAME' value='$besettings{'BE_NAME'}' size='12' /></td>
+</tr>
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+       <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='20%'></td>
+</tr>
+<tr>
+               <td class='base' colspan='4'><b>$Lang::tr{'urlfilter edit domains urls expressions'}</b></td>
+</tr>
+<tr>
+       <td colspan='2'>$Lang::tr{'urlfilter domains'}</td>
+       <td colspan='2'>$Lang::tr{'urlfilter urls'}</td>
+</tr>
+<tr>
+       <td colspan='2'><textarea name='BE_DOMAINS' cols='38' rows='10' wrap='off'>
+END
+;
+
+print $besettings{'BE_DOMAINS'};
+
+print <<END
+</textarea></td>
+       <td colspan='2'><textarea name='BE_URLS' cols='38' rows='10' wrap='off'>
+END
+;
+
+print $besettings{'BE_URLS'};
+
+print <<END
+</textarea></td>
+</tr>
+<tr>
+       <td colspan='4'>$Lang::tr{'urlfilter expressions'}</td>
+</tr>
+<tr>
+       <td colspan='4'><textarea name='BE_EXPRESSIONS' cols='80' rows='3' wrap='off'>
+END
+;
+
+print $besettings{'BE_EXPRESSIONS'};
+
+print <<END
+</textarea></td>
+</tr>
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+               <td class='base' colspan='4'><b>$Lang::tr{'urlfilter load blacklist'}</b></td>
+</tr>
+<tr>
+               <td width='25%' class='base'>$Lang::tr{'urlfilter select blacklist'}:</td>
+       <td width='20%' class='base'>
+       <select name='BE_BLACKLIST'>
+END
+;
+
+&readblockcategories;
+foreach (@categories)
+{
+       print "<option value='$_' $selected{'BE_BLACKLIST'}{$_}>$_</option>\n";
+}
+
+print <<END
+       </select>
+       </td>
+       <td>&nbsp;</td>
+       <td>&nbsp;</td>
+<tr>
+       <td colpsan='4'><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter load blacklist'}' /></td>
+</tr>
+</tr>
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+               <td class='base' colspan='4'><b>$Lang::tr{'urlfilter import blacklist'}</b></td>
+</tr>
+<tr>
+       <td colspan='4'>$Lang::tr{'urlfilter import text'}:</td>
+</tr>
+<tr>
+       <td nowrap><input type='file' name='IMPORTFILE' size='40' /> &nbsp; <input type='submit' name='ACTION' value='$Lang::tr{'urlfilter import blacklist'}' /></td>
+       <td><input type='hidden' name='MODE' value='BLACKLIST_EDITOR' /></td>
+</tr>
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+               <td class='base' colspan='4'><b>$Lang::tr{'urlfilter export blacklist'}</b></td>
+</tr>
+<tr>
+       <td><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter export blacklist'}' /></td>
+</tr>
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+               <td class='base' colspan='4'><b>$Lang::tr{'urlfilter install blacklist'}</b></td>
+</tr>
+<tr>
+       <td width='25%' class='base'>$Lang::tr{'urlfilter dont restart urlfilter'}:</td>
+       <td width='20%' class='base'><input type='checkbox' name='NORESTART' $checked{'NORESTART'}{'on'} /></td>
+       <td>&nbsp;</td>
+       <td>&nbsp;</td>
+</tr>
+<tr>
+       <td><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter install blacklist'}' /></td>
+</tr>
+<tr>
+               <td class='base' colspan='4'><br>$Lang::tr{'urlfilter install information'}</td>
+</tr>
+</table>
+<hr size='1'>
+<table width='20%'>
+<tr>
+       <td><input type='reset' name='ACTION' value='$Lang::tr{'urlfilter reset'}' /></td>
+       <td>&nbsp;</td>
+       <td><input type='button' name='return2main' value='$Lang::tr{'urlfilter back to main page'}' onClick='self.location.href="$ENV{'SCRIPT_NAME'}"'></td>
+</tr>
+</table>
+
+END
+;
+
+&Header::closebox();
+print "</form>\n";
+
+}
+
+&Header::closebigbox();
+
+&Header::closepage();
+
+# -------------------------------------------------------------------
+
+sub savesettings
+{
+       &writeconfigfile;
+
+       delete $filtersettings{'CUSTOM_BLACK_DOMAINS'};
+       delete $filtersettings{'CUSTOM_BLACK_URLS'};
+       delete $filtersettings{'CUSTOM_WHITE_DOMAINS'};
+       delete $filtersettings{'CUSTOM_WHITE_URLS'};
+       delete $filtersettings{'CUSTOM_EXPRESSIONS'};
+       delete $filtersettings{'BACKGROUND'};
+       delete $filtersettings{'UPDATEFILE'};
+
+       &General::writehash("${General::swroot}/urlfilter/settings", \%filtersettings);
+}
+
+# -------------------------------------------------------------------
+
+sub readblockcategories
+{
+       undef(@categories);
+       foreach $blacklist (<$dbdir/*>) {
+         if (-d $blacklist) {
+           $lastslashpos = rindex($blacklist,"/");
+           if ($lastslashpos > -1) {
+             $section = substr($blacklist,$lastslashpos+1);
+           } else {
+             $section = $blacklist;
+           }
+           if (!($section eq 'custom')) { push(@categories,$section) };
+         }
+       }
+
+       @filtergroups = @categories;
+       foreach (@filtergroups) {
+               tr/a-z/A-Z/;
+               $_ = "FILTER_".$_;
+       }
+}
+
+# -------------------------------------------------------------------
+
+sub readcustomlists
+{
+       if (-e "$dbdir/custom/blocked/domains") {
+               open(FILE,"$dbdir/custom/blocked/domains");
+               delete $filtersettings{'CUSTOM_BLACK_DOMAINS'};
+               while (<FILE>) { $filtersettings{'CUSTOM_BLACK_DOMAINS'} .= $_ };
+               close(FILE);
+       }
+
+       if (-e "$dbdir/custom/blocked/urls") {
+               open(FILE,"$dbdir/custom/blocked/urls");
+               delete $filtersettings{'CUSTOM_BLACK_URLS'};
+               while (<FILE>) { $filtersettings{'CUSTOM_BLACK_URLS'} .= $_ };
+               close(FILE);
+       }
+
+       if (-e "$dbdir/custom/blocked/expressions") {
+               open(FILE,"$dbdir/custom/blocked/expressions");
+               delete $filtersettings{'CUSTOM_EXPRESSIONS'};
+               while (<FILE>) { $filtersettings{'CUSTOM_EXPRESSIONS'} .= $_ };
+               close(FILE);
+       }
+
+       if (-e "$dbdir/custom/allowed/domains") {
+               open(FILE,"$dbdir/custom/allowed/domains");
+               delete $filtersettings{'CUSTOM_WHITE_DOMAINS'};
+               while (<FILE>) { $filtersettings{'CUSTOM_WHITE_DOMAINS'} .= $_ };
+               close(FILE);
+       }
+       if (-e "$dbdir/custom/allowed/urls") {
+               open(FILE,"$dbdir/custom/allowed/urls");
+               delete $filtersettings{'CUSTOM_WHITE_URLS'};
+               while (<FILE>) { $filtersettings{'CUSTOM_WHITE_URLS'} .= $_ };
+               close(FILE);
+       }
+}
+
+# -------------------------------------------------------------------
+
+sub aggregatedconstraints
+{
+       my $aggregated;
+       my @old;
+       my @new;
+       my @tmp1;
+       my @tmp2;
+       my $x;
+
+       if (-e $tcfile)
+       {
+               open(TC, $tcfile);
+               @old = <TC>;
+               close(TC);
+
+               while (@old > 0)
+               {
+                       $aggregated = 0;
+                       $x = shift(@old);
+                       chomp($x);
+                       @tmp1 = split(/\,/,$x);
+                       $tmp1[16] = '';
+                       foreach (@new)
+                       {
+                               @tmp2 = split(/\,/);
+                               if ($tmp2[15] eq 'on')
+                               {
+                                       if (($tmp1[0] eq $tmp2[0]) && ($tmp1[12] eq $tmp2[12]) && ($tmp1[13] eq $tmp2[13]) && ($tmp1[14] eq $tmp2[14]))
+                                       {
+                                               $aggregated = 1;
+                                               $tmp2[16] .= "    weekly ";
+                                               if ($tmp1[1] eq 'on') { $tmp2[16] .= "m"; }
+                                               if ($tmp1[2] eq 'on') { $tmp2[16] .= "t"; }
+                                               if ($tmp1[3] eq 'on') { $tmp2[16] .= "w"; }
+                                               if ($tmp1[4] eq 'on') { $tmp2[16] .= "h"; }
+                                               if ($tmp1[5] eq 'on') { $tmp2[16] .= "f"; }
+                                               if ($tmp1[6] eq 'on') { $tmp2[16] .= "a"; }
+                                               if ($tmp1[7] eq 'on') { $tmp2[16] .= "s"; }
+                                               $tmp2[16] .= " $tmp1[8]:$tmp1[9]-$tmp1[10]:$tmp1[11]\n";
+                                               $_ = join(",",@tmp2);
+                                       }
+
+                               }
+                       }
+                       if (!$aggregated)
+                       {
+                               $tmp1[16] .= "    weekly ";
+                               if ($tmp1[1] eq 'on') { $tmp1[16] .= "m"; }
+                               if ($tmp1[2] eq 'on') { $tmp1[16] .= "t"; }
+                               if ($tmp1[3] eq 'on') { $tmp1[16] .= "w"; }
+                               if ($tmp1[4] eq 'on') { $tmp1[16] .= "h"; }
+                               if ($tmp1[5] eq 'on') { $tmp1[16] .= "f"; }
+                               if ($tmp1[6] eq 'on') { $tmp1[16] .= "a"; }
+                               if ($tmp1[7] eq 'on') { $tmp1[16] .= "s"; }
+                               $tmp1[16] .= " $tmp1[8]:$tmp1[9]-$tmp1[10]:$tmp1[11]\n";
+                               $x = join(",",@tmp1);
+                               push(@new,$x);
+                       }
+               }
+       }
+
+       return @new;
+
+}
+
+# -------------------------------------------------------------------
+
+sub writeconfigfile
+{
+       my $executables = "\\.\(ade|adp|asx|bas|bat|chm|com|cmd|cpl|crt|dll|eml|exe|hiv|hlp|hta|inc|inf|ins|isp|jse|jtd|lnk|msc|msh|msi|msp|mst|nws|ocx|oft|ops|pcd|pif|plx|reg|scr|sct|sha|shb|shm|shs|sys|tlb|tsp|url|vbe|vbs|vxd|wsc|wsf|wsh\)\$";
+       my $audiovideo = "\\.\(aiff|asf|avi|dif|divx|mov|movie|mp3|mpe?g?|mpv2|ogg|ra?m|snd|qt|wav|wmf|wmv\)\$";
+       my $archives = "\\.\(bin|bz2|cab|cdr|dmg|gz|hqx|rar|smi|sit|sea|tar|tgz|zip\)\$";
+
+       my $ident = " anonymous";
+
+       my $defaultrule='';
+       my $tcrule='';
+       my $redirect='';
+       my $qredirect='';
+
+       my $idx;
+
+       my @ec=();
+       my @tc=();
+       my @uq=();
+
+       if (!(-d "$dbdir/custom"))         { mkdir("$dbdir/custom") }
+       if (!(-d "$dbdir/custom/blocked")) { mkdir("$dbdir/custom/blocked") }
+       if (!(-d "$dbdir/custom/allowed")) { mkdir("$dbdir/custom/allowed") }
+
+       open(FILE, ">/$dbdir/custom/blocked/domains");
+       print FILE $filtersettings{'CUSTOM_BLACK_DOMAINS'};
+       close(FILE);
+       open(FILE, ">/$dbdir/custom/blocked/urls");
+       print FILE $filtersettings{'CUSTOM_BLACK_URLS'};
+       close(FILE);
+       open(FILE, ">/$dbdir/custom/blocked/expressions");
+       print FILE $filtersettings{'CUSTOM_EXPRESSIONS'};
+       close(FILE);
+       open(FILE, ">/$dbdir/custom/blocked/files");
+       if ($filtersettings{'BLOCK_EXECUTABLES'} eq 'on') { print FILE "$executables\n"; }
+       if ($filtersettings{'BLOCK_AUDIO-VIDEO'} eq 'on') { print FILE "$audiovideo\n"; }
+       if ($filtersettings{'BLOCK_ARCHIVES'} eq 'on') { print FILE "$archives\n"; }
+       close(FILE);
+       open(FILE, ">/$dbdir/custom/allowed/domains");
+       print FILE $filtersettings{'CUSTOM_WHITE_DOMAINS'};
+       close(FILE);
+       open(FILE, ">/$dbdir/custom/allowed/urls");
+       print FILE $filtersettings{'CUSTOM_WHITE_URLS'};
+       close(FILE);
+
+       if ($filtersettings{'ENABLE_USERNAME_LOG'} eq 'on') { $ident = ""; }
+
+       if ($filtersettings{'REDIRECT_PAGE'} eq '')
+       {
+               if (($filtersettings{'SHOW_CATEGORY'} eq 'on') || ($filtersettings{'SHOW_URL'} eq 'on') || ($filtersettings{'SHOW_IP'} eq 'on')) {
+                       if ($filtersettings{'SHOW_CATEGORY'} eq 'on') { $redirect .= "&category=%t"; }
+                       if ($filtersettings{'SHOW_URL'} eq 'on') { $redirect .= "&url=%u"; }
+                       if ($filtersettings{'SHOW_IP'} eq 'on') { $redirect .= "&ip=%a"; }
+                       $redirect  =~ s/^&/?/;
+                       $redirect = "http:\/\/$netsettings{'GREEN_ADDRESS'}:81\/redirect.cgi".$redirect; 
+               } else {
+                       $redirect="http:\/\/$netsettings{'GREEN_ADDRESS'}:81\/redirect.cgi";
+               }
+       } else { $redirect=$filtersettings{'REDIRECT_PAGE'}; }
+
+       if ($filtersettings{'ENABLE_DNSERROR'} eq 'on') { $redirect  = "302:http://0.0.0.0"; }
+
+       undef $defaultrule;
+
+       if ($filtersettings{'ENABLE_CUSTOM_WHITELIST'} eq 'on')
+       {
+               $defaultrule .= "custom-allowed ";
+       }
+       if ($filtersettings{'BLOCK_ALL'} eq 'on')
+       {
+               $defaultrule .= "none";
+       }
+       else
+       {
+               if ($filtersettings{'BLOCK_IP_ADDR'} eq 'on')
+               {
+                       $defaultrule .= "!in-addr ";
+               }
+               for ($i=0; $i<=@filtergroups; $i++) {
+                       if ($filtersettings{@filtergroups[$i]} eq 'on')
+                       {
+                               $defaultrule .= "!@categories[$i] ";
+                       }
+               }
+               if ($filtersettings{'ENABLE_CUSTOM_BLACKLIST'} eq 'on')
+               {
+                       $defaultrule .= "!custom-blocked ";
+               }
+               if ($filtersettings{'ENABLE_CUSTOM_EXPRESSIONS'} eq 'on')
+               {
+                       $defaultrule .= "!custom-expressions ";
+               }
+               if (($filtersettings{'BLOCK_EXECUTABLES'} eq 'on') ||
+                   ($filtersettings{'BLOCK_AUDIO-VIDEO'} eq 'on') ||
+                   ($filtersettings{'BLOCK_ARCHIVES'} eq 'on'))
+               {
+                       $defaultrule .= "!files ";
+               }
+               $defaultrule .= "any";
+       }
+
+       open(FILE, ">${General::swroot}/urlfilter/squidGuard.conf") or die "Unable to write squidGuard.conf file";
+       flock(FILE, 2);
+
+       print FILE "logdir /var/log/squidGuard\n";
+       print FILE "dbhome $dbdir\n\n";
+
+       undef @repositoryfiles;
+       if ($filtersettings{'ENABLE_REWRITE'} eq 'on')
+       {
+               @repositorylist = <$repository/*>;
+               foreach (@repositorylist)
+               {
+                       if (!-d) { push(@repositoryfiles,substr($_,rindex($_,"/")+1));  }
+               }
+       }
+
+       if ((($filtersettings{'ENABLE_REWRITE'} eq 'on') && (@repositoryfiles)) || ($filtersettings{'ENABLE_SAFESEARCH'} eq 'on'))
+       {
+               print FILE "rewrite rew-rule-0 {\n";
+
+               if (($filtersettings{'ENABLE_REWRITE'} eq 'on') && (@repositoryfiles))
+               {
+                       print FILE "    # rewrite localfiles\n";
+                       foreach (@repositoryfiles)
+                       {
+                               print FILE "    s@.*/$_\$\@http://$netsettings{'GREEN_ADDRESS'}:81/repository/$_\@i\n";
+                       }
+               }
+
+               if ($filtersettings{'ENABLE_SAFESEARCH'} eq 'on')
+               {
+                       print FILE "    # rewrite safesearch\n";
+                       print FILE "    s@(.*\\Wgoogle\\.\\w+/(webhp|search|imghp|images|grphp|groups|frghp|froogle)\\?)(.*)(\\bsafe=\\w+)(.*)\@\\1\\3safe=strict\\5\@i\n";
+                       print FILE "    s@(.*\\Wgoogle\\.\\w+/(webhp|search|imghp|images|grphp|groups|frghp|froogle)\\?)(.*)\@\\1safe=strict\\\&\\3\@i\n";
+                       print FILE "    s@(.*\\Wsearch\\.yahoo\\.\\w+/search\\W)(.*)(\\bvm=\\w+)(.*)\@\\1\\2vm=r\\4\@i\n";
+                       print FILE "    s@(.*\\Wsearch\\.yahoo\\.\\w+/search\\W.*)\@\\1\\\&vm=r\@i\n";
+                       print FILE "    s@(.*\\Walltheweb\\.com/customize\\?)(.*)(\\bcopt_offensive=\\w+)(.*)\@\\1\\2copt_offensive=on\\4\@i\n";
+               }
+
+               print FILE "}\n\n";
+
+               if ((!($filtersettings{'UNFILTERED_CLIENTS'} eq '')) && ($filtersettings{'ENABLE_SAFESEARCH'} eq 'on')) {
+                       print FILE "rewrite rew-rule-1 {\n";
+                       if (($filtersettings{'ENABLE_REWRITE'} eq 'on') && (@repositoryfiles))
+                       {
+                               print FILE "    # rewrite localfiles\n";
+                               foreach (@repositoryfiles)
+                               {
+                                       print FILE "    s@.*/$_\$\@http://$netsettings{'GREEN_ADDRESS'}:81/repository/$_\@i\n";
+                               }
+                       } else {
+                               print FILE "    # rewrite nothing\n";
+                       }
+                       print FILE "}\n\n";
+               }
+       }
+
+       if (-e $uqfile)
+       {
+               open(UQ, $uqfile);
+               @uqlist = <UQ>;
+               close(UQ);
+
+               if (@uqlist > 0)
+               {
+                       $idx=0;
+                       foreach (@uqlist)
+                       {
+                               chomp;
+                               @uq = split(/\,/);
+                               if ($uq[4] eq 'on')
+                               {
+                                       $idx++;
+                                       $uq[0] = $uq[0] * 60;
+                                       if ($uq[1] eq '0') {
+                                               if ($uq[2] eq 'hourly') { $uq[1] = 3600 }
+                                               if ($uq[2] eq 'daily')  { $uq[1] = 86400 }
+                                               if ($uq[2] eq 'weekly') { $uq[1] = 604800 }
+                                       }
+                                       $uq[3] =~ s/\|/ /g;
+                                       print FILE "src quota-$idx {\n";
+                                       print FILE "    user $uq[3]\n";
+                                       print FILE "    userquota $uq[0] $uq[1] $uq[2]\n";
+                                       print FILE "}\n\n";
+                               }
+                       }
+
+               }
+       }
+
+       @tclist = &aggregatedconstraints;
+
+       if (@tclist > 0)
+       {
+               $idx=0;
+               foreach (@tclist)
+               {
+                       chomp;
+                       @tc = split(/\,/);
+                       if ($tc[15] eq 'on')
+                       {
+                               $idx++;
+                               print FILE "src network-$idx {\n";
+                               print FILE "    ip $tc[12]\n";
+                               print FILE "}\n\n";
+                       }
+               }
+
+               $idx=0;
+               foreach (@tclist)
+               {
+                       chomp;
+                       @tc = split(/\,/);
+                       if ($tc[15] eq 'on')
+                       {
+                               $idx++;
+                               print FILE "time constraint-$idx {\n";
+                               print FILE "$tc[16]\n";
+                               print FILE "}\n\n";
+                       }
+               }
+       }
+
+       if (!($filtersettings{'UNFILTERED_CLIENTS'} eq '')) {
+               print FILE "src unfiltered {\n";
+               print FILE "    ip $filtersettings{'UNFILTERED_CLIENTS'}\n";
+               print FILE "}\n\n";
+       }
+       if (!($filtersettings{'BANNED_CLIENTS'} eq '')) {
+               print FILE "src banned {\n";
+               print FILE "    ip $filtersettings{'BANNED_CLIENTS'}\n";
+               print FILE "}\n\n";
+       }
+
+       foreach $category (@categories) {
+               print FILE "dest $category {\n";
+               if (-e "$dbdir/$category/domains") {
+                       print FILE "    domainlist     $category\/domains\n";
+               }
+               if (-e "$dbdir/$category/urls") {
+                       print FILE "    urllist        $category\/urls\n";
+               }
+               if ((-e "$dbdir/$category/expressions") && ($filtersettings{'ENABLE_EXPR_LISTS'} eq 'on')) {
+                       print FILE "    expressionlist $category\/expressions\n";
+               }
+               if (($category eq 'ads') && ($filtersettings{'ENABLE_EMPTY_ADS'} eq 'on'))
+               {
+                       print FILE "    redirect       http:\/\/$netsettings{'GREEN_ADDRESS'}:81\/images/urlfilter/1x1.gif\n";
+               }
+               if ($filtersettings{'ENABLE_LOG'} eq 'on')
+               {
+                       if ($filtersettings{'ENABLE_CATEGORY_LOG'} eq 'on')
+                       {
+                               print FILE "    logfile       $ident $category.log\n";
+                       } else {
+                               print FILE "    logfile       $ident urlfilter.log\n";
+                       }
+               }
+               print FILE "}\n\n";
+       }
+       
+       print FILE "dest files {\n";
+       print FILE "    expressionlist custom\/blocked\/files\n";
+       if ($filtersettings{'ENABLE_LOG'} eq 'on')
+       {
+               if ($filtersettings{'ENABLE_CATEGORY_LOG'} eq 'on')
+               {
+                       print FILE "    logfile       $ident files.log\n";
+               } else {
+                       print FILE "    logfile       $ident urlfilter.log\n";
+               }
+       }
+       print FILE "}\n\n";
+
+       print FILE "dest custom-allowed {\n";
+       print FILE "    domainlist     custom\/allowed\/domains\n";
+       print FILE "    urllist        custom\/allowed\/urls\n";
+       print FILE "}\n\n";
+
+       print FILE "dest custom-blocked {\n";
+       print FILE "    domainlist     custom\/blocked\/domains\n";
+       print FILE "    urllist        custom\/blocked\/urls\n";
+       if ($filtersettings{'ENABLE_LOG'} eq 'on')
+       {
+               if ($filtersettings{'ENABLE_CATEGORY_LOG'} eq 'on')
+               {
+                       print FILE "    logfile       $ident custom.log\n";
+               } else {
+                       print FILE "    logfile       $ident urlfilter.log\n";
+               }
+       }
+       print FILE "}\n\n";
+
+       print FILE "dest custom-expressions {\n";
+       print FILE "    expressionlist custom\/blocked\/expressions\n";
+       if ($filtersettings{'ENABLE_LOG'} eq 'on')
+       {
+               if ($filtersettings{'ENABLE_CATEGORY_LOG'} eq 'on')
+               {
+                       print FILE "    logfile       $ident custom.log\n";
+               } else {
+                       print FILE "    logfile       $ident urlfilter.log\n";
+               }
+       }
+       print FILE "}\n\n";
+
+       print FILE "acl {\n";
+       if (!($filtersettings{'UNFILTERED_CLIENTS'} eq '')) {
+               print FILE "    unfiltered {\n";
+               print FILE "        pass all\n";
+               if ($filtersettings{'ENABLE_SAFESEARCH'} eq 'on')
+               {
+                       print FILE "        rewrite rew-rule-1\n";
+               }
+               print FILE "    }\n\n";
+       }
+       if (!($filtersettings{'BANNED_CLIENTS'} eq '')) {
+               print FILE "    banned {\n";
+               print FILE "        pass ";
+               if (($filtersettings{'ENABLE_CUSTOM_WHITELIST'} eq 'on') && ($filtersettings{'ENABLE_GLOBAL_WHITELIST'} eq 'on'))
+               {
+                       print FILE "custom-allowed ";
+               }
+               print FILE "none\n";
+               print FILE "    }\n\n";
+       }
+
+       if (-s $uqfile)
+       {
+               open(UQ, $uqfile);
+               @uqlist = <UQ>;
+               close(UQ);
+
+               $idx=0;
+               foreach (@uqlist)
+               {
+                       chomp;
+                       @uq = split(/\,/);
+                       if ($uq[4] eq 'on')
+                       {
+                               $idx++;
+                               $qredirect = $redirect;
+                               $qredirect =~ s/\%t/\%q\%20-\%20\%i/;
+                               print FILE "    quota-$idx {\n";
+                               print FILE "        pass ";
+                               if (($filtersettings{'ENABLE_CUSTOM_WHITELIST'} eq 'on') && ($filtersettings{'ENABLE_GLOBAL_WHITELIST'} eq 'on'))
+                               {
+                                       print FILE "custom-allowed ";
+                               }
+                               print FILE "none\n";
+                               unless ($redirect eq $qredirect) { print FILE "        redirect $qredirect\n"; }
+                               print FILE "    }\n\n";
+                       }
+               }
+       }
+
+       if (@tclist > 0)
+       {
+               $idx=0;
+               foreach (@tclist)
+               {
+                       chomp;
+                       @tc = split(/\,/);
+                       @ec = split(/\|/,$tc[13]);
+                       if ($tc[15] eq 'on')
+                       {
+                               $idx++;
+                               print FILE "    network-$idx $tc[0] constraint-$idx {\n";
+                               print FILE "        pass ";
+
+                               if ($filtersettings{'BLOCK_ALL'} eq 'on')
+                               {
+                                       if ($tc[14] eq 'block')
+                                       {
+                                               if ((@ec == 1) && ($ec[0] eq 'any')) {
+                                                       if (($filtersettings{'ENABLE_CUSTOM_WHITELIST'} eq 'on') && ($filtersettings{'ENABLE_GLOBAL_WHITELIST'} eq 'on'))
+                                                       {
+                                                               print FILE "custom-allowed ";
+                                                       }
+                                                       print FILE "none";
+                                               } else {
+                                                       print FILE $defaultrule;
+                                               }
+                                       } else {
+                                               foreach (@ec)
+                                               {
+                                                       print FILE "$_ ";
+                                               }
+                                               print FILE $defaultrule unless ((@ec == 1) && ($ec[0] eq 'any'));
+                                       }
+                               } else {
+                                       if ($tc[14] eq 'block')
+                                       {
+                                               $tcrule = $defaultrule;
+                                               if ($filtersettings{'ENABLE_CUSTOM_WHITELIST'} eq 'on') {
+                                                       $tcrule =~ s/custom-allowed //;
+                                                       print FILE "custom-allowed " unless ((@ec == 1) && ($ec[0] eq 'any') && ($filtersettings{'ENABLE_GLOBAL_WHITELIST'} eq 'off'));
+                                               }
+                                               if ((@ec == 1) && ($ec[0] eq 'any')) {
+                                                       print FILE "none";
+                                               } else {
+                                                       foreach (@ec)
+                                                       {
+                                                               print FILE "!$_ " unless (index($defaultrule,"!".$_." ") ge 0);
+                                                       }
+                                               }
+                                               print FILE $tcrule unless ((@ec == 1) && ($ec[0] eq 'any'));
+                                       } else {
+                                               $tcrule = $defaultrule;
+                                               foreach (@ec)
+                                               {
+                                                       $tcrule =~ s/!$_ //;
+                                                       print FILE "$_ " if ($_ eq 'any');
+                                               }
+                                               print FILE $tcrule unless ((@ec == 1) && ($ec[0] eq 'any'));
+                                       }
+                               }
+
+                               print FILE "\n";
+
+                               print FILE "    }\n\n";
+                       }
+               }
+       }
+
+       print FILE "    default {\n";
+       print FILE "        pass $defaultrule\n";
+       if (($filtersettings{'ENABLE_LOG'} eq 'on') && ($filtersettings{'BLOCK_ALL'} eq 'on'))
+       {
+               if ($filtersettings{'ENABLE_CATEGORY_LOG'} eq 'on')
+               {
+                       print FILE "        logfile".$ident." default.log\n";
+               } else {
+                       print FILE "        logfile".$ident." urlfilter.log\n";
+               }
+       }
+       if ((($filtersettings{'ENABLE_REWRITE'} eq 'on') && (@repositoryfiles)) || ($filtersettings{'ENABLE_SAFESEARCH'} eq 'on'))
+       {
+               print FILE "        rewrite rew-rule-0\n";
+       }
+       print FILE "        redirect $redirect\n";
+       print FILE "    }\n";
+       print FILE "}\n";
+
+       close FILE;
+}
+
+# -------------------------------------------------------------------
+#!/usr/bin/perl
+#
+# SmoothWall CGIs
+#
+# This code is distributed under the terms of the GPL
+#
+# (c) written from scratch
+#
+# $Id: urlfilter.cgi,v 1.7 2006/05/08 00:00:00 marco Exp $
+#
+
+use strict;
+
+# enable only the following on debugging purpose
+#use warnings;
+#use CGI::Carp 'fatalsToBrowser';
+
+use File::Copy;
+use IO::Socket;
+
+require '/var/ipfire/general-functions.pl';
+require "${General::swroot}/lang.pl";
+require "${General::swroot}/header.pl";
+
+my %netsettings=();
+my %mainsettings=();
+my %proxysettings=();
+my %filtersettings=();
+my %tcsettings=();
+my %uqsettings=();
+my %besettings=();
+my %updatesettings=();
+my %checked=();
+my %selected=();
+my $id=0;
+my $line='';
+my $i=0;
+my $n=0;
+my $time='';
+my $filesize;
+my $category='';
+my $section='';
+my $blacklist='';
+my $blistbackup='';
+
+my $changed = 'no';
+my $tcfile = "${General::swroot}/urlfilter/timeconst";
+my $uqfile = "${General::swroot}/urlfilter/userquota";
+my $dbdir = "${General::swroot}/urlfilter/blacklists";
+my $editdir = "${General::swroot}/urlfilter/editor";
+my $repository = "/home/httpd/html/repository";
+my $hintcolour = '#FFFFCC';
+
+my $sourceurlfile = "${General::swroot}/urlfilter/autoupdate/autoupdate.urls";
+my $updconffile = "${General::swroot}/urlfilter/autoupdate/autoupdate.conf";
+my $updflagfile = "${General::swroot}/urlfilter/blacklists/.autoupdate.last";
+my $upd_cron_dly = "${General::swroot}/urlfilter/autoupdate/cron.daily";
+my $upd_cron_wly = "${General::swroot}/urlfilter/autoupdate/cron.weekly";
+my $upd_cron_mly = "${General::swroot}/urlfilter/autoupdate/cron.monthly";
+
+my $errormessage='';
+my $updatemessage='';
+my $restoremessage='';
+my $buttontext='';
+my $source_name='';
+my $source_url='';
+my $blacklistage=0;
+
+my @repositorylist=();
+my @repositoryfiles=();
+my @categories=();
+my @selectedcategories=();
+my @filtergroups=();
+my @tclist=();
+my @uqlist=();
+my @source_urllist=();
+my @temp=();
+
+my $lastslashpos=0;
+
+my $toggle='';
+my $gif='';
+my $led='';
+my $ldesc='';
+my $gdesc='';
+
+if (! -d $dbdir) { mkdir("$dbdir"); }
+if (! -e $tcfile) { system("touch $tcfile"); }
+if (! -e $uqfile) { system("touch $uqfile"); }
+if (! -e $sourceurlfile) { system("touch $sourceurlfile"); }
+
+&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
+&General::readhash("${General::swroot}/main/settings", \%mainsettings);
+&General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
+
+&readblockcategories;
+
+open(FILE, $tcfile);
+@tclist = <FILE>;
+close(FILE);
+open(FILE, $uqfile);
+@uqlist = <FILE>;
+close(FILE);
+open(FILE, $sourceurlfile);
+@source_urllist = <FILE>;
+close(FILE);
+
+$filtersettings{'ENABLE_CUSTOM_BLACKLIST'} = 'off';
+$filtersettings{'ENABLE_CUSTOM_WHITELIST'} = 'off';
+$filtersettings{'ENABLE_CUSTOM_EXPRESSIONS'} = 'off';
+$filtersettings{'BLOCK_EXECUTABLES'} = 'off';
+$filtersettings{'BLOCK_AUDIO-VIDEO'} = 'off';
+$filtersettings{'BLOCK_ARCHIVES'} = 'off';
+$filtersettings{'ENABLE_REWRITE'} = 'off';
+$filtersettings{'UNFILTERED_CLIENTS'} = '';
+$filtersettings{'BANNED_CLIENTS'} = '';
+$filtersettings{'SHOW_CATEGORY'} = 'off';
+$filtersettings{'SHOW_URL'} = 'off';
+$filtersettings{'SHOW_IP'} = 'off';
+$filtersettings{'ENABLE_DNSERROR'} = 'off';
+$filtersettings{'ENABLE_JPEG'} = 'off';
+$filtersettings{'REDIRECT_PAGE'} = '';
+$filtersettings{'MSG_TEXT_1'} = '';
+$filtersettings{'MSG_TEXT_2'} = '';
+$filtersettings{'MSG_TEXT_3'} = '';
+$filtersettings{'ENABLE_EXPR_LISTS'} = 'off';
+$filtersettings{'BLOCK_IP_ADDR'} = 'off';
+$filtersettings{'BLOCK_ALL'} = 'off';
+$filtersettings{'ENABLE_EMPTY_ADS'} = 'off';
+$filtersettings{'ENABLE_GLOBAL_WHITELIST'} = 'off';
+$filtersettings{'ENABLE_SAFESEARCH'} = 'off';
+$filtersettings{'ENABLE_LOG'} = 'off';
+$filtersettings{'ENABLE_USERNAME_LOG'} = 'off';
+$filtersettings{'ENABLE_CATEGORY_LOG'} = 'off';
+$filtersettings{'CHILDREN'} = '5';
+$filtersettings{'ENABLE_AUTOUPDATE'} = 'off';
+
+$filtersettings{'ACTION'} = '';
+$filtersettings{'VALID'} = '';
+
+&Header::getcgihash(\%filtersettings);
+&Header::getcgihash(\%tcsettings);
+&Header::getcgihash(\%uqsettings);
+&Header::getcgihash(\%besettings);
+
+if (($filtersettings{'ACTION'} eq $Lang::tr{'save'}) ||
+    ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter save and restart'}) ||
+    ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter upload file'}) ||
+    ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter remove file'}) ||
+    ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter upload background'}) ||
+    ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter upload blacklist'}) ||
+    ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter backup'}) ||
+    ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter restore'}))
+{ 
+       if (!($filtersettings{'CHILDREN'} =~ /^\d+$/) || ($filtersettings{'CHILDREN'} < 1))
+       {
+               $errormessage = $Lang::tr{'urlfilter invalid num of children'};
+               goto ERROR;
+       }
+
+       if ((!($filtersettings{'REDIRECT_PAGE'} eq '')) && (!($filtersettings{'REDIRECT_PAGE'} =~ /^https?:\/\//)))
+       {
+               $filtersettings{'REDIRECT_PAGE'} = "http://".$filtersettings{'REDIRECT_PAGE'};
+       }
+
+       if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter remove file'})
+       {
+               if (-e "$repository/$filtersettings{'ID'}") { unlink("$repository/$filtersettings{'ID'}"); }
+               $filtersettings{'ACTION'} = $Lang::tr{'urlfilter manage repository'};
+       }
+
+       if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter upload file'})
+       {
+               &Header::getcgihash(\%filtersettings, {'wantfile' => 1, 'filevar' => 'UPLOADFILE'});
+
+               $filtersettings{'ACTION'} = $Lang::tr{'urlfilter manage repository'};
+               $_ = $filtersettings{'UPLOADFILE'};
+               tr/\\/\//;
+               $_ = substr($_,rindex($_,"/")+1);
+               if ($_) {
+                       if (copy($filtersettings{'UPLOADFILE'}, "$repository/$_") != 1)
+                       {
+                               $errormessage = $!;
+                               goto ERROR;
+                       }
+               }
+
+       }
+       
+       if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter upload background'})
+       {
+               &Header::getcgihash(\%filtersettings, {'wantfile' => 1, 'filevar' => 'BACKGROUND'});
+
+               if (copy($filtersettings{'BACKGROUND'}, "/home/httpd/html/images/urlfilter/background.jpg") != 1)
+               {
+                       $errormessage = $!;
+                       goto ERROR;
+               }
+       }
+       
+       if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter upload blacklist'})
+       {
+               &Header::getcgihash(\%filtersettings, {'wantfile' => 1, 'filevar' => 'UPDATEFILE'});
+
+               if (!($filtersettings{'UPDATEFILE'} =~ /.tar.gz$/))
+               {
+                       $errormessage = $Lang::tr{'urlfilter wrong filetype'};
+                       goto ERROR;
+               }
+
+               if (copy($filtersettings{'UPDATEFILE'}, "${General::swroot}/urlfilter/blacklists.tar.gz") != 1)
+               {
+                       $errormessage = $!;
+                       goto ERROR;
+               }
+               
+               if (!(-d "${General::swroot}/urlfilter/update")) { mkdir("${General::swroot}/urlfilter/update"); }
+
+               my $exitcode = system("/bin/tar --no-same-owner -xzf ${General::swroot}/urlfilter/blacklists.tar.gz -C ${General::swroot}/urlfilter/update");
+               
+               if ($exitcode > 0)
+               {
+                       $errormessage = $Lang::tr{'urlfilter tar error'};
+               } else {
+
+                       if (-d "${General::swroot}/urlfilter/update/category")
+                       {
+                               system("mv ${General::swroot}/urlfilter/update/category ${General::swroot}/urlfilter/update/blacklists");
+                       }
+
+                       if (!(-d "${General::swroot}/urlfilter/update/blacklists"))
+                       {
+                               $errormessage = $Lang::tr{'urlfilter invalid content'};
+                       } else {
+                               system("cp -r ${General::swroot}/urlfilter/update/blacklists/* $dbdir");
+
+                               &readblockcategories;
+                               &readcustomlists;
+
+                               &writeconfigfile;
+
+                               $updatemessage = $Lang::tr{'urlfilter upload success'};
+                               system("${General::swroot}/urlfilter/bin/prebuild.pl &");
+                               system("logger -t installpackage[urlfilter] \"URL filter blacklist - Blacklist update from local source completed\"");
+                       }
+               }
+               if (-d "${General::swroot}/urlfilter/update") { system("rm -rf ${General::swroot}/urlfilter/update"); }
+               if (-e "${General::swroot}/urlfilter/blacklists.tar.gz") { unlink("${General::swroot}/urlfilter/blacklists.tar.gz"); }
+               if ($errormessage) { goto ERROR; }
+       }
+
+       if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter backup'})
+       {
+               $blistbackup = ($filtersettings{'ENABLE_FULLBACKUP'} eq 'on') ? "blacklists" : "blacklists/custom";
+               if (system("/bin/tar -C ${General::swroot}/urlfilter -czf ${General::swroot}/urlfilter/backup.tar.gz settings timeconst userquota autoupdate $blistbackup"))
+               {
+                       $errormessage = $Lang::tr{'urlfilter backup error'};
+                       goto ERROR;
+               }
+               else
+               {
+                       print "Content-type: application/gzip\n";
+                       print "Content-length: ";
+                       print (-s "${General::swroot}/urlfilter/backup.tar.gz");
+                       print "\n";
+                       print "Content-disposition: attachment; filename=urlfilter-backup.tar.gz\n\n";
+
+                       open (FILE, "${General::swroot}/urlfilter/backup.tar.gz");
+                       while (<FILE>) { print; }
+                       close (FILE);
+
+                       if (-e "${General::swroot}/urlfilter/backup.tar.gz") { unlink("${General::swroot}/urlfilter/backup.tar.gz"); }
+                       exit;
+               }
+       }
+
+       if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter restore'})
+       {
+               &Header::getcgihash(\%filtersettings, {'wantfile' => 1, 'filevar' => 'UPDATEFILE'});
+
+               if (!($filtersettings{'UPDATEFILE'} =~ /.tar.gz$/))
+               {
+                       $errormessage = $Lang::tr{'urlfilter wrong filetype'};
+                       goto ERROR;
+               }
+
+               if (!(-d "${General::swroot}/urlfilter/restore")) { mkdir("${General::swroot}/urlfilter/restore"); }
+
+               if (copy($filtersettings{'UPDATEFILE'}, "${General::swroot}/urlfilter/backup.tar.gz") != 1)
+               {
+                       $errormessage = $!;
+               }
+               
+               my $exitcode = system("/bin/tar --no-same-owner --preserve-permissions -xzf ${General::swroot}/urlfilter/backup.tar.gz -C ${General::swroot}/urlfilter/restore");
+               if ($exitcode > 0)
+               {
+                       $errormessage = $Lang::tr{'urlfilter tar error'};
+               } else {
+                       if (!(-e "${General::swroot}/urlfilter/restore/settings"))
+                       {
+                               $errormessage = $Lang::tr{'urlfilter invalid restore file'};
+                       } else {
+                               system("cp -rp ${General::swroot}/urlfilter/restore/* ${General::swroot}/urlfilter/");
+                               &readblockcategories;
+                               &readcustomlists;
+                               &writeconfigfile;
+
+                               $restoremessage = $Lang::tr{'urlfilter restore success'};
+                       }
+               }
+
+               if (-e "${General::swroot}/urlfilter/backup.tar.gz") { unlink("${General::swroot}/urlfilter/backup.tar.gz"); }
+               if (-d "${General::swroot}/urlfilter/restore") { system("rm -rf ${General::swroot}/urlfilter/restore"); }
+               if ($errormessage) { goto ERROR; }
+       }
+
+       if ($filtersettings{'ACTION'} eq $Lang::tr{'save'})
+       {
+               $filtersettings{'VALID'} = 'yes';
+               &savesettings;
+       }
+
+       if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter save and restart'})
+       {
+               if (!(-e "${General::swroot}/proxy/enable"))
+               {
+                       $errormessage = $Lang::tr{'urlfilter web proxy service required'};
+                       goto ERROR;
+               }
+               if (!($proxysettings{'ENABLE_FILTER'} eq 'on'))
+               {
+                       $errormessage = $Lang::tr{'urlfilter not enabled'};
+                       goto ERROR;
+               }
+
+               $filtersettings{'VALID'} = 'yes';
+               &savesettings;
+
+               system("chown -R nobody.nobody $dbdir");
+
+               if (-e "$dbdir/custom/allowed/domains.db") { unlink("$dbdir/custom/allowed/domains.db"); }
+               if (-e "$dbdir/custom/allowed/urls.db")    { unlink("$dbdir/custom/allowed/urls.db"); }
+               if (-e "$dbdir/custom/blocked/domains.db") { unlink("$dbdir/custom/blocked/domains.db"); }
+               if (-e "$dbdir/custom/blocked/urls.db")    { unlink("$dbdir/custom/blocked/urls.db"); }
+
+               foreach (<$dbdir/*>)
+               {
+                       if (-d $_){ system("chmod 644 $_/*"); }
+                       if (-d $_){ system("chmod 666 $_/*.db"); }
+               }
+               if (-d "$dbdir/custom/allowed")
+               {
+                       system("chmod 755 $dbdir/custom/allowed");
+                       system("chmod 644 $dbdir/custom/allowed/*");
+               }
+               if (-d "$dbdir/custom/blocked")
+               {
+                       system("chmod 755 $dbdir/custom/blocked");
+                       system("chmod 644 $dbdir/custom/blocked/*");
+               }
+
+               system('/usr/local/bin/restartsquid');
+       }
+
+ERROR:
+
+       if ($errormessage) { $filtersettings{'VALID'} = 'no'; }
+
+}
+
+if ($tcsettings{'ACTION'} eq $Lang::tr{'urlfilter set time constraints'}) { $tcsettings{'TCMODE'} = 'on'}
+
+if (($tcsettings{'MODE'} eq 'TIMECONSTRAINT') && ($tcsettings{'ACTION'} eq $Lang::tr{'add'}))
+{
+       $tcsettings{'TCMODE'}='on';
+
+       if (!$tcsettings{'DST'})
+       {
+               $errormessage=$Lang::tr{'urlfilter dst error'};
+       }
+
+       if (!$tcsettings{'SRC'})
+       {
+               $errormessage=$Lang::tr{'urlfilter src error'};
+       }
+
+       if (!($tcsettings{'TO_HOUR'}.$tcsettings{'TO_MINUTE'} gt $tcsettings{'FROM_HOUR'}.$tcsettings{'FROM_MINUTE'}))
+       {
+               $errormessage=$Lang::tr{'urlfilter timespace error'};
+       }
+
+       if (!(($tcsettings{'MON'} eq 'on') || ($tcsettings{'TUE'} eq 'on') || ($tcsettings{'WED'} eq 'on') || ($tcsettings{'THU'} eq 'on') || ($tcsettings{'FRI'} eq 'on') || ($tcsettings{'SAT'} eq 'on') || ($tcsettings{'SUN'} eq 'on')))
+       {
+               $errormessage=$Lang::tr{'urlfilter weekday error'};
+       }
+
+       if (!$errormessage)
+       {
+               if ($tcsettings{'DST'} =~ /^any/) { $tcsettings{'DST'} = 'any'; }
+               if ($tcsettings{'ENABLERULE'} eq 'on') { $tcsettings{'ACTIVE'} = $tcsettings{'ENABLERULE'}; } else { $tcsettings{'ACTIVE'} = 'off'}
+
+               $tcsettings{'ENABLERULE'} = 'on';
+               if($tcsettings{'EDITING'} eq 'no') {
+                       open(FILE,">>$tcfile");
+                       flock FILE, 2;
+                       print FILE "$tcsettings{'DEFINITION'},$tcsettings{'MON'},$tcsettings{'TUE'},$tcsettings{'WED'},$tcsettings{'THU'},$tcsettings{'FRI'},$tcsettings{'SAT'},$tcsettings{'SUN'},$tcsettings{'FROM_HOUR'},$tcsettings{'FROM_MINUTE'},$tcsettings{'TO_HOUR'},$tcsettings{'TO_MINUTE'},$tcsettings{'SRC'},$tcsettings{'DST'},$tcsettings{'ACCESS'},$tcsettings{'ACTIVE'},$tcsettings{'COMMENT'}\n";
+               } else {
+                       open(FILE, ">$tcfile");
+                       flock FILE, 2;
+                       $id = 0;
+                       foreach $line (@tclist)
+                       {
+                               $id++;
+                               if ($tcsettings{'EDITING'} eq $id) {
+                                       print FILE "$tcsettings{'DEFINITION'},$tcsettings{'MON'},$tcsettings{'TUE'},$tcsettings{'WED'},$tcsettings{'THU'},$tcsettings{'FRI'},$tcsettings{'SAT'},$tcsettings{'SUN'},$tcsettings{'FROM_HOUR'},$tcsettings{'FROM_MINUTE'},$tcsettings{'TO_HOUR'},$tcsettings{'TO_MINUTE'},$tcsettings{'SRC'},$tcsettings{'DST'},$tcsettings{'ACCESS'},$tcsettings{'ACTIVE'},$tcsettings{'COMMENT'}\n";
+                               } else { print FILE "$line"; }
+                       }
+               }
+               close(FILE);
+               undef %tcsettings;
+               $tcsettings{'CHANGED'}='yes';
+               $tcsettings{'TCMODE'}='on';
+               $changed = 'yes';
+       } else {
+               if ($tcsettings{'EDITING'} ne 'no')
+               {
+                       $tcsettings{'ACTION'} = $Lang::tr{'edit'};
+                       $tcsettings{'ID'} = $tcsettings{'EDITING'};
+               }
+       }
+}
+
+if (($tcsettings{'MODE'} eq 'TIMECONSTRAINT') && ($tcsettings{'ACTION'} eq $Lang::tr{'remove'}))
+{
+       $id = 0;
+       open(FILE, ">$tcfile");
+       flock FILE, 2;
+       foreach $line (@tclist)
+       {
+               $id++;
+               unless ($tcsettings{'ID'} eq $id) { print FILE "$line"; }
+       }
+       close(FILE);
+       $tcsettings{'CHANGED'}='yes';
+       $tcsettings{'TCMODE'}='on';
+}
+
+if (($tcsettings{'MODE'} eq 'TIMECONSTRAINT') && ($tcsettings{'ACTION'} eq $Lang::tr{'urlfilter restart'}))
+{
+       if (!($proxysettings{'ENABLE_FILTER'} eq 'on'))
+       {
+               $errormessage = $Lang::tr{'urlfilter not enabled'};
+       }
+       if (!(-e "${General::swroot}/proxy/enable"))
+       {
+               $errormessage = $Lang::tr{'urlfilter web proxy service required'};
+       }
+
+       if (!$errormessage) { system('/usr/local/bin/restartsquid'); }
+       $tcsettings{'TCMODE'}='on';
+}
+
+if (($tcsettings{'MODE'} eq 'TIMECONSTRAINT') && ($tcsettings{'ACTION'} eq $Lang::tr{'toggle enable disable'}))
+{
+       open(FILE, ">$tcfile");
+       flock FILE, 2;
+       $id = 0;
+       foreach $line (@tclist)
+       {
+               $id++;
+               unless ($tcsettings{'ID'} eq $id) { print FILE "$line"; }
+               else
+               {
+                       chomp($line);
+                       @temp = split(/\,/,$line);
+                       if ($temp[15] eq 'on') { $temp[15] = 'off'; } else { $temp[15] = 'on' }
+                       print FILE "$temp[0],$temp[1],$temp[2],$temp[3],$temp[4],$temp[5],$temp[6],$temp[7],$temp[8],$temp[9],$temp[10],$temp[11],$temp[12],$temp[13],$temp[14],$temp[15],$temp[16]\n";
+               }
+       }
+       close(FILE);
+       $tcsettings{'CHANGED'}='yes';
+       $tcsettings{'TCMODE'}='on';
+}
+
+if (!$errormessage) {
+       $tcsettings{'ENABLERULE'}='on';
+       $tcsettings{'TO_HOUR'}='24';
+}
+
+if (($tcsettings{'MODE'} eq 'TIMECONSTRAINT') && ($tcsettings{'ACTION'} eq $Lang::tr{'edit'}) && (!$errormessage))
+{
+       $id = 0;
+       foreach $line (@tclist)
+       {
+               $id++;
+               if ($tcsettings{'ID'} eq $id)
+               {
+                       chomp($line);
+                       @temp = split(/\,/,$line);
+                       $tcsettings{'DEFINITION'} = $temp[0];
+                       $tcsettings{'MON'} = $temp[1];
+                       $tcsettings{'TUE'} = $temp[2];
+                       $tcsettings{'WED'} = $temp[3];
+                       $tcsettings{'THU'} = $temp[4];
+                       $tcsettings{'FRI'} = $temp[5];
+                       $tcsettings{'SAT'} = $temp[6];
+                       $tcsettings{'SUN'} = $temp[7];
+                       $tcsettings{'FROM_HOUR'} = $temp[8];
+                       $tcsettings{'FROM_MINUTE'} = $temp[9];
+                       $tcsettings{'TO_HOUR'} = $temp[10];
+                       $tcsettings{'TO_MINUTE'} = $temp[11];
+                       $tcsettings{'SRC'} = $temp[12];
+                       $tcsettings{'DST'} = $temp[13];
+                       $tcsettings{'ACCESS'} = $temp[14];
+                       $tcsettings{'ENABLERULE'} = $temp[15];
+                       $tcsettings{'COMMENT'} = $temp[16];
+               }
+       }
+       $tcsettings{'TCMODE'}='on';
+}
+
+if ($uqsettings{'ACTION'} eq $Lang::tr{'urlfilter set user quota'}) { $uqsettings{'UQMODE'} = 'on'}
+
+if (($uqsettings{'MODE'} eq 'USERQUOTA') && ($uqsettings{'ACTION'} eq $Lang::tr{'add'}))
+{
+       $uqsettings{'UQMODE'}='on';
+
+       if ((!($uqsettings{'TIME_QUOTA'} =~ /^\d+/)) || ($uqsettings{'TIME_QUOTA'} < '1'))
+       {
+               $errormessage=$Lang::tr{'urlfilter quota time error'};
+       }
+
+       @temp = split(/\n/,$uqsettings{'QUOTA_USERS'});
+       undef $uqsettings{'QUOTA_USERS'};
+       foreach (@temp)
+       {
+               s/^\s+//g; s/\s+$//g;
+               if ($_) { $uqsettings{'QUOTA_USERS'} .= $_."\n"; }
+       }
+
+       if ($uqsettings{'QUOTA_USERS'} eq '')
+       {
+               $errormessage=$Lang::tr{'urlfilter quota user error'};
+       }
+
+       $_  = $uqsettings{'QUOTA_USERS'};
+       chomp; s/\n/|/g;
+       my $quota_users = $_;
+
+       if ($uqsettings{'QUOTA_USERS'} =~ /\\/)
+       {
+               $errormessage=$Lang::tr{'urlfilter invalid user error'};
+       }
+
+       if (!$errormessage) {
+               if ($uqsettings{'ENABLEQUOTA'} eq 'on') { $uqsettings{'ACTIVE'} = $uqsettings{'ENABLEQUOTA'}; } else { $uqsettings{'ACTIVE'} = 'off'}
+
+               $uqsettings{'ENABLERULE'} = 'on';
+               if($uqsettings{'EDITING'} eq 'no') {
+                       open(FILE,">>$uqfile");
+                       flock FILE, 2;
+                       print FILE "$uqsettings{'TIME_QUOTA'},$uqsettings{'SPORADIC'},$uqsettings{'RENEWAL'},$quota_users,$uqsettings{'ACTIVE'}\n";
+               } else {
+                       open(FILE, ">$uqfile");
+                       flock FILE, 2;
+                       $id = 0;
+                       foreach $line (@uqlist)
+                       {
+                               $id++;
+                               if ($uqsettings{'EDITING'} eq $id) {
+                                       print FILE "$uqsettings{'TIME_QUOTA'},$uqsettings{'SPORADIC'},$uqsettings{'RENEWAL'},$quota_users,$uqsettings{'ACTIVE'}\n";
+                               } else { print FILE "$line"; }
+                       }
+               }
+               close(FILE);
+               undef %uqsettings;
+               $uqsettings{'CHANGED'}='yes';
+               $uqsettings{'MODE'}='USERQUOTA';
+               $uqsettings{'UQMODE'}='on';
+               $changed = 'yes';
+       } else {
+               if ($uqsettings{'EDITING'} ne 'no')
+               {
+                       $uqsettings{'ACTION'} = $Lang::tr{'edit'};
+                       $uqsettings{'ID'} = $uqsettings{'EDITING'};
+               }
+       }
+}
+
+if (($uqsettings{'MODE'} eq 'USERQUOTA') && ($uqsettings{'ACTION'} eq $Lang::tr{'remove'}))
+{
+       $id = 0;
+       open(FILE, ">$uqfile");
+       flock FILE, 2;
+       foreach $line (@uqlist)
+       {
+               $id++;
+               unless ($uqsettings{'ID'} eq $id) { print FILE "$line"; }
+       }
+       close(FILE);
+       $uqsettings{'CHANGED'}='yes';
+       $uqsettings{'UQMODE'}='on';
+}
+
+if (!$errormessage) {
+       $uqsettings{'ENABLEQUOTA'}='on';
+}
+
+if (($uqsettings{'MODE'} eq 'USERQUOTA') && ($uqsettings{'ACTION'} eq $Lang::tr{'edit'}) && (!$errormessage))
+{
+       $id = 0;
+       foreach $line (@uqlist)
+       {
+               $id++;
+               if ($uqsettings{'ID'} eq $id)
+               {
+                       chomp($line);
+                       @temp = split(/\,/,$line);
+                       $uqsettings{'TIME_QUOTA'} = $temp[0];
+                       $uqsettings{'SPORADIC'} = $temp[1];
+                       $uqsettings{'RENEWAL'} = $temp[2];
+                       $uqsettings{'QUOTA_USERS'} = $temp[3];
+                       $uqsettings{'ENABLEQUOTA'} = $temp[4];
+               }
+       }
+       $uqsettings{'UQMODE'}='on';
+}
+
+if (($uqsettings{'MODE'} eq 'USERQUOTA') && ($uqsettings{'ACTION'} eq $Lang::tr{'toggle enable disable'}))
+{
+       open(FILE, ">$uqfile");
+       flock FILE, 2;
+       $id = 0;
+       foreach $line (@uqlist)
+       {
+               $id++;
+               unless ($uqsettings{'ID'} eq $id) { print FILE "$line"; }
+               else
+               {
+                       chomp($line);
+                       @temp = split(/\,/,$line);
+                       if ($temp[4] eq 'on') { $temp[4] = 'off'; } else { $temp[4] = 'on' }
+                       print FILE "$temp[0],$temp[1],$temp[2],$temp[3],$temp[4]\n";
+               }
+       }
+       close(FILE);
+       $uqsettings{'CHANGED'}='yes';
+       $uqsettings{'UQMODE'}='on';
+}
+
+if (($uqsettings{'MODE'} eq 'USERQUOTA') && ($uqsettings{'ACTION'} eq $Lang::tr{'urlfilter restart'}))
+{
+       if (!($proxysettings{'ENABLE_FILTER'} eq 'on'))
+       {
+               $errormessage = $Lang::tr{'urlfilter not enabled'};
+       }
+       if (!(-e "${General::swroot}/proxy/enable"))
+       {
+               $errormessage = $Lang::tr{'urlfilter web proxy service required'};
+       }
+
+       if (!$errormessage) { system('/usr/local/bin/restartsquid'); }
+       $uqsettings{'UQMODE'}='on';
+}
+
+if ($besettings{'ACTION'} eq $Lang::tr{'urlfilter blacklist editor'}) { $besettings{'BEMODE'} = 'on'; }
+
+if ($besettings{'MODE'} eq 'BLACKLIST_EDITOR')
+{
+       @temp = split(/\n/,$besettings{'BE_DOMAINS'});
+        undef $besettings{'BE_DOMAINS'};
+        foreach (@temp)
+        {
+                s/^\s+//g; s/\s+$//g;
+                if ($_) { $besettings{'BE_DOMAINS'} .= $_."\n"; }
+        }
+       chomp($besettings{'BE_DOMAINS'});
+       @temp = split(/\n/,$besettings{'BE_URLS'});
+        undef $besettings{'BE_URLS'};
+        foreach (@temp)
+        {
+                s/^\s+//g; s/\s+$//g;
+                if ($_) { $besettings{'BE_URLS'} .= $_."\n"; }
+        }
+       chomp($besettings{'BE_URLS'});
+       @temp = split(/\n/,$besettings{'BE_EXPRESSIONS'});
+        undef $besettings{'BE_EXPRESSIONS'};
+        foreach (@temp)
+        {
+                s/^\s+//g; s/\s+$//g;
+                if ($_) { $besettings{'BE_EXPRESSIONS'} .= $_."\n"; }
+        }
+       chomp($besettings{'BE_EXPRESSIONS'});
+}
+
+if (($besettings{'ACTION'} eq $Lang::tr{'urlfilter load blacklist'}) && ($besettings{'MODE'} = 'BLACKLIST_EDITOR'))
+{
+       $besettings{'BEMODE'} = 'on';
+
+       $besettings{'BE_NAME'} = $besettings{'BE_BLACKLIST'};
+
+       delete $besettings{'BE_DOMAINS'};
+       delete $besettings{'BE_URLS'};
+       delete $besettings{'BE_EXPRESSIONS'};
+
+       if (-e "$dbdir/$besettings{'BE_NAME'}/domains")
+       {
+               open(FILE, "$dbdir/$besettings{'BE_NAME'}/domains");
+               while (<FILE>) { unless ($_ eq '\n') { $besettings{'BE_DOMAINS'} .= $_ } };
+               close FILE;
+               chomp($besettings{'BE_DOMAINS'});
+       }
+       if (-e "$dbdir/$besettings{'BE_NAME'}/urls")
+       {
+               open(FILE, "$dbdir/$besettings{'BE_NAME'}/urls");
+               while (<FILE>) { unless ($_ eq '\n') { $besettings{'BE_URLS'} .= $_ } };
+               close FILE;
+               chomp($besettings{'BE_URLS'});
+       }
+       if (-e "$dbdir/$besettings{'BE_NAME'}/expressions")
+       {
+               open(FILE, "$dbdir/$besettings{'BE_NAME'}/expressions");
+               while (<FILE>) { unless ($_ eq '\n') { $besettings{'BE_EXPRESSIONS'} .= $_ } };
+               close FILE;
+               chomp($besettings{'BE_EXPRESSIONS'});
+       }
+}
+
+if (($besettings{'ACTION'} eq $Lang::tr{'urlfilter import blacklist'}) && ($besettings{'MODE'} = 'BLACKLIST_EDITOR'))
+{
+       $besettings{'BEMODE'} = 'on';
+
+       &Header::getcgihash(\%besettings, {'wantfile' => 1, 'filevar' => 'IMPORTFILE'});
+
+       if (!($besettings{'IMPORTFILE'} =~ /.tar.gz$/))
+       {
+               $errormessage = $Lang::tr{'urlfilter wrong filetype'};
+       } else {
+               if (!-d "$editdir") { mkdir("$editdir"); }
+
+               if (copy($besettings{'IMPORTFILE'}, "$editdir/blacklist.tar.gz") != 1)
+               {
+                       $errormessage = $!;
+               } else {
+               
+                       my $exitcode = system("/bin/tar --no-same-owner --preserve-permissions -xzf $editdir/blacklist.tar.gz -C $editdir");
+                       if ($exitcode > 0)
+                       {
+                               $errormessage = $Lang::tr{'urlfilter tar error'};
+                       } else {
+                               $i = 0;
+                               foreach (<$editdir/blacklists/*>)
+                               {
+                                       if (-d)
+                                       {
+                                               $i++;
+                                               $besettings{'BE_NAME'} = substr($_, rindex($_,"/")+1);
+                                       }
+                               }
+
+                               if (!($i == 1))
+                               {
+                                       $errormessage = $Lang::tr{'urlfilter invalid import file'};
+                               } else {
+                                       delete $besettings{'BE_DOMAINS'};
+                                       delete $besettings{'BE_URLS'};
+                                       delete $besettings{'BE_EXPRESSIONS'};
+
+                                       if (-e "$editdir/blacklists/$besettings{'BE_NAME'}/domains")
+                                       {
+                                               open(FILE, "$editdir/blacklists/$besettings{'BE_NAME'}/domains");
+                                               while (<FILE>) { unless ($_ eq '\n') { $besettings{'BE_DOMAINS'} .= $_ } };
+                                               close FILE;
+                                               chomp($besettings{'BE_DOMAINS'});
+                                       }
+                                       if (-e "$editdir/blacklists/$besettings{'BE_NAME'}/urls")
+                                       {
+                                               open(FILE, "$editdir/blacklists/$besettings{'BE_NAME'}/urls");
+                                               while (<FILE>) { unless ($_ eq '\n') { $besettings{'BE_URLS'} .= $_ } };
+                                               close FILE;
+                                               chomp($besettings{'BE_URLS'});
+                                       }
+                                       if (-e "$editdir/blacklists/$besettings{'BE_NAME'}/expressions")
+                                       {
+                                               open(FILE, "$editdir/blacklists/$besettings{'BE_NAME'}/expressions");
+                                               while (<FILE>) { unless ($_ eq '\n') { $besettings{'BE_EXPRESSIONS'} .= $_ } };
+                                               close FILE;
+                                               chomp($besettings{'BE_EXPRESSIONS'});
+                                       }
+                               }
+                       }
+
+               if (-d $editdir) { system("rm -rf $editdir"); }
+
+               }
+       }
+}
+
+if (($besettings{'ACTION'} eq $Lang::tr{'urlfilter export blacklist'}) && ($besettings{'MODE'} = 'BLACKLIST_EDITOR'))
+{
+       $besettings{'BEMODE'} = 'on';
+
+       if ($besettings{'BE_NAME'} eq '')
+       {
+               $errormessage = $Lang::tr{'urlfilter category name error'};
+       } elsif ($besettings{'BE_DOMAINS'} || $besettings{'BE_URLS'} || $besettings{'BE_EXPRESSIONS'}) {
+
+               $_ = $besettings{'BE_NAME'}; tr/A-Z/a-z/; $besettings{'BE_NAME'} = $_;
+
+               if (!(-d "$editdir")) { mkdir("$editdir"); }
+               if (!(-d "$editdir/blacklists")) { mkdir("$editdir/blacklists"); }
+               if (!(-d "$editdir/blacklists/$besettings{'BE_NAME'}")) { mkdir("$editdir/blacklists/$besettings{'BE_NAME'}"); }
+
+               open(FILE, ">$editdir/blacklists/$besettings{'BE_NAME'}/domains");
+               flock FILE, 2;
+               print FILE "$besettings{'BE_DOMAINS'}\n";
+               close FILE;
+               open(FILE, ">$editdir/blacklists/$besettings{'BE_NAME'}/urls");
+               flock FILE, 2;
+               print FILE "$besettings{'BE_URLS'}\n";
+               close FILE;
+               open(FILE, ">$editdir/blacklists/$besettings{'BE_NAME'}/expressions");
+               flock FILE, 2;
+               print FILE "$besettings{'BE_EXPRESSIONS'}\n";
+               close FILE;
+
+               if (system("/bin/tar -C $editdir -czf $editdir/$besettings{'BE_NAME'}.tar.gz blacklists"))
+               {
+                       $errormessage = $Lang::tr{'urlfilter export error'};
+               }
+               else
+               {
+                       print "Content-type: application/gzip\n";
+                       print "Content-length: ";
+                       print (-s "$editdir/$besettings{'BE_NAME'}.tar.gz");
+                       print "\n";
+                       print "Content-disposition: attachment; filename=$besettings{'BE_NAME'}.tar.gz\n\n";
+
+                       open (FILE, "$editdir/$besettings{'BE_NAME'}.tar.gz");
+                       while (<FILE>) { print; }
+                       close (FILE);
+
+                       if (-d $editdir) { system("rm -rf $editdir"); }
+                       exit;
+               }
+       } else {
+               $errormessage = $Lang::tr{'urlfilter category data error'};
+       }
+}
+
+if (($besettings{'ACTION'} eq $Lang::tr{'urlfilter install blacklist'}) && ($besettings{'MODE'} = 'BLACKLIST_EDITOR'))
+{
+       $besettings{'BEMODE'} = 'on';
+
+       if ($besettings{'BE_NAME'} eq '')
+       {
+               $errormessage = $Lang::tr{'urlfilter category name error'};
+       } elsif ($besettings{'BE_DOMAINS'} || $besettings{'BE_URLS'} || $besettings{'BE_EXPRESSIONS'}) {
+
+               $_ = $besettings{'BE_NAME'}; tr/A-Z/a-z/; $besettings{'BE_NAME'} = $_;
+
+               if (!-d "$editdir") { mkdir("$editdir"); }
+
+               if (!-d "$dbdir/$besettings{'BE_NAME'}") { mkdir("$dbdir/$besettings{'BE_NAME'}"); }
+
+               if (-e "$dbdir/$besettings{'BE_NAME'}/domains") { unlink("$dbdir/$besettings{'BE_NAME'}/domains"); }
+               if ($besettings{'BE_DOMAINS'})
+               {
+                       open(FILE, ">$dbdir/$besettings{'BE_NAME'}/domains");
+                       flock FILE, 2;
+                       print FILE "$besettings{'BE_DOMAINS'}\n";
+                       close FILE;
+               }
+               if (-e "$dbdir/$besettings{'BE_NAME'}/urls") { unlink("$dbdir/$besettings{'BE_NAME'}/urls"); }
+               if ($besettings{'BE_URLS'})
+               {
+                       open(FILE, ">$dbdir/$besettings{'BE_NAME'}/urls");
+                       flock FILE, 2;
+                       print FILE "$besettings{'BE_URLS'}\n";
+                       close FILE;
+               }
+               if (-e "$dbdir/$besettings{'BE_NAME'}/expressions") { unlink("$dbdir/$besettings{'BE_NAME'}/expressions"); }
+               if ($besettings{'BE_EXPRESSIONS'})
+               {
+                       open(FILE, ">$dbdir/$besettings{'BE_NAME'}/expressions");
+                       flock FILE, 2;
+                       print FILE "$besettings{'BE_EXPRESSIONS'}\n";
+                       close FILE;
+               }
+
+               open(FILE, ">$editdir/install.conf");
+               flock FILE, 2;
+               print FILE "logdir /var/log/squidGuard\n";
+               print FILE "dbhome $dbdir/$besettings{'BE_NAME'}\n\n";
+               print FILE "dest $besettings{'BE_NAME'} {\n";
+               if ($besettings{'BE_DOMAINS'})     { print FILE "    domainlist  domains\n"; }
+               if ($besettings{'BE_URLS'})        { print FILE "    urllist     urls\n"; }
+               if ($besettings{'BE_EXPRESSIONS'}) { print FILE "    expressions expressions\n"; }
+               print FILE "}\n\n";
+               print FILE "acl {\n";
+               print FILE "    default {\n";
+               print FILE "        pass none\n";
+               print FILE "    }\n";
+               print FILE "}\n";
+               close FILE;
+
+               system("rm -f $dbdir/$besettings{'BE_NAME'}/*.db");
+               system("/usr/sbin/squidGuard -c $editdir/install.conf -C all");
+               system("chmod a+w $dbdir/$besettings{'BE_NAME'}/*.db");
+
+               &readblockcategories;
+               &readcustomlists;
+
+               &writeconfigfile;
+
+               system('/usr/local/bin/restartsquid') unless ($besettings{'NORESTART'} eq 'on');
+
+               if (-d $editdir) { system("rm -rf $editdir"); }
+       } else {
+               $errormessage = $Lang::tr{'urlfilter category data error'};
+       }
+}
+
+if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter save schedule'})
+{
+       if (($filtersettings{'UPDATE_SOURCE'} eq 'custom') && ($filtersettings{'CUSTOM_UPDATE_URL'} eq ''))
+       {
+               $errormessage = $Lang::tr{'urlfilter custom url required'};
+       } else {
+               open (FILE, ">$updconffile");
+               print FILE "ENABLE_AUTOUPDATE=$filtersettings{'ENABLE_AUTOUPDATE'}\n";
+               print FILE "UPDATE_SCHEDULE=$filtersettings{'UPDATE_SCHEDULE'}\n";
+               print FILE "UPDATE_SOURCE=$filtersettings{'UPDATE_SOURCE'}\n";
+               print FILE "CUSTOM_UPDATE_URL=$filtersettings{'CUSTOM_UPDATE_URL'}\n";
+               close FILE;
+
+               if (-e $upd_cron_dly) { unlink($upd_cron_dly); }
+               if (-e $upd_cron_wly) { unlink($upd_cron_wly); }
+               if (-e $upd_cron_mly) { unlink($upd_cron_mly); }
+
+               if (($filtersettings{'ENABLE_AUTOUPDATE'} eq 'on') && ($filtersettings{'UPDATE_SCHEDULE'} eq 'daily'))
+               {
+                       symlink("../bin/autoupdate.pl",$upd_cron_dly)
+               } else {
+                       symlink("/bin/false",$upd_cron_dly)
+               }
+
+               if (($filtersettings{'ENABLE_AUTOUPDATE'} eq 'on') && ($filtersettings{'UPDATE_SCHEDULE'} eq 'weekly'))
+               {
+                       symlink("../bin/autoupdate.pl",$upd_cron_wly)
+               } else {
+                       symlink("/bin/false",$upd_cron_wly)
+               }
+
+               if (($filtersettings{'ENABLE_AUTOUPDATE'} eq 'on') && ($filtersettings{'UPDATE_SCHEDULE'} eq 'monthly'))
+               {
+                       symlink("../bin/autoupdate.pl",$upd_cron_mly)
+               } else {
+                       symlink("/bin/false",$upd_cron_mly)
+               }
+       }
+}
+
+if ($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter update now'})
+{
+       if ($filtersettings{'UPDATE_SOURCE'} eq 'custom')
+       {
+               if ($filtersettings{'CUSTOM_UPDATE_URL'} eq '')
+               {
+                       $errormessage = $Lang::tr{'urlfilter custom url required'};
+               } else {
+                       system("${General::swroot}/urlfilter/bin/autoupdate.pl $filtersettings{'CUSTOM_UPDATE_URL'} &");
+               }
+       } else {
+               system("${General::swroot}/urlfilter/bin/autoupdate.pl $filtersettings{'UPDATE_SOURCE'} &");
+       }
+}
+
+
+if (-e "${General::swroot}/urlfilter/settings") { &General::readhash("${General::swroot}/urlfilter/settings", \%filtersettings); }
+
+&readcustomlists;
+
+$checked{'ENABLE_CUSTOM_BLACKLIST'}{'off'} = '';
+$checked{'ENABLE_CUSTOM_BLACKLIST'}{'on'} = '';
+$checked{'ENABLE_CUSTOM_BLACKLIST'}{$filtersettings{'ENABLE_CUSTOM_BLACKLIST'}} = "checked='checked'";
+$checked{'ENABLE_CUSTOM_WHITELIST'}{'off'} = '';
+$checked{'ENABLE_CUSTOM_WHITELIST'}{'on'} = '';
+$checked{'ENABLE_CUSTOM_WHITELIST'}{$filtersettings{'ENABLE_CUSTOM_WHITELIST'}} = "checked='checked'";
+$checked{'ENABLE_CUSTOM_EXPRESSIONS'}{'off'} = '';
+$checked{'ENABLE_CUSTOM_EXPRESSIONS'}{'on'} = '';
+$checked{'ENABLE_CUSTOM_EXPRESSIONS'}{$filtersettings{'ENABLE_CUSTOM_EXPRESSIONS'}} = "checked='checked'";
+$checked{'BLOCK_EXECUTABLES'}{'off'} = '';
+$checked{'BLOCK_EXECUTABLES'}{'on'} = '';
+$checked{'BLOCK_EXECUTABLES'}{$filtersettings{'BLOCK_EXECUTABLES'}} = "checked='checked'";
+$checked{'BLOCK_AUDIO-VIDEO'}{'off'} = '';
+$checked{'BLOCK_AUDIO-VIDEO'}{'on'} = '';
+$checked{'BLOCK_AUDIO-VIDEO'}{$filtersettings{'BLOCK_AUDIO-VIDEO'}} = "checked='checked'";
+$checked{'BLOCK_ARCHIVES'}{'off'} = '';
+$checked{'BLOCK_ARCHIVES'}{'on'} = '';
+$checked{'BLOCK_ARCHIVES'}{$filtersettings{'BLOCK_ARCHIVES'}} = "checked='checked'";
+$checked{'ENABLE_REWRITE'}{'off'} = '';
+$checked{'ENABLE_REWRITE'}{'on'} = '';
+$checked{'ENABLE_REWRITE'}{$filtersettings{'ENABLE_REWRITE'}} = "checked='checked'";
+$checked{'SHOW_CATEGORY'}{'off'} = '';
+$checked{'SHOW_CATEGORY'}{'on'} = '';
+$checked{'SHOW_CATEGORY'}{$filtersettings{'SHOW_CATEGORY'}} = "checked='checked'";
+$checked{'SHOW_URL'}{'off'} = '';
+$checked{'SHOW_URL'}{'on'} = '';
+$checked{'SHOW_URL'}{$filtersettings{'SHOW_URL'}} = "checked='checked'";
+$checked{'SHOW_IP'}{'off'} = '';
+$checked{'SHOW_IP'}{'on'} = '';
+$checked{'SHOW_IP'}{$filtersettings{'SHOW_IP'}} = "checked='checked'";
+$checked{'ENABLE_DNSERROR'}{'off'} = '';
+$checked{'ENABLE_DNSERROR'}{'on'} = '';
+$checked{'ENABLE_DNSERROR'}{$filtersettings{'ENABLE_DNSERROR'}} = "checked='checked'";
+$checked{'ENABLE_JPEG'}{'off'} = '';
+$checked{'ENABLE_JPEG'}{'on'} = '';
+$checked{'ENABLE_JPEG'}{$filtersettings{'ENABLE_JPEG'}} = "checked='checked'";
+$checked{'ENABLE_EXPR_LISTS'}{'off'} = '';
+$checked{'ENABLE_EXPR_LISTS'}{'on'} = '';
+$checked{'ENABLE_EXPR_LISTS'}{$filtersettings{'ENABLE_EXPR_LISTS'}} = "checked='checked'";
+$checked{'BLOCK_IP_ADDR'}{'off'} = '';
+$checked{'BLOCK_IP_ADDR'}{'on'} = '';
+$checked{'BLOCK_IP_ADDR'}{$filtersettings{'BLOCK_IP_ADDR'}} = "checked='checked'";
+$checked{'BLOCK_ALL'}{'off'} = '';
+$checked{'BLOCK_ALL'}{'on'} = '';
+$checked{'BLOCK_ALL'}{$filtersettings{'BLOCK_ALL'}} = "checked='checked'";
+$checked{'ENABLE_EMPTY_ADS'}{'off'} = '';
+$checked{'ENABLE_EMPTY_ADS'}{'on'} = '';
+$checked{'ENABLE_EMPTY_ADS'}{$filtersettings{'ENABLE_EMPTY_ADS'}} = "checked='checked'";
+$checked{'ENABLE_GLOBAL_WHITELIST'}{'off'} = '';
+$checked{'ENABLE_GLOBAL_WHITELIST'}{'on'} = '';
+$checked{'ENABLE_GLOBAL_WHITELIST'}{$filtersettings{'ENABLE_GLOBAL_WHITELIST'}} = "checked='checked'";
+$checked{'ENABLE_SAFESEARCH'}{'off'} = '';
+$checked{'ENABLE_SAFESEARCH'}{'on'} = '';
+$checked{'ENABLE_SAFESEARCH'}{$filtersettings{'ENABLE_SAFESEARCH'}} = "checked='checked'";
+$checked{'ENABLE_LOG'}{'off'} = '';
+$checked{'ENABLE_LOG'}{'on'} = '';
+$checked{'ENABLE_LOG'}{$filtersettings{'ENABLE_LOG'}} = "checked='checked'";
+$checked{'ENABLE_USERNAME_LOG'}{'off'} = '';
+$checked{'ENABLE_USERNAME_LOG'}{'on'} = '';
+$checked{'ENABLE_USERNAME_LOG'}{$filtersettings{'ENABLE_USERNAME_LOG'}} = "checked='checked'";
+$checked{'ENABLE_CATEGORY_LOG'}{'off'} = '';
+$checked{'ENABLE_CATEGORY_LOG'}{'on'} = '';
+$checked{'ENABLE_CATEGORY_LOG'}{$filtersettings{'ENABLE_CATEGORY_LOG'}} = "checked='checked'";
+
+foreach $category (@filtergroups) {
+       $checked{$category}{'off'} = '';
+       $checked{$category}{'on'} = '';
+       $checked{$category}{$filtersettings{$category}} = "checked='checked'";
+}
+
+$selected{'DEFINITION'}{$tcsettings{'DEFINITION'}} = "selected='selected'";
+$selected{'FROM_HOUR'}{$tcsettings{'FROM_HOUR'}} = "selected='selected'";
+$selected{'FROM_MINUTE'}{$tcsettings{'FROM_MINUTE'}} = "selected='selected'";
+$selected{'TO_HOUR'}{$tcsettings{'TO_HOUR'}} = "selected='selected'";
+$selected{'TO_MINUTE'}{$tcsettings{'TO_MINUTE'}} = "selected='selected'";
+
+@selectedcategories = split(/\|/,$tcsettings{'DST'});
+foreach (@selectedcategories)
+{
+        $selected{'DST'}{$_} = "selected='selected'";
+}
+
+$selected{'ACCESS'}{$tcsettings{'ACCESS'}} = "selected='selected'";
+
+$checked{'ENABLERULE'}{'off'} = '';
+$checked{'ENABLERULE'}{'on'} = '';
+$checked{'ENABLERULE'}{$tcsettings{'ENABLERULE'}} = "checked='checked'";
+$checked{'MON'}{'off'} = '';
+$checked{'MON'}{'on'} = '';
+$checked{'MON'}{$tcsettings{'MON'}} = "checked='checked'";
+$checked{'TUE'}{'off'} = '';
+$checked{'TUE'}{'on'} = '';
+$checked{'TUE'}{$tcsettings{'TUE'}} = "checked='checked'";
+$checked{'WED'}{'off'} = '';
+$checked{'WED'}{'on'} = '';
+$checked{'WED'}{$tcsettings{'WED'}} = "checked='checked'";
+$checked{'THU'}{'off'} = '';
+$checked{'THU'}{'on'} = '';
+$checked{'THU'}{$tcsettings{'THU'}} = "checked='checked'";
+$checked{'FRI'}{'off'} = '';
+$checked{'FRI'}{'on'} = '';
+$checked{'FRI'}{$tcsettings{'FRI'}} = "checked='checked'";
+$checked{'SAT'}{'off'} = '';
+$checked{'SAT'}{'on'} = '';
+$checked{'SAT'}{$tcsettings{'SAT'}} = "checked='checked'";
+$checked{'SUN'}{'off'} = '';
+$checked{'SUN'}{'on'} = '';
+$checked{'SUN'}{$tcsettings{'SUN'}} = "checked='checked'";
+
+$selected{'SPORADIC'}{$uqsettings{'SPORADIC'}} = "selected='selected'";
+$selected{'RENEWAL'} {$uqsettings{'RENEWAL'}}  = "selected='selected'";
+
+$checked{'ENABLEQUOTA'}{'off'} = '';
+$checked{'ENABLEQUOTA'}{'on'} = '';
+$checked{'ENABLEQUOTA'}{$uqsettings{'ENABLEQUOTA'}} = "checked='checked'";
+
+$selected{'BE_BLACKLIST'}{$besettings{'BE_BLACKLIST'}} = "selected='selected'";
+
+
+&Header::showhttpheaders();
+
+&Header::openpage($Lang::tr{'urlfilter configuration'}, 1, '');
+
+&Header::openbigbox('100%', 'left', '', $errormessage);
+
+if ($errormessage) {
+       &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
+       print "<font class='base'>$errormessage&nbsp;</font>\n";
+       &Header::closebox();
+} elsif (($tcsettings{'CHANGED'} eq 'yes') || ($uqsettings{'CHANGED'} eq 'yes') ) {
+       &writeconfigfile;
+       print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
+       &Header::openbox('100%', 'left', "$Lang::tr{'urlfilter restart notification'}:");
+       print "<class name='base'>$Lang::tr{'urlfilter restart message'}\n";
+       if ($uqsettings{'MODE'} eq 'USERQUOTA') { print "<p><class name='base'>$Lang::tr{'urlfilter quota restart message'}\n"; }
+       print "</class>\n";
+       print "<p><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter restart'}' />";
+       if ($tcsettings{'MODE'} eq 'TIMECONSTRAINT') { print "<input type='hidden' name='MODE' value='TIMECONSTRAINT' />"; }
+       if ($uqsettings{'MODE'} eq 'USERQUOTA') { print "<input type='hidden' name='MODE' value='USERQUOTA' />"; }
+       &Header::closebox();
+       print "</form>\n";
+}
+
+if ($restoremessage) {
+       &Header::openbox('100%', 'left', "$Lang::tr{'urlfilter restore results'}:");
+       print "<class name='base'>$restoremessage\n";
+        print "&nbsp;</class>\n";
+       &Header::closebox();
+}
+
+if ((!$tcsettings{'TCMODE'}) && (!$uqsettings{'UQMODE'}) && (!$besettings{'BEMODE'})) {
+
+if (!($filtersettings{'ACTION'} eq $Lang::tr{'urlfilter manage repository'})) {
+
+#==========================================================
+#
+# Section: Main Configuration
+#
+#==========================================================
+
+print "<form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>\n";
+
+&Header::openbox('100%', 'left', "$Lang::tr{'urlfilter filter settings'}:");
+print <<END
+<table width='100%'>
+<tr>
+        <td colspan='4'><b>$Lang::tr{'urlfilter block categories'}</b></td>
+</tr>
+END
+;
+
+if (@categories == 0) {
+print <<END
+<tr>
+        <td><i>$Lang::tr{'urlfilter no categories'}</i></td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+</tr>
+
+END
+;
+}
+
+for ($n=0; $n<=@categories; $n = $n + $i) {
+       for ($i=0; $i<=3; $i++) {
+               if ($i eq 0) { print "<tr>\n"; }
+               if (($n+$i) < @categories) {
+                       print "<td width='15%'>@categories[$n+$i]:<\/td>\n";
+                       print "<td width='10%'><input type='checkbox' name=@filtergroups[$n+$i] $checked{@filtergroups[$n+$i]}{'on'} /></td>\n";
+               }
+               if ($i eq 3) { print "<\/tr>\n"; }
+       }
+}
+
+print <<END
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+        <td><b>$Lang::tr{'urlfilter custom blacklist'}</b></td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+</tr>
+<tr>
+       <td colspan='2'>$Lang::tr{'urlfilter blocked domains'}&nbsp;<img src='/blob.gif' alt='*' /></td>
+       <td colspan='2'>$Lang::tr{'urlfilter blocked urls'}&nbsp;<img src='/blob.gif' alt='*' /></td>
+</tr>
+<tr>
+       <td colspan='2' width='50%'><textarea name='CUSTOM_BLACK_DOMAINS' cols='32' rows='6' wrap='off'>
+END
+;
+
+print $filtersettings{'CUSTOM_BLACK_DOMAINS'};
+
+print <<END
+</textarea></td>
+       <td colspan='2' width='50%'><textarea name='CUSTOM_BLACK_URLS' cols='32' rows='6' wrap='off'>
+END
+;
+
+print $filtersettings{'CUSTOM_BLACK_URLS'};
+
+print <<END
+</textarea></td>
+</tr>
+</table>
+<table width='100%'>
+<tr>
+        <td class='base' width='25%'>$Lang::tr{'urlfilter enable custom blacklist'}:</td>
+        <td><input type='checkbox' name='ENABLE_CUSTOM_BLACKLIST' $checked{'ENABLE_CUSTOM_BLACKLIST'}{'on'} /></td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+</tr>
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+        <td><b>$Lang::tr{'urlfilter custom whitelist'}</b></td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+</tr>
+<tr>
+       <td colspan='2'>$Lang::tr{'urlfilter allowed domains'}&nbsp;<img src='/blob.gif' alt='*' /></td>
+       <td colspan='2'>$Lang::tr{'urlfilter allowed urls'}&nbsp;<img src='/blob.gif' alt='*' /></td>
+</tr>
+<tr>
+       <td colspan='2' width='50%'><textarea name='CUSTOM_WHITE_DOMAINS' cols='32' rows='6' wrap='off'>
+END
+;
+
+print $filtersettings{'CUSTOM_WHITE_DOMAINS'};
+
+print <<END
+</textarea></td>
+       <td colspan='2' width='50%'><textarea name='CUSTOM_WHITE_URLS' cols='32' rows='6' wrap='off'>
+END
+;
+
+print $filtersettings{'CUSTOM_WHITE_URLS'};
+
+print <<END
+</textarea></td>
+</tr>
+</table>
+<table width='100%'>
+<tr>
+        <td class='base' width='25%'>$Lang::tr{'urlfilter enable custom whitelist'}:</td>
+        <td><input type='checkbox' name='ENABLE_CUSTOM_WHITELIST' $checked{'ENABLE_CUSTOM_WHITELIST'}{'on'} /></td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+</tr>
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+        <td colspan='4'><b>$Lang::tr{'urlfilter custom expression list'}</b></td>
+</tr>
+<tr>
+       <td colspan='4'>$Lang::tr{'urlfilter blocked expressions'}&nbsp;<img src='/blob.gif' alt='*' /></td>
+</tr>
+<tr>
+       <td colspan='4'><textarea name='CUSTOM_EXPRESSIONS' cols='70' rows='3' wrap='off'>
+END
+;
+
+print $filtersettings{'CUSTOM_EXPRESSIONS'};
+
+print <<END
+</textarea></td>
+</tr>
+<tr>
+        <td class='base' width='25%'>$Lang::tr{'urlfilter enable custom expression list'}:</td>
+        <td><input type='checkbox' name='ENABLE_CUSTOM_EXPRESSIONS' $checked{'ENABLE_CUSTOM_EXPRESSIONS'}{'on'} /></td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+</tr>
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+        <td colspan='4'><b>$Lang::tr{'urlfilter file ext block'}</b></td>
+</tr>
+<tr>
+        <td width='25%' class='base'>$Lang::tr{'urlfilter block executables'}:</td>
+        <td width='12%'><input type='checkbox' name='BLOCK_EXECUTABLES' $checked{'BLOCK_EXECUTABLES'}{'on'} /></td>
+        <td width='25%'  class='base'>$Lang::tr{'urlfilter block audio-video'}:</td>
+        <td><input type='checkbox' name='BLOCK_AUDIO-VIDEO' $checked{'BLOCK_AUDIO-VIDEO'}{'on'} /></td>
+</tr>
+<tr>
+        <td class='base'>$Lang::tr{'urlfilter block archives'}:</td>
+        <td><input type='checkbox' name='BLOCK_ARCHIVES' $checked{'BLOCK_ARCHIVES'}{'on'} /></td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+</tr>
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+        <td colspan='4'><b>$Lang::tr{'urlfilter local file redirection'}</b></td>
+</tr>
+<tr>
+       <td width='25%' class='base'>$Lang::tr{'urlfilter enable rewrite rules'}:</td>
+       <td width='12%'><input type='checkbox' name='ENABLE_REWRITE' $checked{'ENABLE_REWRITE'}{'on'} /></td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+</tr>
+<tr>
+       <td><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter manage repository'}'></td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+</tr>
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+        <td colspan='2'><b>$Lang::tr{'urlfilter network access control'}</b></td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+</tr>
+<tr>
+        <td class='base'>$Lang::tr{'urlfilter unfiltered clients'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
+        <td><input type='text' name='UNFILTERED_CLIENTS' value='$filtersettings{'UNFILTERED_CLIENTS'}' size='30' /></td>
+        <td class='base'>$Lang::tr{'urlfilter banned clients'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
+        <td><input type='text' name='BANNED_CLIENTS' value='$filtersettings{'BANNED_CLIENTS'}' size='30' /></td>
+</tr>
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+        <td colspan='4'><b>$Lang::tr{'urlfilter timebased access control'}</b></td>
+</tr>
+<tr>
+       <td width='25%'><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter set time constraints'}'></td>
+       <td width='25%'><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter set user quota'}'></td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+</tr>
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+        <td colspan='4'><b>$Lang::tr{'urlfilter block settings'}</b></td>
+</tr>
+<tr>
+       <td width='25%' class='base'>$Lang::tr{'urlfilter show category'}:</td>
+       <td width='12%'><input type='checkbox' name='SHOW_CATEGORY' $checked{'SHOW_CATEGORY'}{'on'} /></td>
+       <td width='25%' class='base'>$Lang::tr{'urlfilter redirectpage'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
+       <td><input type='text' name='REDIRECT_PAGE' value='$filtersettings{'REDIRECT_PAGE'}' size='40' /></td>
+</tr>
+<tr>
+       <td class='base'>$Lang::tr{'urlfilter show url'}:</td>
+       <td><input type='checkbox' name='SHOW_URL' $checked{'SHOW_URL'}{'on'} /></td>
+       <td class='base'>$Lang::tr{'urlfilter msg text 1'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
+       <td><input type='text' name='MSG_TEXT_1' value='$filtersettings{'MSG_TEXT_1'}' size='40' /></td>
+</tr>
+<tr>
+       <td class='base'>$Lang::tr{'urlfilter show ip'}:</td>
+       <td><input type='checkbox' name='SHOW_IP' $checked{'SHOW_IP'}{'on'} /></td>
+       <td class='base'>$Lang::tr{'urlfilter msg text 2'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
+       <td><input type='text' name='MSG_TEXT_2' value='$filtersettings{'MSG_TEXT_2'}' size='40' /></td>
+</tr>
+<tr>
+       <td class='base'>$Lang::tr{'urlfilter show dnserror'}:</td>
+       <td><input type='checkbox' name='ENABLE_DNSERROR' $checked{'ENABLE_DNSERROR'}{'on'} /></td>
+       <td class='base'>$Lang::tr{'urlfilter msg text 3'}:&nbsp;<img src='/blob.gif' alt='*' /></td>
+       <td><input type='text' name='MSG_TEXT_3' value='$filtersettings{'MSG_TEXT_3'}' size='40' /></td>
+</tr>
+<tr>
+       <td class='base'>$Lang::tr{'urlfilter enable jpeg'}:</td>
+       <td><input type='checkbox' name='ENABLE_JPEG' $checked{'ENABLE_JPEG'}{'on'} /></td>
+       <td>&nbsp;</td>
+       <td>&nbsp;</td>
+</tr>
+</table>
+<table width='100%'>
+<tr>
+       <td class='base'><b>$Lang::tr{'urlfilter background image'}</b></td>
+</tr>
+<tr>
+       <td><br>$Lang::tr{'urlfilter background text'}:</td>
+</tr>
+<tr>
+       <td><input type='file' name='BACKGROUND' size='40' /> &nbsp; <input type='submit' name='ACTION' value='$Lang::tr{'urlfilter upload background'}' /></td>
+</tr>
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+       <td colspan='4'><b>$Lang::tr{'urlfilter advanced settings'}</b></td>
+</tr>
+<tr>
+       <td width='25%' class='base'>$Lang::tr{'urlfilter enable expression lists'}:</td>
+       <td width='12%'><input type='checkbox' name='ENABLE_EXPR_LISTS' $checked{'ENABLE_EXPR_LISTS'}{'on'} /></td>
+       <td width='25%' class='base'>$Lang::tr{'urlfilter enable log'}:</td>
+       <td><input type='checkbox' name='ENABLE_LOG' $checked{'ENABLE_LOG'}{'on'} /></td>
+</tr>
+<tr>
+       <td class='base'>$Lang::tr{'urlfilter safesearch'}:</td>
+       <td><input type='checkbox' name='ENABLE_SAFESEARCH' $checked{'ENABLE_SAFESEARCH'}{'on'} /></td>
+       <td class='base'>$Lang::tr{'urlfilter username log'}:</td>
+       <td><input type='checkbox' name='ENABLE_USERNAME_LOG' $checked{'ENABLE_USERNAME_LOG'}{'on'} /></td>
+</tr>
+<tr>
+       <td class='base'>$Lang::tr{'urlfilter empty ads'}:</td>
+       <td><input type='checkbox' name='ENABLE_EMPTY_ADS' $checked{'ENABLE_EMPTY_ADS'}{'on'} /></td>
+       <td class='base'>$Lang::tr{'urlfilter category log'}:</td>
+       <td><input type='checkbox' name='ENABLE_CATEGORY_LOG' $checked{'ENABLE_CATEGORY_LOG'}{'on'} /></td>
+</tr>
+<tr>
+       <td class='base'>$Lang::tr{'urlfilter block ip'}:</td>
+       <td><input type='checkbox' name='BLOCK_IP_ADDR' $checked{'BLOCK_IP_ADDR'}{'on'} /></td>
+       <td class='base'>$Lang::tr{'urlfilter children'}:</td>
+       <td><input type='text' name='CHILDREN' value='$filtersettings{'CHILDREN'}' size='5' /></td>
+</tr>
+<tr>
+       <td class='base'>$Lang::tr{'urlfilter block all'}:</td>
+       <td><input type='checkbox' name='BLOCK_ALL' $checked{'BLOCK_ALL'}{'on'} /></td>
+       <td class='base'>$Lang::tr{'urlfilter whitelist always allowed'}:</td>
+       <td><input type='checkbox' name='ENABLE_GLOBAL_WHITELIST' $checked{'ENABLE_GLOBAL_WHITELIST'}{'on'} /></td>
+</tr>
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+       <td>
+       <img src='/blob.gif' align='top' alt='*' />&nbsp;
+       <font class='base'>$Lang::tr{'this field may be blank'}</font>
+       </td>
+       <td align='right'>
+<sup><small><a href='http://www.urlfilter.net' target='_blank'>URL filter</a></small></sup>
+</td>
+</tr>
+</table>
+<table width='100%'>
+<tr>
+<td>&nbsp;</td>
+<td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'save'}' /></td>
+<td align='center'><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter save and restart'}' /></td>
+<td>&nbsp;</td>
+</tr>
+</table>
+END
+;
+
+&Header::closebox();
+
+print "</form>\n";
+
+print "<form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>\n";
+
+&Header::openbox('100%', 'left', "$Lang::tr{'urlfilter maintenance'}:");
+
+print <<END
+<table width='100%'>
+<tr>
+<td class='base'><b>$Lang::tr{'urlfilter blacklist update'}</b></td>
+</tr>
+<tr>
+<td>$Lang::tr{'urlfilter upload information'}<p>$Lang::tr{'urlfilter upload text'}:</td>
+</tr>
+<tr>
+<td><input type='file' name='UPDATEFILE' size='40' /> &nbsp; <input type='submit' name='ACTION' value='$Lang::tr{'urlfilter upload blacklist'}' /></td>
+</tr>
+</table>
+
+<hr size='1'>
+
+<table width='100%'>
+<tr>
+       <td colspan='2' class='base'><b>$Lang::tr{'urlfilter automatic blacklist update'}</b>
+END
+;
+if (-e "$updflagfile")
+{
+$blacklistage = int(-M "$updflagfile");
+print "&nbsp; <b>[</b> <small><i>$Lang::tr{'urlfilter blacklist age 1'} <b>$blacklistage</b> $Lang::tr{'urlfilter blacklist age 2'}</i></small> <b>]</b>";
+}
+
+$updatesettings{'UPDATE_SCHEDULE'} = 'monthly';
+$updatesettings{'CUSTOM_UPDATE_URL'} = '';
+
+if (-e "$updconffile") { &General::readhash("$updconffile", \%updatesettings); }
+
+$checked{'ENABLE_AUTOUPDATE'}{'off'} = '';
+$checked{'ENABLE_AUTOUPDATE'}{'on'} = '';
+$checked{'ENABLE_AUTOUPDATE'}{$updatesettings{'ENABLE_AUTOUPDATE'}} = "checked='checked'";
+
+$selected{'UPDATE_SCHEDULE'}{$updatesettings{'UPDATE_SCHEDULE'}} = "selected='selected'";
+
+$selected{'UPDATE_SOURCE'}{$updatesettings{'UPDATE_SOURCE'}} = "selected='selected'";
+
+print <<END
+       </td>
+</tr>
+<tr>
+       <td width='25%' class='base'>$Lang::tr{'urlfilter enable automatic blacklist update'}:</td>
+        <td width='75%' class='base'><input type='checkbox' name='ENABLE_AUTOUPDATE' $checked{'ENABLE_AUTOUPDATE'}{'on'} /></td>
+</tr>
+<tr>
+       <td class='base'>$Lang::tr{'urlfilter automatic update schedule'}:</td>
+       <td class='base'>
+       <select name='UPDATE_SCHEDULE'>
+       <option value='daily' $selected{'UPDATE_SCHEDULE'}{'daily'}>$Lang::tr{'urlfilter daily'}</option>
+       <option value='weekly' $selected{'UPDATE_SCHEDULE'}{'weekly'}>$Lang::tr{'urlfilter weekly'}</option>
+       <option value='monthly' $selected{'UPDATE_SCHEDULE'}{'monthly'}>$Lang::tr{'urlfilter monthly'}</option>
+       </select>
+       </td>
+</tr>
+<tr>
+       <td class='base'>$Lang::tr{'urlfilter select source'}:</td>
+       <td class='base' colspan='2'>
+       <select name='UPDATE_SOURCE'>
+END
+;
+
+foreach (@source_urllist) {
+       chomp;
+       $source_name = substr($_,0,rindex($_,","));
+       $source_url = substr($_,index($_,",")+1);
+       print "\t<option value='$source_url' $selected{'UPDATE_SOURCE'}{$source_url}>$source_name</option>\n";
+}
+
+print <<END
+       <option value='custom' $selected{'UPDATE_SOURCE'}{'custom'}>$Lang::tr{'urlfilter custom url'}</option>
+       </select>
+       </td>
+</tr>
+<tr>
+       <td>$Lang::tr{'urlfilter custom url'}:</td>
+       <td><input type='text' name='CUSTOM_UPDATE_URL' value='$updatesettings{'CUSTOM_UPDATE_URL'}' size='72' /></td>
+</tr>
+</table>
+<table width='100%'>
+<tr>
+       <td width='25%'><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter save schedule'}'>&nbsp;&nbsp;&nbsp;<input type='submit' name='ACTION' value='$Lang::tr{'urlfilter update now'}'></td>
+</tr>
+</table>
+
+<hr size='1'>
+
+<table width='100%'>
+<tr>
+       <td class='base'><b>$Lang::tr{'urlfilter blacklist editor'}</b></td>
+</tr>
+<tr>
+       <td>$Lang::tr{'urlfilter blacklist editor info'}</td>
+</tr>
+<tr>
+       <td><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter blacklist editor'}' /></td>
+</tr>
+</table>
+
+<hr size='1'>
+
+<table width='100%'>
+<tr>
+       <td colspan='4' class='base'><b>$Lang::tr{'urlfilter backup settings'}</b></td>
+</tr>
+<tr>
+       <td width='25%' class='base'>$Lang::tr{'urlfilter enable full backup'}:</td>
+        <td width='12%' class='base'><input type='checkbox' name='ENABLE_FULLBACKUP' $checked{'ENABLE_FULLBACKUP'}{'on'} /></td>
+        <td>&nbsp;</td>
+        <td>&nbsp;</td>
+</tr>
+<tr>
+       <td colspan='4' class='base'><input type='submit' name='ACTION' value='$Lang::tr{'urlfilter backup'}' /></td>
+</tr>
+</table>
+
+<hr size='1'>
+
+<table width='100%'>
+<tr>
+       <td class='base'><b>$Lang::tr{'urlfilter restore settings'}</b></td>
+</tr>
+<tr>
+       <td>$Lang::tr{'urlfilter restore text'}:</td>
+</tr>
+<tr>
+       <td><input type='file' name='UPDATEFILE' size='40' /> &nbsp; <input type='submit' name='ACTION' value='$Lang::tr{'urlfilter restore'}' /></td>
+</tr>
+</table>
+</form>
+END
+;
+
+&Header::closebox();
+
+} else {
+
+#==========================================================
+#
+# Section: Manage Repository
+#
+#==========================================================
+
+print "<form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'>\n";
+
+&Header::openbox('100%', 'left', "$Lang::tr{'urlfilter manage local file repository'}:");
+print <<END
+<table width='100%'>
+<tr>
+       <td>$Lang::tr{'urlfilter repository information'}<br><br></td>
+</tr>
+<tr>
+       <td>$Lang::tr{'urlfilter upload file text'}:</td>
+</tr>
+<tr>
+       <td><input type='file' name='UPLOADFILE' size='50' /> &nbsp; <input type='submit' name='ACTION' value='$Lang::tr{'urlfilter upload file'}' /></td>
+</tr>
+<tr>
+       <td><br><b>$Lang::tr{'urlfilter upload file information 1'}:</b> $Lang::tr{'urlfilter upload file information 2'}</td>
+</tr>
+</table>
+<hr size='1'>
+<table width='100%'>
+<tr>
+       <td><input type='button' name='return2main' value='$Lang::tr{'urlfilter back to main page'}' onClick='self.location.href="$ENV{'SCRIPT_NAME'}"'></td>
+</tr>
+</table>
+</form>
+END
+;
+
+&Header::closebox();
+
+&Header::openbox('100%', 'left', "$Lang::tr{'urlfilter current files'}: </b>[$repository]");
+
+@repositorylist = <$repository/*>;
+
+undef @repositoryfiles;
+foreach (@repositorylist)
+{
+       if (!-d) { push(@repositoryfiles,substr($_,rindex($_,"/")+1));  }
+}
+
+if (@repositoryfiles)
+{
+       print <<END
+<table width='100%'>
+<tr>
+       <td align='center'><b>$Lang::tr{'urlfilter filename'}</b></td>
+       <td width='15%' align='center'><b>$Lang::tr{'urlfilter filesize'}</b></td>
+       <td width='10%'></td>
+</tr>
+END
+;
+       $id = 0;
+       foreach $line (@repositoryfiles)
+       {
+               $id++;
+               if ($id % 2) {
+                       print "<tr bgcolor='$Header::table1colour'>\n"; }
+               else {
+                       print "<tr bgcolor='$Header::table2colour'>\n"; }
+               $filesize = (-s "$repository/$line");
+               1 while $filesize =~ s/^(-?\d+)(\d{3})/$1.$2/;
+
+print <<END
+               <td>&nbsp; &nbsp;$line</td>
+               <td align='right'>$filesize&nbsp; &nbsp;</td>
+
+               <td align='center'>
+               <form method='post' name='frma$id' action='$ENV{'SCRIPT_NAME'}'>
+               <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' title='$Lang::tr{'remove'}' alt='$Lang::tr{'remove'}' />
+               <input type='hidden' name='ID' value='$line' />
+               <input type='hidden' name='ACTION' value='$Lang::tr{'urlfilter remove file'}' />
+               </form>
+               </td>
+
+       </tr>
+END
+;
+       }
+
+print <<END
+</table>
+<table>
+       <tr>
+       </tr>
+</table>
+<table>
+       <tr>
+               <td class='boldbase'>&nbsp; <b>$Lang::tr{'legend'}:</b></td>
+               <td>&nbsp; &nbsp; <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
+               <td class='base'>$Lang::tr{'remove'}</td>
+       </tr>
+</table>
+END
+;
+} else {
+
+       print "<i>$Lang::tr{'urlfilter empty repository'}</i>\n";
+}
+
+&Header::closebox();
+
+}
+
+} elsif ($tcsettings{'TCMODE'}) {
+
+#==========================================================
+#
+# Section: Set Time Constraints
+#
+#==========================================================
+
+print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
+
+$buttontext = $Lang::tr{'urlfilter add rule'};
+if ($tcsettings{'ACTION'} eq $Lang::tr{'edit'}) {
+&Header::openbox('100%', 'left', $Lang::tr{'urlfilter edit time constraint rule'}.':');
+$buttontext = $Lang::tr{'urlfilter update rule'};
+} else {
+&Header::openbox('100%', 'left', $Lang::tr{'urlfilter add new time constraint rule'}.':');
+}
+print <<END
+
+<table width='100%'>
+<tr>
+       <td width='2%'>$Lang::tr{'urlfilter constraint definition'}</td>
+       <td width='1%'>&nbsp;&nbsp;</td>
+       <td width='2%' align='center'>$Lang::tr{'urlfilter monday'}</td>
+       <td width='2%' align='center'>$Lang::tr{'urlfilter tuesday'}</td>
+       <td width='2%' align='center'>$Lang::tr{'urlfilter wednesday'}</td>
+       <td width='2%' align='center'>$Lang::tr{'urlfilter thursday'}</td>
+       <td width='2%' align='center'>$Lang::tr{'urlfilter friday'}</td>
+       <td width='2%' align='center'>$Lang::tr{'urlfilter saturday'}</td>
+       <td width='2%' align='center'>$Lang::tr{'urlfilter sunday'}</td>
+       <td width='1%'>&nbsp;&nbsp;</td>
+       <td width='7%' colspan=3>$Lang::tr{'urlfilter from'}</td>
+       <td width='1%'>&nbsp;</td>
+       <td width='7%' colspan=3>$Lang::tr{'urlfilter to'}</td>
+       <td>&nbsp;</td>
+</tr>
+<tr>
+       <td class='base'>
+       <select name='DEFINITION'>
+       <option value='within' $selected{'DEFINITION'}{'within'}>$Lang::tr{'urlfilter constraint within'}</option>
+       <option value='outside' $selected{'DEFINITION'}{'outside'}>$Lang::tr{'urlfilter constraint outside'}</option>
+       </select>
+       </td>
+       <td>&nbsp;</td>
+       <td class='base'><input type='checkbox' name='MON' $checked{'MON'}{'on'} /></td>
+       <td class='base'><input type='checkbox' name='TUE' $checked{'TUE'}{'on'} /></td>
+       <td class='base'><input type='checkbox' name='WED' $checked{'WED'}{'on'} /></td>
+       <td class='base'><input type='checkbox' name='THU' $checked{'THU'}{'on'} /></td>
+       <td class='base'><input type='checkbox' name='FRI' $checked{'FRI'}{'on'} /></td>
+       <td class='base'><input type='checkbox' name='SAT' $checked{'SAT'}{'on'} /></td>
+       <td class='base'><input type='checkbox' name='SUN' $checked{'SUN'}{'on'} /></td>
+       <td>&nbsp;</td>
+       <td class='base'>
+       <select name='FROM_HOUR'>
+END
+;
+for ($i=0;$i<=24;$i++) {
+$_ = sprintf("%02s",$i);
+print "<option $selected{'FROM_HOUR'}{$_}>$_</option>\n";
+}
+print <<END
+       </select>
+       </td>
+       <td>:</td>
+       <td class='base'>
+       <select name='FROM_MINUTE'>
+END
+;
+for ($i=0;$i<=45;$i+=15) {
+$_ = sprintf("%02s",$i);
+print "<option $selected{'FROM_MINUTE'}{$_}>$_</option>\n";
+}
+print <<END
+       </select>
+       <td> - </td>
+       </td>
+       <td class='base'>
+       <select name='TO_HOUR'>
+END
+;
+for ($i=0;$i<=24;$i++) {
+$_ = sprintf("%02s",$i);
+print "<option $selected{'TO_HOUR'}{$_}>$_</option>\n";
+}
+print <<END
+       </select>
+       </td>
+       <td>:</td>
+       <td class='base'>
+       <select name='TO_MINUTE'>
+END
+;
+for ($i=0;$i<=45;$i+=15) {
+$_ = sprintf("%02s",$i);
+print "<option $selected{'TO_MINUTE'}{$_}>$_</option>\n";
+}
+print <<END
+       </select>
+       </td>
+       <td>&nbsp;</td>
+</tr>
+</table>
+
+<br>
+
+<table width='100%'>
+       <tr>
+               <td width='5%'>$Lang::tr{'urlfilter source'}</td>
+               <td width='1%'>&nbsp;&nbsp;</td>
+               <td width='5%'>$Lang::tr{'urlfilter dst'}&nbsp;<img src='/blob.gif' alt='*'><img src='/blob.gif' alt='*'></td>
+               <td width='1%'>&nbsp;&nbsp;</td>
+               <td width='5%'>$Lang::tr{'urlfilter access'}</td>
+               <td>&nbsp;</td>
+       </tr>
+       <tr>
+               <td valign='top'><input type='text' name='SRC' value='$tcsettings{'SRC'}' size='32' /></td>
+               <td>&nbsp;</td>
+               <td class='base' rowspan='3' valign='top'>
+               <select name='DST' size='4' multiple>
+               <option value='any' $selected{'DST'}{'any'} = "selected='selected'">$Lang::tr{'urlfilter category all'}</option>
+               <option value='in-addr' $selected{'DST'}{'in-addr'} = "selected='selected'">in-addr</option>
+END
+;
+
+&readblockcategories;
+foreach (@categories)
+{
+       print "<option value='$_' $selected{'DST'}{$_}>$_</option>\n";
+}
+
+print <<END
+               <option value='files' $selected{'DST'}{'files'} = "selected='selected'">files</option>
+               <option value='custom-blocked' $selected{'DST'}{'custom-blocked'} = "selected='selected'">custom-blocked</option>
+               <option value='custom-expressions' $selected{'DST'}{'custom-expressions'} = "selected='selected'">custom-expressions</option>
+               </select>
+               </td>
+               <td>&nbsp;</td>
+               <td class='base' valign='top'>
+               <select name='ACCESS'>
+               <option value='block' $selected{'ACCESS'}{'block'}>$Lang::tr{'urlfilter mode block'}</option>
+               <option value='allow' $selected{'ACCESS'}{'allow'}>$Lang::tr{'urlfilter mode allow'}</option>
+               </select>
+               </td>
+               <td>&nbsp;</td>
+       </tr>
+       <tr>
+               <td>$Lang::tr{'remark'}&nbsp;<img src='/blob.gif' alt='*'></td>
+               <td>&nbsp;</td>
+               <td>&nbsp;</td>
+               <td>&nbsp;</td>
+               <td>&nbsp;</td>
+       </tr>
+       <tr>
+               <td><input type='text' name='COMMENT' value='$tcsettings{'COMMENT'}' size='32' /></td>
+               <td>&nbsp;</td>
+               <td>&nbsp;</td>
+               <td>&nbsp;</td>
+               <td>&nbsp;</td>
+       </tr>
+</table>
+
+<table width='100%'>
+       <tr>
+               <td class='base'>$Lang::tr{'urlfilter enabled'}<input type='checkbox' name='ENABLERULE' $checked{'ENABLERULE'}{'on'} /></td>
+       </tr>
+</table>
+
+<p>
+
+<table width='50%'>
+       <tr>
+               <td><input type='hidden' name='ACTION' value='$Lang::tr{'add'}' /></td>
+               <td><input type='hidden' name='MODE' value='TIMECONSTRAINT' /></td>
+               <td><input type='submit' name='SUBMIT' value='$buttontext' /></td>
+               <td><input type='reset' name='ACTION' value='$Lang::tr{'urlfilter reset'}' /></td>
+               <td>&nbsp;</td>
+               <td><input type='button' name='return2main' value='$Lang::tr{'urlfilter back to main page'}' onClick='self.location.href="$ENV{'SCRIPT_NAME'}"'></td>
+       </tr>
+</table>
+<p>
+<table width='100%'>
+       <tr>
+               <td width='1%' align='right'> <img src='/blob.gif' align='top' alt='*' />&nbsp;</td>
+               <td><font class='base'>$Lang::tr{'this field may be blank'}</font></td>
+       </tr>
+       <tr>
+               <td width='1%' align='right'><img src='/blob.gif' align='top' alt='*' /><img src='/blob.gif' align='top' alt='*' />&nbsp;</td>
+               <td><font class='base'>$Lang::tr{'urlfilter select multi'}</font></td>
+       </tr>
+</table>
+END
+;
+
+if ($tcsettings{'ACTION'} eq $Lang::tr{'edit'}) {
+       print "<input type='hidden' name='EDITING' value='$tcsettings{'ID'}' />\n";
+} else {
+       print "<input type='hidden' name='EDITING' value='no' />\n";
+}
+
+&Header::closebox();
+print "</form>\n";
+
+&Header::openbox('100%', 'left', $Lang::tr{'current rules'});
+print <<END
+<table width='100%'>
+       <tr>
+               <td width='5%' class='boldbase' align='center'><b>$Lang::tr{'urlfilter constraint definition'}</b></td>
+               <td width='10%' class='boldbase' align='center'><b>$Lang::tr{'urlfilter time space'}</b></td>
+               <td width='15%' class='boldbase' align='center'><b>$Lang::tr{'urlfilter src'}</b></td>
+               <td width='5%' class='boldbase' align='center'><b>$Lang::tr{'urlfilter dst'}</b></td>
+               <td width='10%' class='boldbase' colspan='4' align='center'>&nbsp;</td>
+       </tr>
+END
+;
+
+if ($tcsettings{'ACTION'} ne '' or $changed ne 'no')
+{
+       open(FILE, $tcfile);
+       @tclist = <FILE>;
+       close(FILE);
+}
+
+$id = 0;
+foreach $line (@tclist)
+{
+       $id++;
+       chomp($line);
+       @temp = split(/\,/,$line);
+       if($tcsettings{'ACTION'} eq $Lang::tr{'edit'} && $tcsettings{'ID'} eq $id) {
+               print "<tr bgcolor='$Header::colouryellow'>\n"; }
+       elsif ($id % 2) {
+               print "<tr bgcolor='$Header::table1colour'>\n"; }
+       else {
+               print "<tr bgcolor='$Header::table2colour'>\n"; }
+       if ($temp[0] eq 'within') { $temp[0]=$Lang::tr{'urlfilter constraint within'}; } else { $temp[0]=$Lang::tr{'urlfilter constraint outside'}; }
+       if ($temp[13] eq 'any') { $temp[13]=$Lang::tr{'urlfilter category all'}; }
+       if ($temp[15] eq 'on') { $gif='on.gif'; $toggle='off'; $gdesc=$Lang::tr{'click to disable'};}
+       else { $gif='off.gif'; $toggle='on'; $gdesc=$Lang::tr{'click to enable'}; }
+       if ($temp[14] eq 'block') { $led='led-red.gif'; $ldesc=$Lang::tr{'urlfilter block access'};}
+       else { $led='led-green.gif'; $ldesc=$Lang::tr{'urlfilter allow access'}; }
+
+       undef $time;
+       if ($temp[1] eq 'on') { $time.=$Lang::tr{'urlfilter mon'}; } else { $time.='='; }
+       if ($temp[2] eq 'on') { $time.=$Lang::tr{'urlfilter tue'}; } else { $time.='='; }
+       if ($temp[3] eq 'on') { $time.=$Lang::tr{'urlfilter wed'}; } else { $time.='='; }
+       if ($temp[4] eq 'on') { $time.=$Lang::tr{'urlfilter thu'}; } else { $time.='='; }
+       if ($temp[5] eq 'on') { $time.=$Lang::tr{'urlfilter fri'}; } else { $time.='='; }
+       if ($temp[6] eq 'on') { $time.=$Lang::tr{'urlfilter sat'}; } else { $time.='='; }
+       if ($temp[7] eq 'on') { $time.=$Lang::tr{'urlfilter sun'}; } else { $time.='='; }
+       $time=$time.' &nbsp; '.$temp[8].':'.$temp[9].' to '.$temp[10].':'.$temp[11];
+
+print <<END
+               <td align='center'>$temp[0]</td>
+               <td align='center' nowrap>$time</td>
+               <td align='center'>$temp[12]</td>
+               <td align='center'>$temp[13]</td>
+               <td align='center'><image src='/images/urlfilter/$led' alt='$ldesc'></td>
+
+               <td align='center'>
+               <form method='post' name='frma$id' action='$ENV{'SCRIPT_NAME'}'>
+               <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' title='$gdesc' alt='$gdesc' />
+               <input type='hidden' name='MODE' value='TIMECONSTRAINT' />
+               <input type='hidden' name='ID' value='$id' />
+               <input type='hidden' name='ACTIVE' value='$toggle' />
+               <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
+               </form>
+               </td>
+
+               <td align='center'>
+               <form method='post' name='frmb$id' action='$ENV{'SCRIPT_NAME'}'>
+               <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' title='$Lang::tr{'edit'}' alt='$Lang::tr{'edit'}' />
+               <input type='hidden' name='MODE' value='TIMECONSTRAINT' />
+               <input type='hidden' name='ID' value='$id' />
+               <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
+               </form>
+               </td>
+
+               <td align='center'>
+               <form method='post' name='frmc$id' action='$ENV{'SCRIPT_NAME'}'>
+               <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' title='$Lang::tr{'remove'}' alt='$Lang::tr{'remove'}' />
+               <input type='hidden' name='MODE' value='TIMECONSTRAINT' />
+               <input type='hidden' name='ID' value='$id' />
+               <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' />
+               </form>
+               </td>
+
+       </tr>
+END
+;
+       if($tcsettings{'ACTION'} eq $Lang::tr{'edit'} && $tcsettings{'ID'} eq $id) {
+               print "<tr bgcolor='$Header::colouryellow'>\n"; }
+       elsif ($id % 2) {
+               print "<tr bgcolor='$Header::table1colour'>\n"; }
+       else {
+               print "<tr bgcolor='$Header::table2colour'>\n"; }
+print <<END
+               <td align='center' colspan='4'>$temp[16]
+               </td>
+               <td align='center' colspan='4'>
+               </td>
+       </tr>
+END
+;
+}
+
+print "</table>\n";
+
+# If the time constraint file contains entries, print entries and action icons
+if (! -z "$tcfile") {
+print <<END
+
+<table>
+       <tr>
+               <td class='boldbase'>&nbsp; <b>$Lang::tr{'legend'}:</b></td>
+               <td>&nbsp; &nbsp; <img src='/images/urlfilter/led-green.gif' alt='$Lang::tr{'urlfilter allow access'}' /></td>
+               <td class='base'>$Lang::tr{'urlfilter allow'}</td>
+               <td>&nbsp; &nbsp; <img src='/images/urlfilter/led-red.gif' alt='$Lang::tr{'urlfilter block access'}' /></td>
+               <td class='base'>$Lang::tr{'urlfilter block'}</td>
+               <td>&nbsp; <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
+               <td class='base'>$Lang::tr{'click to disable'}</td>
+               <td>&nbsp; &nbsp; <img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
+               <td class='base'>$Lang::tr{'click to enable'}</td>
+               <td>&nbsp; &nbsp; <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
+               <td class='base'>$Lang::tr{'edit'}</td>
+               <td>&nbsp; &nbsp; <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>
+               <td class='base'>$Lang::tr{'remove'}</td>
+       </tr>
+</table>
+END
+;
+}
+
+&Header::closebox();
+
+} elsif ($uqsettings{'UQMODE'}) {
+
+#==========================================================
+#
+# Section: Set User Quota
+#
+#==========================================================
+
+print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
+
+$buttontext = $Lang::tr{'urlfilter add rule'};
+if ($uqsettings{'ACTION'} eq $Lang::tr{'edit'}) {
+&Header::openbox('100%', 'left', $Lang::tr{'urlfilter edit user quota rule'}.':');
+$buttontext = $Lang::tr{'urlfilter update rule'};
+} else {
+&Header::openbox('100%', 'left', $Lang::tr{'urlfilter add new user quota rule'}.':');
+}
+print <<END
+
+<table width='100%'>
+<tr>
+       <td width='25%'></td> <td width='20%'> </td><td width='25%'> </td><td width='30%'></td>
+</tr>
+<tr>
+        <td class='base'>$Lang::tr{'urlfilter user time quota'}:</td>
+        <td><input type='text' name='TIME_QUOTA' value='$uqsettings{'TIME_QUOTA'}' size='5' /></td>
+       <td colspan='2' rowspan= '5' valign='top' class='base'>
+               <table cellpadding='0' cellspacing='0'>
+                       <tr>
+                               <!-- intentionally left empty -->
+                       </tr>
+                       <tr>
+                       <td>$Lang::tr{'urlfilter assigned quota users'}:</td>
+                       </tr>
+                       <tr>
+                               <!-- intentionally left empty -->
+                       </tr>
+                       <tr>
+                               <!-- intentionally left empty -->
+                       </tr>
+                       <tr>
+                       <td><textarea name='QUOTA_USERS' cols='32' rows='6' wrap='off'>
+END
+;
+
+$uqsettings{'QUOTA_USERS'} =~ s/\|/\n/g;
+print $uqsettings{'QUOTA_USERS'};
+
+print <<END
+</textarea></td>
+               </tr>
+               </table>
+       </td>
+</tr>
+<tr>
+        <td class='base'>$Lang::tr{'urlfilter activity detection'}:</td>
+        <td class='base'><select name='SPORADIC'>
+                <option value='0'   $selected{'SPORADIC'}{'0'}>$Lang::tr{'urlfilter disabled'}</option>
+                <option value='300' $selected{'SPORADIC'}{'300'}>5 $Lang::tr{'urlfilter minutes'}</option>
+                <option value='900' $selected{'SPORADIC'}{'900'}>15 $Lang::tr{'urlfilter minutes'}</option>
+        </select></td>
+</tr>
+<tr>
+        <td class='base'>$Lang::tr{'urlfilter renewal period'}:</td>
+        <td class='base'><select name='RENEWAL'>
+                <option value='hourly' $selected{'RENEWAL'}{'hourly'}>$Lang::tr{'urlfilter hourly'}</option>
+                <option value='daily'  $selected{'RENEWAL'}{'daily'}>$Lang::tr{'urlfilter daily'}</option>
+                <option value='weekly' $selected{'RENEWAL'}{'weekly'}>$Lang::tr{'urlfilter weekly'}</option>
+        </select></td>
+</tr>
+<tr>
+       <td colspan='2'>&nbsp;</td>
+</tr>
+<tr>
+       <td class='base'>$Lang::tr{'urlfilter enabled'}</td>
+       <td class='base'><input type='checkbox' name='ENABLEQUOTA' $checked{'ENABLEQUOTA'}{'on'} /></td>
+</tr>
+
+</table>
+<p>
+
+<table width='50%'>
+       <tr>
+               <td><input type='hidden' name='ACTION' value='$Lang::tr{'add'}' /></td>
+               <td><input type='hidden' name='MODE' value='USERQUOTA' /></td>
+               <td><input type='submit' name='SUBMIT' value='$buttontext' /></td>
+               <td><input type='reset'  name='ACTION' value='$Lang::tr{'urlfilter reset'}' /></td>
+               <td>&nbsp;</td>
+               <td><input type='button' name='return2main' value='$Lang::tr{'urlfilter back to main page'}' onClick='self.location.href="$ENV{'SCRIPT_NAME'}"'></td>
+       </tr>
+</table>
+
+<p>
+END
+;
+
+if ($uqsettings{'ACTION'} eq $Lang::tr{'edit'}) {
+       print "<input type='hidden' name='EDITING' value='$uqsettings{'ID'}' />\n";
+} else {
+       print "<input type='hidden' name='EDITING' value='no' />\n";
+}
+
+&Header::closebox();
+print "</form>\n";
+
+&Header::openbox('100%', 'left', $Lang::tr{'current rules'});
+print <<END
+<table width='100%'>
+       <tr>
+               <td width='15%' class='boldbase' align='center'><b><nobr>$Lang::tr{'urlfilter time quota'}</nobr></b></td>
+               <td width='15%' class='boldbase' align='center'><b><nobr>$Lang::tr{'urlfilter activity detection'}</nobr></b></td>
+               <td width='10%' class='boldbase' align='center'><b>$Lang::tr{'urlfilter renewal'}</b></td>
+               <td class='boldbase' align='center'><b>$Lang::tr{'urlfilter assigned users'}</b></td>
+               <td width='20%' class='boldbase' colspan='4' align='center'>&nbsp;</td>
+       </tr>
+END
+;
+
+if ($uqsettings{'ACTION'} ne '' or $changed ne 'no')
+{
+       open(FILE, $uqfile);
+       @uqlist = <FILE>;
+       close(FILE);
+}
+
+$id = 0;
+foreach $line (@uqlist)
+{
+       $id++;
+       chomp($line);
+       @temp = split(/\,/,$line);
+       if($uqsettings{'ACTION'} eq $Lang::tr{'edit'} && $uqsettings{'ID'} eq $id) {
+               print "<tr bgcolor='$Header::colouryellow'>\n"; }
+       elsif ($id % 2) {
+               print "<tr bgcolor='$Header::table1colour'>\n"; }
+       else {
+               print "<tr bgcolor='$Header::table2colour'>\n"; }
+       if ($temp[4] eq 'on') { $gif='on.gif'; $toggle='off'; $gdesc=$Lang::tr{'click to disable'};}
+       else { $gif='off.gif'; $toggle='on'; $gdesc=$Lang::tr{'click to enable'}; }
+
+       $temp[5] = $temp[1];
+       if ($temp[1] eq '0') { $temp[5] = $Lang::tr{'urlfilter disabled'} } else { $temp[5] = ($temp[5]/60).' '.$Lang::tr{'urlfilter minutes'} }
+       $_ = $temp[3]; s/\|/, /g; $temp[6] = $_;
+
+print <<END
+               <td align='center'>$temp[0] $Lang::tr{'urlfilter minutes'}</td>
+               <td align='center'>$temp[5]</td>
+               <td align='center'>$Lang::tr{'urlfilter '.$temp[2]}</td>
+               <td align='center'>$temp[6]</td>
+
+               <td align='center'>
+               <form method='post' name='frma$id' action='$ENV{'SCRIPT_NAME'}'>
+               <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$gif' title='$gdesc' alt='$gdesc' />
+               <input type='hidden' name='MODE' value='USERQUOTA' />
+               <input type='hidden' name='ID' value='$id' />
+               <input type='hidden' name='ACTIVE' value='$toggle' />
+               <input type='hidden' name='ACTION' value='$Lang::tr{'toggle enable disable'}' />
+               </form>
+               </td>
+
+               <td align='center'>
+               <form method='post' name='frmb$id' action='$ENV{'SCRIPT_NAME'}'>
+               <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' title='$Lang::tr{'edit'}' alt='$Lang::tr{'edit'}' />
+               <input type='hidden' name='MODE' value='USERQUOTA' />
+               <input type='hidden' name='ID' value='$id' />
+               <input type='hidden' name='ACTION' value='$Lang::tr{'edit'}' />
+               </form>
+               </td>
+
+               <td align='center'>
+               <form method='post' name='frmc$id' action='$ENV{'SCRIPT_NAME'}'>
+               <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' title='$Lang::tr{'remove'}' alt='$Lang::tr{'remove'}' />
+               <input type='hidden' name='MODE' value='USERQUOTA' />
+               <input type='hidden' name='ID' value='$id' />
+               <input type='hidden' name='ACTION' value='$Lang::tr{'remove'}' />
+               </form>
+               </td>
+
+       </tr>
+END
+;
+}
+
+print "</table>\n";
+
+# If the user quota file contains entries, print entries and action icons
+if (! -z "$uqfile") {
+print <<END
+
+<table>
+       <tr>
+               <td class='boldbase'>&nbsp; <b>$Lang::tr{'legend'}:</b></td>
+               <td>&nbsp; <img src='/images/on.gif' alt='$Lang::tr{'click to disable'}' /></td>
+               <td class='base'>$Lang::tr{'click to disable'}</td>
+               <td>&nbsp; &nbsp; <img src='/images/off.gif' alt='$Lang::tr{'click to enable'}' /></td>
+               <td class='base'>$Lang::tr{'click to enable'}</td>
+               <td>&nbsp; &nbsp; <img src='/images/edit.gif' alt='$Lang::tr{'edit'}' /></td>
+               <td class='base'>$Lang::tr{'edit'}</td>
+               <td>&nbsp; &nbsp; <img src='/images/delete.gif' alt='$Lang::tr{'remove'}' /></td>