Skip to content

Commit 8bef931

Browse files
authored
v.1.8.4 update
1 parent a5609c2 commit 8bef931

File tree

19 files changed

+190
-106
lines changed

19 files changed

+190
-106
lines changed

CHANGES.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ Unreleased VER.
1212
- provide variables in .env for user defined parser regexps override
1313
- parse log file from the new lines since last parsing
1414

15+
Ver. 1.8.4
16+
- ~~GUI: add ability to config gui max log show interval (now it is 3 days) by .env variable~~
17+
- ~~BUG: gui add non-breaking space ( ) instead of space in multiple recipients row between number and recipient~~
18+
- ~~BUG: add flex-wrap: nowrap; to .multiple_with_aliases .multiple_mailtos to create proper vertical column of recipients in #mail_to_details~~
19+
- ~~BUG: mobile narrow gui users edit page fix~~
20+
- ~~BUG: add error handler for overlimit query (if query output is overlimit RETHINK_ARR_LIMIT env var)~~
21+
- ~~GUI: add ability to turn off gui parser operating block (by .env variable)~~
22+
- ~~GUI: remove > [...] in tips modal~~
23+
- ~~dependabot security fix (python 3.9, quart 0.20.0, werkzeug 3.0.6)~~
24+
- ~~BUG: in user edit menu changing gui settings cause infinite loading circle~~
25+
- ~~BUG: add ability to set length of date string in log file to extract timestamp (by .env variable)~~
26+
1527
VER. 1.8.3
1628
- ~~BUG: multipe recipients view in mobile narrow gui~~
1729
- ~~BUG: block also autorefresh in case of GUI blocking while parsing~~

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Dockerfile for deploy
2-
FROM python:3.8-alpine
2+
FROM python:3.9-alpine
33
RUN apk update
44
RUN apk add bash ncurses musl-dev gcc flock openldap-dev
55
# upgrade pip
@@ -10,4 +10,4 @@ COPY Pipfile /app/
1010
# uncomment to append ypur ca cert for TLS connections i.e. LDAPS
1111
#COPY ca.crt /usr/local/share/ca-certificates/ca.crt
1212
#RUN cat /usr/local/share/ca-certificates/ca.crt >> /etc/ssl/certs/ca-certificates.crt
13-
RUN pipenv install
13+
RUN pipenv install

Pipfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ python-dateutil = "*"
1212
pytz = "*"
1313
rethinkdb = ">=2.4.7"
1414
python-dotenv = "*"
15-
quart = "=0.19.4"
16-
werkzeug = "=3.0.3"
15+
quart = "=0.20.0"
16+
werkzeug = "=3.0.6"
1717
moment = "*"
1818
datefinder = "*"
1919
python-ldap = "*"

README.md

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -41,41 +41,35 @@ All maintained docker images could be found [here](https://hub.docker.com/r/drli
4141
- Docker.io (tested on 23.0.2)
4242
- Docker-compose (tested on 2.9.0)
4343

44-
45-
If you want to use complete image downloaded from docker hub (for production) then you don't have to git clone full repo. You will only need docker-compose.yaml from the root path and create .env file (see description below).
4644
```
45+
If you want to use complete image downloaded from docker hub (fro production) then you don't have to git clone full repo. You will only need docker-compose.yaml from the root path and create .env file (see decription below).
4746
git clone https://github.com/drlight17/mta-log-parser
4847
cd mta-log-parser
4948
cp example.env .env
50-
```
51-
If you want to build your image of mta-log-parser then copy Dockerfile and docker-compose.yaml files from build
52-
dir to the root path (recommended for development). If you want to use complete image downloaded from docker hub then pass this step (recommended for production).
53-
```
49+
50+
# If you want to build your image of mta-log-parser then copy Dockerfile and docker-compose.yaml files from build
51+
# dir to the root path (recommended for development). If you want to use complete image downloaded from docker hub then pass this step (recommended for production).
5452
yes | cp -rf ./build/Dockerfile ./Dockerfile
5553
yes | cp -rf ./build/docker-compose.yaml ./docker-compose.yaml
56-
```
57-
Adjust the example .env as needed. Make sure you set SECRET_KEY to a long random string
58-
to the password you want to use to log into the web application. Other variables are described.
59-
```
54+
55+
# Adjust the example .env as needed. Make sure you set SECRET_KEY to a long random string
56+
# to the password you want to use to log into the web application. Other variables are described.
6057
nano .env
61-
```
62-
To build and run app with web GUI run
63-
```
58+
59+
# To build and run app with web GUI run
6460
docker-compose up -d
65-
```
6661
67-
To stop app with web GUI app run
68-
```
62+
# To stop app with web GUI app run
6963
docker-compose down
70-
```
7164
72-
To schedule log parsing add to your crontab (every minute in example)
73-
```
65+
# To schedule log parsing add to your crontab (every minute in example)
7466
crontab -e
7567
*/1 * * * * docker exec -t mta-log-parser flock /tmp/lck_mlp /app/run.sh cron
76-
```
7768
7869
70+
71+
72+
```
7973
GUI access
8074
========
8175
Rethinkdb web gui is available on the port 8080 (you may change expose port in .env).
@@ -101,13 +95,13 @@ Simply run upgrade.sh
10195

10296
**Application will detect the finished upgrade procedure and will be forced to clear all cached data, cookies and will logout current user session!**
10397

104-
Install in your system (not recommended)
98+
Install in your system (not recommended as I provide **no support** for this type of usage (issues will be closed, questions will not be answered))
10599
========
106100

107101
**Pre-requirements**
108102

109103
- [RethinkDB](https://rethinkdb.com/) (for storing the queryable log data)
110-
- Python 3.7 MINIMUM (will not work on earlier versions)
104+
- Python 3.8 MINIMUM (will not work on earlier versions)
111105
- Pipenv (`python3 -m pip install pipenv`) - for creating a virtualenv + installing dependencies
112106

113107

@@ -119,9 +113,7 @@ apt install -y python3 python3-dev python3-pip libsasl2-dev python-dev-is-python
119113
python3 -m pip install -U pipenv
120114
121115
adduser --gecos "" --disabled-password mailparser
122-
```
123-
To ensure that the parser is able to read the mail.log, add the user to the appropriate groups
124-
```
116+
# To ensure that the parser is able to read the mail.log, add the user to the appropriate groups
125117
gpasswd -a mailparser syslog adm postfix
126118
127119
su - mailparser
@@ -131,29 +123,33 @@ cd mta-log-parser
131123
pipenv install
132124
133125
cp example.env .env
134-
```
135-
Adjust the example .env as needed. Make sure you set SECRET_KEY to a long random string
136-
to the password you want to use to log into the web application.
137-
```
126+
# Adjust the example .env as needed. Make sure you set SECRET_KEY to a long random string
127+
# to the password you want to use to log into the web application.
138128
nano .env
139-
```
140-
Add a crontab entry to run the parse/import script every minute or so
141-
You should use a file lock utility such as `flock` (included by default on Ubuntu) or `lckdo` to prevent the
142-
cron overlapping if there's a lot to parse.
143-
```
129+
130+
# Add a crontab entry to run the parse/import script every minute or so
131+
# You should use a file lock utility such as `flock` (included by default on Ubuntu) or `lckdo` to prevent the
132+
# cron overlapping if there's a lot to parse.
133+
144134
crontab -e
145135
# * * * * * flock /tmp/lck_mailparser /home/mailparser/mta-log-parser/run.sh cron
146-
```
147-
Development
148-
===========
149-
```
136+
137+
####
138+
# DEVELOPMENT
139+
####
140+
150141
./run.sh dev # Run the development server with automatic restart on edits
151142
./run.sh parse # Import MAIL_LOG immediately
152-
```
153143
154-
Production systemd service for the WebUI
155-
===================
156-
```
144+
####
145+
# PRODUCTION
146+
####
147+
148+
exit
149+
150+
# (AS ROOT)
151+
152+
# Production systemd service for the WebUI
157153
install -m 644 /home/mailparser/mta-log-parser/mta-log-parser.service /etc/systemd/system/
158154
systemctl daemon-reload
159155
systemctl enable mta-log-parser.service

build/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Dockerfile for building image
2-
FROM python:3.8-alpine
2+
FROM python:3.9-alpine
33
RUN apk update
44
RUN apk add bash ncurses musl-dev gcc flock openldap-dev
55
# upgrade pip

build/docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ networks:
4141
- subnet: "172.20.0.0/16"
4242
driver_opts:
4343
com.docker.network.enable_ipv6: "false"
44-
com.docker.network.bridge.name: mlp_iface
44+
com.docker.network.bridge.name: mlp_iface

deploy/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Dockerfile for deploy
2-
FROM python:3.8-alpine
2+
FROM python:3.9-alpine
33
RUN apk update
44
RUN apk add bash ncurses musl-dev gcc flock openldap-dev
55
# upgrade pip
@@ -10,4 +10,4 @@ COPY Pipfile /app/
1010
# uncomment to append ypur ca cert for TLS connections i.e. LDAPS
1111
#COPY ca.crt /usr/local/share/ca-certificates/ca.crt
1212
#RUN cat /usr/local/share/ca-certificates/ca.crt >> /etc/ssl/certs/ca-certificates.crt
13-
RUN pipenv install
13+
RUN pipenv install

deploy/docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ networks:
3838
- subnet: "172.20.0.0/16"
3939
driver_opts:
4040
com.docker.network.enable_ipv6: "false"
41-
com.docker.network.bridge.name: mlp_iface
41+
com.docker.network.bridge.name: mlp_iface

example.env

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ PORT=8487
4141
# make date time format (default is "HH:mm:ss, DD.MM.YYYY") to use in GUI for emails list timestamps and date picker according to moment.js templates (https://momentjs.com/)
4242
#DATETIME_FORMAT='HH:mm:ss, DD.MM.YYYY'
4343

44+
# set length of date time string in your log file to process by parser - eliminates many parsing errors, make sure to set properly so that parser won't get extra symbols to further process (20 chars by default)
45+
# for example if your date in log looks like '2025-02-15 00:00:03.474' value 20 will use '2025-02-15 00:00:03.' to extract datetime
46+
#DATETIME_INPUT_LENGTH = 20
47+
4448
# convert related logs timestamp according to the DATETIME_FORMAT. High CPU demanding! (false by default)
4549
#MAIL_LOG_TIMESTAMP_CONVERT=false
4650

@@ -54,7 +58,10 @@ PORT=8487
5458
#EXCLUDE_FROM_TOP_RECIPIENTS='[email protected],[email protected]'
5559

5660
# block GUI refresh while parser worker is running (true by default)
57-
GUI_REFRESH_BLOCK=true
61+
#GUI_REFRESH_BLOCK=false
62+
63+
# set GUI max log period in user setting menu (4320 minutes = 3 days by default)
64+
#GUI_MAX_LOG_PERIOD=4320
5865

5966
# set startup command
6067
# dev to run in python developer mode

mlp/main.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
# !!! change version upon update !!!
4747
global VERSION
48-
VERSION ="1.8.3"
48+
VERSION ="1.8.4"
4949

5050
lockfile = "processing.lock"
5151
# postf_match += r'([A-F0-9]{11})\:[ \t]+?(.*)'
@@ -63,7 +63,8 @@
6363
#exim_match += r'([0-9A-Za-z]{6}-[0-9A-Za-z]{6}-[0-9A-Za-z]{2}).(.+)'
6464
#exim_match += r'([0-9A-Za-z]{6}-[0-9A-Za-z]{6}-[0-9A-Za-z]{2}).(.+)'
6565
#exim_match = r'.*([0-9A-Za-z]{6}-[0-9A-Za-z]{6}-[0-9A-Za-z]{2}).(.+)'
66-
exim_match = r'([0-9A-Za-z]{6}-[0-9A-Za-z]{6}-[0-9A-Za-z]{2}).(.+)'
66+
#exim_match = r'([0-9A-Za-z]{6}-[0-9A-Za-z]{6}-[0-9A-Za-z]{2}).(.+)'
67+
exim_match = r'([0-9A-Za-z]{6}-[0-9A-Za-z]{6,11}-[0-9A-Za-z]{2,4})\s(.+)'
6768
"""Regex to match the (1) Message ID and the (2) Log Message"""
6869

6970
# sendmail regexp
@@ -189,7 +190,10 @@ async def import_log(logfile: str) -> Dict[str, PostfixMessage]:
189190
# TODO test new universal datetime extractor instead of regexps (cut first 20 symbols from the string)
190191
# change to line for exim
191192
#dtimes = datefinder.find_dates(m.group(0)[:20])
192-
dtimes = datefinder.find_dates(line[:20])
193+
# add datetime_input_length
194+
#dtimes = datefinder.find_dates(line[:20])
195+
dtimes = datefinder.find_dates(line[:settings.datetime_input_length])
196+
#print(dtimes)
193197
#print(line[:20])
194198

195199
for dtime in dtimes:
@@ -392,8 +396,18 @@ async def main():
392396
log.info('Housekeeping has deleted NOTHING. There are no emails %d day(s) ago or something went wrong.', housekeeping_days)
393397
else:
394398
log.info('Housekeeping is not configured so there will be no deletion of old data! Pay attention to the disk space!')
399+
400+
# TODO create log lines preparation function before call import_log (1.8.4???)
401+
'''log.info('Prepare %s log file', settings.mta)
402+
prepared_log = await prepare_log(settings.mail_log)
403+
404+
log.info('Importing %s log file', settings.mta)
405+
import_output = import_log(prepared_log)'''
406+
395407
log.info('Importing %s log file', settings.mta)
396408
import_output = await import_log(settings.mail_log)
409+
410+
397411
log.info('Converting %s log data into list',settings.mta)
398412
multiple_recipients_qids = import_output['multiple_recipients_qids']
399413
multiple_recipients = import_output['multiple_recipients']

0 commit comments

Comments
 (0)