--- smeserver-mailstats-0.0.3/root/usr/bin/spamfilter-stats-7.pl.bjrupdate03 2008-04-11 15:14:32.000000000 +0100 +++ smeserver-mailstats-0.0.3/root/usr/bin/spamfilter-stats-7.pl 2008-04-08 15:57:20.000000000 +0100 @@ -86,6 +86,8 @@ # - Added code to save stats to MySQL DB (defaulted to off) # - Fixed interval so that it analyzes Midnight to midnight # - Allow varied interval for report +# 0.6.21 - bjr - Move initial test (and create) for mailstats prop before +# first reference to mailstats # # TODO # ---- @@ -109,8 +111,8 @@ # / SaveDataToMySQL - save data to MySQL database (default is "no") # / DBHost - MySQL server hostname (default is "localhost"). # / DBPort - MySQL server post (default is "3306") -# / Interval - "day", "week", "fortnight", "month", "99999" - last is number of seconds -# / Base - "Midnight", "Midday", "Now", "99" hour (0-23) +# / Interval - "day", "week", "fortnight", "month", "99999" - last is number of seconds (default is day) +# / Base - "Midnight", "Midday", "Now", "99" hour (0-23) (default is midnight) # ############################################################################# # @@ -118,7 +120,7 @@ # # Database : `mailstats` # - +# use mailstats; # -------------------------------------------------------- # @@ -279,9 +281,21 @@ my $hostname = hostname(); my $cdb = esmith::ConfigDB->open_ro or die "Couldn't open ConfigDB : $!\n"; +my $true = 1; +my $false = 0; +#and see if mailstats are disabled +my $disabled; +if ($cdb->get('mailstats')){ + $disabled = !(($cdb->get('mailstats')->prop('Status') || 'enabled') eq 'enabled'); +} else { + my $db = esmith::ConfigDB->open; my $record = $db->new_record('mailstats', { type => 'report', Status => 'enabled', Email => 'admin' }); + $cdb = esmith::ConfigDB->open_ro or die "Couldn't open ConfigDB : $!\n"; #Open up again to pick up new record + $disabled = $false; +} + #Configuration section my %opt = ( - version => '0.6.20', # please update at each change. + version => '0.6.21', # please update at each change. debug => 0, # guess what ? sendmail => '/usr/sbin/sendmail', # Path to sendmail stub from => 'spamfilter-stats', # Who is the mail from @@ -305,9 +319,6 @@ my $maxcutoff = 1; #max percent cutoff applied my $mincutoff = 0.2; #min percent cutoff applied -my $true = 1; -my $false = 0; - my $tstart = time; #Local variables @@ -341,7 +352,6 @@ my @colwidth = (); #width of each column #(auto means only if non zero) - populated from possible db entries my @finaldisplay = (); #final decision on display or not - true or false -my $disabled; #count column names, used for headings - also used for DB mailstats property names my $CATHOUR='Hour'; @@ -440,15 +450,6 @@ # check that logterse is in use #my pluginfile = '/var/service/qpsmtpd/config/peers/0'; -#and see if mailstats are disabled -if ($cdb->get('mailstats')){ - $disabled = !(($cdb->get('mailstats')->prop('Status') || 'enabled') eq 'enabled'); -} else { - my $db = esmith::ConfigDB->open; my $record = $db->new_record('mailstats', { type => 'report', Status => 'enabled' }); - $disabled = $false; -} - - if ( !$RHSenabled || !$DNSenabled ) { $rblnotset = '*'; } @@ -1070,7 +1071,7 @@ if ($savedata) { save_data(); } else { print "No data saved - if you want to save data to a MySQL database, then please use:\n". - "config setprop mailstats SaveDataToMySQL yes\n"; + "config setprop mailstats SaveDataToMySQL yes\nYou must have created the database first."; } @@ -1348,7 +1349,7 @@ print "Saving data.."; my $dbh = DBI->connect( "DBI:mysql:database=$DBname;host=$host;port=$port", "mailstats", "mailstats" ) - or die "Cannot open db"; + or die "Cannot open mailstats db - has it beeen created?"; my $hour = floor( $start / 3600 ); my $reportdate = strftime( "%F", localtime( $hour * 3600 ) );