jummo wrote:@g_kos: Thank you for your script!
I have extend the script a little bit to handle multi-domain setups.
Usage
su - zimbra
/usr/local/bin/zm_password_notify.sh example.com example.net ...
Scripts
zm_password_notify.sh
#!/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
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
days_to_change[x]=pass_change_limit[x] - curtime;
if (curtime
status[x]="no need to notify yet";
}else
if (curtime
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
"
"User-Agent: Zimbra
"
"MIME-Version: 1.0
"
"To: "name[x]"
"
"Subject: Password change reminder (Automatic notification)
"
"Dear " name[x]",
Your current password will expire on " strftime("%d %B %Y ",pass_change_limit[x])".
"
"When you have a free minute, please login to
https://mail.
"
"enter your current username and password, and change your password to a new one.
"
"You have "strftime("%-j",days_to_change[x])" day(s) left.
"
"Regards,
IT-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] "
Name: "name[x] "
Email: "email[x]
print "LastChangeDate: " strftime("%Y %m %d", lc_epoch[x]) "
LastChangeDateEpoch: " lc_epoch[x]
print "Current time: " strftime("%Y %m %d", curtime) "
Current time epoch: " curtime
print "Trigger time: " strftime("%Y %m %d", trigger_date[x]) "
Trigger time epoch: " trigger_date[x]
print "PassChange Limit: " strftime("%Y %m %d", pass_change_limit[x]) "
PassChange Limit: " pass_change_limit[x]
print "Time till change: " strftime("%-j",days_to_change[x]) "
Time till change epoch: " days_to_change[x]
print "
"
}