Skip to content

Commit

Permalink
dovecot: add postlogin script to update vpopmail.lastauth
Browse files Browse the repository at this point in the history
  • Loading branch information
msimerson committed Dec 7, 2024
1 parent b7a9832 commit 452186c
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 23 deletions.
9 changes: 0 additions & 9 deletions include/vpopmail.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,6 @@ install_vpopmail_source()
stage_exec sh -c 'cd /data/src/vpopmail; aclocal' || exit 1
stage_exec sh -c "cd /data/src/vpopmail; CFLAGS=\"-fcommon\" ./configure $_conf_args" || exit 1
stage_exec sh -c 'cd /data/src/vpopmail; make install' || exit 1

# TODO: check and automate this
echo; echo "
ALTER TABLE vpopmail MODIFY column pw_name char(64);
ALTER TABLE vpopmail MODIFY column pw_passwd char(128);
ALTER TABLE vpopmail MODIFY column pw_gecos char(64);
"; echo

tell_status "*** Run the above commands above to update MySQL. *** "
}

install_vpopmail_port()
Expand Down
72 changes: 58 additions & 14 deletions provision/dovecot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,21 @@ service auth {
# mode = 0666
# }
}
service imap {
executable = imap lastauth
}
service pop3 {
executable = pop3 lastauth
}
service lastauth {
executable = script-login /data/bin/lastauth.sh
user = vpopmail
unix_listener lastauth {
user = vpopmail
group = vpopmail
mode = 0660
}
}
service lmtp {
user = vpopmail
inet_listener lmtp {
Expand All @@ -81,6 +95,19 @@ service lmtp {
#mode = 0666
}
}
service tcpwrap {
unix_listener login/tcpwrap {
mode = 0600
user = $default_login_user
group = $default_login_user
}
user = root
}
service managesieve-login {
inet_listener sieve {
port = 4190
}
}
passdb {
driver = sql
Expand Down Expand Up @@ -130,19 +157,6 @@ ssl_cipher_list = AES128+EECDH:AES128+EDH
login_access_sockets = tcpwrap
service tcpwrap {
unix_listener login/tcpwrap {
mode = 0600
user = $default_login_user
group = $default_login_user
}
user = root
}
service managesieve-login {
inet_listener sieve {
port = 4190
}
}
plugin {
quota = maildir:User quota
quota_rule = *:storage=1G
Expand Down Expand Up @@ -550,6 +564,35 @@ pass in quick proto tcp from <insecure_mua> to <dovecot> port { 110 143 }
EO_PF_FILTER
}
configure_dovecot_lastauth()
{
store_exec "$ZFS_DATA_MNT/dovecot/bin/lastauth.sh" <<EO_LASTAUTH
#!/bin/sh
set -e
domain=\$(echo \$USER | cut -f2 -d@)
user=\$(echo \$USER | cut -f1 -d@)
echo "UPDATE vpopmail.lastauth SET timestamp=UNIX_TIMESTAMP(now()), remote_ip='\$IP' WHERE user='\$user' AND domain='\$domain';" \
| mysql --defaults-extra-file=/data/etc/.my.cnf vpopmail
exec "\$@"
EO_LASTAUTH
_mycnf="$ZFS_DATA_MNT/dovecot/etc/.my.cnf"
store_config "$_mycnf" "overwrite" <<EO_DOVECOT_MY
[client]
host=mysql
user=vpopmail
password=$(grep -v ^# "$ZFS_DATA_MNT/vpopmail/home/etc/vpopmail.mysql" | head -n1 | cut -f4 -d'|')
database=vpopmail
EO_DOVECOT_MY
chmod 0640 "$_mycnf"
chown 89:89 "$_mycnf"
}
configure_dovecot()
{
for _d in etc bin; do
Expand All @@ -570,6 +613,7 @@ configure_dovecot()
configure_tls_certs
configure_sieve
configure_dovecot_pf
configure_dovecot_lastauth
mkdir -p "$STAGE_MNT/var/spool/postfix/private"
}
Expand Down
18 changes: 18 additions & 0 deletions provision/vpopmail.sh
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,22 @@ install_vpopmail_mysql_aliastable()
echo "CREATE TABLE IF NOT EXISTS aliasdomains (alias varchar(100) NOT NULL, domain varchar(100) NOT NULL, PRIMARY KEY (alias));" | mysql_query vpopmail || return 1
}
alter_vpopmail_tables()
{
echo "ALTER TABLE vpopmail.vpopmail
MODIFY COLUMN pw_name varchar(64),
MODIFY COLUMN pw_domain varchar(96),
MODIFY COLUMN pw_passwd varchar(128),
MODIFY COLUMN pw_gecos varchar(64),
MODIFY COLUMN pw_dir varchar(160),
MODIFY COLUMN pw_clear_passwd varchar(128);" | mysql_query
echo "ALTER TABLE vpopmail.lastauth
MODIFY COLUMN user varchar(64),
MODIFY COLUMN domain varchar(96),
MODIFY COLUMN remote_ip varchar(39);" | mysql_query
}
install_vpop_nrpe()
{
if [ -z "$TOASTER_NRPE" ]; then
Expand Down Expand Up @@ -259,9 +275,11 @@ install_vpopmail()
install_vpopmail_port
#install_vpopmail_source
if [ "$TOASTER_MYSQL" = "1" ]; then
install_vpopmail_mysql_grants
install_vpopmail_mysql_aliastable
alter_vpopmail_tables
fi
install_qmailadmin
Expand Down

0 comments on commit 452186c

Please sign in to comment.