View | Details | Raw Unified | Return to bug 20929
Collapse All | Expand All

(-)xxxxxx-delete-deactivated.orig/conffiles/etc/cron.d/xxxxxx-delete-deactivated (+3 lines)
Line 0    Link Here 
1
@%@UCRWARNING=# @%@
2
MAILTO=@%@xxxxxx/delete/deactivated/mailaddress/schedule@%@
3
0 3 * * * root /usr/sbin/xxxxxx-delete-deactivated --delete
(-)xxxxxx-delete-deactivated.orig/debian/changelog (+26 lines)
Line 0    Link Here 
1
xxxxxx-delete-deactivated (1.0.3-1) unstable; urgency=low
2
3
  * remove home directory check (Ticket#: 2010090910014184)
4
5
 -- Janek Walkenhorst <walkenhorst@univention.de>  Wed, 14 Dec 2011 15:49:50 +0100
6
7
xxxxxx-delete-deactivated (1.0.2-1) unstable; urgency=low
8
9
  * do not overwrite logfiles (Ticket#: 2010090910014184)
10
11
 -- Janek Walkenhorst <walkenhorst@univention.de>  Wed, 14 Dec 2011 11:05:53 +0100
12
13
xxxxxx-delete-deactivated (1.0.1-1) unstable; urgency=low
14
15
  * update search filter (Ticket#: 2010090910014184)
16
  * add encoding declaration to fix encoding warnings
17
  * only do one LDAP search in xxxxxx-delete-deactivated
18
  * add default values to URCV
19
20
 -- Janek Walkenhorst <walkenhorst@univention.de>  Tue, 13 Dec 2011 14:42:54 +0100
21
22
xxxxxx-delete-deactivated (1.0.0-2) unstable; urgency=low
23
24
  * Initial release. (Ticket#: 2010090910014184)
25
26
 -- Janek Walkenhorst <walkenhorst@univention.de>  Thu, 25 Aug 2011 10:14:30 +0200
(-)xxxxxx-delete-deactivated.orig/debian/compat (+1 lines)
Line 0    Link Here 
1
7
(-)xxxxxx-delete-deactivated.orig/debian/control (+21 lines)
Line 0    Link Here 
1
Source: xxxxxx-delete-deactivated
2
Section: univention
3
Priority: optional
4
Maintainer: Univention GmbH <packages@univention.de>
5
Build-Depends: debhelper (>> 7.0.50~), univention-config-dev
6
Standards-Version: 3.5.5
7
8
Package: xxxxxx-delete-deactivated-master
9
Architecture: all
10
Description: Delete deactivated users
11
 This package is to be installed only on the DC master computer.
12
13
Package: xxxxxx-delete-deactivated-home
14
Architecture: all
15
Description: Delete home directories of deactivated users
16
 This package is to be installed only on computers where the home directories should be deleted.
17
18
Package: xxxxxx-delete-deactivated-mail
19
Architecture: all
20
Description: Delete email directories of deactivated users
21
 This package is to be installed only on computers where the email directories should be deleted.
(-)xxxxxx-delete-deactivated.orig/debian/copyright (+27 lines)
Line 0    Link Here 
1
Copyright 2011 Univention GmbH
2
3
http://www.univention.de/
4
5
All rights reserved.
6
7
The source code of the software contained in this package
8
as well as the source package itself are made available
9
under the terms of the GNU Affero General Public License version 3
10
(GNU AGPL V3) as published by the Free Software Foundation.
11
12
Binary versions of this package provided by Univention to you as
13
well as other copyrighted, protected or trademarked materials like
14
Logos, graphics, fonts, specific documentations and configurations,
15
cryptographic keys etc. are subject to a license agreement between
16
you and Univention and not subject to the GNU AGPL V3.
17
18
In the case you use the software under the terms of the GNU AGPL V3,
19
the program is provided in the hope that it will be useful,
20
but WITHOUT ANY WARRANTY; without even the implied warranty of
21
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
GNU Affero General Public License for more details.
23
24
You should have received a copy of the GNU Affero General Public
25
License with the Debian GNU/Linux or Univention distribution in file
26
/usr/share/common-licenses/AGPL-3; if not, see
27
<http://www.gnu.org/licenses/>.
(-)xxxxxx-delete-deactivated.orig/debian/rules (+45 lines)
Line 0    Link Here 
1
#!/usr/bin/make -f
2
#
3
# xxxxxx-delete-deactivated
4
#  debian/rules file
5
#
6
# Copyright 2011 Univention GmbH
7
#
8
# http://www.univention.de/
9
#
10
# All rights reserved.
11
#
12
# The source code of this program is made available
13
# under the terms of the GNU Affero General Public License version 3
14
# (GNU AGPL V3) as published by the Free Software Foundation.
15
#
16
# Binary versions of this program provided by Univention to you as
17
# well as other copyrighted, protected or trademarked materials like
18
# Logos, graphics, fonts, specific documentations and configurations,
19
# cryptographic keys etc. are subject to a license agreement between
20
# you and Univention and not subject to the GNU AGPL V3.
21
#
22
# In the case you use this program under the terms of the GNU AGPL V3,
23
# the program is provided in the hope that it will be useful,
24
# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
# GNU Affero General Public License for more details.
27
#
28
# You should have received a copy of the GNU Affero General Public
29
# License with the Debian GNU/Linux or Univention distribution in file
30
# /usr/share/common-licenses/AGPL-3; if not, see
31
# <http://www.gnu.org/licenses/>.
32
33
override_dh_auto_install:
34
	dh_auto_install
35
	univention-install-config-registry
36
	univention-install-config-registry-info
37
38
override_dh_clean:
39
	dh_clean
40
	rm -f debian/xxxxxx-delete-deactivated-master.conffiles
41
	rm -f debian/xxxxxx-delete-deactivated-home.conffiles
42
	rm -f debian/xxxxxx-delete-deactivated-mail.conffiles
43
44
%:
45
	dh $@
(-)xxxxxx-delete-deactivated.orig/debian/xxxxxx-delete-deactivated-home.install (+1 lines)
Line 0    Link Here 
1
delete-deactivated-home.py usr/lib/univention-directory-listener/system
(-)xxxxxx-delete-deactivated.orig/debian/xxxxxx-delete-deactivated-home.postinst (+42 lines)
Line 0    Link Here 
1
#!/bin/sh
2
#
3
# xxxxxx-delete-deactivated
4
#  -home postinst
5
#
6
# Copyright 2011 Univention GmbH
7
#
8
# http://www.univention.de/
9
#
10
# All rights reserved.
11
#
12
# The source code of this program is made available
13
# under the terms of the GNU Affero General Public License version 3
14
# (GNU AGPL V3) as published by the Free Software Foundation.
15
#
16
# Binary versions of this program provided by Univention to you as
17
# well as other copyrighted, protected or trademarked materials like
18
# Logos, graphics, fonts, specific documentations and configurations,
19
# cryptographic keys etc. are subject to a license agreement between
20
# you and Univention and not subject to the GNU AGPL V3.
21
#
22
# In the case you use this program under the terms of the GNU AGPL V3,
23
# the program is provided in the hope that it will be useful,
24
# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
# GNU Affero General Public License for more details.
27
#
28
# You should have received a copy of the GNU Affero General Public
29
# License with the Debian GNU/Linux or Univention distribution in file
30
# /usr/share/common-licenses/AGPL-3; if not, see
31
# <http://www.gnu.org/licenses/>.
32
33
#DEBHELPER#
34
35
if [ "$1" = 'configure' ]
36
then
37
	univention-config-registry set 'xxxxxx/delete/deactivated/home/logfile?/var/log/univention/xxxxxx-delete-deactivated-home.log' \
38
		'xxxxxx/delete/deactivated/days?30'
39
	invoke-rc.d univention-directory-listener crestart
40
fi
41
42
exit 0
(-)xxxxxx-delete-deactivated.orig/debian/xxxxxx-delete-deactivated-home.univention-config-registry-variables (+23 lines)
Line 0    Link Here 
1
[xxxxxx/delete/deactivated]
2
Description[de]=Aktiviert das automatische Löschen von deaktivierten Benutzern
3
Description[en]=Activates the automatic deletion of deactivated users.
4
Type=str
5
Categories=management-udm
6
7
[xxxxxx/delete/deactivated/days]
8
Description[de]=Nach wie vielen Tagen deaktivierte Benutzer automatisch gelöscht werden.
9
Description[en]=After how many days deactivated users are automatically deleted.
10
Type=str
11
Categories=management-udm
12
13
[xxxxxx/delete/deactivated/home]
14
Description[de]=Aktiviert das Löschen von Heimatverzeichnissen auf diesem Computer.
15
Description[en]=Activates the deletion of home directories on this computer.
16
Type=str
17
Categories=management-udm
18
19
[xxxxxx/delete/deactivated/home/logfile]
20
Description[de]=Logdatei in der die gelöschten Heimatverzeichnisse protokolliert werden.
21
Description[en]=Log file to log deleted home directories in.
22
Type=str
23
Categories=management-udm
(-)xxxxxx-delete-deactivated.orig/debian/xxxxxx-delete-deactivated-mail.install (+1 lines)
Line 0    Link Here 
1
delete-deactivated-mail.py usr/lib/univention-directory-listener/system
(-)xxxxxx-delete-deactivated.orig/debian/xxxxxx-delete-deactivated-mail.postinst (+42 lines)
Line 0    Link Here 
1
#!/bin/sh
2
#
3
# xxxxxx-delete-deactivated
4
#  -mail postinst
5
#
6
# Copyright 2011 Univention GmbH
7
#
8
# http://www.univention.de/
9
#
10
# All rights reserved.
11
#
12
# The source code of this program is made available
13
# under the terms of the GNU Affero General Public License version 3
14
# (GNU AGPL V3) as published by the Free Software Foundation.
15
#
16
# Binary versions of this program provided by Univention to you as
17
# well as other copyrighted, protected or trademarked materials like
18
# Logos, graphics, fonts, specific documentations and configurations,
19
# cryptographic keys etc. are subject to a license agreement between
20
# you and Univention and not subject to the GNU AGPL V3.
21
#
22
# In the case you use this program under the terms of the GNU AGPL V3,
23
# the program is provided in the hope that it will be useful,
24
# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
# GNU Affero General Public License for more details.
27
#
28
# You should have received a copy of the GNU Affero General Public
29
# License with the Debian GNU/Linux or Univention distribution in file
30
# /usr/share/common-licenses/AGPL-3; if not, see
31
# <http://www.gnu.org/licenses/>.
32
33
#DEBHELPER#
34
35
if [ "$1" = 'configure' ]
36
then
37
	univention-config-registry set 'xxxxxx/delete/deactivated/mail/logfile?/var/log/univention/xxxxxx-delete-deactivated-mail.log' \
38
		'xxxxxx/delete/deactivated/days?30'
39
	invoke-rc.d univention-directory-listener crestart
40
fi
41
42
exit 0
(-)xxxxxx-delete-deactivated.orig/debian/xxxxxx-delete-deactivated-mail.univention-config-registry-variables (+23 lines)
Line 0    Link Here 
1
[xxxxxx/delete/deactivated]
2
Description[de]=Aktiviert das automatische Löschen von deaktivierten Benutzern
3
Description[en]=Activates the automatic deletion of deactivated users.
4
Type=str
5
Categories=management-udm
6
7
[xxxxxx/delete/deactivated/days]
8
Description[de]=Nach wie vielen Tagen deaktivierte Benutzer automatisch gelöscht werden.
9
Description[en]=After how many days deactivated users are automatically deleted.
10
Type=str
11
Categories=management-udm
12
13
[xxxxxx/delete/deactivated/mail]
14
Description[de]=Aktiviert das Löschen von E-Mail-Verzeichnissen auf diesem Computer.
15
Description[en]=Activates the deletion of email directories on this computer.
16
Type=str
17
Categories=management-udm
18
19
[xxxxxx/delete/deactivated/mail/logfile]
20
Description[de]=Logdatei in der die gelöschten Mailboxen protokolliert werden.
21
Description[en]=Log file to log deleted mailboxes in.
22
Type=str
23
Categories=management-udm
(-)xxxxxx-delete-deactivated.orig/debian/xxxxxx-delete-deactivated-master.install (+2 lines)
Line 0    Link Here 
1
delete-deactivated-master.py usr/lib/univention-directory-listener/system
2
xxxxxx-delete-deactivated usr/sbin
(-)xxxxxx-delete-deactivated.orig/debian/xxxxxx-delete-deactivated-master.postinst (+46 lines)
Line 0    Link Here 
1
#!/bin/sh
2
#
3
# xxxxxx-delete-deactivated
4
#  -master postinst
5
#
6
# Copyright 2011 Univention GmbH
7
#
8
# http://www.univention.de/
9
#
10
# All rights reserved.
11
#
12
# The source code of this program is made available
13
# under the terms of the GNU Affero General Public License version 3
14
# (GNU AGPL V3) as published by the Free Software Foundation.
15
#
16
# Binary versions of this program provided by Univention to you as
17
# well as other copyrighted, protected or trademarked materials like
18
# Logos, graphics, fonts, specific documentations and configurations,
19
# cryptographic keys etc. are subject to a license agreement between
20
# you and Univention and not subject to the GNU AGPL V3.
21
#
22
# In the case you use this program under the terms of the GNU AGPL V3,
23
# the program is provided in the hope that it will be useful,
24
# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
# GNU Affero General Public License for more details.
27
#
28
# You should have received a copy of the GNU Affero General Public
29
# License with the Debian GNU/Linux or Univention distribution in file
30
# /usr/share/common-licenses/AGPL-3; if not, see
31
# <http://www.gnu.org/licenses/>.
32
33
#DEBHELPER#
34
35
if [ "$1" = 'configure' ]
36
then
37
	ldap_base="$(univention-config-registry get ldap/base)"
38
	univention-config-registry set 'xxxxxx/delete/deactivated/logfile?/var/log/univention/xxxxxx-delete-deactivated.log' \
39
		'xxxxxx/delete/deactivated/days?30' \
40
		'xxxxxx/delete/deactivated/mailaddress/schedule?root' \
41
		'xxxxxx/delete/deactivated/mailaddress/error?root' \
42
		'xxxxxx/delete/deactivated/blacklist?uid=join-backup,cn=users,'"$ldap_base"'|uid=join-slave,cn=users,'"$ldap_base"'|uid=spam,cn=users,'"$ldap_base"'|uid=Administrator,cn=users,'"$ldap_base"
43
	invoke-rc.d univention-directory-listener crestart
44
fi
45
46
exit 0
(-)xxxxxx-delete-deactivated.orig/debian/xxxxxx-delete-deactivated-master.univention-config-registry (+3 lines)
Line 0    Link Here 
1
Type: file
2
File: etc/cron.d/xxxxxx-delete-deactivated
3
Variables: xxxxxx/delete/deactivated/mailaddress/schedule
(-)xxxxxx-delete-deactivated.orig/debian/xxxxxx-delete-deactivated-master.univention-config-registry-variables (+35 lines)
Line 0    Link Here 
1
[xxxxxx/delete/deactivated]
2
Description[de]=Aktiviert das automatische Löschen von deaktivierten Benutzern
3
Description[en]=Activates the automatic deletion of deactivated users.
4
Type=str
5
Categories=management-udm
6
7
[xxxxxx/delete/deactivated/days]
8
Description[de]=Nach wie vielen Tagen deaktivierte Benutzer automatisch gelöscht werden.
9
Description[en]=After how many days deactivated users are automatically deleted.
10
Type=str
11
Categories=management-udm
12
13
[xxxxxx/delete/deactivated/mailaddress/schedule]
14
Description[de]=E-Mail Adresse an die eine Übersicht der zu löschenden Benutzer geschickt wird.
15
Description[en]=Email address to recieve an overview of the users which are going to be deleted.
16
Type=str
17
Categories=management-udm
18
19
[xxxxxx/delete/deactivated/mailaddress/error]
20
Description[de]=E-Mail Adresse an die Fehlermeldungen versendet werden.
21
Description[en]=Email address to recieve error messages.
22
Type=str
23
Categories=management-udm
24
25
[xxxxxx/delete/deactivated/logfile]
26
Description[de]=Protokolldatei in der die gelöschten Benutzer protokolliert werden.
27
Description[en]=Logfile to log deleted users in.
28
Type=str
29
Categories=management-udm
30
31
[xxxxxx/delete/deactivated/blacklist]
32
Description[de]=Liste der Benutzer, die nicht automatisch gelöscht werden sollen, wenn sie deaktiviert werden (Einträge sind DNs mit | getrennt)
33
Description[en]=List of users which should not be deleted automatically if deactivated (Entries are DNs separated with |)
34
Type=str
35
Categories=management-udm
(-)xxxxxx-delete-deactivated.orig/delete-deactivated-home.py (+133 lines)
Line 0    Link Here 
1
# -*- coding: utf-8 -*-
2
# xxxxxx-delete-deactivated-home
3
#  listener plugin to delete home directories
4
#
5
# Copyright 2011 Univention GmbH
6
#
7
# http://www.univention.de/
8
#
9
# All rights reserved.
10
#
11
# The source code of this program is made available
12
# under the terms of the GNU Affero General Public License version 3
13
# (GNU AGPL V3) as published by the Free Software Foundation.
14
#
15
# Binary versions of this program provided by Univention to you as
16
# well as other copyrighted, protected or trademarked materials like
17
# Logos, graphics, fonts, specific documentations and configurations,
18
# cryptographic keys etc. are subject to a license agreement between
19
# you and Univention and not subject to the GNU AGPL V3.
20
#
21
# In the case you use this program under the terms of the GNU AGPL V3,
22
# the program is provided in the hope that it will be useful,
23
# but WITHOUT ANY WARRANTY; without even the implied warranty of
24
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
# GNU Affero General Public License for more details.
26
#
27
# You should have received a copy of the GNU Affero General Public
28
# License with the Debian GNU/Linux or Univention distribution in file
29
# /usr/share/common-licenses/AGPL-3; if not, see
30
# <http://www.gnu.org/licenses/>.
31
32
name = 'delete-deactivated-home'
33
description = 'deletes the home directory of automatically deleted users'
34
filter = '(objectClass=posixAccount)'
35
attributes = ['uid']
36
modrdn = '1'
37
38
import listener
39
import univention.debug
40
import datetime
41
import time
42
43
UCRV_ACTIVATED = 'xxxxxx/delete/deactivated'
44
UCRV_ACTIVATED_HOME = 'xxxxxx/delete/deactivated/home'
45
UCRV_DAYS = 'xxxxxx/delete/deactivated/days'
46
UCRV_LOGFILE_HOME = 'xxxxxx/delete/deactivated/home/logfile'
47
48
def userIsDeactivated(user):
49
	if not user.get('krb5KDCFlags', []) == ['254']:
50
		return False
51
	if not user.get('shadowExpire', []) == ['1']:
52
		return False
53
	if not user.get('sambaAcctFlags', []) in (['[UD         ]'], ['[ULD       ]'], ):
54
		return False
55
	return True
56
57
def encodeTimestamp(timestamp):
58
	return (timestamp - datetime.timedelta(10000)).strftime('%Y%m%d%H%M%SZ')
59
60
def decodeTimestamp(text):
61
	return datetime.date(*time.strptime(text, '%Y%m%d%H%M%SZ')[:3]) + datetime.timedelta(10000)
62
63
def now():
64
	return datetime.date(*time.gmtime()[:3])
65
66
def userHasDeactivationTimestamp(user):
67
	return user.get('krb5ValidEnd') and decodeTimestamp(user['krb5ValidEnd'][0]) <= now()
68
69
def userHasExpired(user, expiryAfterDays):
70
	if not expiryAfterDays:
71
		return False
72
	return decodeTimestamp(user['krb5ValidEnd'][0]) + datetime.timedelta(expiryAfterDays) <= now()
73
74
def logfile(message):
75
	if UCRV_LOGFILE_HOME not in listener.baseConfig:
76
		return
77
	listener.setuid(0)
78
	try:
79
		log = open(listener.baseConfig[UCRV_LOGFILE_HOME], 'a')
80
		log.write(message + '\n')
81
		log.close()
82
	finally:
83
		listener.unsetuid()
84
85
def deleteHome(dn, user):
86
	if not 'homeDirectory' in user:
87
		univention.debug.debug(univention.debug.LISTENER, univention.debug.WARN, "[delete-deactivated-home] 'homeDirectory' not in user %r" % (dn, ))
88
		return
89
	logfile('Deleting %r for %r' % (user['homeDirectory'][0], dn, ))
90
	listener.run('/usr/bin/find', ['find', user['homeDirectory'][0], '-delete', ], 0, False)
91
92
def handler(dn, new, old, command):
93
	if listener.baseConfig.get(UCRV_ACTIVATED, '').lower() not in ('yes', 'true', '1', 'enable', 'enabled', 'on'):
94
		univention.debug.debug(univention.debug.LISTENER, univention.debug.INFO, "[delete-deactivated-home] disabled via UCRV " + UCRV_ACTIVATED)
95
		return
96
	if listener.baseConfig.get(UCRV_ACTIVATED_HOME, '').lower() not in ('yes', 'true', '1', 'enable', 'enabled', 'on'):
97
		univention.debug.debug(univention.debug.LISTENER, univention.debug.WARN, "[delete-deactivated-home] disabled via UCRV " + UCRV_ACTIVATED_HOME)
98
		return
99
	univention.debug.debug(univention.debug.LISTENER, univention.debug.INFO, "[delete-deactivated-home] command == %r" % (command, ))
100
	if command == 'm': # object modified
101
		pass # don't care
102
	elif command == 'd': # object deleted
103
		univention.debug.debug(univention.debug.LISTENER, univention.debug.INFO, "[delete-deactivated-home] userHasDeactivationTimestamp(old) == %r" % (userHasDeactivationTimestamp(old), ))
104
		if userHasDeactivationTimestamp(old): # correctly (==automatically) deleted
105
			expiryAfterDays = None
106
			try:
107
				expiryAfterDays = max(0, int(listener.baseConfig.get(UCRV_DAYS)))
108
			except (TypeError, ValueError, ):
109
				pass
110
			univention.debug.debug(univention.debug.LISTENER, univention.debug.INFO, "[delete-deactivated-home] userHasExpired(old, %r) == %r" % (expiryAfterDays, userHasExpired(old, expiryAfterDays), ))
111
			if userHasExpired(old, expiryAfterDays):
112
				deleteHome(dn, old)
113
			else:
114
				univention.debug.debug(univention.debug.LISTENER, univention.debug.WARN, "[delete-deactivated-home] user %r deleted before expiry" % (dn, ))
115
		else: # incorrectly (==manually) deleted
116
			pass # don't care (the listener on master whines about wrong deletion)
117
	elif command == 'r': # object "deleted" for rename
118
		pass # don't care
119
	elif command == 'a': # object added || object "added" for rename (last was 'r')
120
		pass # don't care
121
	elif command == 'n': # initial/resync
122
		pass # don't care
123
	else:
124
		univention.debug.debug(univention.debug.LISTENER, univention.debug.ERROR, "[delete-deactivated-home] command == %r is unknown!" % (command, ))
125
126
def postrun():
127
	pass
128
129
def clean():
130
	pass
131
132
def initialize():
133
	pass
(-)xxxxxx-delete-deactivated.orig/delete-deactivated-mail.py (+133 lines)
Line 0    Link Here 
1
# -*- coding: utf-8 -*-
2
# xxxxxx-delete-deactivated
3
#  listener plugin to delete home directories
4
#
5
# Copyright 2011 Univention GmbH
6
#
7
# http://www.univention.de/
8
#
9
# All rights reserved.
10
#
11
# The source code of this program is made available
12
# under the terms of the GNU Affero General Public License version 3
13
# (GNU AGPL V3) as published by the Free Software Foundation.
14
#
15
# Binary versions of this program provided by Univention to you as
16
# well as other copyrighted, protected or trademarked materials like
17
# Logos, graphics, fonts, specific documentations and configurations,
18
# cryptographic keys etc. are subject to a license agreement between
19
# you and Univention and not subject to the GNU AGPL V3.
20
#
21
# In the case you use this program under the terms of the GNU AGPL V3,
22
# the program is provided in the hope that it will be useful,
23
# but WITHOUT ANY WARRANTY; without even the implied warranty of
24
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
# GNU Affero General Public License for more details.
26
#
27
# You should have received a copy of the GNU Affero General Public
28
# License with the Debian GNU/Linux or Univention distribution in file
29
# /usr/share/common-licenses/AGPL-3; if not, see
30
# <http://www.gnu.org/licenses/>.
31
32
name = 'delete-deactivated-mail'
33
description = 'deletes the mail of automatically deleted users'
34
filter = '(objectClass=posixAccount)'
35
attributes = ['uid']
36
modrdn = '1'
37
38
import listener
39
import univention.debug
40
import datetime
41
import time
42
43
UCRV_ACTIVATED = 'xxxxxx/delete/deactivated'
44
UCRV_ACTIVATED_MAIL = 'xxxxxx/delete/deactivated/mail'
45
UCRV_DAYS = 'xxxxxx/delete/deactivated/days'
46
UCRV_LOGFILE_MAIL = 'xxxxxx/delete/deactivated/mail/logfile'
47
48
def userIsDeactivated(user):
49
	if not user.get('krb5KDCFlags', []) == ['254']:
50
		return False
51
	if not user.get('shadowExpire', []) == ['1']:
52
		return False
53
	if not user.get('sambaAcctFlags', []) in (['[UD         ]'], ['[ULD       ]'], ):
54
		return False
55
	return True
56
57
def encodeTimestamp(timestamp):
58
	return (timestamp - datetime.timedelta(10000)).strftime('%Y%m%d%H%M%SZ')
59
60
def decodeTimestamp(text):
61
	return datetime.date(*time.strptime(text, '%Y%m%d%H%M%SZ')[:3]) + datetime.timedelta(10000)
62
63
def now():
64
	return datetime.date(*time.gmtime()[:3])
65
66
def userHasDeactivationTimestamp(user):
67
	return user.get('krb5ValidEnd') and decodeTimestamp(user['krb5ValidEnd'][0]) <= now()
68
69
def userHasExpired(user, expiryAfterDays):
70
	if not expiryAfterDays:
71
		return False
72
	return decodeTimestamp(user['krb5ValidEnd'][0]) + datetime.timedelta(expiryAfterDays) <= now()
73
74
def logfile(message):
75
	if UCRV_LOGFILE_MAIL not in listener.baseConfig:
76
		return
77
	listener.setuid(0)
78
	try:
79
		log = open(listener.baseConfig[UCRV_LOGFILE_MAIL], 'a')
80
		log.write(message + '\n')
81
		log.close()
82
	finally:
83
		listener.unsetuid()
84
85
def deleteMail(dn, user):
86
	if not 'mailPrimaryAddress' in user:
87
		univention.debug.debug(univention.debug.LISTENER, univention.debug.WARN, "[delete-deactivated-mail] 'mailPrimaryAddress' not in user %r" % (dn, ))
88
		return
89
	logfile('Deleting %r for %r' % (user['mailPrimaryAddress'][0], dn, ))
90
	listener.run('/usr/sbin/univention-cyrus-mailbox-delete', ['univention-cyrus-mailbox-delete', '--user', user['mailPrimaryAddress'][0], ], 0, False)
91
92
def handler(dn, new, old, command):
93
	if listener.baseConfig.get(UCRV_ACTIVATED, '').lower() not in ('yes', 'true', '1', 'enable', 'enabled', 'on'):
94
		univention.debug.debug(univention.debug.LISTENER, univention.debug.INFO, "[delete-deactivated-mail] disabled via UCRV " + UCRV_ACTIVATED)
95
		return
96
	if listener.baseConfig.get(UCRV_ACTIVATED_MAIL, '').lower() not in ('yes', 'true', '1', 'enable', 'enabled', 'on'):
97
		univention.debug.debug(univention.debug.LISTENER, univention.debug.WARN, "[delete-deactivated-mail] disabled via UCRV " + UCRV_ACTIVATED_MAIL)
98
		return
99
	univention.debug.debug(univention.debug.LISTENER, univention.debug.INFO, "[delete-deactivated-mail] command == %r" % (command, ))
100
	if command == 'm': # object modified
101
		pass # don't care
102
	elif command == 'd': # object deleted
103
		univention.debug.debug(univention.debug.LISTENER, univention.debug.INFO, "[delete-deactivated-mail] userHasDeactivationTimestamp(old) == %r" % (userHasDeactivationTimestamp(old), ))
104
		if userHasDeactivationTimestamp(old): # correctly (==automatically) deleted
105
			expiryAfterDays = None
106
			try:
107
				expiryAfterDays = max(0, int(listener.baseConfig.get(UCRV_DAYS)))
108
			except (TypeError, ValueError, ):
109
				pass
110
			univention.debug.debug(univention.debug.LISTENER, univention.debug.INFO, "[delete-deactivated-mail] userHasExpired(old, %r) == %r" % (expiryAfterDays, userHasExpired(old, expiryAfterDays), ))
111
			if userHasExpired(old, expiryAfterDays):
112
				deleteMail(dn, old)
113
			else:
114
				univention.debug.debug(univention.debug.LISTENER, univention.debug.WARN, "[delete-deactivated-mail] user %r deleted before expiry" % (dn, ))
115
		else: # incorrectly (==manually) deleted
116
			pass # don't care (the listener on master whines about wrong deletion)
117
	elif command == 'r': # object "deleted" for rename
118
		pass # don't care
119
	elif command == 'a': # object added || object "added" for rename (last was 'r')
120
		pass # don't care
121
	elif command == 'n': # initial/resync
122
		pass # don't care
123
	else:
124
		univention.debug.debug(univention.debug.LISTENER, univention.debug.ERROR, "[delete-deactivated-mail] command == %r is unknown!" % (command, ))
125
126
def postrun():
127
	pass
128
129
def clean():
130
	pass
131
132
def initialize():
133
	pass
(-)xxxxxx-delete-deactivated.orig/delete-deactivated-master.py (+195 lines)
Line 0    Link Here 
1
# -*- coding: utf-8 -*-
2
# xxxxxx-delete-deactivated
3
#  listener plugin to delete home directories
4
#
5
# Copyright 2011 Univention GmbH
6
#
7
# http://www.univention.de/
8
#
9
# All rights reserved.
10
#
11
# The source code of this program is made available
12
# under the terms of the GNU Affero General Public License version 3
13
# (GNU AGPL V3) as published by the Free Software Foundation.
14
#
15
# Binary versions of this program provided by Univention to you as
16
# well as other copyrighted, protected or trademarked materials like
17
# Logos, graphics, fonts, specific documentations and configurations,
18
# cryptographic keys etc. are subject to a license agreement between
19
# you and Univention and not subject to the GNU AGPL V3.
20
#
21
# In the case you use this program under the terms of the GNU AGPL V3,
22
# the program is provided in the hope that it will be useful,
23
# but WITHOUT ANY WARRANTY; without even the implied warranty of
24
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
# GNU Affero General Public License for more details.
26
#
27
# You should have received a copy of the GNU Affero General Public
28
# License with the Debian GNU/Linux or Univention distribution in file
29
# /usr/share/common-licenses/AGPL-3; if not, see
30
# <http://www.gnu.org/licenses/>.
31
32
name = 'delete-deactivated-master'
33
description = 'Stores the timestamp when a user is deactivated'
34
filter = '(&(|(&(objectClass=posixAccount)(objectClass=shadowAccount))(objectClass=univentionMail)(objectClass=sambaSamAccount)(objectClass=simpleSecurityObject)(&(objectClass=person)(objectClass=organizationalPerson)(objectClass=inetOrgPerson)))(!(uidNumber=0))(!(uid=*$)))'
35
attributes = ['krb5KDCFlags', 'shadowExpire', 'sambaAcctFlags']
36
modrdn = '1'
37
38
import listener
39
import univention.debug
40
import univention.uldap
41
import datetime
42
import time
43
44
UCRV_ACTIVATED = 'xxxxxx/delete/deactivated'
45
UCRV_BLACKLIST = 'xxxxxx/delete/deactivated/blacklist'
46
UCRV_DAYS = 'xxxxxx/delete/deactivated/days'
47
UCRV_MAIL_ERROR = 'xxxxxx/delete/deactivated/mailaddress/error'
48
49
def userIsDeactivated(user):
50
	if not user.get('krb5KDCFlags', []) == ['254']:
51
		return False
52
	if not user.get('shadowExpire', []) == ['1']:
53
		return False
54
	if not user.get('sambaAcctFlags', []) in (['[UD         ]'], ['[ULD       ]'], ):
55
		return False
56
	return True
57
58
def encodeTimestamp(timestamp):
59
	return (timestamp - datetime.timedelta(10000)).strftime('%Y%m%d%H%M%SZ')
60
61
def decodeTimestamp(text):
62
	return datetime.date(*time.strptime(text, '%Y%m%d%H%M%SZ')[:3]) + datetime.timedelta(10000)
63
64
def now():
65
	return datetime.date(*time.gmtime()[:3])
66
67
def userHasDeactivationTimestamp(user):
68
	return user.get('krb5ValidEnd') and decodeTimestamp(user['krb5ValidEnd'][0]) <= now()
69
70
def userHasExpired(user, expiryAfterDays):
71
	if not expiryAfterDays:
72
		return False
73
	return decodeTimestamp(user['krb5ValidEnd'][0]) + datetime.timedelta(expiryAfterDays) <= now()
74
75
import email.MIMEText
76
import smtplib
77
def errorMail(message, user):
78
	textMessage = 'Hallo,\n\nxxxxxx-delete-deactivated meldet folgendes Problem:\n'
79
	textMessage+= message.strip() + '\n'
80
	textMessage+= '\n\nDie Attribute des Benutzers waren:\n{\n'
81
	for (key, value, ) in user.items():
82
		textMessage+= '%r: %r,' % (key, value, )
83
	textMessage+= '}\n'
84
	mailMessage = email.MIMEText.MIMEText(message, 'plain', 'utf-8')
85
	mailMessage['Subject'] = message
86
	mailMessage['To'] = listener.baseConfig.get(UCRV_MAIL_ERROR, 'root')
87
	mailMessage['From'] = 'root@' + listener.baseConfig.get('hostname', 'localhost')
88
	s = smtplib.SMTP('localhost')
89
	s.sendmail(mailMessage['From'], [mailMessage['To']], mailMessage.as_string())
90
	s.quit()
91
92
def userIsBlacklisted(dn):
93
	if UCRV_BLACKLIST not in listener.baseConfig:
94
		return False
95
	blacklist = listener.baseConfig[UCRV_BLACKLIST].split('|')
96
	return dn in blacklist
97
98
def handler(dn, new, old, command):
99
	if listener.baseConfig.get(UCRV_ACTIVATED, '').lower() not in ('yes', 'true', '1', 'enable', 'enabled', 'on'):
100
		univention.debug.debug(univention.debug.LISTENER, univention.debug.INFO, "[delete-deactivated-master] disabled via UCRV " + UCRV_ACTIVATED)
101
		return
102
	univention.debug.debug(univention.debug.LISTENER, univention.debug.INFO, "[delete-deactivated-master] command == %r" % (command, ))
103
	if userIsBlacklisted(dn):
104
		univention.debug.debug(univention.debug.LISTENER, univention.debug.INFO, "[delete-deactivated-master] ignoring blacklisted %r" % (dn, ))
105
		return
106
	if command == 'm': # object modified
107
		if old and new: # modification
108
			univention.debug.debug(univention.debug.LISTENER, univention.debug.INFO, "[delete-deactivated-master] userIsDeactivated(old) == %s userIsDeactivated(new) == %s" % (userIsDeactivated(old), userIsDeactivated(new), ))
109
			if not userIsDeactivated(old) and userIsDeactivated(new): # activated → deactivated
110
				postrun.actions.append( ('deactivated', dn, ) )
111
			if userIsDeactivated(old) and not userIsDeactivated(new): # deactivated → activated
112
				postrun.actions.append( (  'activated', dn, ) )
113
		else:
114
			univention.debug.debug(univention.debug.LISTENER, univention.debug.ERROR, "[delete-deactivated-master] command == 'm' and not (old and new)! old=%r new=%r" % (old, new, ))
115
	elif command == 'd': # object deleted
116
		if userHasDeactivationTimestamp(old): # deleted correctly (==automatically)
117
			expiryAfterDays = None
118
			try:
119
				expiryAfterDays = max(0, int(listener.baseConfig.get(UCRV_DAYS)))
120
			except (TypeError, ValueError, ):
121
				pass
122
			univention.debug.debug(univention.debug.LISTENER, univention.debug.INFO, "[delete-deactivated-master] userHasExpired(old, %r) == %r" % (expiryAfterDays, userHasExpired(old, expiryAfterDays), ))
123
			if userHasExpired(old, expiryAfterDays):
124
				pass # don't care (the other listeners process automatic user deletion)
125
			else:
126
				univention.debug.debug(univention.debug.LISTENER, univention.debug.WARN, "[delete-deactivated-master] user %r deleted before expiry" % (dn, ))
127
			errorMail('Benutzer %r wurde vor Ablauf gelöscht' % (dn, ), old)
128
		else: # deleted incorrectly (==manually)
129
			univention.debug.debug(univention.debug.LISTENER, univention.debug.WARN, "[delete-deactivated-master] user %r deleted incorrectly" % (dn, ))
130
			errorMail('Benutzer %r wurde manuell gelöscht' % (dn, ), old)
131
	elif command == 'r': # object "deleted" for rename
132
		pass # don't care
133
	elif command == 'a': # object added || object "added" for rename (last was 'r')
134
		pass # don't care
135
	elif command == 'n': # initial/resync
136
		pass # don't care
137
	else:
138
		univention.debug.debug(univention.debug.LISTENER, univention.debug.ERROR, "[delete-deactivated-master] command == %r is unknown!" % (command, ))
139
140
def postrun():
141
	univention.debug.debug(univention.debug.LISTENER, univention.debug.INFO, "[delete-deactivated-master] postrun.actions == %r" % (postrun.actions, ))
142
	actions = {}
143
	for (action, dn, ) in postrun.actions:
144
		actions[dn] = action
145
	postrun.actions = []
146
	for (dn, action, ) in actions.items():
147
		if not ldap_info['lo']:
148
			ldap_reconnect()
149
		if action == 'deactivated':
150
			changes = [('krb5ValidEnd', ldap_info['lo'].getAttr(dn, 'krb5ValidEnd'), [encodeTimestamp(now())], ),
151
			           ('shadowExpire', ldap_info['lo'].getAttr(dn, 'shadowExpire'), ['1'], )]
152
		elif action == 'activated':
153
			changes = [('krb5ValidEnd', ldap_info['lo'].getAttr(dn, 'krb5ValidEnd'), [], ),
154
			           ('shadowExpire', ldap_info['lo'].getAttr(dn, 'shadowExpire'), [], )]
155
		if ldap_info['lo']:
156
			ldap_info['lo'].modify(dn, changes)
157
		else:
158
			univention.debug.debug(univention.debug.LISTENER, univention.debug.ERROR, "[delete-deactivated-master] ldap_info['lo'] is %r! Could not set timestamp for %r" % (ldap_info['lo'], dn, ))
159
postrun.actions = []
160
161
def clean():
162
	pass
163
164
def initialize():
165
	pass
166
167
ldap_info = {}
168
def ldap_reconnect():
169
	univention.debug.debug(univention.debug.LISTENER, univention.debug.INFO, '[delete-deactivated-master] ldap reconnect triggered')
170
	if 'ldapserver' in ldap_info and 'basedn' in ldap_info and 'binddn' in ldap_info and 'bindpw' in ldap_info:
171
		try:
172
			ldap_info['lo'] = univention.uldap.access(host = ldap_info['ldapserver'],
173
			                                          base = ldap_info['basedn'],
174
			                                          binddn = ldap_info['binddn'],
175
			                                          bindpw = ldap_info['bindpw'],
176
			                                          start_tls = 2)
177
		except ValueError, ex:
178
			univention.debug.debug(univention.debug.LISTENER, univention.debug.ERROR, '[delete-deactivated-master] ldap reconnect failed: %s' % str(ex))
179
			ldap_info['lo'] = None
180
		else:
181
			if ldap_info['lo'] == None:
182
				univention.debug.debug(univention.debug.LISTENER, univention.debug.ERROR, '[delete-deactivated-master] ldap reconnect failed')
183
184
def setdata(key, value):
185
	if key == 'bindpw':
186
		univention.debug.debug(univention.debug.LISTENER, univention.debug.INFO, '[delete-deactivated-master] listener passed key="%s" value="<HIDDEN>"' % key)
187
	else:
188
		univention.debug.debug(univention.debug.LISTENER, univention.debug.INFO, '[delete-deactivated-master] listener passed key="%s" value="%s"' % (key, value))
189
	if key in [ 'ldapserver', 'basedn', 'binddn', 'bindpw' ]:
190
		ldap_info[ key ] = value
191
	else:
192
		univention.debug.debug(univention.debug.LISTENER, univention.debug.INFO, '[delete-deactivated-master] listener passed unknown data (key="%s" value="%s")' % (key, value))
193
	if key == 'ldapserver':
194
		univention.debug.debug(univention.debug.LISTENER, univention.debug.INFO, '[delete-deactivated-master] ldap server changed to %s' % value)
195
		ldap_reconnect()
(-)xxxxxx-delete-deactivated.orig/README (+46 lines)
Line 0    Link Here 
1
Allgemein:
2
  Benutzer werden nicht mehr gelöscht, sondern deaktiviert (Benutzer-Konto → Konto-Deaktiviertung → Alle deaktiviert).
3
  Wird ein Benutzer deaktiviert speichert ein listener-Modul nach kurzer Zeit das Datum des deaktivierens (aka Heute) in dem Konto-Ablaufdatum (Wert = Deaktivierungszeitpunkt - 10000 Tage)
4
  Ein cron-job löscht täglich alle Benutzer die länger als xxxxxx/delete/deactivated/days deaktiviert waren und schreibt dies in eine Protokolldatei.
5
  Listener-Skripte auf den Systemen auf denen home/mail gelöscht werden sollen erkennen das Löschen, prüfen ob der Benutzer nach Ablauf gelöscht wurde, und löschen dann das entsprechende /home oder die mailbox
6
7
  xxxxxx/delete/deactivated/days muss auf allen Systemen, auf denen eines der Pakete installiert ist, gleich gesetzt sein.
8
9
  Der Listener muss neu gestartet werden, damit die Änderungen an UCR-Variablen übernommen werden!
10
11
Paket xxxxxx-delete-deactivated-master:
12
  Wird auf dem Master installiert
13
  Enthält ein Listener-Skript, das für deaktivierte Benutzer das Konto-Ablaufdatum setzt
14
    Sofern xxxxxx/delete/deactivated=yes
15
    Fehlbedienungen (Benutzer manuell gelöscht) werden per E-Mail an xxxxxx/delete/deactivated/mailaddress/error gesendet
16
    Sofern der Benutzer nicht in der xxxxxx/delete/deactivated/blacklist steht
17
  Enthält /usr/sbin/xxxxxx-delete-deactivated
18
    Löscht abgelaufene Benutzer, sofern
19
      xxxxxx/delete/deactivated=yes
20
      xxxxxx/delete/deactivated/days >= 1
21
    Kann auch manuell aufgerufen werden, ohne --force werden die Benutzer nicht gelöscht.
22
    Protokolliert gelöschte Benutzer in xxxxxx/delete/deactivated/logfile
23
  Enthält cron-job der täglich xxxxxx-delete-deactivated aufruft
24
    Ausgaben gehen per E-Mail an xxxxxx/delete/deactivated/mailaddress/schedule
25
26
Paket xxxxxx-delete-deactivated-home:
27
  Wird dort installiert wo /home gelöscht werden soll
28
  Enthält ein Listener-Skript, das für gelöschte Benutzer das /home löscht, sofern
29
    sie nach dem Ablauf (also automatisch) gelöscht wurden,
30
    xxxxxx/delete/deactivated=yes
31
    xxxxxx/delete/deactivated/home=yes
32
      (Warnt (in der listener.log) wenn diese Variable nicht gesetzt ist - dann sollte das Paket auch nicht installiert sein)
33
    xxxxxx/delete/deactivated/days >= 1
34
    Das Home-Verzeichnis == /home/$USER ist
35
      (Ansonsten wird ein Fehler in die listener.log eingetragen)
36
    Protokolliert gelöschte Heimatverzeichnisse in xxxxxx/delete/deactivated/home/logfile
37
38
Paket xxxxxx-delete-deactivated-mail:
39
  Wird dort installiert wo Mailboxen gelöscht werden sollen
40
  Enthält ein Listener-Skript, das für gelöschte Benutzer die Mailbox löscht, sofern
41
    sie nach dem Ablauf (also automatisch) gelöscht wurden,
42
    xxxxxx/delete/deactivated=yes
43
    xxxxxx/delete/deactivated/mail=yes
44
      (Warnt (in der listener.log) wenn diese Variable nicht gesetzt ist - dann sollte das Paket auch nicht installiert sein)
45
    xxxxxx/delete/deactivated/days >= 1
46
    Protokolliert gelöschte Mailboxen in xxxxxx/delete/deactivated/mail/logfile
(-)xxxxxx-delete-deactivated.orig/xxxxxx-delete-deactivated (+133 lines)
Line 0    Link Here 
1
#!/usr/bin/python2.4
2
# -*- coding: utf-8 -*-
3
#
4
# xxxxxx-delete-deactivated
5
#  summarize and delete deactivated users
6
#
7
# Copyright 2011 Univention GmbH
8
#
9
# http://www.univention.de/
10
#
11
# All rights reserved.
12
#
13
# The source code of this program is made available
14
# under the terms of the GNU Affero General Public License version 3
15
# (GNU AGPL V3) as published by the Free Software Foundation.
16
#
17
# Binary versions of this program provided by Univention to you as
18
# well as other copyrighted, protected or trademarked materials like
19
# Logos, graphics, fonts, specific documentations and configurations,
20
# cryptographic keys etc. are subject to a license agreement between
21
# you and Univention and not subject to the GNU AGPL V3.
22
#
23
# In the case you use this program under the terms of the GNU AGPL V3,
24
# the program is provided in the hope that it will be useful,
25
# but WITHOUT ANY WARRANTY; without even the implied warranty of
26
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
# GNU Affero General Public License for more details.
28
#
29
# You should have received a copy of the GNU Affero General Public
30
# License with the Debian GNU/Linux or Univention distribution in file
31
# /usr/share/common-licenses/AGPL-3; if not, see
32
# <http://www.gnu.org/licenses/>.
33
import univention.config_registry
34
import univention.uldap
35
import subprocess
36
import sys
37
import datetime
38
import time
39
import optparse
40
41
UCRV_ACTIVATED = 'xxxxxx/delete/deactivated'
42
UCRV_DAYS = 'xxxxxx/delete/deactivated/days'
43
UCRV_LOGFILE = 'xxxxxx/delete/deactivated/logfile'
44
LDAP_SEARCHFILTER = '(&(|(&(objectClass=posixAccount)(objectClass=shadowAccount))(objectClass=univentionMail)(objectClass=sambaSamAccount)(objectClass=simpleSecurityObject)(&(objectClass=person)(objectClass=organizationalPerson)(objectClass=inetOrgPerson)))(!(uidNumber=0))(!(uid=*$)))'
45
46
def userIsDeactivated(user):
47
	if not user.get('krb5KDCFlags', []) == ['254']:
48
		return False
49
	if not user.get('shadowExpire', []) == ['1']:
50
		return False
51
	if not user.get('sambaAcctFlags', []) in (['[UD         ]'], ['[ULD       ]'], ):
52
		return False
53
	return True
54
55
def encodeTimestamp(timestamp):
56
	return (timestamp - datetime.timedelta(10000)).strftime('%Y%m%d%H%M%SZ')
57
58
def decodeTimestamp(text):
59
	return datetime.date(*time.strptime(text, '%Y%m%d%H%M%SZ')[:3]) + datetime.timedelta(10000)
60
61
def now():
62
	return datetime.date(*time.gmtime()[:3])
63
64
def userHasDeactivationTimestamp(user):
65
	return user.get('krb5ValidEnd') and decodeTimestamp(user['krb5ValidEnd'][0]) <= now()
66
67
def userHasExpired(user, expiryAfterDays):
68
	if not expiryAfterDays:
69
		return False
70
	return decodeTimestamp(user['krb5ValidEnd'][0]) + datetime.timedelta(expiryAfterDays) <= now()
71
72
def deleteExpiredUsers(searchResults, expiryAfterDays, logFile):
73
	errorsOccurred = False
74
	for (dn, user, ) in searchResults:
75
		if userHasDeactivationTimestamp(user):
76
			if userHasExpired(user, expiryAfterDays):
77
				logFile.write('deleting %r\n' % dn)
78
				if not subprocess.call( ('/usr/sbin/univention-directory-manager', 'users/user', 'remove', '--dn', dn, ) ) == 0:
79
					errorsOccurred = True
80
	return not errorsOccurred
81
82
def buildDeletionSchedule(searchResults, expiryAfterDays):
83
	if not expiryAfterDays:
84
		print 'ACHTUNG: ' + UCRV_DAYS + ' ist ungültig, daher werden keine automatischen Löschungen durchgeführt!'
85
		return
86
	schedule = []
87
	for (dn, user, ) in searchResults:
88
		if userHasDeactivationTimestamp(user):
89
			expiryIn = (datetime.timedelta(expiryAfterDays) - (now() - decodeTimestamp(user['krb5ValidEnd'][0]))).days
90
			schedule.append( (expiryIn, dn, ) )
91
	schedule.sort()
92
	print 'Die folgenden Benutzer werden gelöscht:'
93
	foundDelete = False
94
	for (expiryIn, dn, ) in schedule:
95
		if expiryIn <= 0:
96
			foundDelete = True
97
			print '    %s' % (dn, )
98
	if not foundDelete:
99
		print '    -keine-'
100
	print
101
	print 'Die folgenden Benutzer sind für die Löschung in den nächsten Tagen vorgesehen:'
102
	found = False
103
	for (expiryIn, dn, ) in sorted(schedule):
104
		if expiryIn > 0:
105
			found = True
106
			print '%3d %s' % (expiryIn, dn, )
107
	if not found:
108
		print '    -keine-'
109
	if foundDelete:
110
		print
111
		print 'Detailierte Informationen zum Löschvorgang:'
112
113
if __name__ == "__main__":
114
	parser = optparse.OptionParser()
115
	parser.add_option('-d', '--delete', dest='delete', action='store_true', default=False, help='actually delete users')
116
	(options, args, ) = parser.parse_args()
117
	uldap = univention.uldap.getAdminConnection()
118
	ucr = univention.config_registry.ConfigRegistry()
119
	ucr.load()
120
	expiryAfterDays = None
121
	if ucr.get(UCRV_ACTIVATED, '').lower() not in ('yes', 'true', '1', 'enable', 'enabled', 'on'):
122
		sys.exit()
123
	try:
124
		expiryAfterDays = max(0, int(ucr.get(UCRV_DAYS)))
125
	except (TypeError, ValueError, ):
126
		pass
127
	if UCRV_LOGFILE in ucr:
128
		logFile = open(ucr[UCRV_LOGFILE], 'a')
129
	searchResults = uldap.search(filter=LDAP_SEARCHFILTER)
130
	buildDeletionSchedule(searchResults, expiryAfterDays)
131
	if options.delete:
132
		if not deleteExpiredUsers(searchResults, expiryAfterDays, logFile):
133
			sys.exit(1)

Return to bug 20929