]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Start evaluating differences.
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 24 May 2023 13:16:06 +0000 (15:16 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 24 May 2023 13:16:06 +0000 (15:16 +0200)
lib/pp_admintools/app/barracuda_sync.py

index 8b540133b625c3eebe2928dac2135d70b9ca9db3..7b93c3567595fa800f06e4097eaaa5693fd688a5 100644 (file)
@@ -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()
 
 
 # =============================================================================