- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
- 73
- 74
- 75
- 76
- 77
- 78
#!/usr/bin/perl -w
# apt install libdatetime-format-dateparse-perl libemail-sender-perl libemail-mime-perl
use warnings FATAL => 'all';
use strict;
use v5.28;
use utf8;
use Date::Parse;
use Date::Language;
use Date::Language::English;
use Socket;
use Email::Sender::Simple qw(sendmail);
use Email::Sender::Transport::SMTP qw();
use Email::MIME;
use Encode;
use constant FROM_MAIL => '[email protected]';
use constant TO_MAIL => 'postmaster';
# user->ip->error
my %errors;
my $dateLang = Date::Language->new('English');
my $yesterday = time() - 86400;
my %patterns = (
"Ошибка аутентификаици" => qr/.+Authentication failed for user (.+?)\. Attempt from IP address ([0-9.]+)\. (.+)$/,
"Попытка отправки с чужого адреса" => qr/.+Message from authenticated user: <([a-z.@]+)> was rejected, because sender identity was detected as spoofed. \(Source IP address: ([0-9.]+), (From header: <[.a-z@]+?>).*/,
);
while (<>) {
next unless m/^\[(.+)\](.+)/;
my $time = $dateLang->str2time($1);
next unless $time > $yesterday .. 0;
my $message = $2;
while ((my $error, my $regex) = each %patterns) {
next unless $message =~ m/$regex/;
$errors{$error}{$1}{$2}{$3} += 1;
}
}
exit 0 if !%errors;
my @message;
while ((my $error, my $userIpLogTimes) = each %errors) {
push @message, $error;
while ((my $user, my $ipLogTimes) = each %$userIpLogTimes) {
push @message, "\tПользователь $user";
while ((my $ip, my $logTimes) = each %$ipLogTimes) {
my $hostName = gethostbyaddr(inet_aton($ip), AF_INET) || $ip;
push @message, "\t\tс IP $ip ($hostName)";
while ((my $log, my $times) = each %$logTimes) {
push @message, "\t\t\t$times раз: $log";
}
}
}
}
my $email = Email::MIME->create(
attributes => {
content_type => "text/plain",
charset => "UTF-8",
},
header_str => [
From => FROM_MAIL,
To => [ TO_MAIL ],
Subject => 'Неудачи на почтовике за последние сутки',
],
body => encode('utf8', join "\n", @message));
sendmail(
$email,
{
from => FROM_MAIL,
to => TO_MAIL,
transport => Email::Sender::Transport::SMTP->new({ host => 'localhost' })
}
) || die 'Cant send';
guest6 29.07.2022 15:49 # 0
guest6 29.07.2022 16:09 # +1
Вот так и дикари разрушали античные статуи...
guest6 29.07.2022 20:06 # +1
ObeseYoungPidor 29.07.2022 21:10 # 0
ObeseYoungPidor 29.07.2022 21:12 # 0
Прыщебляди экономят на символах? Почему user не назвать папку?
Fike 29.07.2022 21:33 # +1
Добро пожаловать.
guest6 29.07.2022 22:28 # +1
nyTuH_nugop 29.07.2022 22:36 # 0
Fike 29.07.2022 23:31 # 0
Da_xyu_BAC_PA36EPET 30.07.2022 01:26 # 0
CBuHOCO6AKA 30.07.2022 00:20 # 0
ObeseYoungPidor 29.07.2022 21:22 # 0
Support 30.07.2022 01:26 # 0