HELP Perl - script mod in ipcop.
Evan
evan_lsa at internode.on.net
Wed Nov 8 02:46:31 CST 2006
List,
Apologies for the noobie question.
We are running IPCOP with Copfilter (spamassasin filtering)
Anyway the quarantined directory is parsed and the information displayed.
I want to sort it in descending order of mod date
Having googled my finger tips off I found what I had thought would do it.
Sadly, it doesnt appear to work (neither does my attempt to exit the
loop early (after first 5))
Could someone take a look and let me know WTF I'm going wrong?
Cheers
Evan
PERL follows:
######### Show spam quarantine
if ( $copfiltersettings{'ACTION'} eq $Lang::tr{'copfilter show spam
quarantine'} )
{
&copfilter_start_log();
if (system ("ls /var/log/copfilter/default/opt/p3scan/quarantine
>/dev/null 2>&1") eq 0 )
{
my ($dir, $file, $file2, $hit, $subject, $subject2, $sender, $sender2,
$recipient, $recipient2, $date, $date2);
$dir = "/var/log/copfilter/default/opt/p3scan/quarantine";
print "<br />\n";
print "<b>$Lang::tr{'copfilter show spam quarantine'} - POP3 - $dir</b>\n";
print "<form method='post' action='/cgi-bin/copfilter_status.cgi'
enctype='multipart/form-data'>\n";
print "<table width='100%' cellpadding='2' cellspacing='0'
color='#ffffff' border='1'>\n";
print "<TR>\n";
print "<td align='center'>del</td>\n";
print "<td align='center'>send</td>\n";
print "<td align='center'>add</td>\n";
print "<td align='center'> $Lang::tr{'copfilter q_from'} </td>\n";
print "<td align='center'> $Lang::tr{'copfilter q_to'} </td>\n";
print "<td align='center'> $Lang::tr{'copfilter q_subject'} </td>\n";
print "<td align='center'> $Lang::tr{'copfilter q_date'} </td>\n";
print "<td align='center'> $Lang::tr{'copfilter q_filename'} </td>\n";
print "</TR>\n";
# New Code
opendir(BIN, $dir) or die "Can't open $dir: $!";
my %allfiles = map { $_ , (stat($_))[9]} readdir(BIN);
close(BIN);
# Old Iteration
#foreach my $file (grep {/\.spam/} readdir BIN){
#my limiting var
my %cnt = 0;
#New Iteration
foreach my $file (sort {$allfiles{$b} <=> $allfiles{$a}} keys %allfiles) {
$hit = 0;
$subject = "";
$subject2 = "";
$sender = "";
$recipient = "";
$date = "";
$hit = 1 if -T "$dir/$file";
%cnt = %cnt+1;
if (%cnt <= 5) {
if ($hit == 1) {
open (EP,"$dir/$file");
while (<EP>) {
if (/^From: /i) {
$_ =~ s/.+<(.+)>/$1/i;
$sender = $_;
}
if (/^To: /i) {
$_ =~ s/.+<(.+)>/$1/i;
$_ =~ s/to:(.+)/$1/i;
$recipient = $_;
}
if (/^Subject: /i) {
$_ =~ s/subject:(.+)/$1/i;
$subject = $_;
}
if (/Date:/i) {
$_ =~ s/date:(.+)/$1/i;
$date = $_;
}
}
my ($sec, $tm);
$sec = stat("$dir/$file")->mtime;
$sender2 = substr($sender, 0, 30);
$subject2 = substr($subject, 14, 70);
$recipient2 = substr($recipient, 0, 30);
$date2 = substr($date, 6, 21);
$file2 = substr($file, 0, 13);
print "<TR>\n";
print "<td class='base' align='center'><input type='checkbox'
name='$dir/$file.delete' /></td>";
print "<td class='base' align='center'><input type='checkbox'
name='$dir/$file' /></td>";
print "<td class='base' align='center'><input type='checkbox'
name='$dir/$file.whitelist' /></td>";
print "<td class='base' align='left'>$sender2</td>";
print "<td class='base' align='left'>$recipient2</td>";
print "<td class='base' align='left'>$subject2</td>";
print "<td class='base' align='left'>";
$tm = localtime($sec);
printf("%04d%02d%02d_%02d:%02d:%02d\n",
$tm->year+1900, $tm->mon+1, $tm->mday,
$tm->hour, $tm->min, $tm->sec);
print "</td>";
print "<td class='base' align='left'><a
href='/p3scan_quarantine/$file' target='_blank'>$file2</a></td>";
print "</TR>";
}
}
}
closedir(BIN);
print "</table>";
More information about the linuxsa
mailing list