Leser: 19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
$cgierr->LogError( 'Ablaufdauer (gesamt): ' . scalar tv_interval( $t0 ) . ' Sekunden' ); # ====== # Benachrichtigung per E-Mail (Forking!) local $SIG{ CHLD } = 'IGNORE'; unless ( fork() ) { close STDERR; close STDOUT; close STDIN; my $mailprog = '/usr/sbin/sendmail'; if ( $status == 501 || $status == 500 || $status == 401 || $status == 404 || $status == 410 || $status == 403 ) { my @a = localtime( time ); # 0 1 2 3 4 5 6 7 8 #($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); my $t = sprintf( '%02d.%02d.%04d um %02d:%02d.%02d Uhr', $a[ 3 ], $a[ 4 ] + 1, $a[ 5 ] + 1900, $a[ 2 ], $a[ 1 ], $a[ 0 ] ); my $proxyip = ( # Proxy-IP $ENV{ 'HTTP_CLIENT_IP' } || $ENV{ 'HTTP_X_FORWARDED_FOR' } || $ENV{ 'HTTP_X_FORWARDED' } || $ENV{ 'HTTP_FORWARDED' } || $ENV{ 'HTTP_VIA' } || $ENV{ 'HTTP_X_COMING_FROM' } || $ENV{ 'HTTP_COMING_FROM' } ); my $remoteip = $ENV{ 'REMOTE_ADDR' } || '(unknown)'; $remoteip = "$proxyip,$remoteip" if defined $proxyip; # deutscher Datenschutz, kein IP-Logging $remoteip = '**NOIPLOGGING**'; $proxyip = $remoteip; $ENV{ 'HTTP_USER_AGENT' } ||= '(unknown)'; $ENV{ 'HTTP_REFERER' } ||= '(unknown)'; ${ Cgi::Error::URL } ||= '(unknown)'; $cgierr->AlertByMail( $mailprog, <<"MAIL"); To: Webadmin <webmaster\@${Cgi::Error::DOMAIN}> From: Webadmin <webmaster\@${Cgi::Error::DOMAIN}> Subject: Serverfehler $errnum - ${Cgi::Error::SUBDOMAIN} Meldung von Domain ${Cgi::Error::SUBDOMAIN} Fehler $errnum trat auf am: $t URL: ${Cgi::Error::URL} UserAgent: $ENV{'HTTP_USER_AGENT'} Referrer: $ENV{'HTTP_REFERER'} RemoteIP: $remoteip MAIL } # end if } #end fork 1;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
sub AlertByMail ($;$) { my ( $self, $mailprog, $msg ) = @_; warn('usage: $handler->AlertByMail($mailprog,$mail)') if $Cgi::Log::WARN and ref($self) ne __PACKAGE__; foreach my $mp ( $mailprog, '/bin/sendmail', '/usr/bin/sendmail', '/usr/sbin/sendmail', '/usr/lib/sendmail' ) { if (-x $mp) { $mailprog = $mp; last; } } if ( ! -x $mailprog ) { $self->LogError("$mailprog: no mailsending program found"); return; } if ( open( my $mh, "| $mailprog -t -oi" ) ) { print $mh "$msg" or do { $self->LogError("$mailprog: Mail can not be sent"); return; }; close( $mh ) or do { $self->LogError("$mailprog: Mail queue can not be closed $? # $!"); #$self->LogError("$mailprog: Mail queue can not be closed"); return; }; } else { $self->LogError("$mailprog: Mail queue can not be opened"); return; } return 1; }