X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=bin%2FBackupPC_sendEmail;h=055884a447e5e1f631aadc92b04e803e4f410311;hp=802b8f017553cf92e8b6db6c757b7e1969889418;hb=5b79f9a3c01bca16dd4d211e76fc53daa549e421;hpb=c2b072c9ad558447fb73fedf0cad170214b7d80e diff --git a/bin/BackupPC_sendEmail b/bin/BackupPC_sendEmail index 802b8f0..055884a 100755 --- a/bin/BackupPC_sendEmail +++ b/bin/BackupPC_sendEmail @@ -13,7 +13,7 @@ # Craig Barratt # # COPYRIGHT -# Copyright (C) 2001-2003 Craig Barratt +# Copyright (C) 2001-2007 Craig Barratt # # 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 @@ -31,7 +31,7 @@ # #======================================================================== # -# Version 3.0.0, released 28 Jan 2007. +# Version 3.1.0, released 25 Nov 2007. # # See http://backuppc.sourceforge.net. # @@ -42,6 +42,7 @@ no utf8; use lib "/usr/local/BackupPC/lib"; use BackupPC::Lib; use BackupPC::FileZIO; +use Encode; use Data::Dumper; use Getopt::Std; @@ -120,99 +121,37 @@ EOF exit(0); } -########################################################################### -# Generate sysadmin warning messages -########################################################################### -my $mesg = ""; - -my @badHosts = (); -foreach my $host ( sort(keys(%Status)) ) { - next if ( ($Status{$host}{reason} ne "Reason_backup_failed" - && $Status{$host}{reason} ne "Reason_restore_failed") - || $Status{$host}{error} =~ /^lost network connection to host/ ); - push(@badHosts, "$host ($Status{$host}{error})"); -} -if ( @badHosts ) { - my $badHosts = join("\n - ", sort(@badHosts)); - $mesg .= < 0 ) { - my $n = $Info{DUDailySkipHostCntPrev}; - my $m = $Conf{DfMaxUsagePct}; - $mesg .= <new("$TopDir/pc") or die("Can't read $TopDir/pc: $!"); -my @oldDirs = (); -my @files = $d->read; -$d->close; -foreach my $host ( @files ) { - next if ( $host =~ /^\./ || defined($Status{$host}) ); - push(@oldDirs, "$TopDir/pc/$host"); -} -if ( @oldDirs ) { - my $oldDirs = join("\n - ", sort(@oldDirs)); - $mesg .= <HostInfoRead(); +my @AdminBadHosts = (); foreach my $host ( sort(keys(%Status)) ) { - next if ( $Hosts->{$host}{user} eq "" ); # # read any per-PC config settings (allowing per-PC email settings) # $bpc->ConfigRead($host); %Conf = $bpc->Conf(); my $user = $Hosts->{$host}{user}; + + # + # Accumulate host errors for the admin email below + # + if ( ($Status{$host}{reason} eq "Reason_backup_failed" + || $Status{$host}{reason} eq "Reason_restore_failed") + && $Status{$host}{error} !~ /^lost network connection to host/ + && !$Conf{BackupsDisable} + ) { + push(@AdminBadHosts, "$host ($Status{$host}{error})"); + } + next if ( time - $UserEmailInfo{$user}{lastTime} - < $Conf{EMailNotifyMinDays} * 24*3600 ); - next if ($Conf{XferMethod} eq "archive" ); + < $Conf{EMailNotifyMinDays} * 24*3600 + || $Conf{XferMethod} eq "archive" + || $Conf{BackupsDisable} + || $Hosts->{$host}{user} eq "" + ); my @Backups = $bpc->BackupInfoRead($host); my $numBackups = @Backups; if ( $numBackups == 0 ) { @@ -326,6 +265,80 @@ foreach my $host ( sort(keys(%Status)) ) { }) if ( !defined($Jobs{$host}) ); } } + +########################################################################### +# Generate sysadmin warning message +########################################################################### +my $adminMesg = ""; + +if ( @AdminBadHosts ) { + my $badHosts = join("\n - ", sort(@AdminBadHosts)); + $adminMesg .= < 0 ) { + my $n = $Info{DUDailySkipHostCntPrev}; + my $m = $Conf{DfMaxUsagePct}; + $adminMesg .= <new("$TopDir/pc") or die("Can't read $TopDir/pc: $!"); +my @oldDirs = (); +my @files = $d->read; +$d->close; +foreach my $host ( @files ) { + next if ( $host =~ /^\./ || defined($Status{$host}) ); + push(@oldDirs, "$TopDir/pc/$host"); +} +if ( @oldDirs ) { + my $oldDirs = join("\n - ", sort(@oldDirs)); + $adminMesg .= <Dump( @@ -337,6 +350,7 @@ if ( !$opts{t} ) { close(HOST); } } +exit(0); sub user2name { @@ -350,6 +364,8 @@ sub user2name sub sendUserEmail { my($user, $host, $mesg, $subj, $vars) = @_; + return if ( $Conf{BackupsDisable} ); + $vars->{user} = $user; $vars->{host} = $host; $vars->{headers} = $Conf{EMailHeaders}; @@ -357,7 +373,7 @@ sub sendUserEmail $vars->{domain} = $Conf{EMailUserDestDomain}; $vars->{CgiURL} = $Conf{CgiURL}; $subj =~ s/\$(\w+)/defined($vars->{$1}) ? $vars->{$1} : "\$$1"/eg; - $vars->{subj} = $subj; + $vars->{subj} = $subj; $mesg =~ s/\$(\w+)/defined($vars->{$1}) ? $vars->{$1} : "\$$1"/eg; SendMail($mesg); $UserEmailInfo{$user}{lastTime} = time; @@ -375,6 +391,7 @@ sub SendMail if ( $opts{t} ) { binmode(STDOUT, ":utf8") if ( $utf8 ); + print("#" x 75, "\n"); print $mesg; return; @@ -386,7 +403,13 @@ sub SendMail printf("Can't run sendmail ($Conf{SendmailPath}): $!\n"); return; } - binmode(MAIL, ":utf8") if ( $utf8 ); + if ( $utf8 ) { + binmode(MAIL, ":utf8"); + if ($mesg =~ /^Subject: (.*)$/m) { + my $new_subj = encode('MIME-Header', $1); + $mesg =~ s/^Subject: .*$/Subject: $new_subj/m; + } + } print MAIL $mesg; close(MAIL); }