diff -ur -X excl /usr/local/source/CVS/dspam/webui/cgi-bin/configure.pl.in cgi-bin/configure.pl.in --- /usr/local/source/CVS/dspam/webui/cgi-bin/configure.pl.in 2006-02-13 19:31:49.000000000 +0100 +++ cgi-bin/configure.pl.in 2006-03-27 15:07:55.000000000 +0200 @@ -36,11 +36,14 @@ $CONFIG{'WEB_ROOT'} = ""; # URL location of included htdocs/ files # Default DSPAM display +#$CONFIG{'DATE_FORMAT'} = "%d.%m.%Y %H:%M"; # Date format in strftime style + # if undefined use default DSPAM display format $CONFIG{'HISTORY_SIZE'} = 799; # Number of items in history $CONFIG{'HISTORY_PER_PAGE'} = 100; $CONFIG{'MAX_COL_LEN'} = 50; # Max chars in list columns $CONFIG{'SORT_DEFAULT'} = "Date"; # Show quarantine by "Date" or "Rating" $CONFIG{'3D_GRAPHS'} = 1; +$CONFIG{'OPTMODE'} = "NONE"; # OUT=OptOut IN=OptIn NONE=not selectable $CONFIG{'LOCAL_DOMAIN'} = "localhost"; # Add customized settings below diff -ur -X excl /usr/local/source/CVS/dspam/webui/cgi-bin/dspam.cgi cgi-bin/dspam.cgi --- /usr/local/source/CVS/dspam/webui/cgi-bin/dspam.cgi 2006-02-15 17:27:50.000000000 +0100 +++ cgi-bin/dspam.cgi 2006-03-27 16:19:37.000000000 +0200 @@ -27,6 +27,10 @@ # Read configuration parameters common to all CGI scripts require "configure.pl"; +if($CONFIG{"DATE_FORMAT"}) { + use POSIX qw(strftime); +} + # # The current CGI script # @@ -108,6 +112,9 @@ $FORM{'template'} = "performance"; } +my($MYURL); +$MYURL = "$CONFIG{'ME'}?user=$FORM{'user'}&template=$FORM{'template'}"; + # # Set up initial display variables # @@ -120,25 +127,44 @@ # Performance if ($FORM{'template'} eq "performance") { - &ResetStats if ($FORM{'command'} eq "resetStats"); - &Tweak if ($FORM{'command'} eq "tweak"); - &DisplayIndex; + if ($FORM{'command'} eq "resetStats") { + &ResetStats; + redirect($MYURL); + } elsif ($FORM{'command'} eq "tweak") { + &Tweak; + redirect($MYURL); + } else { + &DisplayIndex; + } # Quarantine } elsif ($FORM{'template'} eq "quarantine") { if ($FORM{'command'} eq "viewMessage") { &Quarantine_ViewMessage; } else { - &ProcessQuarantine if ($FORM{'command'} eq "processQuarantine"); - &ProcessFalsePositive if ($FORM{'command'} eq "processFalsePositive"); - &DisplayQuarantine; + $MYURL .= "&sortby=$FORM{'sortby'}" if ($FORM{'sortby'} ne ""); + if ($FORM{'command'} eq "processQuarantine") { + &ProcessQuarantine; + redirect($MYURL); + } elsif ($FORM{'command'} eq "processFalsePositive") { + &ProcessFalsePositive; + redirect($MYURL); + } else { + &DisplayQuarantine; + } } # Alerts } elsif ($FORM{'template'} eq "alerts") { - &AddAlert if ($FORM{'command'} eq "addAlert"); - &DeleteAlert if ($FORM{'command'} eq "deleteAlert"); - &DisplayAlerts; + if ($FORM{'command'} eq "addAlert") { + &AddAlert; + redirect($MYURL); + } elsif ($FORM{'command'} eq "deleteAlert") { + &DeleteAlert; + redirect($MYURL); + } else { + &DisplayAlerts; + } # Preferences } elsif ($FORM{'template'} eq "preferences") { @@ -178,8 +204,8 @@ } sub DisplayHistory { - my($history_page) = $FORM{'history_page'}; - my($all_lines , $end, $begin, $history_pages); + my($all_lines , $begin, $history_pages, $rec, $history_page); + unless ($history_page = $FORM{'history_page'}) { $history_page = 1;} my(@buffer, @history, $line, %rec); my($rowclass) = "rowEven"; @@ -199,6 +225,7 @@ system("$CONFIG{'DSPAM'} --source=error --class=" . quotemeta($retrain) . " --signature=" . quotemeta($signature) . " --user " . quotemeta("$CURRENT_USER")); } } + redirect("$MYURL&history_page=$history_page"); } else { if ($FORM{'retrain'} ne "") { if ($FORM{'retrain'} eq "innocent") { @@ -206,6 +233,7 @@ } else { system("$CONFIG{'DSPAM'} --source=error --class=" . quotemeta($FORM{'retrain'}) . " --signature=" . quotemeta($FORM{'signatureID'}) . " --user " . quotemeta("$CURRENT_USER")); } + redirect("$MYURL&history_page=$history_page"); } } @@ -214,49 +242,12 @@ &error("No historical data is available"); } - if ($CONFIG{'HISTORY_PER_PAGE'} > 0) { - - $history_page = 1 if $history_page eq ""; - - open(LINES,"wc -l $LOG|"); - while (){ - chomp; - s/^ +//; - if (/([0-9]*)/) { $all_lines = $1; } - } - close (LINES); - - $begin = $all_lines - ($CONFIG{'HISTORY_PER_PAGE'} * $history_page); - $end = $all_lines - ($CONFIG{'HISTORY_PER_PAGE'} * ($history_page - 1)); - - if ($begin < 0) { - $begin = 1; - } elsif ($begin < $all_lines - $CONFIG{'HISTORY_SIZE'} - $CONFIG{'HISTORY_PER_PAGE'}) { - $begin = $all_lines - $CONFIG{'HISTORY_SIZE'} + 1; - } - - if ($all_lines < $CONFIG{'HISTORY_PER_PAGE'}) { - $history_pages = 1; - } elsif ($all_lines > $CONFIG{'HISTORY_SIZE'}) { - $history_pages = ($CONFIG{'HISTORY_SIZE'} + $CONFIG{'HISTORY_PER_PAGE'}) / $CONFIG{'HISTORY_PER_PAGE'}; - } else { - $history_pages = $all_lines / $CONFIG{'HISTORY_PER_PAGE'}; - } - - open(LOG, "sed -n \'$begin,$end\p\' $LOG|"); - } - - while() { - push(@buffer, $_); - } - close(LOG); - - # Preseed retraining information and delivery errors - foreach $line (@buffer) { + open(LOG, "< $LOG") or die "Can't open log file $LOG"; + while() { my($time, $class, $from, $signature, $subject, $info, $messageid) - = split(/\t/, $line); + = split(/\t/, $_); next if ($signature eq ""); if ($class eq "M" || $class eq "F" || $class eq "E") { if ($class eq "E") { @@ -267,14 +258,47 @@ $rec{$signature}->{'info'} = $info if ($rec{$signature}->{'info'} eq ""); } + # filter out resents if there are any. Since it's the same + # message we only allow retraining on the 1st occurence of it. + } elsif ($messageid == '' + || $rec{$signature}->{'messageid'} != $messageid) { + $rec{$signature}->{'time'} = $time; + $rec{$signature}->{'class'} = $class; + $rec{$signature}->{'from'} = $from; + $rec{$signature}->{'signature'} = $signature; + $rec{$signature}->{'subject'} = $subject; + $rec{$signature}->{'info'} = $info; + $rec{$signature}->{'messageid'} = $messageid; + + unshift(@buffer, $rec{$signature}); } } + close(LOG); + + if($CONFIG{'HISTORY_SIZE'} < ($#buffer+1)) { + $history_pages = int($CONFIG{'HISTORY_SIZE'} / $CONFIG{'HISTORY_PER_PAGE'}); + $history_pages += 1 if($CONFIG{'HISTORY_SIZE'} % $CONFIG{'HISTORY_PER_PAGE'}); + } else { + $history_pages = int( ($#buffer+1) / $CONFIG{'HISTORY_PER_PAGE'}); + $history_pages += 1 if(($#buffer+1) % $CONFIG{'HISTORY_PER_PAGE'}); + } + $begin = int(($history_page - 1) * $CONFIG{'HISTORY_PER_PAGE'}) ; + + # Now lets just keep the information that we really need. + @buffer = splice(@buffer, $begin,$CONFIG{'HISTORY_PER_PAGE'}); my $retrain_checked_msg_no = 0; - while($line = shift(@buffer)) { - chomp($line); - my($time, $class, $from, $signature, $subject, $info, $messageid) - = split(/\t/, $line); + while ($rec = pop@buffer) { + my($time, $class, $from, $signature, $subject, $info, $messageid); + + $time = $rec->{'time'}; + $class = $rec->{'class'}; + $from = $rec->{'from'}; + $signature = $rec->{'signature'}; + $subject = $rec->{'subject'}; + $info = $rec->{'info'}; + $messageid = $rec->{'messageid'}; + next if ($signature eq ""); next if ($rec{$signature}->{'displayed'} ne ""); next if ($class eq "E"); @@ -296,13 +320,18 @@ $from = "" if ($from eq ""); $subject = "" if ($subject eq ""); - my($ctime) = ctime($time); - my(@t) = split(/\:/, (split(/\s+/, $ctime))[3]); - my($x) = (split(/\s+/, $ctime))[0]; - my($m) = "a"; - if ($t[0]>12) { $t[0] -= 12; $m = "p"; } - if ($t[0] == 0) { $t[0] = 12; } - $ctime = "$x $t[0]:$t[1]$m"; + my $ctime; + if($CONFIG{"DATE_FORMAT"}) { + $ctime = strftime($CONFIG{"DATE_FORMAT"}, localtime($time)); + } else { + $ctime = ctime($time); + my(@t) = split(/\:/, (split(/\s+/, $ctime))[3]); + my($x) = (split(/\s+/, $ctime))[0]; + my($m) = "a"; + if ($t[0]>12) { $t[0] -= 12; $m = "p"; } + if ($t[0] == 0) { $t[0] = 12; } + $ctime = "$x $t[0]:$t[1]$m"; + } # Set the appropriate type and label for this message @@ -342,9 +371,12 @@ $subject =~ s//>/g; - $from = substr($from, 0, 32) . "..." if (length($from)>32); - $subject = substr($subject, 0, 40) . "..." if (length($subject)>40); - $time = sprintf("%01.2f", $time); + if (length($from)>$CONFIG{'MAX_COL_LEN'}) { + $from = substr($from, 0, $CONFIG{'MAX_COL_LEN'}) . "..." + } + if (length($subject)>$CONFIG{'MAX_COL_LEN'}) { + $subject = substr($subject, 0, $CONFIG{'MAX_COL_LEN'}) . "..." + } my($rclass); $rclass = "spam" if ($class eq "I" || $class eq "W" || $class eq "F"); @@ -366,14 +398,15 @@ my(%pairs); $pairs{'template'} = "fragment"; $pairs{'signatureID'} = $signature; - $subject =~ s/#//g; - $pairs{'subject'} = $subject; + my($sub) = $subject; + $sub =~ s/#//g; + $sub =~ s/(['])/\\$1/g; + $pairs{'subject'} = $sub; $pairs{'from'} = $from; $pairs{'info'} = $info; $pairs{'time'} = $ctime; $pairs{'user'} = $FORM{'user'}; my($url) = &SafeVars(%pairs); - #$from = qq!$from!; $from = qq!$from!; } @@ -409,14 +442,22 @@ if ($CONFIG{'HISTORY_PER_PAGE'} > 0) { $DATA{'HISTORY'} .= "
["; + if (($history_pages > 1) && ($history_page > 1)) { + my $i = $history_page-1; + $DATA{'HISTORY'} .= " < "; + } for(my $i = 1; $i <= $history_pages; $i++) { if ($i == $history_page) { - $DATA{'HISTORY'} .= " $i "; + $DATA{'HISTORY'} .= " $i "; } else { - $DATA{'HISTORY'} .= " $i "; + $DATA{'HISTORY'} .= " $i "; } } + if (($history_pages > 1) && ($history_page < $history_pages)) { + my $i = $history_page+1; + $DATA{'HISTORY'} .= " > "; + } $DATA{'HISTORY'} .= "]

"; } &output(%DATA); @@ -602,6 +643,7 @@ _END close(FILE); } + redirect("$CONFIG{'ME'}?user=$FORM{'user'}&template=preferences"); } %PREFS = GetPrefs(); @@ -627,6 +669,14 @@ $DATA{"C_WHITELIST"} = "CHECKED"; } + if ($CONFIG{'OPTMODE'} eq "OUT") { + $DATA{"OPTION"} = "Disable DSPAM filtering
"; + } elsif ($CONFIG{'OPTMODE'} eq "IN") { + $DATA{"OPTION"} = "Enable DSPAM filtering
"; + } else { + $DATA{"OPTION"} = ""; + } + &output(%DATA); } @@ -917,6 +967,10 @@ print(FILE "$size"); close(FILE); + open(FILE, ">$MAILBOX.stamp"); + close(FILE); + chmod 0660, "$MAILBOX.stamp"; + open(FILE, "<$USER.alerts"); while() { chomp; @@ -1023,6 +1077,7 @@ @headings = reverse @headings; } + $DATA{'SORTBY'} = $sortBy; $DATA{'SORT_SELECTOR'} .= "Sort by: "; if ($sortBy eq "Rating") { $DATA{'SORT_SELECTOR'} .= "Rating"; @@ -1080,10 +1135,28 @@ my(@ptfields) = split(/\s+/, $row->{'X-DSPAM-Processed'}); my(@times) = split(/\:/, $ptfields[3]); - my($mer) = "a"; - if ($times[0] > 12) { $times[0] -= 12; $mer = "p"; } - if ($times[0] == 0) { $times[0] = "12"; } - my($ptime) = "$ptfields[1] $ptfields[2] $times[0]:$times[1]$mer"; + my($ptime); + if($CONFIG{"DATE_FORMAT"}) { + my($month); + $month->{'Jan'}=0; + $month->{'Feb'}=1; + $month->{'Mar'}=2; + $month->{'Apr'}=3; + $month->{'May'}=4; + $month->{'Jun'}=5; + $month->{'Jul'}=6; + $month->{'Aug'}=7; + $month->{'Sep'}=8; + $month->{'Oct'}=9; + $month->{'Nov'}=10; + $month->{'Dec'}=11; + $ptime = strftime($CONFIG{"DATE_FORMAT"}, $times[2],$times[1],$times[0],$ptfields[2],$month->{$ptfields[1]},$ptfields[4]-1900); + } else { + my($mer) = "a"; + if ($times[0] > 12) { $times[0] -= 12; $mer = "p"; } + if ($times[0] == 0) { $times[0] = "12"; } + $ptime = "$ptfields[1] $ptfields[2] $times[0]:$times[1]$mer"; + } $DATA{'QUARANTINE'} .= <<_END; @@ -1332,6 +1405,15 @@ # Global Functions # +sub redirect { + my($loc) = @_; + print "Expires: now\n"; + print "Pragma: no-cache\n"; + print "Cache-control: no-cache\n"; + print "Location: $loc\n\n"; + exit(0); + } + sub output { if ($FORM{'template'} eq "" || $FORM{'template'} !~ /^([A-Z0-9]*)$/i) { $FORM{'template'} = "performance"; @@ -1486,6 +1568,16 @@ my($FILE) = "$USER.prefs"; if ($CONFIG{'PREFERENCES_EXTENSION'} == 1) { + # read default parameters first and override them with user + # preferences later if available + open(PIPE, "$CONFIG{'DSPAM_BIN'}/dspam_admin l pref default |"); + while() { + chomp; + my($directive, $value) = split(/\=/); + $PREFS{$directive} = $value; + } + close(PIPE); + open(PIPE, "$CONFIG{'DSPAM_BIN'}/dspam_admin l pref " . quotemeta($CURRENT_USER) . "|"); while() { chomp; @@ -1496,22 +1588,27 @@ } if (keys(%PREFS) eq "0" || $CONFIG{'PREFERENCES_EXTENSION'} != 1) { - if (! -e $FILE) { - $FILE = "./default.prefs"; - } - if (! -e $FILE) { + if (! -e "./default.prefs") { &error("Unable to load default preferences"); } - - open(FILE, "<$FILE"); + open(FILE, "<./default.prefs"); while() { chomp; my($directive, $value) = split(/\=/); $PREFS{$directive} = $value; } close(FILE); - } + if( -e $FILE) { + open(FILE, "<$FILE"); + while() { + chomp; + my($directive, $value) = split(/\=/); + $PREFS{$directive} = $value; + } + close(FILE); + } + } return %PREFS } diff -ur -X excl /usr/local/source/CVS/dspam/webui/cgi-bin/templates/nav_alerts.html cgi-bin/templates/nav_alerts.html --- /usr/local/source/CVS/dspam/webui/cgi-bin/templates/nav_alerts.html 2005-07-14 15:29:33.000000000 +0200 +++ cgi-bin/templates/nav_alerts.html 2006-03-27 13:21:35.000000000 +0200 @@ -19,9 +19,9 @@
  • Performance
  • Preferences
  • Alerts
  • -
  • Quarantine ($TOTAL_QUARANTINED_MESSAGES$)
  • +
  • Quarantine ($TOTAL_QUARANTINED_MESSAGES$)
  • Analysis
  • -
  • History
  • +
  • History
  • $NAV_ADMIN$ diff -ur -X excl /usr/local/source/CVS/dspam/webui/cgi-bin/templates/nav_analysis.html cgi-bin/templates/nav_analysis.html --- /usr/local/source/CVS/dspam/webui/cgi-bin/templates/nav_analysis.html 2006-01-18 17:48:54.000000000 +0100 +++ cgi-bin/templates/nav_analysis.html 2006-03-27 13:22:19.000000000 +0200 @@ -19,9 +19,9 @@
  • Performance
  • Preferences
  • Alerts
  • -
  • Quarantine ($TOTAL_QUARANTINED_MESSAGES$)
  • +
  • Quarantine ($TOTAL_QUARANTINED_MESSAGES$)
  • Analysis
  • -
  • History
  • +
  • History
  • $NAV_ADMIN$ diff -ur -X excl /usr/local/source/CVS/dspam/webui/cgi-bin/templates/nav_error.html cgi-bin/templates/nav_error.html --- /usr/local/source/CVS/dspam/webui/cgi-bin/templates/nav_error.html 2005-07-14 15:29:33.000000000 +0200 +++ cgi-bin/templates/nav_error.html 2006-03-27 13:22:15.000000000 +0200 @@ -19,9 +19,9 @@
  • Performance
  • Preferences
  • Alerts
  • -
  • Quarantine ($TOTAL_QUARANTINED_MESSAGES$)
  • +
  • Quarantine ($TOTAL_QUARANTINED_MESSAGES$)
  • Analysis
  • -
  • History
  • +
  • History
  • $NAV_ADMIN$ diff -ur -X excl /usr/local/source/CVS/dspam/webui/cgi-bin/templates/nav_history.html cgi-bin/templates/nav_history.html --- /usr/local/source/CVS/dspam/webui/cgi-bin/templates/nav_history.html 2006-02-11 01:34:42.000000000 +0100 +++ cgi-bin/templates/nav_history.html 2006-03-27 13:22:06.000000000 +0200 @@ -19,9 +19,9 @@
  • Performance
  • Preferences
  • Alerts
  • -
  • Quarantine ($TOTAL_QUARANTINED_MESSAGES$)
  • +
  • Quarantine ($TOTAL_QUARANTINED_MESSAGES$)
  • Analysis
  • -
  • History
  • +
  • History
  • $NAV_ADMIN$ diff -ur -X excl /usr/local/source/CVS/dspam/webui/cgi-bin/templates/nav_performance.html cgi-bin/templates/nav_performance.html --- /usr/local/source/CVS/dspam/webui/cgi-bin/templates/nav_performance.html 2005-07-14 15:29:33.000000000 +0200 +++ cgi-bin/templates/nav_performance.html 2006-03-27 13:21:59.000000000 +0200 @@ -19,9 +19,9 @@
  • Performance
  • Preferences
  • Alerts
  • -
  • Quarantine ($TOTAL_QUARANTINED_MESSAGES$)
  • +
  • Quarantine ($TOTAL_QUARANTINED_MESSAGES$)
  • Analysis
  • -
  • History
  • +
  • History
  • $NAV_ADMIN$ diff -ur -X excl /usr/local/source/CVS/dspam/webui/cgi-bin/templates/nav_preferences.html cgi-bin/templates/nav_preferences.html --- /usr/local/source/CVS/dspam/webui/cgi-bin/templates/nav_preferences.html 2005-07-14 15:29:33.000000000 +0200 +++ cgi-bin/templates/nav_preferences.html 2006-03-27 14:22:11.000000000 +0200 @@ -19,9 +19,9 @@
  • Performance
  • Preferences
  • Alerts
  • -
  • Quarantine ($TOTAL_QUARANTINED_MESSAGES$)
  • +
  • Quarantine ($TOTAL_QUARANTINED_MESSAGES$)
  • Analysis
  • -
  • History
  • +
  • History
  • $NAV_ADMIN$ @@ -92,6 +92,7 @@

    Features - Tuning SPAM filtering

    +$OPTION$ Enable noise reduction, which usually improves filtering accuracy
    diff -ur -X excl /usr/local/source/CVS/dspam/webui/cgi-bin/templates/nav_quarantine.html cgi-bin/templates/nav_quarantine.html --- /usr/local/source/CVS/dspam/webui/cgi-bin/templates/nav_quarantine.html 2005-07-14 15:29:33.000000000 +0200 +++ cgi-bin/templates/nav_quarantine.html 2006-03-27 16:16:21.000000000 +0200 @@ -19,9 +19,9 @@

  • Performance
  • Preferences
  • Alerts
  • -
  • Quarantine ($TOTAL_QUARANTINED_MESSAGES$)
  • +
  • Quarantine ($TOTAL_QUARANTINED_MESSAGES$)
  • Analysis
  • -
  • History
  • +
  • History
  • $NAV_ADMIN$
    @@ -40,6 +40,7 @@ +   diff -ur -X excl /usr/local/source/CVS/dspam/webui/cgi-bin/templates/nav_viewmessage.html cgi-bin/templates/nav_viewmessage.html --- /usr/local/source/CVS/dspam/webui/cgi-bin/templates/nav_viewmessage.html 2005-07-14 15:29:33.000000000 +0200 +++ cgi-bin/templates/nav_viewmessage.html 2006-03-27 13:21:17.000000000 +0200 @@ -19,9 +19,9 @@
  • Performance
  • Preferences
  • Alerts
  • -
  • Quarantine (View)
  • +
  • Quarantine (View)
  • Analysis
  • -
  • History
  • +
  • History
  • $NAV_ADMIN$