[Postfix, Web] Feature: Show last SMTP login

This commit is contained in:
andryyy
2020-09-15 11:02:53 +02:00
parent 28041b1d97
commit 1f36ae28d4
7 changed files with 49 additions and 7 deletions

View File

@@ -25,6 +25,7 @@ RUN groupadd -g 102 postfix \
postfix \
postfix-mysql \
postfix-pcre \
redis-tools \
sasl2-bin \
sudo \
supervisor \
@@ -44,6 +45,7 @@ COPY postfix.sh /opt/postfix.sh
COPY rspamd-pipe-ham /usr/local/bin/rspamd-pipe-ham
COPY rspamd-pipe-spam /usr/local/bin/rspamd-pipe-spam
COPY whitelist_forwardinghosts.sh /usr/local/bin/whitelist_forwardinghosts.sh
COPY smtpd_last_login.sh /usr/local/bin/smtpd_last_login.sh
COPY stop-supervisor.sh /usr/local/sbin/stop-supervisor.sh
COPY docker-entrypoint.sh /docker-entrypoint.sh
@@ -51,6 +53,7 @@ RUN chmod +x /opt/postfix.sh \
/usr/local/bin/rspamd-pipe-ham \
/usr/local/bin/rspamd-pipe-spam \
/usr/local/bin/whitelist_forwardinghosts.sh \
/usr/local/bin/smtpd_last_login.sh \
/usr/local/sbin/stop-supervisor.sh
RUN rm -rf /tmp/* /var/tmp/*

View File

@@ -0,0 +1,20 @@
#!/bin/bash
# Do not attempt to write to slave
if [[ ! -z ${REDIS_SLAVEOF_IP} ]]; then
REDIS_CMDLINE="redis-cli -h ${REDIS_SLAVEOF_IP} -p ${REDIS_SLAVEOF_PORT}"
else
REDIS_CMDLINE="redis-cli -h redis -p 6379"
fi
while read QUERY; do
QUERY=($QUERY)
# If nothing matched, end here - Postfix last line will be empty
if [[ -z "$(echo ${QUERY[0]} | tr -d '\040\011\012\015')" ]]; then
echo -ne "action=dunno\n\n"
# We found a username, log and return
elif [[ "${QUERY[0]}" =~ sasl_username ]]; then
${REDIS_CMDLINE} SET "last-login/smtp/$(echo ${QUERY[0]#sasl_username=})" "$(date +%s)"
echo -ne "action=dunno\n\n"
fi
done