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
1eba7b06
Commit
1eba7b06
authored
Feb 24, 2018
by
Joshua Tauberer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
send the mail_log.py report to the box admin every Monday
parent
9c7820f4
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
12 deletions
+38
-12
CHANGELOG.md
CHANGELOG.md
+1
-0
daily_tasks.sh
management/daily_tasks.sh
+6
-0
email_administrator.py
management/email_administrator.py
+21
-3
mail_log.py
management/mail_log.py
+10
-9
No files found.
CHANGELOG.md
View file @
1eba7b06
...
...
@@ -4,6 +4,7 @@ CHANGELOG
In Development
--------------
*
A report of box activity, including sent/received mail totals and logins by user, is now emailed to the box's administrator user each week.
*
Update Roundcube to version 1.3.4 and Z-Push to version 2.3.9.
*
The undocumented feature for proxying web requests to another server now sets X-Forwarded-For.
...
...
management/daily_tasks.sh
View file @
1eba7b06
...
...
@@ -9,6 +9,12 @@ export LC_ALL=en_US.UTF-8
export
LANG
=
en_US.UTF-8
export
LC_TYPE
=
en_US.UTF-8
# On Mondays, i.e. once a week, send the administrator a report of total emails
# sent and received so the admin might notice server abuse.
if
[
`
date
"+%u"
`
-eq
1
]
;
then
management/mail_log.py
-t
week | management/email_administrator.py
"Mail-in-a-Box Usage Report"
fi
# Take a backup.
management/backup.py | management/email_administrator.py
"Backup Status"
...
...
management/email_administrator.py
View file @
1eba7b06
...
...
@@ -4,8 +4,14 @@
import
sys
import
html
import
smtplib
from
email.message
import
Message
from
email.mime.multipart
import
MIMEMultipart
from
email.mime.text
import
MIMEText
# In Python 3.6:
#from email.message import Message
from
utils
import
load_environment
...
...
@@ -26,11 +32,23 @@ if content == "":
sys
.
exit
(
0
)
# create MIME message
msg
=
Message
()
msg
=
MIMEMultipart
(
'alternative'
)
# In Python 3.6:
#msg = Message()
msg
[
'From'
]
=
"
\"
%
s
\"
<
%
s>"
%
(
env
[
'PRIMARY_HOSTNAME'
],
admin_addr
)
msg
[
'To'
]
=
admin_addr
msg
[
'Subject'
]
=
"[
%
s]
%
s"
%
(
env
[
'PRIMARY_HOSTNAME'
],
subject
)
msg
.
set_payload
(
content
,
"UTF-8"
)
content_html
=
"<html><body><pre>{}</pre></body></html>"
.
format
(
html
.
escape
(
content
))
msg
.
attach
(
MIMEText
(
content
,
'plain'
))
msg
.
attach
(
MIMEText
(
content_html
,
'html'
))
# In Python 3.6:
#msg.set_content(content)
#msg.add_alternative(content_html, "html")
# send
smtpclient
=
smtplib
.
SMTP
(
'127.0.0.1'
,
25
)
...
...
management/mail_log.py
View file @
1eba7b06
...
...
@@ -76,6 +76,7 @@ def scan_files(collector):
tmp_file
=
tempfile
.
NamedTemporaryFile
()
shutil
.
copyfileobj
(
gzip
.
open
(
fn
),
tmp_file
)
if
VERBOSE
:
print
(
"Processing file"
,
fn
,
"..."
)
fn
=
tmp_file
.
name
if
tmp_file
else
fn
...
...
@@ -119,8 +120,8 @@ def scan_mail_log(env):
except
ImportError
:
pass
print
(
"Scanning
from {:
%
Y-
%
m-
%
d
%
H:
%
M:
%
S} back
to {:
%
Y-
%
m-
%
d
%
H:
%
M:
%
S}"
.
format
(
START_DATE
,
END
_DATE
)
print
(
"Scanning
logs from {:
%
Y-
%
m-
%
d
%
H:
%
M:
%
S}
to {:
%
Y-
%
m-
%
d
%
H:
%
M:
%
S}"
.
format
(
END_DATE
,
START
_DATE
)
)
# Scan the lines in the log files until the date goes out of range
...
...
@@ -138,8 +139,8 @@ def scan_mail_log(env):
# Print Sent Mail report
if
collector
[
"sent_mail"
]:
msg
=
"Sent email
between {:
%
Y-
%
m-
%
d
%
H:
%
M:
%
S} and {:
%
Y-
%
m-
%
d
%
H:
%
M:
%
S}
"
print_header
(
msg
.
format
(
END_DATE
,
START_DATE
)
)
msg
=
"Sent email"
print_header
(
msg
)
data
=
OrderedDict
(
sorted
(
collector
[
"sent_mail"
]
.
items
(),
key
=
email_sort
))
...
...
@@ -173,8 +174,8 @@ def scan_mail_log(env):
# Print Received Mail report
if
collector
[
"received_mail"
]:
msg
=
"Received email
between {:
%
Y-
%
m-
%
d
%
H:
%
M:
%
S} and {:
%
Y-
%
m-
%
d
%
H:
%
M:
%
S}
"
print_header
(
msg
.
format
(
END_DATE
,
START_DATE
)
)
msg
=
"Received email"
print_header
(
msg
)
data
=
OrderedDict
(
sorted
(
collector
[
"received_mail"
]
.
items
(),
key
=
email_sort
))
...
...
@@ -202,8 +203,8 @@ def scan_mail_log(env):
# Print login report
if
collector
[
"logins"
]:
msg
=
"User logins per hour
between {:
%
Y-
%
m-
%
d
%
H:
%
M:
%
S} and {:
%
Y-
%
m-
%
d
%
H:
%
M:
%
S}
"
print_header
(
msg
.
format
(
END_DATE
,
START_DATE
)
)
msg
=
"User logins per hour"
print_header
(
msg
)
data
=
OrderedDict
(
sorted
(
collector
[
"logins"
]
.
items
(),
key
=
email_sort
))
...
...
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