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

[-dev] Small refactoring. Parameterize arguments of compute_auth() and request_auth().


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@12613 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent e5641c8a
......@@ -6035,7 +6035,9 @@ sub do_subscribe {
'subrequest',
{ 'who' => $param->{'user'}{'email'},
'keyauth' => Sympa::compute_auth(
$list, $param->{'user'}{'email'}, 'add'
context => $list,
email => $param->{'user'}{'email'},
action => 'add'
),
'replyto' => Conf::get_robot_conf($robot, 'sympa'),
'custom_attribute' => $in{custom_attribute},
......@@ -6614,8 +6616,10 @@ sub unsubscribe {
'sigrequest',
{ 'who' => $param->{'user'}{'email'},
'keyauth' => Sympa::compute_auth(
$list, $param->{'user'}{'email'}, 'del'
)
context => $list,
email => $param->{'user'}{'email'},
action => 'del'
),
}
);
wwslog('info', 'Signoff sent to owner');
......
......@@ -67,12 +67,8 @@ my $log = Sympa::Log->instance;
=over
=item compute_auth
# To compute site-wide token
Sympa::compute_auth(('*', 'user@dom.ain', 'remind');
# To cpmpute a token specific to a list
Sympa::compute_auth($list, 'user@dom.ain', 'subscribe');
=item compute_auth ( context =E<gt> $that, email =E<gt> $email,
action =E<gt> $cmd )
Genererate a MD5 checksum using private cookie and parameters.
......@@ -80,17 +76,17 @@ Parameters:
=over
=item $that
=item context =E<gt> $that
L<Sympa::List>, Robot or Site.
=item $email
=item email =E<gt> $email
Recipient (the person who asked for the command).
=item $cmd
=item action =E<gt> $cmd
XXX
TBD.
=back
......@@ -105,9 +101,11 @@ Authenticaton key.
# Old name: List::compute_auth().
sub compute_auth {
$log->syslog('debug3', '(%s, %s, %s)', @_);
my $that = shift;
my $email = shift;
my $cmd = shift;
my %options = @_;
my $that = $options{context};
my $email = $options{email};
my $cmd = $options{action};
my ($list, $robot);
if (ref $that eq 'Sympa::List') {
......@@ -118,8 +116,9 @@ sub compute_auth {
$robot = '*';
}
$email =~ y/[A-Z]/[a-z]/;
$cmd =~ y/[A-Z]/[a-z]/;
$email = '' unless defined $email;
$email =~ tr/A-Z/a-z/;
$cmd =~ tr/A-Z/a-z/;
my ($cookie, $key, $listname);
......@@ -141,12 +140,8 @@ sub compute_auth {
=over
=item request_auth
# To send robot or site auth request
Sympa::request_auth('*', 'user@dom.ain', 'remind');
# To send auth request specific to a list
Sympa::request_auth($list, 'user@dom.ain', 'subscribe'):
=item request_auth ( context =E<gt> $that, sender =E<gt> $sender,
action =E<gt> $cmd, [ email =E<gt> $email ], [ other options... ] )
Sends an authentication request for a requested
command.
......@@ -155,23 +150,26 @@ Parameters:
=over
=item $that
=item context =E<gt> $that
L<Sympa::List>, Robot or Site.
=item $email
=item sender =E<gt> $email
Recipient (the person who asked for the command)
=item $cmd
=item action =E<gt> $cmd
'signoff', 'subscribe', 'add', 'del' or 'remind' if $that is List.
'remind' else.
=item @param
=item email =E<gt> $email
[0] is used if $cmd is subscribe|add|del|invite.
[1] is used if $cmd is C<'add'>.
Used if $cmd is add|del|invite|signoff.
=item gecos =E<gt> $comment
May be used if $cmd is C<'add'> or C<'subscribe'>.
=back
......@@ -186,16 +184,22 @@ C<1> or C<undef>.
# Old name: List::request_auth().
sub request_auth {
$log->syslog('debug2', '(%s, %s, %s, %s)', @_);
my $that = shift;
my $email = shift;
my $cmd = shift;
my @param = @_;
my %options = @_;
# Suppress warnings on uninitialized value.
foreach my $i ((0 .. 1)) {
$param[$i] = '' unless defined $param[$i];
foreach my $i (qw(sender email gecos)) {
$options{$i} = '' unless defined $options{$i};
}
my $that = $options{context} || '*';
my $sender = $options{sender};
my $cmd = $options{action};
my $email = $options{email};
my $gecos = $options{gecos};
my $quiet = $options{quiet};
$cmd = "quiet $cmd" if $quiet;
my ($list, $robot);
if (ref $that eq 'Sympa::List') {
$list = $that;
......@@ -207,60 +211,82 @@ sub request_auth {
}
my $keyauth;
my $data = {'to' => $email};
my $data = {'to' => $sender};
if ($list) {
my $listname = $list->{'name'};
$data->{'list_context'} = 1;
if ($cmd =~ /signoff$/) {
$param[0] ||= $email;
$keyauth = Sympa::compute_auth($list, $param[0], 'signoff');
$data->{'command'} = "auth $keyauth $cmd $listname $param[0]";
$email ||= $sender;
$keyauth = Sympa::compute_auth(
context => $list,
email => $email,
action => 'signoff'
);
$data->{'command'} = "auth $keyauth $cmd $listname $email";
$data->{'type'} = 'signoff';
} elsif ($cmd =~ /subscribe$/) {
$keyauth = Sympa::compute_auth($list, $email, 'subscribe');
$data->{'command'} = "auth $keyauth $cmd $listname $param[0]";
$keyauth = Sympa::compute_auth(
context => $list,
email => $sender,
action => 'subscribe'
);
$data->{'command'} = "auth $keyauth $cmd $listname $gecos";
$data->{'type'} = 'subscribe';
} elsif ($cmd =~ /add$/) {
$keyauth = Sympa::compute_auth($list, $param[0], 'add');
$data->{'command'} =
"auth $keyauth $cmd $listname $param[0] $param[1]";
$data->{'type'} = 'add';
$keyauth = Sympa::compute_auth(
context => $list,
email => $email,
action => 'add'
);
$data->{'command'} = "auth $keyauth $cmd $listname $email $gecos";
$data->{'type'} = 'add';
} elsif ($cmd =~ /del$/) {
my $keyauth = Sympa::compute_auth($list, $param[0], 'del');
$data->{'command'} = "auth $keyauth $cmd $listname $param[0]";
my $keyauth = Sympa::compute_auth(
context => $list,
email => $email,
action => 'del'
);
$data->{'command'} = "auth $keyauth $cmd $listname $email";
$data->{'type'} = 'del';
} elsif ($cmd eq 'remind') {
my $keyauth = Sympa::compute_auth($list, '', 'remind');
my $keyauth =
Sympa::compute_auth(context => $list, action => 'remind');
$data->{'command'} = "auth $keyauth $cmd $listname";
$data->{'type'} = 'remind';
} elsif ($cmd eq 'invite') {
my $keyauth = Sympa::compute_auth($list, $param[0], 'invite');
$data->{'command'} = "auth $keyauth $cmd $listname $param[0]";
my $keyauth = Sympa::compute_auth(
context => $list,
email => $email,
action => 'invite'
);
$data->{'command'} = "auth $keyauth $cmd $listname $email";
$data->{'type'} = 'invite';
} elsif ($cmd eq 'review') {
my $keyauth = Sympa::compute_auth($list, '', 'review');
my $keyauth =
Sympa::compute_auth(context => $list, action => 'review');
$data->{'command'} = "auth $keyauth $cmd $listname";
$data->{'type'} = 'review';
}
$data->{'command_escaped'} = tools::escape_url($data->{'command'});
$data->{'auto_submitted'} = 'auto-replied';
unless (Sympa::send_file($list, 'request_auth', $email, $data)) {
unless (Sympa::send_file($list, 'request_auth', $sender, $data)) {
$log->syslog('notice',
'Unable to send template "request_auth" to %s', $email);
'Unable to send template "request_auth" to %s', $sender);
return undef;
}
} else {
if ($cmd eq 'remind') {
my $keyauth = Sympa::compute_auth('*', '', $cmd);
my $keyauth =
Sympa::compute_auth(context => '*', action => 'remind');
$data->{'command'} = "auth $keyauth $cmd *";
$data->{'command_escaped'} =
tools::escape_url($data->{'command'});
......@@ -268,9 +294,9 @@ sub request_auth {
}
$data->{'auto_submitted'} = 'auto-replied';
unless (Sympa::send_file($robot, 'request_auth', $email, $data)) {
unless (Sympa::send_file($robot, 'request_auth', $sender, $data)) {
$log->syslog('notice',
'Unable to send template "request_auth" to %s', $email);
'Unable to send template "request_auth" to %s', $sender);
return undef;
}
}
......
......@@ -871,7 +871,13 @@ sub review {
if ($action =~ /request_auth/i) {
$log->syslog('debug2', 'Auth requested from %s', $sender);
unless (Sympa::request_auth($list, $sender, 'review')) {
unless (
Sympa::request_auth(
context => $list,
sender => $sender,
action => 'review'
)
) {
my $error =
'Unable to request authentication for command "review"';
Sympa::Report::reject_report_cmd('intern', $error,
......@@ -1137,7 +1143,11 @@ sub subscribe {
$list->send_notify_to_owner(
'subrequest',
{ 'who' => $sender,
'keyauth' => Sympa::compute_auth($list, $sender, 'add'),
'keyauth' => Sympa::compute_auth(
context => $list,
email => $sender,
action => 'add'
),
'replyto' => Conf::get_robot_conf($robot, 'sympa'),
'gecos' => $comment
}
......@@ -1176,9 +1186,15 @@ sub subscribe {
return 1;
}
if ($action =~ /request_auth/i) {
my $cmd = 'subscribe';
$cmd = "quiet $cmd" if $quiet;
unless (Sympa::request_auth($list, $sender, $cmd, $comment)) {
unless (
Sympa::request_auth(
context => $list,
sender => $sender,
action => 'subscribe',
gecos => $comment,
quiet => $quiet
)
) {
my $error =
'Unable to request authentication for command "subscribe"';
Sympa::Report::reject_report_cmd('intern', $error,
......@@ -1561,9 +1577,15 @@ sub signoff {
} else {
$to = $sender;
}
my $cmd = 'signoff';
$cmd = "quiet $cmd" if $quiet;
unless (Sympa::request_auth($list, $to, $cmd, $email)) {
unless (
Sympa::request_auth(
context => $list,
sender => $to,
email => $email,
action => 'signoff',
quiet => $quiet
)
) {
my $error =
'Unable to request authentication for command "signoff"';
Sympa::Report::reject_report_cmd('intern', $error,
......@@ -1584,7 +1606,11 @@ sub signoff {
$list->send_notify_to_owner(
'sigrequest',
{ 'who' => $sender,
'keyauth' => Sympa::compute_auth($list, $sender, 'del')
'keyauth' => Sympa::compute_auth(
context => $list,
email => $sender,
action => 'del'
)
}
)
) {
......@@ -1769,9 +1795,16 @@ sub add {
}
if ($action =~ /request_auth/i) {
my $cmd = 'add';
$cmd = "quiet $cmd" if $quiet;
unless (Sympa::request_auth($list, $sender, $cmd, $email, $comment)) {
unless (
Sympa::request_auth(
context => $list,
sender => $sender,
action => 'add',
quiet => $quiet,
email => $email,
gecos => $comment
)
) {
my $error = 'Unable to request authentication for command "add"';
Sympa::Report::reject_report_cmd('intern', $error,
{'listname' => $which},
......@@ -1967,7 +2000,14 @@ sub invite {
if ($action =~ /request_auth/i) {
unless (
Sympa::request_auth($list, $sender, 'invite', $email, $comment)) {
Sympa::request_auth(
context => $list,
sender => $sender,
action => 'invite',
email => $email,
gecos => $comment
)
) {
my $error =
'Unable to request authentication for command "invite"';
Sympa::Report::reject_report_cmd('intern', $error,
......@@ -2021,7 +2061,11 @@ sub invite {
}
if ($action =~ /request_auth/i) {
my $keyauth = Sympa::compute_auth($list, $email, 'subscribe');
my $keyauth = Sympa::compute_auth(
context => $list,
email => $email,
action => 'subscribe'
);
my $command = "auth $keyauth sub $which $comment";
$context{'subject'} = $command;
$context{'url'} = "mailto:$sympa?subject=$command";
......@@ -2234,7 +2278,13 @@ sub remind {
} elsif ($action =~ /request_auth/i) {
$log->syslog('debug2', 'Auth requested from %s', $sender);
if ($listname eq '*') {
unless (Sympa::request_auth('*', $sender, 'remind')) {
unless (
Sympa::request_auth(
context => '*',
sender => $sender,
action => 'remind'
)
) {
my $error =
'Unable to request authentication for command "remind"';
Sympa::Report::reject_report_cmd('intern', $error,
......@@ -2243,7 +2293,13 @@ sub remind {
return undef;
}
} else {
unless (Sympa::request_auth($list, $sender, 'remind')) {
unless (
Sympa::request_auth(
context => $list,
sender => $sender,
action => 'remind'
)
) {
my $error =
'Unable to request authentication for command "remind"';
Sympa::Report::reject_report_cmd('intern', $error,
......@@ -2497,9 +2553,15 @@ sub del {
return 'not_allowed';
}
if ($action =~ /request_auth/i) {
my $cmd = 'del';
$cmd = "quiet $cmd" if $quiet;
unless (Sympa::request_auth($list, $sender, $cmd, $who)) {
unless (
Sympa::request_auth(
context => $list,
sender => $sender,
action => 'del',
quiet => $quiet,
email => $who
)
) {
my $error = 'Unable to request authentication for command "del"';
Sympa::Report::reject_report_cmd('intern', $error,
{'listname' => $which, 'list' => $list},
......@@ -3163,11 +3225,19 @@ sub get_auth_method {
my $compute;
if (ref $list eq 'Sympa::List') {
$compute = Sympa::compute_auth($list, $email, $cmd);
$compute = Sympa::compute_auth(
context => $list,
email => $email,
action => $cmd
);
$that = $list->{'domain'}; # Robot
} else {
$compute = Sympa::compute_auth('*', $email, $cmd);
$that = '*'; # Site
$compute = Sympa::compute_auth(
context => '*',
email => $email,
action => $cmd
);
$that = '*'; # Site
}
if ($auth eq $compute) {
$auth_method = 'md5';
......
......@@ -1471,7 +1471,11 @@ sub subscribe {
$list->send_notify_to_owner(
'subrequest',
{ 'who' => $sender,
'keyauth' => Sympa::compute_auth($list, $sender, 'add'),
'keyauth' => Sympa::compute_auth(
context => $list,
email => $sender,
action => 'add'
),
'replyto' => Conf::get_robot_conf($robot, 'sympa'),
'gecos' => $gecos
}
......@@ -1491,8 +1495,12 @@ sub subscribe {
return SOAP::Data->name('result')->type('boolean')->value(1);
}
if ($action =~ /request_auth/i) {
my $cmd = 'subscribe';
Sympa::request_auth($list, $sender, $cmd, $gecos);
Sympa::request_auth(
context => $list,
sender => $sender,
action => 'subscribe',
gecos => $gecos
);
$log->syslog('info', '%s from %s, auth requested', $listname,
$sender);
return SOAP::Data->name('result')->type('boolean')->value(1);
......
Markdown is supported
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