Compare commits

...

21 Commits

Author SHA1 Message Date
Daniel Berteaud 6d99639d6d Spec file update 2014-06-26 06:53:38 +02:00
Daniel Berteaud 3c7d17a2e5 Define HOME so cron task works on EL6 2014-06-26 06:51:52 +02:00
Daniel Berteaud 432eaa8de8 update spec file 2013-05-15 09:38:00 +02:00
Daniel Berteaud e6b501d606 Only convert to InnoDB if not already done 2013-05-15 09:37:17 +02:00
Daniel Berteaud 52e7d7997c update spec file 2013-04-22 12:16:52 +02:00
Daniel Berteaud 8669325555 Fix a typo in SQL template 2013-04-22 12:16:21 +02:00
Daniel Berteaud c9f983db0d update spec file 2013-04-19 16:41:44 +02:00
Daniel Berteaud 3b05c5c5f6 Alter table to migrate existing databases to InnoDB 2013-04-19 16:40:58 +02:00
Daniel Berteaud f9260644a5 Use InnoDB engine 2013-04-19 14:54:42 +02:00
Daniel Berteaud 1a090306f9 Mise à jour du fichier spec 2012-10-16 17:23:50 +02:00
Daniel Berteaud 825e337c60 Log headers in a separate table 2012-10-16 15:59:47 +02:00
Daniel Berteaud 260359acbb Add a script to remove old entries from the database, default keeps 2 years of logs 2012-10-16 14:52:05 +02:00
Daniel Berteaud 70be65c741 Mise à jour du fichier spec 2012-10-14 22:18:50 +02:00
Daniel Berteaud ebf4c1e73d Log de l'utilisateur authentifié 2012-10-14 22:10:54 +02:00
Daniel Berteaud b56e73795a UTF-8 pour les connexions MySQL 2012-10-14 20:43:17 +02:00
Daniel Berteaud 6a89bb0203 Mise àjour du fichier spec 2012-10-12 16:11:36 +02:00
Daniel Berteaud 4c6a38ccde Décode le sujet des mails 2012-10-12 16:10:55 +02:00
Daniel Berteaud 84c162873b Mise à jour du fichier spec 2012-10-12 13:55:14 +02:00
Daniel Berteaud 142219c7aa Possibilité de sélectionner un hôte alternatif pour la base de donnée 2012-10-12 12:59:50 +02:00
Daniel Berteaud 7030e6afe6 Base de donnée renommée en smtp_log 2012-10-12 12:57:21 +02:00
Daniel Berteaud d5fe6325be Nettoyage du style de code (pas de changement fonctionnel) 2012-10-11 18:56:38 +02:00
9 changed files with 346 additions and 258 deletions

View File

@ -0,0 +1,18 @@
#!/bin/bash
HOME=/root
LOG=$(/sbin/e-smith/db configuration getprop qpsmtpd Log2Sql || echo 'disabled')
if [ "$LOG" != "enabled" ]; then
exit 0
fi
RETENTION=$(/sbin/e-smith/db configuration getprop qpsmtpd Log2SqlRetention || echo 730)
DB=$(/sbin/e-smith/db configuration getprop qpsmtpd DbName || echo smtp_log)
echo "delete from rcpts where mail_id IN (select mail_id from messages where date_day<DATE_SUB(NOW(), INTERVAL $RETENTION DAY));" | mysql $DB
echo "delete from message_body where mail_id IN (select mail_id from messages where date_day<DATE_SUB(NOW(), INTERVAL $RETENTION DAY));" | mysql $DB
echo "delete from message_headers where mail_id IN (select mail_id from messages where date_day<DATE_SUB(NOW(), INTERVAL $RETENTION DAY));" | mysql $DB
echo "delete from messages where date_day<DATE_SUB(NOW(), INTERVAL $RETENTION DAY);" | mysql $DB

View File

@ -1 +1 @@
mail_log
smtp_log

View File

@ -0,0 +1 @@
enabled

View File

@ -1,9 +1,15 @@
{
my $db = ${'qpsmtpd'}{'DbName'} || 'mail_log';
my $db = ${'qpsmtpd'}{'DbName'} || 'smtp_log';
my $user = ${'qpsmtpd'}{'DbUser'} || 'qpsmtpd';
my $pass = ${'qpsmtpd'}{'DbPassword'} || 'secret';
my $dbstruct = `rpm -qd smeserver-qpsmtpd-log2sql | grep mail_log.sql`;
my $dbstruct = `rpm -qd smeserver-qpsmtpd-log2sql | grep smtp_log.sql`;
my $convertInnoDB = '';
foreach my $table qw(messages message_headers message_body rcpts){
$convertInnoDB .= "ALTER TABLE $table ENGINE=InnoDB;\n"
if (-e "/var/lib/mysql/$db/$table.MYD");
}
$OUT .= <<"END";
#! /bin/sh
@ -41,6 +47,10 @@ REPLACE INTO db (
'N', 'Y', 'Y');
FLUSH PRIVILEGES;
USE smtp_log;
$convertInnoDB
EOF
END
}

View File

@ -1,12 +1,13 @@
{
if (($qpsmtpd{'Log2Sql'} || 'enabled') eq 'enabled'){
my $dbname = $qpsmtpd{'DbName'} || 'mail_log';
my $dbname = $qpsmtpd{'DbName'} || 'smtp_log';
my $dbuser = $qpsmtpd{'DbUser'} || 'qpsmtpd';
my $dbpass = $qpsmtpd{'DbPassword'} || 'secret';
my $dbhost = $qpsmtpd{'DbHost'} || 'localhost';
$OUT .=<<"EOF";
# Log to MySQL
logging/log2sql d $dbname o mysql_socket=/var/lib/mysql/mysql.sock u $dbuser p $dbpass D Yes
logging/log2sql d $dbname h $dbhost u $dbuser p $dbpass D Yes H Yes
EOF
}
else{

View File

@ -1,12 +1,13 @@
{
if (($qpsmtpd{'Log2Sql'} || 'enabled') eq 'enabled'){
my $dbname = $qpsmtpd{'DbName'} || 'mail_log';
my $dbname = $qpsmtpd{'DbName'} || 'smtp_log';
my $dbuser = $qpsmtpd{'DbUser'} || 'qpsmtpd';
my $dbpass = $qpsmtpd{'DbPassword'} || 'secret';
my $dbhost = $qpsmtpd{'DbHost'} || 'localhost';
$OUT .=<<"EOF";
# Log to MySQL
logging/log2sql d $dbname o mysql_socket=/var/lib/mysql/mysql.sock u $dbuser p $dbpass D Yes
logging/log2sql d $dbname h $dbhost u $dbuser p $dbpass D Yes H Yes
EOF
}
else{

View File

@ -10,244 +10,258 @@
#####################################################
use DBI;
use Encode qw(decode);
use strict;
#plugin level variables are here since version 0.02
my($dsn,$mail_table,$rcpt_table,$user,$passwd,$mail_id);
my($log_header);
my($log_all_body,$log_deny_body,$body_table);
my($dbh,$sth);
my ($dsn,$mail_table,$rcpt_table,$user,$passwd,$mail_id);
my ($log_header);
my ($log_all_body,$log_deny_body,$body_table,$headers_table);
my ($dbh,$sth);
sub register
{my ($self,$qp) = (shift,shift);
$self->log(LOGERROR,"Bad count of parameters in log2sql plugin.") if @_ % 2;
my(%args) = @_;
sub register {
my ($self,$qp) = (shift,shift);
$self->log(LOGERROR,"Bad count of parameters in log2sql plugin.") if @_ % 2;
my (%args) = @_;
$self->register_hook("connect", "connect_handler");
$self->register_hook("mail", "mail_handler");
$self->register_hook("rcpt", "rcpt_handler");
$self->register_hook("data_post", "data_post_handler");
$self->register_hook("queue", "queue_handler");
$self->register_hook("connect", "connect_handler");
$self->register_hook("auth-plain", "auth_handler");
$self->register_hook("auth-login", "auth_handler");
$self->register_hook("mail", "mail_handler");
$self->register_hook("rcpt", "rcpt_handler");
$self->register_hook("data_post", "data_post_handler");
$self->register_hook("queue", "queue_handler");
$self->register_hook("deny", "deny_handler") if $args{D};
$self->register_hook("disconnect", "disconnect_handler");
$self->register_hook("deny", "deny_handler") if $args{D};
$dsn = 'DBI';
$dsn .= ':'.($args{t} || 'mysql');
$dsn .= ':'.($args{d} || 'qpsmtpd');
$dsn .= ';host='.$args{h} if $args{h};
$dsn .= ';port='.$args{P} if $args{P};
$dsn .= ';'.$args{o} if $args{o};
$self->register_hook("disconnect", "disconnect_handler");
$mail_table = $args{m} || 'messages';
$rcpt_table = $args{r} || 'rcpts';
$dsn = 'DBI';
$dsn .= ':'.($args{t} || 'mysql');
$dsn .= ':'.($args{d} || 'qpsmtpd');
$dsn .= ';host='.$args{h} if $args{h};
$dsn .= ';port='.$args{P} if $args{P};
$dsn .= ';'.$args{o} if $args{o};
$user = $args{u} || 'root';
$passwd = $args{p} || '';
$mail_table = $args{m} || 'messages';
$rcpt_table = $args{r} || 'rcpts';
$log_header = $args{H} || undef;
$user = $args{u} || 'root';
$passwd = $args{p} || '';
$log_header = $args{H} || undef;
$log_all_body = $args{B} || undef;
$log_deny_body = $args{DB} || undef;
$body_table = $args{b} || 'message_body';
}#end register
sub connect_handler
{my ($self,$transaction) = @_;
$self->log(LOGDEBUG,"DSN:$dsn");
$dbh = DBI->connect($dsn,$user,$passwd)
|| $self->log(LOGERROR,DBI::errstr);
# generate mail id
$mail_id = $$.'.'.time.'.'.int(rand(10000));
# set note for other plugins
$transaction->notes('log2sql_mail_id', $mail_id);
# quote the mail_id for later use:
$mail_id = $dbh->quote($mail_id);
my ($sec,$min,$hour,$day,$mon,$year) = localtime;
$year += 1900;
$mon += 1;
my($statement) = "INSERT INTO ".$mail_table." (mail_id,".
$mail_table.".date_day,".
$mail_table.".date_time,".
"remote_ip,remote_host,remote_info) ".
"VALUES(".
$mail_id.",".
$dbh->quote($year.'-'.$mon.'-'.$day).",".
$dbh->quote($hour.':'.$min.':'.$sec).",".
$dbh->quote($self->qp->connection->remote_ip).",".
$dbh->quote($self->qp->connection->remote_host).",".
$dbh->quote($self->qp->connection->remote_info).")";
$self->log(LOGDEBUG,"connect_handler statement:".$statement);
$dbh->do($statement)
|| $self->log(LOGERROR,$dbh->errstr());
return(DECLINED);
$log_all_body = $args{B} || undef;
$log_deny_body = $args{DB} || undef;
$body_table = $args{b} || 'message_body';
$headers_table = $args{I} || 'message_headers';
}
sub connect_handler {
my ($self,$transaction) = @_;
sub mail_handler
{my ($self, $transaction, $sender) =@_;
$self->log(LOGDEBUG,"DSN:$dsn");
$dbh = DBI->connect($dsn,$user,$passwd) || $self->log(LOGERROR,DBI::errstr);
my($statement) = "UPDATE ".$mail_table." SET sender=".
$dbh->quote($sender->user.'@'.$sender->host).
" WHERE mail_id=".$mail_id;
# Use UTF8
$dbh->do("SET NAMES 'utf8';") || $self->log(LOGERROR,$dbh->errstr());
# generate mail id
$mail_id = $$.'.'.time.'.'.int(rand(10000));
# set note for other plugins
$transaction->notes('log2sql_mail_id', $mail_id);
# quote the mail_id for later use:
$mail_id = $dbh->quote($mail_id);
my ($sec,$min,$hour,$day,$mon,$year) = localtime;
$year += 1900;
$mon += 1;
my ($statement) = "INSERT INTO ".$mail_table." (mail_id,".
$mail_table.".date_day,".
$mail_table.".date_time,".
"remote_ip,remote_host,remote_info) ".
"VALUES(".
$mail_id.",".
$dbh->quote($year.'-'.$mon.'-'.$day).",".
$dbh->quote($hour.':'.$min.':'.$sec).",".
$dbh->quote($self->qp->connection->remote_ip).",".
$dbh->quote($self->qp->connection->remote_host).",".
$dbh->quote($self->qp->connection->remote_info).")";
$self->log(LOGDEBUG,"connect_handler statement:".$statement);
$dbh->do($statement) || $self->log(LOGERROR,$dbh->errstr());
return(DECLINED);
}
sub auth_handler {
my ($self, $transaction, $method, $user) = @_;
my ($statement) = "UPDATE ".$mail_table." SET auth_user=".
$dbh->quote($user).
" WHERE mail_id=".$mail_id;
$self->log(LOGDEBUG,"auth_handler statement:".$statement);
$dbh->do($statement)
|| $self->log(LOGERROR,$dbh->errstr());
return(DECLINED);
}
sub mail_handler {
my ($self, $transaction, $sender) = @_;
my ($statement) = "UPDATE ".$mail_table." SET sender=".
$dbh->quote($sender->user.'@'.$sender->host).
" WHERE mail_id=".$mail_id;
$self->log(LOGDEBUG,"mail_handler statement:".$statement);
$dbh->do($statement)
|| $self->log(LOGERROR,$dbh->errstr());
return(DECLINED);
}
sub rcpt_handler
{my($self,$transaction,$recipient) = @_;
my($statement) = "INSERT INTO ".$rcpt_table." (mail_id,".
"recipient) ".
"VALUES(".
$mail_id.",".
$dbh->quote($recipient->user.'@'.$recipient->host).")";
$self->log(LOGDEBUG,"rcpt_handler statement:".$statement);
$dbh->do($statement)
|| $self->log(LOGERROR,$dbh->errstr());
return(DECLINED);
}
sub data_post_handler
{my($self,$transaction)=@_;
my($header) = $transaction->header();
# In data_post handler the header is not actual,
# but in queue handler somethimes there are problems with
# header, sizes, subject logs (don't know why?!?!)
#'touch' this message :-))
$header->add("X-Sql-Log-ID",$mail_id);
my $subject = scalar $header->get("Subject");
chomp($subject);
# Only keep the first 255 chars to be sure it can be inserted in the table
$subject= substr $subject, 0, 254 if (length($subject) > 254);
my($statement) = "UPDATE ".$mail_table." SET subject=".
$dbh->quote($subject).
",header_size=".$dbh->quote(length($header->as_string())).
",body_size=".$dbh->quote($transaction->data_size()).
" WHERE mail_id=".$mail_id;
$self->log(LOGDEBUG,"data_post_handler statement:".$statement);
$dbh->do($statement)
|| $self->log(LOGERROR,$dbh->errstr());
#if $args{H} then log the message header in the main 'messages' table
if ($log_header)
{$statement = "UPDATE ".$mail_table." SET ".
"header=".$dbh->quote($header->as_string()).
"WHERE mail_id=".$mail_id;
$self->log(LOGDEBUG,"data_post_handler log header statement:".$statement);
$self->log(LOGDEBUG,"mail_handler statement:".$statement);
$dbh->do($statement)
|| $self->log(LOGERROR,$dbh->errstr());
}#end log geader
#if args{B} then log message body in a separated table
if ($log_all_body)
{my(@body) = ($transaction->header()->as_string());
$transaction->body_resetpos();
while(my $line = $transaction->body_getline())
{push(@body,$line);
}
$statement = "INSERT INTO ".$body_table." (mail_id,body)".
" VALUES(".$mail_id.",".$dbh->quote(join('',@body)).")";
$self->log(LOGDEBUG,"data_post body log statement:".$statement);
$dbh->do($statement)
|| $self->log(LOGERROR,$dbh->errstr());
}#end body log
return(DECLINED);
return(DECLINED);
}
sub rcpt_handler {
my ($self,$transaction,$recipient) = @_;
sub queue_handler
{my($self,$transaction) = @_;
my($status) = $transaction->header->get('X-Spam-Status') or return (DECLINED);
my($score) = ($status =~ m/hits=(\d+\.\d+)/)[0] || "0" ;
my ($statement) = "INSERT INTO ".$rcpt_table." (mail_id,".
"recipient) ".
"VALUES(".
$mail_id.",".
$dbh->quote($recipient->user.'@'.$recipient->host).")";
my($statement) = "UPDATE ".$mail_table." SET ".
"spam_status=".$dbh->quote($score).
" WHERE mail_id=".$mail_id;
$self->log(LOGDEBUG,"rcpt_handler statement:".$statement);
$self->log(LOGDEBUG,"queue_handler statement:".$statement);
$dbh->do($statement) || $self->log(LOGERROR,$dbh->errstr());
$dbh->do($statement)
return(DECLINED);
}
sub data_post_handler{
my ($self,$transaction) = @_;
my ($header) = $transaction->header();
# In data_post handler the header is not actual,
# but in queue handler somethimes there are problems with
# header, sizes, subject logs (don't know why?!?!)
#'touch' this message :-))
$header->add("X-Sql-Log-ID",$mail_id);
my $subject = decode('MIME-Header', scalar $header->get("Subject"));
chomp($subject);
# Only keep the first 255 chars to be sure it can be inserted in the table
$subject= substr $subject, 0, 254 if (length($subject) > 254);
my ($statement) = "UPDATE ".$mail_table." SET subject=".
$dbh->quote($subject).
",header_size=".$dbh->quote(length($header->as_string())).
",body_size=".$dbh->quote($transaction->data_size()).
" WHERE mail_id=".$mail_id;
$self->log(LOGDEBUG,"data_post_handler statement:".$statement);
$dbh->do($statement)
|| $self->log(LOGERROR,$dbh->errstr());
return(DECLINED);
}
#if $args{H} then log the message header in the main 'messages' table
if ($log_header){
$statement = "INSERT INTO ".$headers_table." (mail_id,header)".
" VALUES(".$mail_id.",".$dbh->quote($header->as_string()).
")";
$self->log(LOGDEBUG,"data_post_handler log header statement:".$statement);
sub deny_handler
{my($self,$transaction,$plugin,$code,$msg) = @_;
my($statement) = "UPDATE ".$mail_table." SET ".
"deny='YES'".
",deny_plugin=".$dbh->quote($plugin).
",deny_code=".$dbh->quote($code).
",deny_msg=".$dbh->quote($msg).
" WHERE mail_id=".$mail_id;
$self->log(LOGDEBUG,"deny_handler statement:".$statement);
$dbh->do($statement)
$dbh->do($statement)
|| $self->log(LOGERROR,$dbh->errstr());
}
#if configured to log the body of the denied messages
if ($log_deny_body && ! $log_all_body)
{my(@body) = ($transaction->header()->as_string());
#if args{B} then log message body in a separated table
if ($log_all_body) {
my (@body) = ($transaction->header()->as_string());
$transaction->body_resetpos();
$transaction->body_resetpos();
while(my $line = $transaction->body_getline())
{push(@body,$line);
}
while(my $line = $transaction->body_getline()) {
push(@body,$line);
}
$statement = "INSERT INTO ".$body_table." (mail_id,body)".
" VALUES(".$mail_id.",".$dbh->quote(join('',@body)).")";
$self->log(LOGDEBUG,"data_post body log statement:".$statement);
$statement = "INSERT INTO ".$body_table." (mail_id,body)".
" VALUES(".$mail_id.",".$dbh->quote(join('',@body)).")";
$self->log(LOGDEBUG,"data_post body log statement:".$statement);
$dbh->do($statement)
$dbh->do($statement)
|| $self->log(LOGERROR,$dbh->errstr());
}#end body log
}
return(DECLINED);
return(DECLINED);
}
sub disconnect_handler
{my($self,$transaction) = @_;
$dbh->disconnect();
sub queue_handler {
my ($self,$transaction) = @_;
my ($status) = $transaction->header->get('X-Spam-Status') or return (DECLINED);
my ($score) = ($status =~ m/hits=(\d+\.\d+)/)[0] || "0" ;
return(DECLINED);
my ($statement) = "UPDATE ".$mail_table." SET ".
"spam_status=".$dbh->quote($score).
" WHERE mail_id=".$mail_id;
$self->log(LOGDEBUG,"queue_handler statement:".$statement);
$dbh->do($statement)
|| $self->log(LOGERROR,$dbh->errstr());
return(DECLINED);
}
sub deny_handler {
my ($self,$transaction,$plugin,$code,$msg) = @_;
my ($statement) = "UPDATE ".$mail_table." SET ".
"deny='YES'".
",deny_plugin=".$dbh->quote($plugin).
",deny_code=".$dbh->quote($code).
",deny_msg=".$dbh->quote($msg).
" WHERE mail_id=".$mail_id;
$self->log(LOGDEBUG,"deny_handler statement:".$statement);
$dbh->do($statement) || $self->log(LOGERROR,$dbh->errstr());
#if configured to log the body of the denied messages
if ($log_deny_body && ! $log_all_body) {
my (@body) = ($transaction->header()->as_string());
$transaction->body_resetpos();
while (my $line = $transaction->body_getline()) {
push(@body,$line);
}
$statement = "INSERT INTO ".$body_table." (mail_id,body)".
" VALUES(".$mail_id.",".$dbh->quote(join('',@body)).")";
$self->log(LOGDEBUG,"data_post body log statement:".$statement);
$dbh->do($statement) || $self->log(LOGERROR,$dbh->errstr());
}
return(DECLINED);
}
sub disconnect_handler {
my ($self,$transaction) = @_;
$dbh->disconnect();
return(DECLINED);
}
=head1 NAME
@ -264,25 +278,26 @@ recipients table - one recipient per row. One message could have more than one r
The plugin accepts the following parameters:
t - type of the SQL database (mysql, postgresql, etc.)
d - database name (default qpsmtpd)
h - hostname of the database server (optional)
P - tcp port of the database server (optional)
o - dsn options (in format like DBI dsn options). For example: "o mysql_socket=/path/to/socket"
m - database table for mail messages (default messages)
r - database table for the recipients (default rcpts)
u - database user (default root)
p - database password (default '')
H - log the header of the message in the main table for mail messages (e.g. 'messages'). For example "H Yes".
t - type of the SQL database (mysql, postgresql, etc.)
d - database name (default qpsmtpd)
h - hostname of the database server (optional)
P - tcp port of the database server (optional)
o - dsn options (in format like DBI dsn options). For example: "o mysql_socket=/path/to/socket"
m - database table for mail messages (default messages)
r - database table for the recipients (default rcpts)
u - database user (default root)
p - database password (default '')
H - log the header of the message in the main table for mail messages (e.g. 'messages'). For example "H Yes".
I - sql table for the message headers. H parameter is requiered
=head1 CONFIGURATION OF THE ADDITIONAL FEATURES
You can configure the following additional features:
D - log the deny information for denied messages in the 'messages' table. Example "D Yes". The 'deny' hook must be enabled in order to use this feature.
B - log the body of all messages in the separated table (e.g. 'message_body'). Example "B Yes".
DB - log the body of the denied messages. D parameter required. Example "DB Yes".
b - sql table for the message bodies. Default: 'message_body'.
D - log the deny information for denied messages in the 'messages' table. Example "D Yes". The 'deny' hook must be enabled in order to use this feature.
B - log the body of all messages in the separated table (e.g. 'message_body'). Example "B Yes".
DB - log the body of the denied messages. D parameter required. Example "DB Yes".
b - sql table for the message bodies. Default: 'message_body'.
As default the plugin sets a note 'log2sql_mail_id'. This chunk of data is passed to other plugins. As default the plugin sets a field 'X-Sql-Log-ID' in the message header.
@ -290,40 +305,46 @@ As default the plugin sets a note 'log2sql_mail_id'. This chunk of data is passe
Here are the CREATE statements for the tables. Assuming the 'messages' table is the table for logging main information for messages, 'rcpts' table is the table for recipients, 'message_body' is optional table if You want to log messages bodies (of the denied messages OR of all messages). This syntax is MySQL syntax. For other databases the syntax could be slightly different.
CREATE TABLE `messages` (
`mail_id` varchar(255) NOT NULL default '',
`time` int(11) default '0',
`remote_ip` varchar(255) default NULL,
`remote_host` varchar(255) default NULL,
`remote_info` varchar(255) default NULL,
`sender` varchar(255) default NULL,
`subject` text,
`header_size` int(11) default NULL,
`body_size` int(11) default NULL,
`spam_status` float default NULL,
`header` text,
`deny` set('YES','NO') default NULL,
`deny_plugin` varchar(100) default '',
`deny_code` int(11) default '0',
`deny_msg` text,
PRIMARY KEY (`mail_id`)
) TYPE=MyISAM;
CREATE TABLE `rcpts` (
`rcpt_id` int(11) NOT NULL auto_increment,
`mail_id` varchar(255) NOT NULL default '',
`recipient` varchar(255),
PRIMARY KEY (`rcpt_id`)
) TYPE=MyISAM;
CREATE TABLE `message_body` (
`bdy_id` int(11) NOT NULL auto_increment,
`mail_id` varchar(255) NOT NULL default '',
`body` text,
PRIMARY KEY (`bdy_id`)
) TYPE=MyISAM;
CREATE TABLE `messages` (
`mail_id` varchar(255) NOT NULL default '',
`date_day` date,
`date_time` time,
`remote_ip` varchar(255) default NULL,
`remote_host` varchar(255) default NULL,
`remote_info` varchar(255) default NULL,
`sender` varchar(255) default NULL,
`subject` varchar(255) default NULL,
`header_size` int(11) default NULL,
`body_size` int(11) default NULL,
`spam_status` float default NULL,
`deny` set('YES','NO') default NULL,
`deny_plugin` varchar(100) default '',
`deny_code` int(11) default '0',
`deny_msg` text,
PRIMARY KEY (`mail_id`)
) TYPE=MyISAM;
CREATE TABLE `rcpts` (
`rcpt_id` int(11) NOT NULL auto_increment,
`mail_id` varchar(255) NOT NULL default '',
`recipient` varchar(255),
PRIMARY KEY (`rcpt_id`)
) TYPE=MyISAM;
CREATE TABLE `message_body` (
`bdy_id` int(11) NOT NULL auto_increment,
`mail_id` varchar(255) NOT NULL default '',
`body` text,
PRIMARY KEY (`bdy_id`)
) TYPE=MyISAM;
CREATE TABLE `message_headers` (
`header_id` int(11) NOT NULL auto_increment,
`mail_id` varchar(255) NOT NULL default '',
`header` text,
PRIMARY KEY (`header_id`)
) TYPE=MyISAM;
=head1 AUTHOR

View File

@ -1,4 +1,4 @@
%define version 0.1.0
%define version 0.1.8
%define release 1
%define name smeserver-qpsmtpd-log2sql
@ -20,10 +20,38 @@ Requires: e-smith-mysql
Requires: perl(DBI)
%description
Log every smtpd transaction in a database
Log every smtp transaction in a database
%changelog
* Thu Oct 11 2012 Daniel Berteaud <daniel@firewall-services.com> 0.1.0
* Thu Jun 26 2014 Daniel Berteaud <daniel@firewall-services.com> 0.1.8-1
- Define HOME in cron task so it works on EL6
* Wed May 15 2013 Daniel Berteaud <daniel@firewall-services.com> 0.1.7-1
- Only convert to InnoDB if not already done
* Mon Apr 22 2013 Daniel Berteaud <daniel@firewall-services.com> 0.1.6-1
- Fix a typo in MySQL template
* Fri Apr 19 2013 Daniel Berteaud <daniel@firewall-services.com> 0.1.5-1
- Use InnoDB instead of MyISAM
* Tue Oct 16 2012 Daniel Berteaud <daniel@firewall-services.com> 0.1.4-1
- purge old entries from the database
- log headers in a separate table
* Sun Oct 14 2012 Daniel Berteaud <daniel@firewall-services.com> 0.1.3-1
- use UTF-8 for MySQL connexion
- log auth user name
* Fri Oct 12 2012 Daniel Berteaud <daniel@firewall-services.com> 0.1.2-1
- decode (MIME-Header) mail subject
* Thu Oct 11 2012 Daniel Berteaud <daniel@firewall-services.com> 0.1.1-1
- update coding style
- DB renamed to smtp_log
- Possibility to choose an other database host (default is localhost)
* Thu Oct 11 2012 Daniel Berteaud <daniel@firewall-services.com> 0.1.0-1
- Initial release
%prep
@ -37,10 +65,11 @@ perl ./createlinks
(cd root ; /usr/bin/find . -depth -print | /bin/cpio -dump $RPM_BUILD_ROOT)
/bin/rm -f %{name}-%{version}-filelist
/sbin/e-smith/genfilelist $RPM_BUILD_ROOT \
--file /etc/cron.daily/qpsmtpd-db-cleanup 'attr(0755,root,root)' \
> %{name}-%{version}-filelist
echo "%doc CHANGELOG.git" >> %{name}-%{version}-filelist
echo "%doc mail_log.sql" >> %{name}-%{version}-filelist
echo "%doc smtp_log.sql" >> %{name}-%{version}-filelist
%files -f %{name}-%{version}-filelist
%defattr(-,root,root)

View File

@ -5,29 +5,36 @@ CREATE TABLE `messages` (
`remote_ip` varchar(255) default NULL,
`remote_host` varchar(255) default NULL,
`remote_info` varchar(255) default NULL,
`auth_user` varchar(30) default NULL,
`sender` varchar(255) default NULL,
`subject` varchar(255) default NULL,
`header_size` int(11) default NULL,
`body_size` int(11) default NULL,
`spam_status` float default NULL,
`header` text,
`deny` set('YES','NO') default NULL,
`deny_plugin` varchar(100) default '',
`deny_code` int(11) default '0',
`deny_msg` text,
PRIMARY KEY (`mail_id`)
) TYPE=MyISAM;
) TYPE=InnoDB;
CREATE TABLE `rcpts` (
`rcpt_id` int(11) NOT NULL auto_increment,
`mail_id` varchar(255) NOT NULL default '',
`recipient` varchar(255),
PRIMARY KEY (`rcpt_id`)
) TYPE=MyISAM;
) TYPE=InnoDB;
CREATE TABLE `message_body` (
`bdy_id` int(11) NOT NULL auto_increment,
`mail_id` varchar(255) NOT NULL default '',
`body` text,
PRIMARY KEY (`bdy_id`)
) TYPE=MyISAM;
) TYPE=InnoDB;
CREATE TABLE `message_headers` (
`header_id` int(11) NOT NULL auto_increment,
`mail_id` varchar(255) NOT NULL default '',
`header` text,
PRIMARY KEY (`header_id`)
) TYPE=InnoDB;