Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mailinabox
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
mailinabox
Commits
ae1b56d2
Commit
ae1b56d2
authored
Jun 10, 2016
by
Rinze
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added POP3 support to mail log management script
parent
946cd63e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
6 deletions
+19
-6
mail_log.py
management/mail_log.py
+19
-6
No files found.
management/mail_log.py
View file @
ae1b56d2
...
@@ -23,10 +23,12 @@ def scan_mail_log(logger, env):
...
@@ -23,10 +23,12 @@ def scan_mail_log(logger, env):
collector
=
{
collector
=
{
"other-services"
:
set
(),
"other-services"
:
set
(),
"imap-logins"
:
{},
"imap-logins"
:
{},
"pop3-logins"
:
{},
"postgrey"
:
{},
"postgrey"
:
{},
"rejected-mail"
:
{},
"rejected-mail"
:
{},
"activity-by-hour"
:
{
"activity-by-hour"
:
{
"imap-logins"
:
defaultdict
(
int
),
"imap-logins"
:
defaultdict
(
int
),
"pop3-logins"
:
defaultdict
(
int
),
"smtp-sends"
:
defaultdict
(
int
),
"smtp-sends"
:
defaultdict
(
int
),
},
},
"real_mail_addresses"
:
(
"real_mail_addresses"
:
(
...
@@ -44,11 +46,18 @@ def scan_mail_log(logger, env):
...
@@ -44,11 +46,18 @@ def scan_mail_log(logger, env):
if
collector
[
"imap-logins"
]:
if
collector
[
"imap-logins"
]:
logger
.
add_heading
(
"Recent IMAP Logins"
)
logger
.
add_heading
(
"Recent IMAP Logins"
)
logger
.
print_block
(
"The most recent login from each remote IP adddress is shown"
)
logger
.
print_block
(
"The most recent login from each remote IP adddress is shown
.
"
)
for
k
in
utils
.
sort_email_addresses
(
collector
[
"imap-logins"
],
env
):
for
k
in
utils
.
sort_email_addresses
(
collector
[
"imap-logins"
],
env
):
for
ip
,
date
in
sorted
(
collector
[
"imap-logins"
][
k
]
.
items
(),
key
=
lambda
kv
:
kv
[
1
]):
for
ip
,
date
in
sorted
(
collector
[
"imap-logins"
][
k
]
.
items
(),
key
=
lambda
kv
:
kv
[
1
]):
logger
.
print_line
(
k
+
"
\t
"
+
str
(
date
)
+
"
\t
"
+
ip
)
logger
.
print_line
(
k
+
"
\t
"
+
str
(
date
)
+
"
\t
"
+
ip
)
if
collector
[
"pop3-logins"
]:
logger
.
add_heading
(
"Recent POP3 Logins"
)
logger
.
print_block
(
"The most recent login from each remote IP adddress is shown."
)
for
k
in
utils
.
sort_email_addresses
(
collector
[
"pop3-logins"
],
env
):
for
ip
,
date
in
sorted
(
collector
[
"pop3-logins"
][
k
]
.
items
(),
key
=
lambda
kv
:
kv
[
1
]):
logger
.
print_line
(
k
+
"
\t
"
+
str
(
date
)
+
"
\t
"
+
ip
)
if
collector
[
"postgrey"
]:
if
collector
[
"postgrey"
]:
logger
.
add_heading
(
"Greylisted Mail"
)
logger
.
add_heading
(
"Greylisted Mail"
)
logger
.
print_block
(
"The following mail was greylisted, meaning the emails were temporarily rejected. "
logger
.
print_block
(
"The following mail was greylisted, meaning the emails were temporarily rejected. "
...
@@ -70,11 +79,14 @@ def scan_mail_log(logger, env):
...
@@ -70,11 +79,14 @@ def scan_mail_log(logger, env):
logger
.
print_line
(
k
+
"
\t
"
+
str
(
date
)
+
"
\t
"
+
sender
+
"
\t
"
+
message
)
logger
.
print_line
(
k
+
"
\t
"
+
str
(
date
)
+
"
\t
"
+
sender
+
"
\t
"
+
message
)
logger
.
add_heading
(
"Activity by Hour"
)
logger
.
add_heading
(
"Activity by Hour"
)
logger
.
print_block
(
"Logins and sent mail per hour."
)
logger
.
print_block
(
"Hour
\t
IMAP
\t
POP3
\t
Sent"
)
for
h
in
range
(
24
):
for
h
in
range
(
24
):
logger
.
print_line
(
logger
.
print_line
(
"
%
d
\t
%
d
\t
%
d"
%
(
"
%
d
\t
%
d
\t
\t
%
d
\t\t
%
d"
%
(
h
,
h
,
collector
[
"activity-by-hour"
][
"imap-logins"
][
h
],
collector
[
"activity-by-hour"
][
"imap-logins"
][
h
],
collector
[
"activity-by-hour"
][
"pop3-logins"
][
h
],
collector
[
"activity-by-hour"
][
"smtp-sends"
][
h
]
collector
[
"activity-by-hour"
][
"smtp-sends"
][
h
]
)
)
)
)
...
@@ -114,13 +126,14 @@ def scan_mail_log_line(line, collector):
...
@@ -114,13 +126,14 @@ def scan_mail_log_line(line, collector):
def
scan_dovecot_line
(
date
,
line
,
collector
):
def
scan_dovecot_line
(
date
,
line
,
collector
):
""" Scan a dovecot log line and extract interesting data """
""" Scan a dovecot log line and extract interesting data """
m
=
re
.
match
(
"
imap
-login: Login: user=<(.*?)>, method=PLAIN, rip=(.*?),"
,
line
)
m
=
re
.
match
(
"
(imap|pop3)
-login: Login: user=<(.*?)>, method=PLAIN, rip=(.*?),"
,
line
)
if
m
:
if
m
:
login
,
ip
=
m
.
group
(
1
),
m
.
group
(
2
)
prot
,
login
,
ip
=
m
.
group
(
1
),
m
.
group
(
2
),
m
.
group
(
3
)
logins_key
=
"
%
s-logins"
%
prot
if
ip
!=
"127.0.0.1"
:
# local login from webmail/zpush
if
ip
!=
"127.0.0.1"
:
# local login from webmail/zpush
collector
[
"imap-logins"
]
.
setdefault
(
login
,
{})[
ip
]
=
date
collector
[
logins_key
]
.
setdefault
(
login
,
{})[
ip
]
=
date
collector
[
"activity-by-hour"
][
"imap-logins"
][
date
.
hour
]
+=
1
collector
[
"activity-by-hour"
][
logins_key
][
date
.
hour
]
+=
1
def
scan_postgrey_line
(
date
,
log
,
collector
):
def
scan_postgrey_line
(
date
,
log
,
collector
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment