Commit 9b7ce191 authored by sikeda's avatar sikeda
Browse files

[dev] Sympa::Report::*_report_cmd() are deprecated. Instead, use stash of...

[dev] Sympa::Report::*_report_cmd() are deprecated.  Instead, use stash of spindle to keep command reports.


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@12650 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent bab1ef18
......@@ -45,313 +45,23 @@ my $log = Sympa::Log->instance;
### MAIL COMMAND REPORT ###
# for rejected command because of internal error
my @intern_error_cmd;
# for rejected command because of user error
my @user_error_cmd;
# for errors no relative to a command
my @global_error_cmd;
# for rejected command because of no authorization
my @auth_reject_cmd;
# for command notice
my @notice_cmd;
# DEPRECATED: No longer used.
#sub init_report_cmd;
#########################################################
# init_report_cmd
#########################################################
# init arrays for mail command reports :
#
#
# IN : -
#
# OUT : -
#
#########################################################
sub init_report_cmd {
undef @intern_error_cmd;
undef @user_error_cmd;
undef @global_error_cmd;
undef @auth_reject_cmd;
undef @notice_cmd;
}
#########################################################
# is_there_any_report_cmd
#########################################################
# Look for some mail command report in one of arrays report
#
# IN : -
#
# OUT : 1 if there are some reports to send
#
#########################################################
sub is_there_any_report_cmd {
return ( @intern_error_cmd
|| @user_error_cmd
|| @global_error_cmd
|| @auth_reject_cmd
|| @notice_cmd);
}
#########################################################
# send_report_cmd
#########################################################
# Send the template command_report to $sender
# with global arrays :
# @intern_error_cmd,@user_error_cmd,@global_error_cmd,
# @auth_reject_cmd,@notice_cmd.
#
#
# IN : -$sender (+): SCALAR
# -$robot (+): SCALAR
#
# OUT : 1 if there are some reports to send
#
#########################################################
sub send_report_cmd {
my ($sender, $robot) = @_;
unless ($sender) {
$log->syslog('err',
'Unable to send template "command_report": No user to notify');
return undef;
}
unless ($robot) {
$log->syslog('err',
'Unable to send template "command_report": No robot');
return undef;
}
# for mail layout
my $before_auth = 0;
$before_auth = 1 if @notice_cmd;
my $before_user_err;
$before_user_err = 1 if $before_auth or @auth_reject_cmd;
my $before_intern_err;
$before_intern_err = 1 if $before_user_err or @user_error_cmd;
chomp($sender);
# Ensure 1 second elapsed since last message.
Sympa::send_file(
$robot,
'command_report',
$sender,
{ to => $sender,
nb_notice => scalar(@notice_cmd),
nb_auth => scalar(@auth_reject_cmd),
nb_user_err => scalar(@user_error_cmd),
nb_intern_err => scalar(@intern_error_cmd),
nb_global => scalar(@global_error_cmd),
before_auth => $before_auth,
before_user_err => $before_user_err,
before_intern_err => $before_intern_err,
notices => [@notice_cmd],
auths => [@auth_reject_cmd],
user_errors => [@user_error_cmd],
intern_errors => [@intern_error_cmd],
globals => [@global_error_cmd],
},
date => time + 1
);
init_report_cmd();
}
#########################################################
# global_report_cmd
#########################################################
# puts global report of mail with commands in
# @global_report_cmd used to send message with template
# mail_tt2/command_report.tt2
# if $now , the template is sent now
# if $type eq 'intern', the listmaster is notified
#
# IN : -$type (+): 'intern'||'intern_quiet||'user'
# -$error : scalar - $glob.entry in command_report.tt2 if $type = 'user'
# - string error for listmaster if $type = 'intern'
# -$data : ref(HASH) - var used in command_report.tt2
# -$sender : required if $type eq 'intern' or if $now
# scalar - the user to notify
# -$robot : required if $type eq 'intern' or if $now
# scalar - to notify useror listmaster
# -$now : send now if true
#
# OUT : 1|| undef
#
#########################################################
sub global_report_cmd {
my ($type, $error, $data, $sender, $robot, $now) = @_;
my $entry;
unless ($type eq 'intern' || $type eq 'intern_quiet' || $type eq 'user') {
$log->syslog(
'err',
'Error to prepare parsing "command_report" template to %s: Not a valid error type',
$sender
);
return undef;
}
if ($type eq 'intern') {
if ($robot) {
my $param = $data;
$param ||= {};
$param->{'error'} = $error;
$param->{'who'} = $sender;
$param->{'action'} = 'Command process';
Sympa::send_notify_to_listmaster($robot, 'mail_intern_error',
$param);
} else {
$log->syslog('notice',
'Unable to send notify to listmaster: No robot');
}
}
# DEPRECATED: No longer used.
#sub is_there_any_report_cmd;
if ($type eq 'user') {
$entry = $error;
# DEPRECATED. Use Sympa::Spindle::DoCommand::_send_report().
#sub send_report_cmd;
} else {
$entry = 'intern_error';
}
# DEPRECATED. No longer used.
#sub global_report_cmd;
$data ||= {};
$data->{'entry'} = $entry;
push @global_error_cmd, $data;
if ($now) {
unless ($sender && $robot) {
$log->syslog('err',
'Unable to send template "command_report" now: No sender or robot'
);
return undef;
}
send_report_cmd($sender, $robot);
# DEPRECATED. No longer used.
#sub reject_report_cmd;
}
}
#########################################################
# reject_report_cmd
#########################################################
# puts errors reports of processed commands in
# @user/intern_error_cmd, @auth_reject_cmd
# used to send message with template
# mail_tt2/command_report.tt2
# if $type eq 'intern', the listmaster is notified
#
# IN : -$type (+): 'intern'||'intern_quiet||'user'||'auth'
# -$error : scalar - $u_err.entry in command_report.tt2 if $type = 'user'
# - $auth.entry in command_report.tt2 if $type = 'auth'
# - string error for listmaster if $type = 'intern'
# -$data : ref(HASH) - var used in command_report.tt2
# -$cmd : SCALAR - the rejected cmd : $xx.cmd in command_report.tt2
# -$sender : required if $type eq 'intern'
# scalar - the user to notify
# -$list : required if $type eq 'intern'
# scalar - to notify listmaster
#
# OUT : 1|| undef
#
#########################################################
sub reject_report_cmd {
my $request = shift;
my $type = shift;
my $error = shift || '';
my $data = shift || {};
my $cmd = $request->{cmd_line};
my $sender = $request->{sender};
my $list = $request->{context};
unless ($type eq 'intern'
|| $type eq 'intern_quiet'
|| $type eq 'user'
|| $type eq 'auth') {
$log->syslog(
'err',
'Error to prepare parsing "command_report" template to %s: Not a valid error type',
$sender
);
return undef;
}
$data ||= {};
$data->{cmd} = $cmd;
if (ref $list eq 'Sympa::List') {
$data->{listname} = $list->{'name'};
}
if ($type eq 'intern') {
if (ref $list eq 'Sympa::List') {
Sympa::send_notify_to_listmaster(
$list,
'mail_intern_error',
{ %$data,
error => $error,
who => $sender,
action => 'Command process',
}
);
} else {
$log->syslog('notice',
'Unable to notify listmaster for error: "%s": (no list)',
$error);
}
}
if ($type eq 'auth') {
$data->{'entry'} = $error;
push @auth_reject_cmd, $data;
} elsif ($type eq 'user') {
$data->{'entry'} = $error;
push @user_error_cmd, $data;
} else {
$data->{'entry'} = 'intern_error';
push @intern_error_cmd, $data;
}
}
#########################################################
# notice_report_cmd
#########################################################
# puts notices reports of processed commands in
# @notice_cmd used to send message with template
# mail_tt2/command_report.tt2
#
# IN : -$entry : $notice.entry to select string in
# command_report.tt2
# -$data : ref(HASH) - var used in command_report.tt2
# -$cmd : SCALAR - the noticed cmd
#
# OUT : 1
#
#########################################################
sub notice_report_cmd {
my $request = shift;
my $entry = shift;
my $data = shift || {};
my $list = $request->{context};
$data->{'cmd'} = $request->{cmd_line};
$data->{'entry'} = $entry;
if (ref $list eq 'Sympa::List') {
$data->{listname} = $list->{'name'};
}
push @notice_cmd, $data;
}
# DEPRECATED. No longer used.
#sub notice_report_cmd;
### WEB COMMAND REPORT ###
......
......@@ -31,7 +31,6 @@ use Time::HiRes qw();
use Sympa;
use Sympa::CommandDef;
use Sympa::Log;
use Sympa::Report;
use Sympa::Request;
use Sympa::Scenario;
use Sympa::Spool::Request;
......@@ -76,7 +75,7 @@ sub _twist {
my $action;
my $result;
my $auth_method = _get_auth_method($request);
my $auth_method = _get_auth_method($self, $request);
return 'wrong_auth'
unless defined $auth_method;
......@@ -96,7 +95,15 @@ sub _twist {
);
my $error = sprintf 'Unknown requested action in scenario: %s',
($action || '');
Sympa::Report::reject_report_cmd($request, 'intern', $error);
Sympa::send_notify_to_listmaster(
$request->{context},
'mail_intern_error',
{ error => $error,
who => $sender,
action => 'Command process',
}
);
$self->add_stash($request, 'intern');
return undef;
}
......@@ -135,12 +142,10 @@ sub _twist {
) {
$log->syslog('notice', 'Unable to send template "%s" to %s',
$result->{'tt2'}, $sender);
Sympa::Report::reject_report_cmd($request, 'auth',
$result->{'reason'});
$self->add_stash($request, 'auth', $result->{'reason'});
}
} else {
Sympa::Report::reject_report_cmd($request, 'auth',
$result->{'reason'});
$self->add_stash($request, 'auth', $result->{'reason'});
}
$log->syslog(
'info',
......@@ -160,7 +165,7 @@ sub _twist {
# Returns 'smime', 'md5', 'dkim' or 'smtp' if authentication OK, undef else.
# Old name: Sympa::Commands::get_auth_method().
sub _get_auth_method {
$log->syslog('debug3', '(%s)', @_);
my $self = shift;
my $request = shift;
my $list = $request->{context};
......@@ -201,11 +206,18 @@ sub _get_auth_method {
} else {
$log->syslog('debug2', 'Auth should be %s', $compute);
if (grep { $cmd eq $_ } qw(add del invite signoff subscribe)) {
Sympa::Report::reject_report_cmd($request, 'user',
$self->add_stash($request, 'user',
'wrong_email_confirm', {command => $cmd});
} else {
Sympa::Report::reject_report_cmd($request, 'intern',
'The authentication process failed');
Sympa::send_notify_to_listmaster(
$list,
'mail_intern_error',
{ error => 'The authentication process failed',
who => $sender,
action => 'Command process',
}
);
$self->add_stash($request, 'intern');
}
$log->syslog('info', 'Command "%s" from %s refused, auth failed',
$request->{cmd_line}, $sender);
......
This diff is collapsed.
......@@ -31,7 +31,6 @@ use English qw(-no_match_vars);
use Sympa;
use Conf;
use Sympa::Log;
use Sympa::Report;
use Sympa::Spindle::ProcessMessage;
use base qw(Sympa::Spindle::ProcessIncoming); # Derives _splicing_to().
......@@ -99,15 +98,21 @@ sub _twist {
# Keep track of known message IDs...if any.
$self->{_msgid}{'sympa@' . $robot}{$messageid} = time;
# Initialize command report.
Sympa::Report::init_report_cmd();
my $spindle_message =
Sympa::Spindle::ProcessMessage->new(message => $message);
unless ($spindle_message and $spindle_message->spin) {
my $spindle = Sympa::Spindle::ProcessMessage->new(message => $message);
unless ($spindle and $spindle->spin) {
# No command found.
$log->syslog('info', "No command found in message");
Sympa::Report::global_report_cmd('user', 'no_cmd_found', {});
Sympa::send_file(
$robot,
'command_report',
$sender,
{ to => $sender,
nb_global => 1,
globals => [{entry => 'no_cmd_found'}],
},
# Ensure 1 second elapsed since last message.
date => time + 1
);
$log->db_log(
'robot' => $robot,
#'list' => 'sympa',
......@@ -119,12 +124,14 @@ sub _twist {
'error_type' => 'no_cmd_found',
'user_email' => $sender
);
return undef;
}
my $status = $spindle_message->{success} if $spindle_message;
my $status = $spindle->{success} if $spindle;
# Mail back the result.
if (Sympa::Report::is_there_any_report_cmd()) {
## Loop prevention
if (@{$spindle->{stash} || []}) {
# Loop prevention.
## Count reports sent to $sender
$self->{_loop_info}{$sender}{'count'}++;
......@@ -162,8 +169,8 @@ sub _twist {
$Conf::Conf{'loop_command_decrease_factor'};
}
## Send the reply message
Sympa::Report::send_report_cmd($sender, $robot);
# Send the reply message.
_send_report($robot, $sender, $spindle->{stash});
$log->db_log(
'robot' => $robot,
#'list' => 'sympa',
......@@ -181,6 +188,63 @@ sub _twist {
return $status;
}
# Send the template command_report to $sender with list of reports.
# Old name: Sympa::Report::send_report_cmd().
sub _send_report {
my $robot = shift;
my $sender = shift;
my $reports = shift;
my @reports;
foreach my $report (@{$reports || []}) {
my ($request, $type, $error, $params) = @$report;
my %data = %{$params || {}};
$data{type} = $type;
$data{cmd} = $request->{cmd_line};
$data{entry} = ($type eq 'intern') ? 'intern_error' : ($error || '');
my $that = $request->{context};
if (ref $that eq 'Sympa::List') {
$data{listname} = $that->{'name'};
}
push @reports, \%data;
}
my @notice_cmd = grep { $_->{type} eq 'notice' } @reports;
my @auth_reject_cmd = grep { $_->{type} eq 'auth' } @reports;
my @user_error_cmd = grep { $_->{type} eq 'user' } @reports;
my @intern_error_cmd = grep { $_->{type} eq 'intern' } @reports;
# for mail layout
my $before_auth = @notice_cmd ? 1 : 0;
my $before_user_err = ($before_auth or @auth_reject_cmd) ? 1 : 0;
my $before_intern_err = ($before_user_err or @user_error_cmd) ? 1 : 0;
# Ensure 1 second elapsed since last message.
Sympa::send_file(
$robot,
'command_report',
$sender,
{ to => $sender,
nb_notice => scalar(@notice_cmd),
nb_auth => scalar(@auth_reject_cmd),
nb_user_err => scalar(@user_error_cmd),
nb_intern_err => scalar(@intern_error_cmd),
#nb_global => scalar(@global_error_cmd),
before_auth => $before_auth,
before_user_err => $before_user_err,
before_intern_err => $before_intern_err,
notices => [@notice_cmd],
auths => [@auth_reject_cmd],
user_errors => [@user_error_cmd],
intern_errors => [@intern_error_cmd],
#globals => [@global_error_cmd],
},
date => time + 1
);
}
1;
__END__
......
......@@ -30,7 +30,6 @@ use Time::HiRes qw();
use Sympa;
use Sympa::Log;
use Sympa::Report;
use base qw(Sympa::Spindle);
......@@ -48,7 +47,15 @@ sub _twist {
my $error = sprintf
'Unable to request authentication for command "%s"',
$request->{action};
Sympa::Report::reject_report_cmd($request, 'intern', $error);
Sympa::send_notify_to_listmaster(
$request->{context},
'mail_intern_error',
{ error => $error,
who => $sender,
action => 'Command process',
}
);
$self->add_stash($request, 'intern');
return undef;
}
$log->syslog(
......
......@@ -30,7 +30,6 @@ use Time::HiRes qw();
use Sympa;
use Sympa::Log;
use Sympa::Report;
use Sympa::Request;
use Sympa::Spool::Request;
......@@ -46,7 +45,7 @@ sub _twist {
my $message = $request->{message};
my $sender = $request->{sender};
Sympa::Report::notice_report_cmd($request, 'req_forward')
$self->add_stash($request, 'notice', 'req_forward')
unless $request->{quiet};
my $tpl =
......@@ -74,11 +73,17 @@ sub _twist {
$log->syslog('info',
'Unable to send notify "%s" to %s list owner',
$tpl, $list);
Sympa::Report::reject_report_cmd(
$request, 'intern',
sprintf('Unable to send subrequest to %s list owner',
$list->get_id)
my $error = sprintf 'Unable to send subrequest to %s list owner',
$list->get_id;
Sympa::send_notify_to_listmaster(
$list,
'mail_intern_error',
{ error => $error,
who => $sender,
action => 'Command process',
}
);
$self->add_stash($request, 'intern');
}
my $spool_req = Sympa::Spool::Request->new;
......
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