Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: password expiry email notification

  1. #11
    Join Date
    Feb 2007
    Location
    Portland, OR
    Posts
    1,147
    Rep Power
    10

    Default

    This forum has a bug where it randomly adds spaces in some words when they aren't wrapped in a [code ] block, it usually only shows up in LDAP filters though, not sure why. Anyway...

    It looks like you only pasted part of the command as the full one looks like this (and works for me on 6.0.10 at least):
    Code:
    ldapsearch -w `zmlocalconfig -s zimbra_ldap_password | awk '{print $3}'` -D uid=zimbra,cn=admins,cn=zimbra -x -h 192.168.1.6 -b ou=people,dc=domain,dc=com "(&(objectclass=posixAccount)(objectclass=sambaSamAccount))" | awk '/zimbraPasswordModifiedTime:/ {print substr($2,1,8)}'
    20081016
    20101115
    ...
    I'm not sure which "awk" isn't working for you, the first or second? The first is to split out the password only from the response of the zmlocalconfig query, the second is what actually gets the password modified times.

  2. #12
    Join Date
    Oct 2010
    Location
    Poland
    Posts
    5
    Rep Power
    5

    Default

    Yep, the ldapsearch command returns all zimbra users in domain. But the awk script don't work. It's even creating temp files in /tmp - just run and return 0.

    I used ldapsearch command and awk script from second g_cos post.

  3. #13
    Join Date
    Feb 2007
    Location
    Portland, OR
    Posts
    1,147
    Rep Power
    10

    Default

    So it's creating the "/tmp/password_change_notification.msg" file? And this file looks like a raw mail message?

    is the cron entry setup to run as the zimbra user?

  4. #14
    Join Date
    Oct 2010
    Location
    Poland
    Posts
    5
    Rep Power
    5

    Default

    Thx, everything works fine now. Debug function was realy useful.

  5. #15
    Join Date
    May 2009
    Location
    Bremen, Germany
    Posts
    122
    Rep Power
    6

    Default

    @g_kos: Thank you for your script!

    I have extend the script a little bit to handle multi-domain setups.


    Usage
    Code:
    su - zimbra
    /usr/local/bin/zm_password_notify.sh example.com example.net ...
    Scripts

    zm_password_notify.sh
    Code:
    #!/bin/bash
     
    for i in $@; do
     
    domain=$(echo $i | sed -e 's/\(.*\)\./dc=\1,dc=/')
     
    ldapsearch -w `zmlocalconfig -s zimbra_ldap_password | awk '{print $3}'` \
     -D uid=zimbra,cn=admins,cn=zimbra -x -h mail.example.com \
     -b ou=people,${domain} \
     "(&(objectclass=zimbraAccount)(!(objectclass=zimbraCalendarResource)))" \
     zimbraMailDeliveryAddress \
     zimbraPasswordModifiedTime \
     displayName | awk -f /usr/local/bin/zm_password_notify.awk
    done
    zm_password_notify.awk
    Code:
    BEGIN {OFS=";";
    max_age=30
    warn_age=25
    curtime=systime();
    one_day=24 * 60 * 60
    mail_msg="/tmp/password_change_notification.msg"
    logfile="/tmp/zimbra_password_change.log"
    }
     
     
    /^dn: / {++no}
    /zimbraMailDeliveryAddress:/ {email[no]=$2}
    /zimbraPasswordModifiedTime:/ {datescalc($2)}
    /displayName:/ {name[no]=substr($0,14)}
     
     
     
    END{
    for (x = 1; x <= no; x++) {
     
    days_to_change[x]=pass_change_limit[x] - curtime;
     
    if (curtime < trigger_date[x]) {
    status[x]="no need to notify yet";
    }else
    if (curtime <= pass_change_limit[x]) {
    send_mail()
    status[x]="send notification email"
    }else
    {days_to_change[x]="overdue";
    status[x]="too late to notify"}
     
    # unhash for debugging
    #status_log()
    }
    }
     
    function datescalc (field) {
    lc_yyyy[no]=substr($2,1,4);
    lc_mm[no]=substr($2,5,2);
    lc_dd[no]=substr($2,7,2);
    lc_epoch[no]=mktime(lc_yyyy[no]" "lc_mm[no]" "lc_dd[no]" 00 00 00")
    trigger_date[no]=lc_epoch[no] + warn_age * one_day
    pass_change_limit[no]=lc_epoch[no] + max_age * one_day
    }
     
    function send_mail(field) {
    # get domain
    domain=email[x];
    sub(/.*@/, "", domain);
     
    message[x]="From: Password Change Reminder <it-support@"domain">\n" \
    "User-Agent: Zimbra\n" \
    "MIME-Version: 1.0\n" \
    "To: "name[x]" <"email[x]">\n" \
    "Subject: Password change reminder (Automatic notification)\n\n" \
    "Dear " name[x]",\n\nYour current password will expire on " strftime("%d %B %Y ",pass_change_limit[x])".\n" \
    "When you have a free minute, please login to https://mail."domain",\n" \
    "enter your current username and password, and change your password to a new one.\n\n" \
    "You have "strftime("%-j",days_to_change[x])" day(s) left.\n\n\n" \
    "Regards,\nIT-Support"
    print message[x] > "/tmp/password_change_notification.msg"
    system ("zmlmtpinject -r " email[x] " -s it-support@"domain " " mail_msg " > /dev/null")
    close (mail_msg)
    }
     
    function status_log(field) {
    print "Action: "status[x] "\nName: "name[x] "\nEmail: "email[x]
    print "LastChangeDate: " strftime("%Y %m %d", lc_epoch[x]) "\nLastChangeDateEpoch: " lc_epoch[x]
    print "Current time: " strftime("%Y %m %d", curtime) "\nCurrent time epoch: " curtime
    print "Trigger time: " strftime("%Y %m %d", trigger_date[x]) "\nTrigger time epoch: " trigger_date[x]
    print "PassChange Limit: " strftime("%Y %m %d", pass_change_limit[x]) "\nPassChange Limit: " pass_change_limit[x]
    print "Time till change: " strftime("%-j",days_to_change[x]) "\nTime till change epoch: " days_to_change[x]
    print "\n\n\n"
    }
    Last edited by jummo; 09-22-2011 at 07:50 AM. Reason: Typo

  6. #16
    Join Date
    Jun 2011
    Location
    Caracas Venezuela
    Posts
    476
    Rep Power
    4

    Default

    Quote Originally Posted by jummo View Post
    @g_kos: Thank you for your script!

    I have extend the script a little bit to handle multi-domain setups.


    Usage
    Code:
    su - zimbra
    /usr/local/bin/zm_password_notify.sh example.com example.net ...
    Scripts

    zm_password_notify.sh
    Code:
    #!/bin/bash
     
    for i in $@; do
     
    domain=$(echo $i | sed -e 's/\(.*\)\./dc=\1,dc=/')
     
    ldapsearch -w `zmlocalconfig -s zimbra_ldap_password | awk '{print $3}'` \
     -D uid=zimbra,cn=admins,cn=zimbra -x -h mail.example.com \
     -b ou=people,${domain} \
     "(&(objectclass=zimbraAccount)(!(objectclass=zimbraCalendarResource)))" \
     zimbraMailDeliveryAddress \
     zimbraPasswordModifiedTime \
     displayName | awk -f /usr/local/bin/zm_password_notify.awk
    done
    zm_password_notify.awk
    Code:
    BEGIN {OFS=";";
    max_age=30
    warn_age=25
    curtime=systime();
    one_day=24 * 60 * 60
    mail_msg="/tmp/password_change_notification.msg"
    logfile="/tmp/zimbra_password_change.log"
    }
     
     
    /^dn: / {++no}
    /zimbraMailDeliveryAddress:/ {email[no]=$2}
    /zimbraPasswordModifiedTime:/ {datescalc($2)}
    /displayName:/ {name[no]=substr($0,14)}
     
     
     
    END{
    for (x = 1; x <= no; x++) {
     
    days_to_change[x]=pass_change_limit[x] - curtime;
     
    if (curtime < trigger_date[x]) {
    status[x]="no need to notify yet";
    }else
    if (curtime <= pass_change_limit[x]) {
    send_mail()
    status[x]="send notification email"
    }else
    {days_to_change[x]="overdue";
    status[x]="too late to notify"}
     
    # unhash for debugging
    #status_log()
    }
    }
     
    function datescalc (field) {
    lc_yyyy[no]=substr($2,1,4);
    lc_mm[no]=substr($2,5,2);
    lc_dd[no]=substr($2,7,2);
    lc_epoch[no]=mktime(lc_yyyy[no]" "lc_mm[no]" "lc_dd[no]" 00 00 00")
    trigger_date[no]=lc_epoch[no] + warn_age * one_day
    pass_change_limit[no]=lc_epoch[no] + max_age * one_day
    }
     
    function send_mail(field) {
    # get domain
    domain=email[x];
    sub(/.*@/, "", domain);
     
    message[x]="From: Password Change Reminder <it-support@"domain">\n" \
    "User-Agent: Zimbra\n" \
    "MIME-Version: 1.0\n" \
    "To: "name[x]" <"email[x]">\n" \
    "Subject: Password change reminder (Automatic notification)\n\n" \
    "Dear " name[x]",\n\nYour current password will expire on " strftime("%d %B %Y ",pass_change_limit[x])".\n" \
    "When you have a free minute, please login to https://mail."domain",\n" \
    "enter your current username and password, and change your password to a new one.\n\n" \
    "You have "strftime("%-j",days_to_change[x])" day(s) left.\n\n\n" \
    "Regards,\nIT-Support"
    print message[x] > "/tmp/password_change_notification.msg"
    system ("zmlmtpinject -r " email[x] " -s it-support@"domain " " mail_msg " > /dev/null")
    close (mail_msg)
    }
     
    function status_log(field) {
    print "Action: "status[x] "\nName: "name[x] "\nEmail: "email[x]
    print "LastChangeDate: " strftime("%Y %m %d", lc_epoch[x]) "\nLastChangeDateEpoch: " lc_epoch[x]
    print "Current time: " strftime("%Y %m %d", curtime) "\nCurrent time epoch: " curtime
    print "Trigger time: " strftime("%Y %m %d", trigger_date[x]) "\nTrigger time epoch: " trigger_date[x]
    print "PassChange Limit: " strftime("%Y %m %d", pass_change_limit[x]) "\nPassChange Limit: " pass_change_limit[x]
    print "Time till change: " strftime("%-j",days_to_change[x]) "\nTime till change epoch: " days_to_change[x]
    print "\n\n\n"
    }
    Thanks, works like a charm!

    Just tweak a little bit on ldapsearch to fit our requirements.

    ccelis
    Last edited by ccelis5215; 12-06-2013 at 03:43 PM. Reason: add comment

Similar Threads

  1. [SOLVED] mailboxmanager does not start
    By jrefl5 in forum Administrators
    Replies: 18
    Last Post: 01-30-2012, 11:40 PM
  2. [SOLVED] Moving Zimbra to a new server
    By krolen in forum Administrators
    Replies: 109
    Last Post: 02-05-2009, 11:38 AM
  3. need advice on configuring zimbra to work with fax server
    By pheonix1t in forum Administrators
    Replies: 0
    Last Post: 07-11-2007, 08:46 PM
  4. upgrade to 4.0.3 antispam does'nt work
    By lucanannipieri in forum Administrators
    Replies: 14
    Last Post: 11-07-2006, 03:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •