diff --git a/README.md b/README.md index 78fe82f..7f30580 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,8 @@ Configure DKIM signing maps by replacing the example hostname and token in `/etc The authenticated-user ratelimit map is configured in `/etc/rspamd/custom_ratelimit.lua`; replace its example hostname and token with your map endpoint settings. Accounts registered within the last 14 days receive lower sending limits. A mailbox marked as trusted in the admin editor receives higher limits; other authenticated mailboxes receive the default limits. +Postfix updates a mailbox's `last_login` timestamp when an authenticated SMTP session reaches the `MAIL FROM` command. Install the policy script at `/var/www/mail/tools/postfix_last_login_policy.php` and reload Postfix after updating `/etc/postfix/main.cf` and `/etc/postfix/master.cf`. An SMTP session that authenticates but disconnects before `MAIL FROM` cannot be recorded by this policy hook. + Create a password used for your TURN server and replace all `YOUR_SECRET` in `/etc/prosody/prosody.cfg.lua` with it. Install [acme.sh](https://github.com/acmesh-official/acme.sh) or [certbot](https://certbot.eff.org/) to obtain a free letsencrypt SSL certificate, then update the path to this new certificate in the following files: diff --git a/etc/postfix/main.cf b/etc/postfix/main.cf index 2c9c4b4..d5e7c3d 100644 --- a/etc/postfix/main.cf +++ b/etc/postfix/main.cf @@ -65,7 +65,7 @@ smtpd_sasl_type = dovecot smtpd_sasl_path = private/auth smtpd_client_restrictions = reject_unauth_pipelining smtpd_recipient_restrictions = check_policy_service inet:127.0.0.1:12340, permit_sasl_authenticated, check_recipient_access proxy:mysql:/etc/postfix/sql/mysql_tls_policy_in.cf -smtpd_sender_restrictions = reject_sender_login_mismatch, check_sender_access inline:{{<> = REJECT}}, permit_sasl_authenticated +smtpd_sender_restrictions = reject_sender_login_mismatch, check_sender_access inline:{{<> = REJECT}}, check_policy_service { unix:private/last-login, timeout=5s, default_action=DUNNO }, permit_sasl_authenticated smtpd_relay_restrictions = permit_sasl_authenticated, permit_auth_destination, reject_unauth_destination smtpd_sender_login_maps = proxy:mysql:/etc/postfix/sql/mysql_virtual_auth_maps.cf diff --git a/etc/postfix/master.cf b/etc/postfix/master.cf index c334016..b2600ac 100644 --- a/etc/postfix/master.cf +++ b/etc/postfix/master.cf @@ -12,6 +12,8 @@ smtp inet n - n - 2 smtpd -o smtpd_sasl_auth_enable=no -o { smtpd_sender_restrictions = check_sender_access inline:{double-bounce@mail.danwin1210.de=OK} check_sender_access mysql:/etc/postfix/sql/mysql_virtual_domain_unauth_block.cf } +last-login unix - n n - 0 spawn + user=www-data argv=/usr/bin/php /var/www/mail/tools/postfix_last_login_policy.php 26 inet n - n - 2 smtpd -o smtpd_sasl_auth_enable=no -o { smtpd_sender_restrictions = check_sender_access mysql:/etc/postfix/sql/mysql_virtual_domain_unauth_block.cf } @@ -129,4 +131,3 @@ scache unix - - y - 1 scache #mailman unix - n n - - pipe # flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py # ${nexthop} ${user} - diff --git a/tools/postfix_last_login_policy.php b/tools/postfix_last_login_policy.php new file mode 100644 index 0000000..8cf29ce --- /dev/null +++ b/tools/postfix_last_login_policy.php @@ -0,0 +1,49 @@ + PDO::ERRMODE_EXCEPTION, PDO::ATTR_PERSISTENT => PERSISTENT, PDO::ATTR_TIMEOUT => 5 ] + ); + $stmt = $db->prepare( 'UPDATE mailbox SET last_login = ? WHERE username = ? AND active = 1;' ); + $stmt->execute( [ time(), mb_strtolower( $attributes[ 'sasl_username' ] ) ] ); + } catch ( PDOException $exception ) { + error_log( 'Unable to update mailbox last_login from Postfix policy request: ' . $exception->getMessage() ); + } + } + + fwrite( STDOUT, "action=DUNNO\n\n" ); + return true; +} + +while ( handle_postfix_policy_request() ) { +}