Topic: Implementing Dovecot PostLoginScripting
======== Required information ====
- iRedMail version (check /etc/iredmail-release): 0.9.5-1
- Linux/BSD distribution name and version: Ubuntu 14.04 x64
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): MySQL
- Web server (Apache or Nginx): Nginx
- Manage mail accounts with iRedAdmin-Pro? no
- Related log if you're reporting an issue:
====
Hi Zhang,
I need to record lastlogindate in vmail database on mailbox table.
I use reference from here https://wiki.dovecot.org/PostLoginScripting
My actual implementation is:
/usr/local/bin$ ls -l postlogin.sh
-rwxr-x--- 1 vmail vmail 401 May 11 19:50 postlogin.sh
/usr/local/bin$ sudo cat postlogin.sh
#!/bin/sh
# a) Filesystem based timestamp in user's home directory
# touch ~/.last_login
# b) SQL based tracking. Beware of potential SQL injection holes if you allow
# users to have ' characters in usernames. Following is just an example:
echo "UPDATE mailbox SET lastlogindate=now(),lastloginipv4='$IP' WHERE username = '$USER'" | mysql vmail -uvmailadmin -pvmailadminpassword
exec "$@"
My changes on /etc/dovecot/conf.d/10-master.conf
...
service lmtp {
unix_listener lmtp {
#mode = 0666
}
# Create inet listener only if you can't use the above UNIX socket
#inet_listener lmtp {
# Avoid making LMTP visible for the entire internet
#address =
#port =
#}
executable = lmtp custom-postlogin
}
service imap {
# Most of the memory goes to mmap()ing files. You may need to increase this
# limit if you have huge mailboxes.
#vsz_limit = $default_vsz_limit
# Max. number of IMAP processes (connections)
#process_limit = 1024
executable = imap custom-postlogin
}
service pop3 {
# Max. number of POP3 processes (connections)
#process_limit = 1024
executable = pop3 custom-postlogin
}
service custom-postlogin {
# all post-login scripts are executed via script-login binary
executable = script-login /usr/local/bin/postlogin.sh
# the script process runs as the user specified here (v2.0.14+):
user = vmail
# this UNIX socket listener must use the same name as given to imap executable
unix_listener custom-postlogin {
}
}
...
Then I restart dovecot using: sudo doveadm reload
But nothing get updated to mailbox table.
And I don't know which log file I need to check for the script-login execution status.
I knew my postlogin.sh is working when I executed it manually from console.
Can you help me with this problem? Thanks.
----
Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.