|
# Basic init of arrays |
|
# Systems and Administration will have to make sure the base |
|
# organizations are accurate and up to date. |
|
base_list = [ |
|
"ou=Employee,ou=SOM,o=hsc", |
|
"ou=Employee,ou=Library,o=hsc", |
|
"ou=Affiliate,ou=Library,o=hsc", |
|
"ou=Employee,ou=COP,o=hsc", |
|
"ou=Employee,ou=CRTC,ou=SOM,o=hsc", |
|
"ou=Employee,ou=Administration,o=hsc", |
|
"ou=Employee,ou=CON,o=hsc", |
|
"ou=Employee,ou=Services,o=hsc", |
|
"ou=Student,ou=COP,o=hsc", |
|
"ou=Student,ou=SOM,o=hsc", |
|
"ou=Student,ou=CON,o=hsc", |
|
"ou=CON,ou=Trans,o=HSC", |
|
"ou=HSLIC,ou=Trans,o=HSC" |
|
] |
|
|
|
# Days until expiration to warn on |
|
warning_days = [30,14,7,3,2,1] |
|
|
|
# CON has its own email text to send, use this array to find them |
|
con_mail_exception = [ |
|
"ou=Employee,ou=CON,o=hsc", |
|
"ou=Student,ou=CON,o=hsc" |
|
] |
|
|
|
# Actual look up and email code! |
|
# Start main search by going through each organizational group |
|
base_list.each do |area| |
|
|
|
puts "Searching #{area}" |
|
conn = LDAP::SSLConn.new(host, port) |
|
conn.bind(username, password) |
|
conn.perror("bind") |
|
begin |
|
conn.search(area, scope, filter, attrs) { |entry| |
|
if entry.vals('passwordExpirationTime').nil? || entry.vals('mail').nil? |
|
#puts "none" |
|
else |
|
pswrd_expire = entry.to_hash() |
|
# Today's date and the entry's expiaration date split from string to date |
|
today = Time.now |
|
expire_date = Time.new( |
|
pswrd_expire['passwordExpirationTime'].to_s.slice(2,4), |
|
pswrd_expire['passwordExpirationTime'].to_s.slice(6,2), |
|
pswrd_expire['passwordExpirationTime'].to_s.slice(8,2) |
|
) |
|
# Calculate the remaining days diff/24 hours/60 minues/60 seconds + 1 day |
|
days_remaining = (((expire_date - today)/24/60/60)+1).to_i |
|
|
|
# For use in the body text |
|
if days_remaining == 1 |
|
plural_text = "day" |
|
else |
|
plural_text = "days" |
|
end |
|
|
|
if con_mail_exception.include?(area) |
|
mail_body = "Your HSC NetID password for the account #{pswrd_expire['cn']} will expire in #{days_remaining} #{plural_text}, on #{expire_date.strftime('%m/%d/%Y')}." |
|
# Add in College of Nursing specific text! |
|
else |
|
mail_body ="Your HSC NetID password for the account #{pswrd_expire['cn']} will expire in #{days_remaining} #{plural_text}, on #{expire_date.strftime('%m/%d/%Y')}." |
|
end |
|
puts "#{pswrd_expire['sn']} (#{pswrd_expire['mail']})on #{expire_date.strftime('%m/%d/%Y')} in #{days_remaining} #{plural_text}" |
|
# Add in remaining HSC specific text! |
|
|
|
# Look to see if the days_remaining is on one of the warning intervals and send mail |
|
if warning_days.include?(days_remaining) |
|
Pony.mail( |
|
:to => 'me@unm.edu', |
|
:via => :smtp, |
|
:via_options => { |
|
:address => 'relay.health.unm.edu', |
|
:port => '25', |
|
:openssl_verify_mode => 'none' |
|
}, |
|
:subject => 'Your HSC NetID Password Expires Soon', |
|
:body => mail_body, |
|
:from => '"HSC Support" <hscsupport@salud.unm.edu>' |
|
) |
|
|
|
end |
|
|
|
end |
|
} |
|
rescue LDAP::ResultError |
|
conn.perror("search") |
|
exit |
|
end |
|
conn.perror("search") |
|
conn.unbind |
|
|
|
end |