Commit e7a01961 authored by sikeda's avatar sikeda
Browse files

[dev] Now Sympa::Log is used instead of Log; Log is no longer used.


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@12038 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent 7b14f8a8
This diff is collapsed.
......@@ -55,7 +55,6 @@ nobase_modules_DATA = \
Sympa/ListDef.pm \
Sympa/LockedFile.pm \
Sympa/Log.pm \
Log.pm \
Sympa/Mailer.pm \
Sympa/Marc.pm \
Sympa/Marc/Search.pm \
......
This diff is collapsed.
......@@ -29,13 +29,15 @@ use warnings;
use Sympa::Bulk;
use Conf;
use Log;
use Sympa::Log;
use Sympa::Mailer;
use Sympa::Message;
use tools;
use base qw(Class::Singleton);
my $log = Sympa::Log->instance;
# Constructor for Class::Singleton.
sub _new_instance {
my $class = shift;
......@@ -74,7 +76,7 @@ sub store {
my @rcpts = ref $rcpt ? @$rcpt : ($rcpt);
# stack if too much messages w/ same code
Log::do_log('info', 'Stacking message about "%s" for %s (%s)',
$log->syslog('info', 'Stacking message about "%s" for %s (%s)',
$operation, join(', ', @rcpts), $robot_id)
unless $operation eq 'logs_failed';
foreach my $rcpt (@rcpts) {
......@@ -119,7 +121,7 @@ sub flush {
my %messages =
%{$self->{_stack}->{$robot_id}{$operation}{'messages'}};
Log::do_log(
$log->syslog(
'info', 'Got messages about "%s" (%s)',
$operation, join(', ', keys %messages)
);
......@@ -135,7 +137,7 @@ sub flush {
. tools::get_message_id($robot_id)
};
Log::do_log('info', 'Send messages to %s', $rcpt);
$log->syslog('info', 'Send messages to %s', $rcpt);
# Skip DB access because DB is not accessible
$rcpt = [$rcpt]
......@@ -148,7 +150,7 @@ sub flush {
'listmaster_groupednotifications',
$rcpt, $param);
unless ($message) {
Log::do_log(
$log->syslog(
'notice',
'Unable to send template "listmaster_groupnotification" to %s listmaster %s',
$robot_id,
......@@ -157,7 +159,7 @@ sub flush {
return undef;
}
unless (defined $mailer->store($message, $rcpt)) {
Log::do_log(
$log->syslog(
'notice',
'Unable to send template "listmaster_groupnotification" to %s listmaster %s',
$robot_id,
......@@ -167,7 +169,7 @@ sub flush {
}
}
Log::do_log('info', 'Cleaning stacked notifications');
$log->syslog('info', 'Cleaning stacked notifications');
delete $self->{_stack}->{$robot_id}{$operation};
}
}
......
......@@ -32,11 +32,13 @@ use Encode qw();
use HTML::Entities qw();
use Conf;
use Log;
use Sympa::Log;
use Sympa::Message;
use tools;
use Sympa::Tools::File;
my $log = Sympa::Log->instance;
my $serial_number = 0; # incremented on each archived mail
## RCS identification.
......@@ -47,7 +49,7 @@ my $serial_number = 0; # incremented on each archived mail
sub store_last {
my ($list, $msg) = @_;
Log::do_log('debug2', '');
$log->syslog('debug2', '');
return unless $list->is_archived();
my $dir = $list->{'dir'} . '/archives';
......@@ -72,17 +74,17 @@ sub store_last {
sub list {
my $name = shift;
Log::do_log('debug', '(%s)', $name);
$log->syslog('debug', '(%s)', $name);
my (@l, $i);
unless (-d "$name") {
Log::do_log('err', '(%s) Failed, no directory %s', $name, $name);
$log->syslog('err', '(%s) Failed, no directory %s', $name, $name);
# @l = ($msg::no_archives_available);
return @l;
}
unless (opendir(DIR, "$name")) {
Log::do_log('err', '(%s) Failed, cannot open directory %s',
$log->syslog('err', '(%s) Failed, cannot open directory %s',
$name, $name);
# @l = ($msg::no_archives_available);
return @l;
......@@ -98,7 +100,7 @@ sub list {
}
sub scan_dir_archive {
Log::do_log('debug3', '(%s, %s)', @_);
$log->syslog('debug3', '(%s, %s)', @_);
my ($list, $month) = @_;
my $dir =
......@@ -106,7 +108,7 @@ sub scan_dir_archive {
. $list->get_list_id();
unless (opendir(DIR, "$dir/$month/arctxt")) {
Log::do_log('info', 'Unable to open dir %s/%s/arctxt', $dir, $month);
$log->syslog('info', 'Unable to open dir %s/%s/arctxt', $dir, $month);
return undef;
}
......@@ -114,21 +116,21 @@ sub scan_dir_archive {
my $i = 0;
foreach my $file (sort readdir(DIR)) {
next unless ($file =~ /^\d+$/);
Log::do_log('debug', 'Start parsing message %s/%s/arctxt/%s',
$log->syslog('debug', 'Start parsing message %s/%s/arctxt/%s',
$dir, $month, $file);
my $message =
Sympa::Message->new_from_file("$dir/$month/arctxt/$file",
context => $list);
unless ($message) {
Log::do_log('err', 'Unable to create Message object from file %s',
$file);
$log->syslog('err',
'Unable to create Message object from file %s', $file);
return undef;
}
# Decrypt message if possible
$message->smime_decrypt;
Log::do_log('debug', 'MAIL object: %s', $message);
$log->syslog('debug', 'MAIL object: %s', $message);
$i++;
my $msg = {};
......@@ -140,7 +142,7 @@ sub scan_dir_archive {
$msg->{'full_msg'} = $message->as_string;
Log::do_log('debug', 'Adding message %s in archive to send',
$log->syslog('debug', 'Adding message %s in archive to send',
$msg->{'subject'});
push @{$all_msg}, $msg;
......@@ -166,18 +168,18 @@ sub search_msgid {
my ($dir, $msgid) = @_;
Log::do_log('info', '(%s, %s)', $dir, $msgid);
$log->syslog('info', '(%s, %s)', $dir, $msgid);
if ($msgid =~ /NO-ID-FOUND\.mhonarc\.org/) {
Log::do_log('err', 'No message id found');
$log->syslog('err', 'No message id found');
return undef;
}
unless ($dir =~ /\d\d\d\d\-\d\d\/arctxt/) {
Log::do_log('info', 'Dir %s look unproper', $dir);
$log->syslog('info', 'Dir %s look unproper', $dir);
return undef;
}
unless (opendir(ARC, "$dir")) {
Log::do_log('info',
$log->syslog('info',
"archive::scan_dir_archive($dir, $msgid): unable to open dir $dir"
);
return undef;
......@@ -213,7 +215,7 @@ sub exist {
# return path for latest message distributed in the list
sub last_path {
Log::do_log('debug', '(%s)', @_);
$log->syslog('debug', '(%s)', @_);
my $list = shift;
return undef unless $list->is_archived();
......@@ -229,11 +231,11 @@ sub last_path {
sub load_html_message {
my %parameters = @_;
Log::do_log('debug2', $parameters{'file_path'});
$log->syslog('debug2', $parameters{'file_path'});
my %metadata;
unless (open ARC, $parameters{'file_path'}) {
Log::do_log(
$log->syslog(
'err',
'Failed to load message "%s": %m',
$parameters{'file_path'}
......@@ -265,7 +267,7 @@ sub load_html_message {
}
sub clean_archive_directory {
Log::do_log('debug2', '(%s, %s)', @_);
$log->syslog('debug2', '(%s, %s)', @_);
my $robot = shift;
my $dir_to_rebuild = shift;
......@@ -279,7 +281,7 @@ sub clean_archive_directory {
$answer->{'cleaned_dir'}
)
) {
Log::do_log(
$log->syslog(
'err',
'Unable to create a temporary directory where to store files for HTML escaping (%s). Cancelling',
$number_of_copies
......@@ -299,13 +301,13 @@ sub clean_archive_directory {
}
closedir DIR;
if ($files_left_uncleaned) {
Log::do_log('err',
$log->syslog('err',
'HTML cleaning failed for %s files in the directory %s',
$files_left_uncleaned, $answer->{'dir_to_rebuild'});
}
$answer->{'dir_to_rebuild'} = $answer->{'cleaned_dir'};
} else {
Log::do_log(
$log->syslog(
'err',
'Unable to open directory %s: %m',
$answer->{'dir_to_rebuild'}
......@@ -317,7 +319,7 @@ sub clean_archive_directory {
}
sub clean_archived_message {
Log::do_log('debug2', '(%s, %s, %s)', @_);
$log->syslog('debug2', '(%s, %s, %s)', @_);
my $robot = shift;
my $list = shift;
my $input = shift;
......@@ -326,7 +328,7 @@ sub clean_archived_message {
my $message =
Sympa::Message->new_from_file($input, context => ($list || $robot),);
unless ($message) {
Log::do_log('err', 'Unable to create a Message object with file %s',
$log->syslog('err', 'Unable to create a Message object with file %s',
$input);
return undef;
}
......@@ -337,7 +339,7 @@ sub clean_archived_message {
close TMP;
return 1;
} else {
Log::do_log(
$log->syslog(
'err',
'Unable to create a tmp file to write clean HTML to file %s',
$output
......@@ -345,7 +347,7 @@ sub clean_archived_message {
return undef;
}
} else {
Log::do_log('err', 'HTML cleaning in file %s failed', $output);
$log->syslog('err', 'HTML cleaning in file %s failed', $output);
return undef;
}
}
......@@ -395,20 +397,20 @@ sub convert_single_message {
my $mhonarc_ressources =
tools::search_fullpath($that, 'mhonarc-ressources.tt2');
unless ($mhonarc_ressources) {
Log::do_log('notice', 'Cannot find any MhOnArc ressource file');
$log->syslog('notice', 'Cannot find any MhOnArc ressource file');
return undef;
}
unless (-d $destination_dir) {
unless (Sympa::Tools::File::mkdir_all($destination_dir, 0755)) {
Log::do_log('err', 'Unable to create %s', $destination_dir);
$log->syslog('err', 'Unable to create %s', $destination_dir);
return undef;
}
}
my $msg_file = $destination_dir . '/msg00000.txt';
unless (open OUT, '>', $msg_file) {
Log::do_log('notice', 'Could Not open %s', $msg_file);
$log->syslog('notice', 'Could Not open %s', $msg_file);
return undef;
}
print OUT $msg_as_string;
......@@ -419,7 +421,7 @@ sub convert_single_message {
## generate HTML
unless (chdir $destination_dir) {
Log::do_log('err', 'Could not change working directory to %s',
$log->syslog('err', 'Could not change working directory to %s',
$destination_dir);
return undef;
}
......@@ -446,7 +448,7 @@ sub convert_single_message {
chdir $pwd;
if ($exitcode) {
Log::do_log(
$log->syslog(
'err',
'Command %s failed with exit code %d',
Conf::get_robot_conf($robot, 'mhonarc'), $exitcode
......
......@@ -31,7 +31,7 @@ use POSIX qw();
use Conf;
use Sympa::Database;
use Log;
use Sympa::Log;
use Sympa::Report;
use Sympa::Robot;
use SDM;
......@@ -41,11 +41,13 @@ use Sympa::Tools::Data;
use Sympa::Tools::Time;
use Sympa::User;
my $log = Sympa::Log->instance;
## return the password finger print (this proc allow futur replacement of md5
## by sha1 or ....)
sub password_fingerprint {
Log::do_log('debug', '');
$log->syslog('debug', '');
my $pwd = shift;
if (Conf::get_robot_conf('*', 'password_case') eq 'insensitive') {
......@@ -60,7 +62,7 @@ sub check_auth {
my $robot = shift;
my $auth = shift; ## User email or UID
my $pwd = shift; ## Password
Log::do_log('debug', '(%s)', $auth);
$log->syslog('debug', '(%s)', $auth);
my ($canonic, $user);
......@@ -90,7 +92,7 @@ sub check_auth {
} else {
Sympa::Report::reject_report_web('user', 'incorrect_passwd', {})
unless ($ENV{'SYMPA_SOAP'});
Log::do_log('err', "Incorrect LDAP password");
$log->syslog('err', "Incorrect LDAP password");
return undef;
}
}
......@@ -127,7 +129,7 @@ sub may_use_sympa_native_auth {
sub authentication {
my ($robot, $email, $pwd) = @_;
my ($user, $canonic);
Log::do_log('debug', '(%s)', $email);
$log->syslog('debug', '(%s)', $email);
unless ($user = Sympa::User::get_global_user($email)) {
$user = {'email' => $email};
......@@ -143,7 +145,7 @@ sub authentication {
{wrong_login_count => $user->{'wrong_login_count'} + 1});
Sympa::Report::reject_report_web('user', 'too_many_wrong_login', {})
unless ($ENV{'SYMPA_SOAP'});
Log::do_log('err',
$log->syslog('err',
'Login is blocked: too many wrong password submission for %s',
$email);
return undef;
......@@ -195,7 +197,7 @@ sub authentication {
Sympa::Report::reject_report_web('user', 'incorrect_passwd', {})
unless ($ENV{'SYMPA_SOAP'});
Log::do_log('err', 'Incorrect password for user %s', $email);
$log->syslog('err', 'Incorrect password for user %s', $email);
my $param; #FIXME FIXME: not used.
$param->{'init_email'} = $email;
......@@ -206,8 +208,8 @@ sub authentication {
sub ldap_authentication {
my ($robot, $ldap, $auth, $pwd, $whichfilter) = @_;
my $mesg;
Log::do_log('debug2', '(%s, %s, %s)', $auth, '****', $whichfilter);
Log::do_log('debug3', 'Password used: %s', $pwd);
$log->syslog('debug2', '(%s, %s, %s)', $auth, '****', $whichfilter);
$log->syslog('debug3', 'Password used: %s', $pwd);
unless (tools::search_fullpath($robot, 'auth.conf')) {
return undef;
......@@ -215,7 +217,7 @@ sub ldap_authentication {
## No LDAP entry is defined in auth.conf
if ($#{$Conf::Conf{'auth_services'}{$robot}} < 0) {
Log::do_log('notice', 'Skipping empty auth.conf');
$log->syslog('notice', 'Skipping empty auth.conf');
return undef;
}
......@@ -238,7 +240,7 @@ sub ldap_authentication {
my $db = Sympa::Database->new('LDAP', %$ldap);
unless ($db and $db->connect()) {
Log::do_log('err', 'Unable to connect to the LDAP server "%s"',
$log->syslog('err', 'Unable to connect to the LDAP server "%s"',
$ldap->{'host'});
return undef;
}
......@@ -252,7 +254,7 @@ sub ldap_authentication {
);
unless ($mesg and $mesg->count()) {
Log::do_log('notice',
$log->syslog('notice',
'No entry in the LDAP Directory Tree of %s for %s',
$ldap->{'host'}, $auth);
$db->disconnect();
......@@ -274,7 +276,7 @@ sub ldap_authentication {
);
unless ($db and $db->connect()) {
Log::do_log('err', 'Unable to connect to the LDAP server "%s"',
$log->syslog('err', 'Unable to connect to the LDAP server "%s"',
$ldap->{'host'});
return undef;
}
......@@ -288,7 +290,7 @@ sub ldap_authentication {
);
unless ($mesg and $mesg->count()) {
Log::do_log('notice', "No entry in the LDAP Directory Tree of %s",
$log->syslog('notice', "No entry in the LDAP Directory Tree of %s",
$ldap->{'host'});
$db->disconnect();
return undef;
......@@ -326,8 +328,8 @@ sub ldap_authentication {
$param->{'alt_emails'}{$alt} = $previous->{$alt};
}
$db->disconnect() or Log::do_log('notice', 'Unable to unbind');
Log::do_log('debug3', 'Canonic: %s', $canonic_email[0]);
$db->disconnect() or $log->syslog('notice', 'Unable to unbind');
$log->syslog('debug3', 'Canonic: %s', $canonic_email[0]);
## If the identifier provided was a valid email, return the provided
## email.
## Otherwise, return the canonical email guessed after the login.
......@@ -347,7 +349,7 @@ sub get_email_by_net_id {
my $auth_id = shift;
my $attributes = shift;
Log::do_log('debug', '(%s, %s)', $auth_id, $attributes->{'uid'});
$log->syslog('debug', '(%s, %s)', $auth_id, $attributes->{'uid'});
if (defined $Conf::Conf{'auth_services'}{$robot}[$auth_id]
{'internal_email_by_netid'}) {
......@@ -368,7 +370,7 @@ sub get_email_by_net_id {
my $db = Sympa::Database->new('LDAP', %$ldap);
unless ($db and $db->connect()) {
Log::do_log('err', 'Unable to connect to the LDAP server "%s"',
$log->syslog('err', 'Unable to connect to the LDAP server "%s"',
$ldap->{'host'});
return undef;
}
......@@ -388,7 +390,7 @@ sub get_email_by_net_id {
);
unless ($mesg and $mesg->count()) {
Log::do_log('notice', "No entry in the LDAP Directory Tree of %s",
$log->syslog('notice', "No entry in the LDAP Directory Tree of %s",
$ldap->{'host'});
$db->disconnect();
return undef;
......@@ -408,7 +410,7 @@ sub get_email_by_net_id {
# undef;
sub remote_app_check_password {
my ($trusted_application_name, $password, $robot, $service) = @_;
Log::do_log('debug', '(%s, %s, %s)', $trusted_application_name, $robot,
$log->syslog('debug', '(%s, %s, %s)', $trusted_application_name, $robot,
$service);
my $md5 = Digest::MD5::md5_hex($password);
......@@ -423,7 +425,7 @@ sub remote_app_check_password {
if (lc($application->{'name'}) eq lc($trusted_application_name)) {
if ($md5 eq $application->{'md5password'}) {
# Log::do_log('debug', 'Authentication succeed for %s',$application->{'name'});
# $log->syslog('debug', 'Authentication succeed for %s',$application->{'name'});
my %proxy_for_vars;
my %set_vars;
foreach my $varname (@{$application->{'proxy_for_variables'}})
......@@ -439,7 +441,7 @@ sub remote_app_check_password {
return (\%proxy_for_vars, \%set_vars)
if $cmdname eq $service;
}
Log::do_log(
$log->syslog(
'info', 'Illegal command %s received from %s',
$service, $trusted_application_name
);
......@@ -447,14 +449,14 @@ sub remote_app_check_password {
}
return (\%proxy_for_vars, \%set_vars);
} else {
Log::do_log('info', 'Bad password from %s',
$log->syslog('info', 'Bad password from %s',
$trusted_application_name);
return;
}
}
}
# no matching application found
Log::do_log('info', 'Unknown application name %s',
$log->syslog('info', 'Unknown application name %s',
$trusted_application_name);
return;
}
......@@ -469,7 +471,7 @@ sub create_one_time_ticket {
## Value may be 'mail' if the IP address is not known
my $ticket = Sympa::Session::get_random();
#Log::do_log('info', '(%s, %s, %s, %s) Value = %s',
#$log->syslog('info', '(%s, %s, %s, %s) Value = %s',
# $email, $robot, $data_string, $remote_addr, $ticket);
my $date = time;
......@@ -487,7 +489,7 @@ sub create_one_time_ticket {
$remote_addr, 'open'
)
) {
Log::do_log(
$log->syslog(
'err',
'Unable to insert new one time ticket for user %s, robot %s in the database',
$email,
......@@ -500,7 +502,7 @@ sub create_one_time_ticket {
# read one_time_ticket from table and remove it
sub get_one_time_ticket {
Log::do_log('debug2', '(%s, %s, %s)', @_);
$log->syslog('debug2', '(%s, %s, %s)', @_);
my $robot = shift;
my $ticket_number = shift;
my $addr = shift;
......@@ -521,7 +523,7 @@ sub get_one_time_ticket {
$ticket_number, $robot
)
) {
Log::do_log('err',
$log->syslog('err',
'Unable to retrieve one time ticket %s from database',
$ticket_number);
return {'result' => 'error'};
......@@ -531,7 +533,7 @@ sub get_one_time_ticket {
$sth->finish;
unless ($ticket) {
Log::do_log('info', 'Unable to find one time ticket %s', $ticket);
$log->syslog('info', 'Unable to find one time ticket %s', $ticket);
return {'result' => 'not_found'};
}
......@@ -546,17 +548,17 @@ sub get_one_time_ticket {
if ($lockout eq 'one_time' and $ticket->{'status'} ne 'open') {
$result = 'closed';
Log::do_log('info', 'Ticket %s from %s has been used before (%s)',
$log->syslog('info', 'Ticket %s from %s has been used before (%s)',
$ticket_number, $ticket->{'email'}, $printable_date);
} elsif ($lockout eq 'remote_addr'
and $ticket->{'status'} ne $addr
and $ticket->{'status'} ne 'open') {
$result = 'closed';
Log::do_log('info',
$log->syslog('info',
'ticket %s from %s refused because accessed by the other (%s)',
$ticket_number, $ticket->{'email'}, $printable_date);
} elsif ($lifetime and $ticket->{'date'} + $lifetime < time) {
Log::do_log('info', 'Ticket %s from %s refused because expired (%s)',
$log->syslog('info', 'Ticket %s from %s refused because expired (%s)',
$ticket_number, $ticket->{'email'}, $printable_date);
$result = 'expired';
} else {
......@@ -573,18 +575,18 @@ sub get_one_time_ticket {
$addr, $ticket_number, $robot
)
) {
Log::do_log('err',
$log->syslog('err',
'Unable to set one time ticket %s status to %s',
$ticket_number, $addr);
} elsif (!$sth->rows) {
# ticket may be removed by task.
Log::do_log('info', 'Unable to find one time ticket %s',
$log->syslog('info', 'Unable to find one time ticket %s',
$ticket_number);
return {'result' => 'not_found'};
}
}
Log::do_log('info', 'Ticket: %s; Result: %s', $ticket_number, $result);
$log->syslog('info', 'Ticket: %s; Result: %s', $ticket_number, $result);
return {
'result' => $result,
'date' => $ticket->{'date'},
......
......@@ -34,11 +34,13 @@ use Time::HiRes qw();
use Conf;
use Sympa::Constants;
use Sympa::LockedFile;
use Log;
use Sympa::Log;
use Sympa::Message;