Commit e185f1f2 authored by sikeda's avatar sikeda
Browse files

[change] Now messages sent via WWSympa will be stored in bulk spool, directly...

[change] Now messages sent via WWSympa will be stored in bulk spool, directly if they are outbound messages.  On earlier releases outbound messages were injected in msg spool with special checksum.

A program upgrade_send_spool.pl to migrate messages with old format is proveded.


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@11325 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent e20f8468
......@@ -37,12 +37,14 @@ perlscripts = \
testlogs.pl \
mod2html.pl \
tpl2tt2.pl \
sympa_soap_client.pl
sympa_soap_client.pl \
upgrade_send_spool.pl
script_SCRIPTS = $(dbscripts) $(perlscripts)
man1_MANS = \
mod2html.1
mod2html.1 \
upgrade_send_spool.1
EXTRA_DIST = $(dbscripts) \
arc2webarc.pl.in \
......@@ -53,11 +55,12 @@ EXTRA_DIST = $(dbscripts) \
testldap.pl.in \
testlogs.pl.in \
tpl2tt2.pl.in \
sympa_soap_client.pl.in
sympa_soap_client.pl.in \
upgrade_send_spool.pl.in
CLEANFILES = $(perlscripts) $(bin_SCRIPTS) $(man1_MANS)
arc2webarc.pl crypt_passwd.pl init_comment.pl mod2html.pl p12topem.pl testldap.pl testlogs.pl tpl2tt2.pl sympa_soap_client.pl: Makefile
arc2webarc.pl crypt_passwd.pl init_comment.pl mod2html.pl p12topem.pl testldap.pl testlogs.pl tpl2tt2.pl sympa_soap_client.pl upgrade_send_spool.pl: Makefile
rm -f $@
$(AM_V_GEN)$(SED) \
-e 's|--PERL--|$(PERL)|' \
......@@ -83,6 +86,7 @@ testldap.pl: $(srcdir)/testldap.pl.in
testlogs.pl: $(srcdir)/testlogs.pl.in
tpl2tt2.pl: $(srcdir)/tpl2tt2.pl.in
sympa_soap_client.pl: $(srcdir)/sympa_soap_client.pl.in
upgrade_send_spool.pl: $(srcdir)/upgrade_send_spool.pl.in
.pl.1: Makefile
rm -f $@
......
#! --PERL--
# -*- indent-tabs-mode: nil; -*-
# vim:ft=perl:et:sw=4
# $Id$
# Sympa - SYsteme de Multi-Postage Automatique
#
# Copyright (c) 1997, 1998, 1999 Institut Pasteur & Christophe Wolfhugel
# Copyright (c) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
# 2006, 2007, 2008, 2009, 2010, 2011 Comite Reseau des Universites
# Copyright (c) 2011, 2012, 2013, 2014 GIP RENATER
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
use lib split(/:/, $ENV{SYMPALIB} || ''), '--modulesdir--';
use strict;
use warnings;
use Digest::MD5;
use English qw(-no_match_vars);
use Getopt::Long;
use Pod::Usage;
use Sympa::Bulk;
use Sympa::Constants;
use Conf;
use Log;
my %options;
unless (GetOptions(\%options, 'help|h', 'dry_run', 'version|v')) {
pod2usage(-exitval => 1, -output => \*STDERR);
}
if ($main::options{'help'}) {
pod2usage(0);
} elsif ($main::options{'version'}) {
printf "Sympa %s\n", Sympa::Constants::VERSION;
exit 0;
}
unless (Conf::load(Conf::get_sympa_conf(), 'no_db')) {
die sprintf 'Configuration file %s has errors.\n', Conf::get_sympa_conf();
}
# Set the User ID & Group ID for the process
$GID = $EGID = (getgrnam(Sympa::Constants::GROUP))[2];
$UID = $EUID = (getpwnam(Sympa::Constants::USER))[2];
# Required on FreeBSD to change ALL IDs (effective UID + real UID + saved UID)
POSIX::setuid((getpwnam(Sympa::Constants::USER))[2]);
POSIX::setgid((getgrnam(Sympa::Constants::GROUP))[2]);
# Check if the UID has correctly been set (useful on OS X)
unless (($GID == (getgrnam(Sympa::Constants::GROUP))[2])
&& ($UID == (getpwnam(Sympa::Constants::USER))[2])) {
die
"Failed to change process user ID and group ID. Note that on some OS Perl scripts can't change their real UID. In such circumstances Sympa should be run via sudo.";
}
# Sets the UMASK
umask(oct($Conf::Conf{'umask'}));
my $spool_dir = $Conf::Conf{'queue'};
my ($dh, $filename);
unless (open $dh, $spool_dir) {
printf STDERR "Cannot open directory %s.\n", $spool_dir;
exit 1;
}
while ($filename = readdir $dh) {
next unless -f "$spool_dir/$filename";
next if $filename =~ /,lock/; # Skip lock.
next unless /\AT\./;
next unless /\ABAD-/;
next unless /\A\.+/;
my $metadata = tools::unmarshal_metadata(
$spool_dir, $filename,
qr{\A([^\s\@]+)(?:\@([\w\.\-]+))?\.(\d+)\.(\w+)(?:,.*)?\z},
[qw(localpart domainpart date pid)]
);
next unless $metadata;
my $fh;
next unless open $fh, '<', "$spool_dir/$filename";
my $msg_string = do { local $RS; <$fh> };
close $fh;
my $message = Sympa::Message->new($msg_string, %$metadata);
next unless $message;
next unless $message->{checksum};
unless (process($message)) {
rename $spool_dir . '/' . $filename, $spool_dir . '/bad/' . $filename
unless $options{dry_run};
} else {
rename $spool_dir . '/' . $filename,
$spool_dir . '/moved/' . $filename
unless $options{dry_run};
}
}
closedir $dh;
sub process {
my $message = shift;
## valid X-Sympa-Checksum prove the message comes from web interface with
## authenticated sender
unless ($message->{'checksum'} eq sympa_checksum($message->{'rcpt'})) {
Log::do_log('err', '%s: Incorrect X-Sympa-Checksum header', $message);
return undef;
}
if (ref $message->{context} eq 'Sympa::List') {
$message->{'md5_check'} = 1;
delete $message->{checksum};
tools::store_spool($spool_dir, $message, '%s@%s.%ld.%ld,%d',
[qw(localpart domainpart date pid RAND)])
unless $options{dry_run};
Log::do_log('info', '%s: Moved to msg spool', $message);
} else {
Sympa::Bulk::store(
$message,
rcpts => [split /\s*,\s*/, $message->{rcpt}],
priority_message => $message->{'priority'},
delivery_date => $message->{'date'},
tag_as_last => 1,
) unless $options{dry_run};
Log::do_log('info', '%s: Moved to bulk spool', $message);
}
return 1;
}
sub sympa_checksum {
my $rcpt = shift;
return (
substr(
Digest::MD5::md5_hex(join('/', $Conf::Conf{'cookie'}, $rcpt)), -10
)
);
}
__END__
=encoding utf-8
=head1 NAME
upgrade_send_spool, upgrade_send_spool.pl - Upgrade messages in incoming spool
=head1 SYNOMSIS
upgrade_send_spool.pl [ --dry_run ]
=head1 DESCRIPTION
On Sympa earlier than 6.2, messages sent from WWSympa were injected in
msg spool with special checksum.
Recent release of Sympa and WWSympa injects outbound messages in outgoing
spool or sends them by Mailer directly.
This program migrates messages with old format in appropriate spools.
=head1 OPTIONS
=over
=item --dry_run
Shows what will be done but won't really perform upgrade process.
=back
=head1 RETURN VALUE
This program exits with status 0 if processing secceeded.
Otherwise exits with non-zero status.
=head1 CONFIGURATION OPTIONS
Following site configuration parameters in F<--CONFIG--> are referred.
=over
=item cookie
=item queue
=item umask
=back
=head1 SEE ALSO
L<sympa.conf(5)>, L<Sympa::Message>.
=head1 HISTORY
upgrade_send_spool.pl appeared on Sympa 6.2.
=cut
......@@ -129,7 +129,7 @@ if (eval "require Sympa::Plugin::Manager") {
$plugins = Sympa::Plugin::Manager->new(application => 'website');
}
 
Sympa::Mail::set_send_spool($Conf::Conf{'queue'});
$Sympa::Bulk::always_use_bulk = 1; #FIXME: Should instantiate Sympa::Bulk.
 
if ($Conf::Conf{'use_fast_cgi'}) {
require CGI::Fast;
......
......@@ -54,27 +54,14 @@ EOF
my %pid = ();
my $send_spool; ## for calling context
our $always_use_bulk; ## for calling context
our $log_smtp; # SMTP logging is enabled or not
### PUBLIC FUNCTIONS ###
####################################################
# public set_send_spool
####################################################
# set in global $send_spool, the concerned spool for
# sending message when it is not done by smtpto
#
# IN : $spool (+): spool concerned by sending
# OUT :
#
####################################################
sub set_send_spool {
my $spool = pop;
$send_spool = $spool;
}
#sub set_send_spool($spool_dir);
#DEPRECATED: No longer used.
#sub mail_file($robot, $filename, $rcpt, $data, $return_message_as_string);
##DEPRECATED: Use Sympa::Message->new_from_template() & sending().
......@@ -163,7 +150,7 @@ sub sending {
Conf::get_robot_conf($robot_id, 'sympa_packet_priority');
my $delivery_date = $params{'delivery_date'};
$delivery_date = time() unless ($delivery_date);
my $use_bulk = $params{'use_bulk'};
my $use_bulk = $always_use_bulk || $params{'use_bulk'};
my $tag_as_last = $params{'tag_as_last'};
my $sympa_file;
my $fh;
......@@ -188,42 +175,6 @@ sub sending {
{'listname' => $listname});
return undef;
}
} elsif (defined $send_spool) {
# in context wwsympa.fcgi do not send message to reciepients but copy
# it to standard spool
Log::do_log('debug', "NOT USING BULK");
my $sympa_email = Conf::get_robot_conf($robot_id, 'sympa');
$sympa_file =
"$send_spool/T.$sympa_email." . time . '.' . int(rand(10000));
unless (open TMP, ">$sympa_file") {
Log::do_log('notice', 'Cannot create %s: %s', $sympa_file, $!);
return undef;
}
my $all_rcpt;
if (ref($rcpt) eq 'SCALAR') {
$all_rcpt = $$rcpt;
} elsif (ref($rcpt) eq 'ARRAY') {
$all_rcpt = join(',', @{$rcpt});
} else {
$all_rcpt = $rcpt;
}
$message->{'rcpt'} = $all_rcpt;
$message->{'envelope_sender'} = $from;
$message->{'checksum'} = tools::sympa_checksum($all_rcpt);
printf TMP $message->to_string;
close TMP;
my $new_file = $sympa_file;
$new_file =~ s/T\.//g;
unless (rename $sympa_file, $new_file) {
Log::do_log('notice', 'Cannot rename %s to %s: %s',
$sympa_file, $new_file, $!);
return undef;
}
} else { # send it now
Log::do_log('debug', "NOT USING BULK");
*SMTP = smtpto($from, $rcpt, $robot_id);
......@@ -343,59 +294,8 @@ sub smtpto {
return ("Sympa::Mail::$fh"); # Symbol for the write descriptor.
}
#XXX NOT USED
####################################################
# send_in_spool : not used but if needed ...
####################################################
# send a message by putting it in global $send_spool
#
# IN : $rcpt (+): ref(SCALAR)|ref(ARRAY) - recepients
# $robot(+) : robot
# $sympa_email : for the file name
# $XSympaFrom : for "X-Sympa-From" field
# OUT : $return->
# -filename : name of temporary file
# needing to be renamed
# -fh : file handle opened for writing
# on
####################################################
sub send_in_spool {
my ($rcpt, $robot, $sympa_email, $XSympaFrom) = @_;
Log::do_log('debug3', '(%s, %s, %s)', $XSympaFrom, $rcpt);
unless ($sympa_email) {
$sympa_email = Conf::get_robot_conf($robot, 'sympa');
}
unless ($XSympaFrom) {
$XSympaFrom = Conf::get_robot_conf($robot, 'sympa');
}
my $sympa_file =
"$send_spool/T.$sympa_email." . time . '.' . int(rand(10000));
my $all_rcpt;
if (ref($rcpt) eq "ARRAY") {
$all_rcpt = join(',', @$rcpt);
} else {
$all_rcpt = $$rcpt;
}
unless (open TMP, ">$sympa_file") {
Log::do_log('notice', 'Cannot create %s: %s', $sympa_file, $!);
return undef;
}
printf TMP "X-Sympa-To: %s\n", $all_rcpt;
printf TMP "X-Sympa-From: %s\n", $XSympaFrom;
printf TMP "X-Sympa-Checksum: %s\n", tools::sympa_checksum($all_rcpt);
my $return;
$return->{'filename'} = $sympa_file;
$return->{'fh'} = \*TMP;
return $return;
}
#This has never been used.
#sub send_in_spool($rcpt, $robot, $sympa_email, $XSympaFrom);
#DEPRECATED: Use Sympa::Message::reformat_utf8_message().
#sub reformat_message($;$$);
......
......@@ -143,7 +143,7 @@ sub new {
if ($k eq 'X-Sympa-To') {
$self->{'rcpt'} = join ',', split(/\s*,\s*/, $v);
} elsif ($k eq 'X-Sympa-Checksum') {
} elsif ($k eq 'X-Sympa-Checksum') { # To migrate format <= 6.2a.40
$self->{'checksum'} = $v;
} elsif ($k eq 'X-Sympa-Family') {
$self->{'family'} = $v;
......@@ -261,16 +261,6 @@ sub new {
$self->{'decoded_subject'} = $subject;
}
## valid X-Sympa-Checksum prove the message comes from web interface with
## authenticated sender
if ($self->{'checksum'}) {
if ($self->{'checksum'} eq tools::sympa_checksum($self->{'rcpt'})) {
$self->{'md5_check'} = 1;
} else {
Log::do_log('err', 'Incorrect X-Sympa-Checksum header');
}
}
## TOPICS
my $topics;
if ($topics = $hdr->get('X-Sympa-Topic')) {
......
......@@ -1066,14 +1066,9 @@ sub tmp_passwd {
}
# Check sum used to authenticate communication from wwsympa to sympa
sub sympa_checksum {
my $rcpt = shift;
return (
substr(
Digest::MD5::md5_hex(join('/', $Conf::Conf{'cookie'}, $rcpt)), -10
)
);
}
# DEPRECATED: No longer used: This is moved to upgrade_send_spool.pl to be
# used for migrating old spool.
#sub sympa_checksum($rcpt);
BEGIN { eval 'use Crypt::CipherSaber'; }
......
......@@ -1399,6 +1399,15 @@ while ($signal ne 'term') { #as long as a signal is not received }
Sympa::Message->new_from_file($t_spool . '/' . $filename,
%$metadata);
# Compatibility: Message with checksum by Sympa <=6.2a.40
# They should be migrated.
if ($message->{checksum}) {
Log::do_log('err',
'%s: Message with old format. Run upgrade_send_spool.pl',
$message);
next;
}
my $robot =
(ref $message->{context} eq 'Sympa::List')
? $message->{context}->{'domain'}
......@@ -1665,14 +1674,6 @@ sub process_message {
$robot, Conf::get_robot_conf($robot, 'log_level'));
}
# Compatibility: Message contains a valid checksum. It comes from
# WWSympa of Sympa 6.2a.40 or earlier. Mail it without other processing
# unless it is for a valid list.
if ($message->{checksum} and $message->{md5_check}) {
return DoSendMessage($message)
unless ref $message->{context} eq 'Sympa::List';
}
## Strip of the initial X-Sympa-To and X-Sympa-Checksum internal headers
delete $message->{'rcpt'};
delete $message->{'checksum'};
......@@ -2192,92 +2193,8 @@ sub process_message {
return $status;
}
############################################################
# DoSendMessage
############################################################
# Send a message pushed in spool by another process.
#
# IN : -$msg (+): ref(Sympa::Message)
#
# OUT : 1
# | undef
#
##############################################################
sub DoSendMessage {
Log::do_log('debug2', '');
my $message = shift;
my $robot_id = $message->{'context'} || '*';
my $chksum = $message->{'checksum'};
my $rcpt = $message->{'rcpt'};
my $from = $message->{'envelope_sender'};
Log::do_log('info', "Processing web message for %s", $rcpt);
my $string = $message->as_string;
my $msg_id = $message->{'message_id'};
my $sender = $message->{'sender'};
delete $message->{'checksum'};
delete $message->{'rcpt'};
#XXXdelete $message->{'envelope_sender'};
## Multiple recepients
my @rcpts = split /,/, $rcpt;
unless (
defined Sympa::Mail::sending(
$message, \@rcpts, $from,
'priority' => Conf::get_robot_conf($robot_id, 'request_priority'),
use_bulk => 1
)
) {
Log::do_log('err', 'Impossible to forward mail from %s', $from);
Sympa::Report::reject_report_msg(
'intern',
'Impossible to forward a message pushed in spool by another process than sympa.pl.',
$sender,
{'msg_id' => $msg_id, 'message' => $message->as_entity},
$robot_id,
$string,
''
);
Log::db_log(
{ 'robot' => $robot_id,
'list' => $rcpt,
'action' => 'sendMessage',
'parameters' => "$msg_id,$rcpt",
'target_email' => '',
'msg_id' => $msg_id,
'status' => 'error',
'error_type' => 'internal',
'user_email' => $sender,
'client' => $ip,
'daemon' => $daemon_name
}
);
return undef;
}
Log::do_log('info', "Message for %s sent", $rcpt);
Log::db_log(
{ 'robot' => $robot_id,
'list' => $rcpt,
'action' => 'sendMessage',
'parameters' => "$msg_id,$rcpt",
'target_email' => '',
'msg_id' => $msg_id,
'status' => 'succes',
'error_type' => '',
'user_email' => $sender,
'client' => $ip,
'daemon' => $daemon_name
}
);
return 1;
}
#sub DoSendMessage($message);
#DEPRECATED: Run upgrade_send_spool.pl to migrate message with old format.
############################################################
# DoForward
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment