[sysadmin-bin] Add comment to user of removal of groups and send email.
- From: Patrick Uiterwijk <puiterwijk src gnome org>
- To: gnome-sysadmin gnome org,commits-list gnome org
- Subject: [sysadmin-bin] Add comment to user of removal of groups and send email.
- Date: Fri, 28 Aug 2015 14:34:32 +0000 (UTC)
commit 3f3159bdea481412fefd25079efff9f5d889d143
Author: Patrick Uiterwijk <puiterwijk redhat com>
Date: Fri Aug 28 16:34:04 2015 +0200
Add comment to user of removal of groups and send email.
Signed-off-by: Patrick Uiterwijk <puiterwijk redhat com>
cleanup-inactive-ldap-accounts.py | 57 ++++++++++++++++++++++++++++++++++--
1 files changed, 53 insertions(+), 4 deletions(-)
---
diff --git a/cleanup-inactive-ldap-accounts.py b/cleanup-inactive-ldap-accounts.py
index 6ccde4d..bd1a74d 100755
--- a/cleanup-inactive-ldap-accounts.py
+++ b/cleanup-inactive-ldap-accounts.py
@@ -1,6 +1,7 @@
#!/usr/bin/python
from __future__ import print_function
+import datetime
import os
import sys
import calendar
@@ -9,6 +10,8 @@ import ldap
import ldap.filter
import socket
from optparse import OptionParser
+import smtplib
+from email.MIMEText import MIMEText
LDAP_GROUP_BASE='cn=groups,cn=accounts,dc=gnome,dc=org'
LDAP_USER_BASE='cn=users,cn=accounts,dc=gnome,dc=org'
@@ -94,6 +97,50 @@ def get_uids_from_group(group):
return people
+def add_remove_comment_to_user(username, group):
+ new_comment = 'Removed from group %s by cleanup-inactive-ldap-accounts at %s.' % (group,
datetime.date.today())
+ filter = ldap.filter.filter_format('(uid=%s)', (username, ))
+ results = l.search_s(LDAP_USER_BASE, ldap.SCOPE_SUBTREE, filter, ('uid', 'cn', 'description', 'mail', ))
+
+ if not len(results) > 0:
+ # Something went very wrong here...
+ return False
+
+ current_comment = results[0][1]['description'][0]
+ comment = '%s %s' % (current_comment, new_comment)
+
+ update_comment = [(ldap.MOD_REPLACE, 'description', comment)]
+ l.modify_s('uid=%s,%s' % (username, LDAP_USER_BASE), update_comment)
+
+ name = results[0][1]['cn'][0]
+ mail = results[0][1]['mail'][0]
+
+ form_letter = """
+Hello %s, your membership of the group %s has been automatically removed, due to inactivity.
+
+For more information, please see the following email:
+https://mail.gnome.org/archives/foundation-list/2014-March/msg00063.html
+
+With cordiality,
+
+the GNOME Accounts Team""" % (name, group)
+
+ try:
+ msg = MIMEText(form_letter)
+ msg['Subject'] = "Your GNOME group membership expired"
+ msg['From'] = "noreply gnome org"
+ msg['To'] = "%s" % (mail)
+ msg['Reply-To']= "accounts gnome org"
+ server = smtplib.SMTP("localhost")
+ server.sendmail(msg['From'], msg['To'], msg.as_string())
+ server.quit()
+ except smtplib.SMTPException:
+ # Too bad, they'll have to contact sysadmin
+ pass
+
+ return True
+
+
gnomecvs_users = (get_uids_from_group('gnomecvs'))
ftpadmin_users = (get_uids_from_group('ftpadmin'))
@@ -101,12 +148,14 @@ for gnomecvs_user in gnomecvs_users:
if not user_is_current(gnomecvs_user):
if options.verbose:
print ("Removing user %s from gnomecvs" % gnomecvs_user, end='\n')
- remove_members = [ (ldap.MOD_DELETE, 'member','uid=%s,cn=users,cn=accounts,dc=gnome,dc=org' %
gnomecvs_user) ]
- l.modify_s('cn=gnomecvs,cn=groups,cn=accounts,dc=gnome,dc=org', remove_members)
+ remove_members = [ (ldap.MOD_DELETE, 'member','uid=%s,%s' % (gnomecvs_user, LDAP_USER_BASE)) ]
+ l.modify_s('cn=gnomecvs,%s' % LDAP_GROUP_BASE, remove_members)
+ add_remove_comment_to_user(gnomecvs_user, 'gnomecvs')
for ftpadmin_user in ftpadmin_users:
if not user_is_current(ftpadmin_user):
if options.verbose:
print ("Removing user %s from ftpadmin" % ftpadmin_user, end='\n')
- remove_members = [ (ldap.MOD_DELETE, 'member','uid=%s,cn=users,cn=accounts,dc=gnome,dc=org' %
ftpadmin_user) ]
- l.modify_s('cn=ftpadmin,cn=groups,cn=accounts,dc=gnome,dc=org', remove_members)
+ remove_members = [ (ldap.MOD_DELETE, 'member','uid=%s,%s' % (ftpadmin_user, LDAP_USER_BASE)) ]
+ l.modify_s('cn=ftpadmin,%s' % LDAP_GROUP_BASE, remove_members)
+ add_remove_comment_to_user(gnomecvs_user, 'ftpadmin')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]