1

Topic: PostLoginScript

==== Required information ====
- iRedMail version: Pro 1.1
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): PGSQL
- Linux/BSD distribution name and version: Ubuntu 12.04 LTS
- Related log if you're reporting an issue:
====

Hi, i've a problem with the implementation of postloginscript.

I just want to update the lastlogindate in vmail db, but i've no found information about dovecot 2.x and backend DB PGSQL.

I had copy the script trackLastLogin.sh and paste it in /usr/local/bin.

I've changed the /etc/dovecot/conf.d/10-master.conf in

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 = 256M
executable = imap imap-postlogin

  # Max. number of IMAP processes (connections)
  #process_limit = 1024
}

service pop3 {
  # Max. number of POP3 processes (connections)
  #process_limit = 1024
}

# The service name below doesn't actually matter.
service imap-postlogin {
  # all post-login scripts are executed via script-login binary
  executable = script-login /usr/local/bin/trackLastLogin.sh

  # the script process runs as the user specified here (v2.0.14+):
  user = $default_internal_user
  # this UNIX socket listener must use the same name as given to imap executable
  unix_listener imap-postlogin {
  }
}

what's wrong?

Thanks in advance

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2

Re: PostLoginScript

Why not just try to print values of variables in your trackLastLogin.sh in a plain text file first? So that you can verify whether you have correct data.

Dovecot wiki site has detailed tutorial: http://wiki2.dovecot.org/PostLoginScripting

3 (edited by cedbiella 2013-01-10 22:00:19)

Re: PostLoginScript

i think that the problem is the psql command that not accept the password.
I'm looking for a solution, the env variable PGPASSWORD seems non function.

4

Re: PostLoginScript

ok i've controlled the script and it's ok.

As wiki say i've modified the /etc/dovecot/conf.d/10-master.conf

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 = 256M
executable = imap imap-postlogin

  # Max. number of IMAP processes (connections)
  #process_limit = 1024
}

service pop3 {
  # Max. number of POP3 processes (connections)
  #process_limit = 1024
}

# The service name below doesn't actually matter.
service imap-postlogin {
  # all post-login scripts are executed via script-login binary
  executable = script-login /usr/local/bin/trackLastLogin.sh
  # the script process runs as the user specified here (v2.0.14+):
  #user = $default_internal_user
  # this UNIX socket listener must use the same name as given to imap executable
  unix_listener imap-postlogin {
  }
}

but i have no success.

the script work good.

May you help me?

5

Re: PostLoginScript

iRedMail doesn't use config files under /etc/dovecot/conf.d/, please update /etc/dovecot/dovecot.conf instead.

6 (edited by cedbiella 2017-09-06 22:45:05)

Re: PostLoginScript

Hello, if i put the lines in dovecot.conf, the service don't start.

If i put only the code below the service start but postlogin not start.

If i uncomment the line  #executable = imap imap-postlogin under protocol imap service don't start.

How i change the dovecot.conf to make it work?

Thanks in advance



service imap-postlogin {
  # all post-login scripts are executed via script-login binary
  executable = script-login /usr/local/bin/trackLastLogin.sh

  # the script process runs as the user specified here (v2.0.14+):
  #user = $default_internal_user
  #user = $default_internal_user
  # this UNIX socket listener must use the same name as given to imap executable
  unix_listener imap-postlogin {
  }
}
###### Fine Righe

protocol lda {
    # Reference: http://wiki2.dovecot.org/LDA
    mail_plugins = quota sieve autocreate
    auth_socket_path = /var/run/dovecot/auth-master
    log_path = /var/log/sieve.log
    lda_mailbox_autocreate = yes
    postmaster_address = root
}
protocol imap {
    imap_client_workarounds = tb-extra-mailbox-sep
    mail_plugins = quota imap_quota autocreate
    #executable = imap imap-postlogin
}

7

Re: PostLoginScript

Please paste error message here to help troubleshoot.

Did you simply append new lines in dovecot.conf? That might not work, because it must contain duplicate settings.

8

Re: PostLoginScript

ZhangHuangbin wrote:

Please paste error message here to help troubleshoot.

Did you simply append new lines in dovecot.conf? That might not work, because it must contain duplicate settings.


I see no error message, the service seem to start correctly, but the clients cannot receive and send mail.

9

Re: PostLoginScript

cedbiella wrote:

but the clients cannot receive and send mail.

Then client should have some error message. Paste it here.
And paste related log triggered by this client in Dovecot log file.

10

Re: PostLoginScript

finally i got it works, the problem was in the script because postgres use PGPASSFILE to use comman line not like MySql.

Now i get in database this record:

Last Login Date                          IP                              Protocol

2013-01-24 09:32:42.032582    192.168.4.83    /usr/lib/dovecot/script-login                                                                                                                                                                                                                                 
2013-01-24 09:32:40.979952    127.0.0.1    /usr/lib/dovecot/script-login                                                                                                                                                                                                                                 
2013-01-24 09:32:35.908215    192.168.17.46    /usr/lib/dovecot/script-login                                                                                                                                                                                                                                 
2013-01-24 09:32:33.941375    192.168.17.46    /usr/lib/dovecot/script-login                                                                                                                                                                                                                                 
2013-01-24 09:32:26.071862    192.168.4.151    /usr/lib/dovecot/script-login                                                                                                                                                                                                                                 
The protocol is not correct.
My script was:

#!/usr/bin/env bash

# $USER -> login username. It should be a valid email address.
# $IP   -> remote ip address (IPv4).
# ${1}  -> mail protocol: imap, pop3

VMAIL_DB_NAME='vmail'
#
if [ X"${USER}" != X"dump-capability" ]; then
sqlstring="UPDATE mailbox SET lastloginipv4='$IP',lastlogindate=NOW(),lastloginprotocol='${1}' WHERE username='$USER';"
su - postgres -c "psql -w vmail >/dev/null 2>&1 <<EOF
       UPDATE mailbox SET
       lastloginipv4='$IP',
       lastlogindate=NOW(),
       lastloginprotocol='${1}'
       WHERE username='$USER';
EOF"
fi

# Execute POP3/IMAP process.
if [ -f /etc/redhat-release ]; then
    # RHEL/CentOS.
    exec /usr/libexec/dovecot/${1} $*
elif [ -f /etc/debian_version ]; then
    # Debian & Ubuntu:
#    exec /usr/lib/dovecot/${1} $*
    exec ${1} $*
fi

I take off almost all comment, it's simplest to read.

11

Re: PostLoginScript

Thanks very much for your sharing. smile

12

Re: PostLoginScript

ZhangHuangbin wrote:

Thanks very much for your sharing. smile

How i can correct the protocol?

I want that it's POP or IMAP or WEBMAIL if it's possibile.

13

Re: PostLoginScript

WEBMAIL uses IMAP protocol, you cannot recognize which imap connection comes from webmail or other mail clients.