Changeset View
Standalone View
ucs/listener.py
Show All 15 Lines | |||||
# You should have received a copy of the GNU General Public License | # You should have received a copy of the GNU General Public License | ||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
# | # | ||||
# workaround for PEP 366 | # workaround for PEP 366 | ||||
__package__ = '' | __package__ = '' | ||||
import listener | import listener | ||||
Lint: PEP8 E402: module level import not at top of file | |||||
import logging | import logging | ||||
Lint: PEP8 E402 module level import not at top of file Lint: PEP8 E402: module level import not at top of file | |||||
import os | import os | ||||
Lint: PEP8 E402 module level import not at top of file Lint: PEP8 E402: module level import not at top of file | |||||
import sys | import sys | ||||
Lint: PEP8 E402 module level import not at top of file Lint: PEP8 E402: module level import not at top of file | |||||
from univention.config_registry import ConfigRegistry | from univention.config_registry import ConfigRegistry | ||||
Lint: PEP8 E402 module level import not at top of file Lint: PEP8 E402: module level import not at top of file | |||||
import univention.debug as ulog | import univention.debug as ulog | ||||
Lint: PEP8 E402 module level import not at top of file Lint: PEP8 E402: module level import not at top of file | |||||
sys.path = [ | sys.path = [ | ||||
os.path.abspath( | os.path.abspath( | ||||
os.path.join( | os.path.join( | ||||
os.path.dirname( | os.path.dirname( | ||||
os.path.realpath(os.path.abspath(__file__)) | os.path.realpath(os.path.abspath(__file__)) | ||||
), | ), | ||||
'..' | '..' | ||||
) | ) | ||||
) ] + sys.path | )] + sys.path | ||||
#sys.stderr = open('/dev/null', 'a') | #sys.stderr = open('/dev/null', 'a') | ||||
Lint: PEP8 E265 block comment should start with '# ' Lint: PEP8 E265: block comment should start with '# ' | |||||
name = 'kolab' | name = 'kolab' | ||||
description = "Kolab Groupware Listener for UCS" | description = "Kolab Groupware Listener for UCS" | ||||
# The filter has to be composed to make sure only Kolab Groupware | # The filter has to be composed to make sure only Kolab Groupware | ||||
# related objects are passed along to this listener module. | # related objects are passed along to this listener module. | ||||
filter = '(|(objectClass=kolabInetOrgPerson)(objectClass=univentionMailSharedFolder))' | filter = '(|(objectClass=kolabInetOrgPerson)(objectClass=univentionMailSharedFolder))' | ||||
Lint: PEP8 E501 line too long (86 > 79 characters) Lint: PEP8 E501: line too long (86 > 79 characters) | |||||
#attributes = [ '*' ] | # attributes = ['*'] | ||||
import pykolab | import pykolab | ||||
Lint: PEP8 E402 module level import not at top of file Lint: PEP8 E402: module level import not at top of file | |||||
from pykolab import constants | from pykolab import constants | ||||
Lint: PEP8 E402 module level import not at top of file Lint: PEP8 E402: module level import not at top of file | |||||
from pykolab import utils | from pykolab import utils | ||||
Lint: PEP8 E402 module level import not at top of file Lint: PEP8 E402: module level import not at top of file | |||||
log = pykolab.getLogger('pykolab.listener') | log = pykolab.getLogger('pykolab.listener') | ||||
#log.remove_stdout_handler() | # log.remove_stdout_handler() | ||||
log.setLevel(logging.DEBUG) | log.setLevel(logging.DEBUG) | ||||
log.debuglevel = 9 | log.debuglevel = 9 | ||||
conf = pykolab.getConf() | conf = pykolab.getConf() | ||||
conf.finalize_conf(fatal=False) | conf.finalize_conf(fatal=False) | ||||
conf.debuglevel = 9 | conf.debuglevel = 9 | ||||
from pykolab.auth import Auth | from pykolab.auth import Auth | ||||
Lint: PEP8 E402 module level import not at top of file Lint: PEP8 E402: module level import not at top of file | |||||
def handler(*args, **kw): | def handler(*args, **kw): | ||||
log.info("kolab.handler(args(%d): %r, kw: %r)" % (len(args), args, kw)) | log.info("kolab.handler(args(%d): %r, kw: %r)" % (len(args), args, kw)) | ||||
auth = Auth() | auth = Auth() | ||||
auth.connect() | auth.connect() | ||||
if len(args) == 4: | if len(args) == 4: | ||||
# moddn | # moddn | ||||
Show All 12 Lines | elif len(args) == 3: | ||||
# Two options: | # Two options: | ||||
# - entry changed | # - entry changed | ||||
# - entry deleted | # - entry deleted | ||||
log.info("user %r, old is dict" % (dn)) | log.info("user %r, old is dict" % (dn)) | ||||
if isinstance(new, dict) and len(new.keys()) > 0: | if isinstance(new, dict) and len(new.keys()) > 0: | ||||
log.info("Modify entry %r" % (dn)) | log.info("Modify entry %r" % (dn)) | ||||
mailserver_attribute = conf.get('ldap', 'mailserver_attribute').lower() | mailserver_attribute = conf.get('ldap', 'mailserver_attribute').lower() | ||||
Lint: PEP8 E501 line too long (87 > 79 characters) Lint: PEP8 E501: line too long (87 > 79 characters) | |||||
if mailserver_attribute == None: | if mailserver_attribute is None: | ||||
log.error("Mail server attribute is not set") | log.error("Mail server attribute is not set") | ||||
return | return | ||||
if old.has_key(mailserver_attribute): | if mailserver_attribute in old: | ||||
log.info("Modified entry %r has mail server attribute %s: %r" % (dn, mailserver_attribute, new[mailserver_attribute])) | log.info("Modified entry %r has mail server attribute %s: %r" % (dn, mailserver_attribute, new[mailserver_attribute])) | ||||
Lint: PEP8 E501 line too long (138 > 79 characters) Lint: PEP8 E501: line too long (138 > 79 characters) | |||||
if not old[mailserver_attribute] == constants.fqdn: | if not old[mailserver_attribute] == constants.fqdn: | ||||
# Even though the new mailserver can be us, it is the | # Even though the new mailserver can be us, it is the | ||||
# *current* mail server that needs to push for the XFER. | # *current* mail server that needs to push for the XFER. | ||||
Lint: PEP8 E501 line too long (80 > 79 characters) Lint: PEP8 E501: line too long (80 > 79 characters) | |||||
log.info("The mail server for user %r is set, and it is not me (%r)" % (dn, old[mailserver_attribute])) | log.info("The mail server for user %r is set, and it is not me (%r)" % (dn, old[mailserver_attribute])) | ||||
Lint: PEP8 E501 line too long (127 > 79 characters) Lint: PEP8 E501: line too long (127 > 79 characters) | |||||
return | return | ||||
else: | else: | ||||
# If old has no mailserver attribute, but new does, we need to create | # If old has no mailserver attribute, but new does, we need to create | ||||
Lint: PEP8 E501 line too long (89 > 79 characters) Lint: PEP8 E501: line too long (89 > 79 characters) | |||||
# the user locally. | # the user locally. | ||||
if new.has_key(mailserver_attribute): | if mailserver_attribute in new: | ||||
if not new[mailserver_attribute] == constants.fqdn: | if not new[mailserver_attribute] == constants.fqdn: | ||||
log.info("The mail server for user %r is set (in new, not old), but it is not me (%r)" % (dn, new[mailserver_attribute])) | log.info("The mail server for user %r is set (in new, not old), but it is not me (%r)" % (dn, new[mailserver_attribute])) | ||||
Lint: PEP8 E501 line too long (149 > 79 characters) Lint: PEP8 E501: line too long (149 > 79 characters) | |||||
return | return | ||||
else: | else: | ||||
log.info("Entry %r does not have a mail server attribute." % (dn)) | log.info("Entry %r does not have a mail server attribute." % (dn)) | ||||
Lint: PEP8 E501 line too long (90 > 79 characters) Lint: PEP8 E501: line too long (90 > 79 characters) | |||||
return | return | ||||
auth._auth._synchronize_callback( | auth._auth._synchronize_callback( | ||||
change_type = 'modify', | change_type='modify', | ||||
previous_dn = None, | previous_dn=None, | ||||
change_number = None, | change_number=None, | ||||
dn = dn, | dn=dn, | ||||
entry = new | entry=new | ||||
) | ) | ||||
else: | else: | ||||
log.info("Delete entry %r" % (dn)) | log.info("Delete entry %r" % (dn)) | ||||
# See if the mailserver_attribute exists | # See if the mailserver_attribute exists | ||||
mailserver_attribute = conf.get('ldap', 'mailserver_attribute').lower() | mailserver_attribute = conf.get('ldap', 'mailserver_attribute').lower() | ||||
Lint: PEP8 E501 line too long (87 > 79 characters) Lint: PEP8 E501: line too long (87 > 79 characters) | |||||
if mailserver_attribute == None: | if mailserver_attribute is None: | ||||
log.error("Mail server attribute is not set") | log.error("Mail server attribute is not set") | ||||
# TODO: Perhaps, query for IMAP servers. If there is only one, | # TODO: Perhaps, query for IMAP servers. If there is only one, | ||||
Lint: PEP8 E501 line too long (82 > 79 characters) Lint: PEP8 E501: line too long (82 > 79 characters) | |||||
# we know what to do. | # we know what to do. | ||||
return | return | ||||
if old.has_key(mailserver_attribute): | if mailserver_attribute in old: | ||||
log.info("Deleted entry %r has mail server attribute %s: %r" % (dn, mailserver_attribute, old[mailserver_attribute])) | log.info("Deleted entry %r has mail server attribute %s: %r" % (dn, mailserver_attribute, old[mailserver_attribute])) | ||||
Lint: PEP8 E501 line too long (137 > 79 characters) Lint: PEP8 E501: line too long (137 > 79 characters) | |||||
if not old[mailserver_attribute] == constants.fqdn: | if not old[mailserver_attribute] == constants.fqdn: | ||||
log.info("The mail server for user %r is set, and it is not me (%r)" % (dn, old[mailserver_attribute])) | log.info("The mail server for user %r is set, and it is not me (%r)" % (dn, old[mailserver_attribute])) | ||||
Lint: PEP8 E501 line too long (127 > 79 characters) Lint: PEP8 E501: line too long (127 > 79 characters) | |||||
return | return | ||||
else: | else: | ||||
log.info("Entry deletion notification for %r does not have a mail server attribute specified." % (dn)) | log.info("Entry deletion notification for %r does not have a mail server attribute specified." % (dn)) | ||||
Lint: PEP8 E501 line too long (122 > 79 characters) Lint: PEP8 E501: line too long (122 > 79 characters) | |||||
cfg = ConfigRegistry() | cfg = ConfigRegistry() | ||||
cfg.load() | cfg.load() | ||||
if cfg.is_true('mail/cyrus/mailbox/delete', True): | if cfg.is_true('mail/cyrus/mailbox/delete', True): | ||||
auth._auth._synchronize_callback( | auth._auth._synchronize_callback( | ||||
change_type = 'delete', | change_type='delete', | ||||
previous_dn = None, | previous_dn=None, | ||||
change_number = None, | change_number=None, | ||||
dn = dn, | dn=dn, | ||||
entry = old | entry=old | ||||
) | ) | ||||
elif isinstance(new, dict) and len(new.keys()) > 0: | elif isinstance(new, dict) and len(new.keys()) > 0: | ||||
# Old is not a dict (or empty), so the entry is just created | # Old is not a dict (or empty), so the entry is just created | ||||
log.info("Add entry %r" % (dn)) | log.info("Add entry %r" % (dn)) | ||||
# See if the mailserver_attribute exists | # See if the mailserver_attribute exists | ||||
mailserver_attribute = conf.get('ldap', 'mailserver_attribute').lower() | mailserver_attribute = conf.get('ldap', 'mailserver_attribute').lower() | ||||
Lint: PEP8 E501 line too long (83 > 79 characters) Lint: PEP8 E501: line too long (83 > 79 characters) | |||||
if mailserver_attribute == None: | if mailserver_attribute is None: | ||||
log.error("Mail server attribute is not set") | log.error("Mail server attribute is not set") | ||||
# TODO: Perhaps, query for IMAP servers. If there is only one, | # TODO: Perhaps, query for IMAP servers. If there is only one, | ||||
# we know what to do. | # we know what to do. | ||||
return | return | ||||
if new.has_key(mailserver_attribute): | if mailserver_attribute in new: | ||||
log.info("Added entry %r has mail server attribute %s: %r" % (dn, mailserver_attribute, new[mailserver_attribute])) | log.info("Added entry %r has mail server attribute %s: %r" % (dn, mailserver_attribute, new[mailserver_attribute])) | ||||
Lint: PEP8 E501 line too long (131 > 79 characters) Lint: PEP8 E501: line too long (131 > 79 characters) | |||||
if not new[mailserver_attribute] == constants.fqdn: | if not new[mailserver_attribute] == constants.fqdn: | ||||
log.info("The mail server for user %r is set, and it is not me (%r)" % (dn, new[mailserver_attribute])) | log.info("The mail server for user %r is set, and it is not me (%r)" % (dn, new[mailserver_attribute])) | ||||
Lint: PEP8 E501 line too long (123 > 79 characters) Lint: PEP8 E501: line too long (123 > 79 characters) | |||||
return | return | ||||
else: | else: | ||||
log.info("Added entry %r does not have a mail server attribute set." % (dn)) | log.info("Added entry %r does not have a mail server attribute set." % (dn)) | ||||
Lint: PEP8 E501 line too long (92 > 79 characters) Lint: PEP8 E501: line too long (92 > 79 characters) | |||||
return | return | ||||
auth._auth._synchronize_callback( | auth._auth._synchronize_callback( | ||||
change_type = 'add', | change_type='add', | ||||
previous_dn = None, | previous_dn=None, | ||||
change_number = None, | change_number=None, | ||||
dn = dn, | dn=dn, | ||||
entry = new | entry=new | ||||
) | ) | ||||
else: | else: | ||||
log.info("entry %r changed, but no new or old attributes" % (dn)) | log.info("entry %r changed, but no new or old attributes" % (dn)) | ||||
def initialize(): | def initialize(): | ||||
log.info("kolab.initialize()") | log.info("kolab.initialize()") |
module level import not at top of file