X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=bin%2FBackupPC_sendEmail;h=5c33fae934bd423d49bdffe25fe0327f6214c2c9;hp=cb5c5331e34788335f27f2a66a9f2cea2eb80d62;hb=b81d2da5e16975674f011e4833337ac0fa24e0ea;hpb=d13d57e035dac9362ca393991b978530402969b7 diff --git a/bin/BackupPC_sendEmail b/bin/BackupPC_sendEmail index cb5c533..5c33fae 100755 --- a/bin/BackupPC_sendEmail +++ b/bin/BackupPC_sendEmail @@ -31,7 +31,7 @@ # #======================================================================== # -# Version 2.1.0, released 20 Jun 2004. +# Version 3.0.0beta2, released 11 Nov 2006. # # See http://backuppc.sourceforge.net. # @@ -46,10 +46,11 @@ use BackupPC::FileZIO; use Data::Dumper; use Getopt::Std; use DirHandle (); -use vars qw($Lang $TopDir $BinDir %Conf); +use vars qw($Lang $TopDir $BinDir $LogDir %Conf); die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) ); $TopDir = $bpc->TopDir(); +$LogDir = $bpc->LogDir(); $BinDir = $bpc->BinDir(); %Conf = $bpc->Conf(); $Lang = $bpc->Lang(); @@ -57,24 +58,68 @@ $Lang = $bpc->Lang(); $bpc->ChildInit(); use vars qw(%UserEmailInfo); -do "$TopDir/log/UserEmailInfo.pl"; +do "$LogDir/UserEmailInfo.pl"; my %opts; -if ( !getopts("t", \%opts) || @ARGV != 0 ) { - print("usage: $0 [-t]\n"); +if ( !getopts("ctu:", \%opts) || @ARGV != 0 ) { + print <ServerConnect($Conf{ServerHost}, $Conf{ServerPort}); if ( $err ) { + if ( $opts{c} && $Conf{EMailAdminUserName} ne "" ) { + my $headers = $Conf{EMailHeaders}; + $headers .= "\n" if ( $headers !~ /\n$/ ); + my $mesg = <ServerMesg("status hosts"); $reply = $1 if ( $reply =~ /(.*)/s ); my(%Status, %Info, %Jobs, @BgQueue, @UserQueue, @CmdQueue); eval($reply); +########################################################################### +# Generate test message if required +########################################################################### +if ( $opts{u} ne "" ) { + my $headers = $Conf{EMailHeaders}; + $headers .= "\n" if ( $headers !~ /\n$/ ); + my $mesg = < only fulls and incrs should be used + # in figuring out when the last good backup was + # + next if ( $Backups[$i]{type} eq "partial" ); $lastNum = $Backups[$i]{num} if ( $lastNum < $Backups[$i]{num} ); if ( $Backups[$i]{type} eq "full" ) { $lastFull = $Backups[$i]{startTime} @@ -284,7 +331,7 @@ if ( !$opts{t} ) { my $dumpStr = Data::Dumper->Dump( [\%UserEmailInfo], [qw(*UserEmailInfo)]); - if ( open(HOST, ">", "$TopDir/log/UserEmailInfo.pl") ) { + if ( open(HOST, ">", "$LogDir/UserEmailInfo.pl") ) { binmode(HOST); print(HOST $dumpStr); close(HOST); @@ -303,19 +350,16 @@ sub user2name sub sendUserEmail { my($user, $host, $mesg, $subj, $vars) = @_; - $vars->{user} = $user; - $vars->{host} = $host; - $vars->{domain} = $Conf{EMailUserDestDomain}; - $vars->{CgiURL} = $Conf{CgiURL}; + $vars->{user} = $user; + $vars->{host} = $host; + $vars->{headers} = $Conf{EMailHeaders}; + $vars->{headers} .= "\n" if ( $vars->{headers} !~ /\n$/ ); + $vars->{domain} = $Conf{EMailUserDestDomain}; + $vars->{CgiURL} = $Conf{CgiURL}; $subj =~ s/\$(\w+)/defined($vars->{$1}) ? $vars->{$1} : "\$$1"/eg; $vars->{subj} = $subj; $mesg =~ s/\$(\w+)/defined($vars->{$1}) ? $vars->{$1} : "\$$1"/eg; - if ( $opts{t} ) { - print("#" x 75, "\n"); - print $mesg; - } else { - SendMail($mesg); - } + SendMail($mesg); $UserEmailInfo{$user}{lastTime} = time; $UserEmailInfo{$user}{lastSubj} = $subj; $UserEmailInfo{$user}{lastHost} = $host; @@ -324,14 +368,25 @@ sub sendUserEmail sub SendMail { my($mesg) = @_; - my($from) = $Conf{EMailFromUserName}; + my $from = $Conf{EMailFromUserName}; + my $utf8 = 1 + if ( $Conf{EMailHeaders} =~ /Content-Type:.*charset="utf-?8"/i ); local(*MAIL); + if ( $opts{t} ) { + binmode(STDOUT, ":utf8") if ( $utf8 ); + print("#" x 75, "\n"); + print $mesg; + return; + } $from = "-f $from" if ( $from ne "" ); + print("Sending test email using $Conf{SendmailPath} -t $from\n") + if ( $opts{u} ne "" ); if ( !open(MAIL, "|$Conf{SendmailPath} -t $from") ) { printf("Can't run sendmail ($Conf{SendmailPath}): $!\n"); return; } + binmode(MAIL, ":utf8") if ( $utf8 ); print MAIL $mesg; close(MAIL); }