From a1297d15feba4f88fe0a9564d52e7d1772f4d726 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 24 May 2023 15:16:06 +0200 Subject: [PATCH] Start evaluating differences. --- lib/pp_admintools/app/barracuda_sync.py | 36 +++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/pp_admintools/app/barracuda_sync.py b/lib/pp_admintools/app/barracuda_sync.py index 8b54013..7b93c35 100644 --- a/lib/pp_admintools/app/barracuda_sync.py +++ b/lib/pp_admintools/app/barracuda_sync.py @@ -27,7 +27,7 @@ from ldap3 import BASE from .ldap import BaseLdapApplication from ..xlate import XLATOR -__version__ = '0.8.4' +__version__ = '0.8.5' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -111,6 +111,7 @@ class BarracudaSyncApp(BaseLdapApplication): self.ldap_mail_dns = {} self.aliases_to_create = [] self.aliases_to_remove = [] + self.aliases_to_modify = [] self.ignore_aliases_res = [] desc = _( @@ -511,11 +512,41 @@ class BarracudaSyncApp(BaseLdapApplication): if dn not in self.ldap_mail_dns[mail]: self.ldap_mail_dns[mail].append(dn) - if self.verbose > 1: + if self.verbose > 2: msg = _('LDAP entries with mail attributes except them for Barracuda:') msg += '\n' + pp(self.ldap_mail_dns) LOG.debug(msg) + # ------------------------------------------------------------------------- + def eval_diffs(self): + """Evaluate all entries to create, to change or to modify.""" + LOG.info(_('Evaluating all LDAP entries to create, to change or to modify.')) + + self.aliases_to_create = [] + self.aliases_to_remove = [] + self.aliases_to_modify = [] + + for dn in self.ldap_aliases: + entry = self.ldap_aliases[dn] + do_delete = False + entry_in_local_aliases = False + for mail in entry['mail']: + if mail in self.ldap_mail_dns: + do_delete = True + break + for cn in self.existing_aliases.keys(): + local_alias = self.existing_aliases[cn] + if mail.lower() == local_alias['alias'].lower(): + entry_in_local_aliases = True + if not entry_in_local_aliases: + do_delete = True + if do_delete: + self.aliases_to_remove.append(dn) + + if self.berbose > 1: + msg = _('LDAP Entries to remove:') + '\n' + pp(self.aliases_to_remove) + LOG.debug(msg) + # ------------------------------------------------------------------------- def _run(self): @@ -523,6 +554,7 @@ class BarracudaSyncApp(BaseLdapApplication): self.read_virtual_alias_mappings() self.read_barracuda_ldap_aliases() self.get_other_ldap_mail_entries() + self.eval_diffs() # ============================================================================= -- 2.39.5