########################################################### This subroutine writes the item list for a given filter section.
sub write_items
{
my ($chk_header) = @_;
my $tmp_count = 0;
my $tmp_header = param('SecName');
my $t_items = param('display_items');
my @tmp_items = split("-endofline-",$t_items);
my $t_write_items;
my $tmp_item;
my $c = 0;
my $tmp_item;
my $tmp_name;
my $tmp_hold;
my $tmp_ct;
my @item_list = "";
#Initialize the item_line array.
for ($c=0; $c<1; $c++)
{
$item_line[$c] = "";
}
# tmp_header is the filter that has been modified. Check each header (chk_header)
# to see if it is the one that has been modified.
if ($chk_header eq $tmp_header)
{
for($c=0; $c<1; $c++)
{
$tmp_name ="item_" . $c; #This section writes the content for the section being modified.
$tmp_hold = param($tmp_name);
chomp $tmp_hold;
$tmp_ct = 0;
$tmp_ct++ while $tmp_hold =~ /./g;
if ($tmp_ct >= 1)
{
$item_list[$c] = $tmp_hold;
}#end if
}#end for
}#end if
else
{
$t_write_items = $tmp_items[$a];
@item_list = split("\",\"",$t_write_items);
}
foreach $tmp_item (@item_list)
{
if ($tmp_count > 4)
{
$tmp_count = 0;
}
if ($tmp_item eq "")
{next;}
if ($tmp_item ne "")
{
$item_line[$line_count] = $item_line[$line_count] . $tmp_item;
}
$tmp_count++;
}#end foreach
}
######################################################
sub deleted_section
{
my ($chk_header) = @_;
my $tmp_header = param('SecName');
if ($chk_header eq $tmp_header)
{
# This is the section header that we want to delete.
1;
}
else
{
0;
}
}
###################################
sub write_filter
{
my $name = param('header_name');
my $ttl = param('total_headers');
my $if_act = param('action_line');
my @act = split("-endofline-",$if_act);
my $if_tmp = param('if_line');
my @if = split("-endofline-",$if_tmp);
my $write_header;
my $write_action;
my $write_if;
my $header_line;
my $j = "#";
$a=0;
my $delete_only_once = 0;
@tmp_headers = split("-endofline-",$name);
chdir "$home_dir";
open FILE, ">$filename" or die "Could not open file '$filename' for appending: $! ";
print FILE "########## Spamassassin White List ##########\n\n";
while($a<=$ttl)
{
if (deleted_section($tmp_headers[$a]))
{
$delete_only_once++;
if ( $delete_only_once > 1 )
{
# error msg
sieve_util_generic_error("Duplicate Section Name: $tmp_headers[$a] Delete from UNIX command line.
Go To the Miscellaneous link and click the 'Remove whitelist lock'");
}
}
$a++;
}
$a = 0;
while($a<=$ttl)
{
$line_count = 0;
$write_header = $j . $tmp_headers[$a] . $j;
$write_if = $if[$a];
$write_action = $act[$a];
# Write out only those sections that weren't deleted.
if (!deleted_section($tmp_headers[$a]))
{
# Write Section Header
#print FILE "$write_header\n";
# Create item list for the individual section
write_items($tmp_headers[$a]);
my $t = -1;
while ($t++ <= $line_count)
{
if ($item_line[$t] ne "")
{
print FILE "$item_line[$t]\n\n";
}
}
}
$a++;
}#end while
close FILE;
}#end sub
####
#################################
sub sieve_util_remove_filter
{
my ($relay, $relay_dir, $filename, $home_dir, @lock) = @_;
my $lt = localtime();
my @tmp = split " ", $lt;
my @online;
foreach my $filelock (@lock)
{
$tmp[3] =~ s/\:/_/g;
my $tdate = $tmp[4] . $tmp[1] . $tmp[2] . "_" . $tmp[3];
my $flag_stamp = $filename . $tdate;
$| = 1;
chdir "$home_dir";
if (my $ftp = Net::FTP->new($filelock))
{
#next;
die "Cannot login: $@ "unless $ftp;
if ($ftp->login("$uid", "$pass"))
{
if ($ftp->cwd($relay_dir))
{
$ftp->binary;
@check_dir = $ftp->ls($relay_dir);
# File name(s) you want to download
foreach $chk (@check_dir)
{
if ($chk =~ m/$flag_file/)
{
$ftp->delete($flag_file)
}#end if
}#end foreach
$ftp->quit;
}
else
{
sieve_util_generic_error ("Unable to switch to $relay_dir.");
}
}
else
{
sieve_util_generic_error ("Unable to login to $relay.");
}
}
else
{
next;
}
} #end foreach
return ($uid,$pass);
}