]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Adding barracuda-sync, Renaming pp_lib/barracuda_aliases_app.py -> pp_lib/barracuda_s...
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 4 May 2017 10:15:24 +0000 (12:15 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 4 May 2017 10:15:24 +0000 (12:15 +0200)
barracuda-sync [new file with mode: 0755]
pp_lib/barracuda_aliases_app.py [deleted file]
pp_lib/barracuda_sync_app.py [new file with mode: 0644]

diff --git a/barracuda-sync b/barracuda-sync
new file mode 100755 (executable)
index 0000000..6cb3770
--- /dev/null
@@ -0,0 +1,41 @@
+#!/usr/bin/env python3
+
+# Standard modules
+import sys
+import os
+import logging
+import locale
+
+# own modules:
+cur_dir = os.getcwd()
+base_dir = cur_dir
+
+if sys.argv[0] != '' and sys.argv[0] != '-c':
+    cur_dir = os.path.dirname(sys.argv[0])
+if os.path.exists(os.path.join(cur_dir, 'pp_lib')):
+    sys.path.insert(0, os.path.abspath(cur_dir))
+
+from pp_lib.common import pp
+
+from pp_lib.barracuda_sync_app import PpBarracudaSyncApp
+
+log = logging.getLogger(__name__)
+
+__author__ = 'Frank Brehm <frank.brehm@pixelpark.com>'
+__copyright__ = '(C) 2017 by Frank Brehm, Pixelpark GmbH, Berlin'
+
+appname = os.path.basename(sys.argv[0])
+
+locale.setlocale(locale.LC_ALL, '')
+
+app = PpBarracudaSyncApp(appname=appname)
+app.initialized = True
+
+if app.verbose > 2:
+    print("{c}-Object:\n{a}".format(c=app.__class__.__name__, a=app))
+
+app()
+
+sys.exit(0)
+
+# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
diff --git a/pp_lib/barracuda_aliases_app.py b/pp_lib/barracuda_aliases_app.py
deleted file mode 100644 (file)
index 00bec45..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-"""
-@author: Frank Brehm
-@contact: frank.brehm@pixelpark.com
-@copyright: © 2017 by Frank Brehm, Berlin
-@summary: The module for the barracuda-sync application object.
-"""
-from __future__ import absolute_import
-
-# Standard modules
-import sys
-import os
-import logging
-import logging.config
-import re
-import traceback
-import textwrap
-import copy
-import shutil
-import stat
-
-# Third party modules
-import six
-
-import ldap3
-
-from ldap3 import ObjectDef, AttrDef, Reader, Writer
-
-from ldap3.core.exceptions import LDAPKeyError
-
-# Own modules
-from .global_version import __version__ as __global_version__
-
-from .errors import FunctionNotImplementedError, PpAppError
-
-from .common import pp, terminal_can_colors, to_bytes, to_bool
-
-from .merge import merge_structure
-
-from .ldap_app import PpLdapAppError, PpLdapApplication
-
-__version__ = '0.1.0'
-LOG = logging.getLogger(__name__)
-
-
-# =============================================================================
-class PpBarracudaSyncError(PpLdapAppError):
-    pass
-
-# =============================================================================
-
-if __name__ == "__main__":
-
-    pass
-
-# =============================================================================
-
-# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 list
diff --git a/pp_lib/barracuda_sync_app.py b/pp_lib/barracuda_sync_app.py
new file mode 100644 (file)
index 0000000..9d68ee8
--- /dev/null
@@ -0,0 +1,128 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+@author: Frank Brehm
+@contact: frank.brehm@pixelpark.com
+@copyright: © 2017 by Frank Brehm, Berlin
+@summary: The module for the barracuda-sync application object.
+"""
+from __future__ import absolute_import
+
+# Standard modules
+import sys
+import os
+import logging
+import logging.config
+import re
+import traceback
+import textwrap
+import copy
+import shutil
+import stat
+
+# Third party modules
+import six
+
+import ldap3
+
+from ldap3 import ObjectDef, AttrDef, Reader, Writer
+
+from ldap3.core.exceptions import LDAPKeyError
+
+# Own modules
+from .global_version import __version__ as __global_version__
+
+from .errors import FunctionNotImplementedError, PpAppError
+
+from .common import pp, terminal_can_colors, to_bytes, to_bool
+
+from .merge import merge_structure
+
+from .ldap_app import PpLdapAppError, PpLdapApplication
+
+from .mailaddress import MailAddress
+
+__version__ = '0.2.0'
+LOG = logging.getLogger(__name__)
+
+
+# =============================================================================
+class PpBarracudaSyncError(PpLdapAppError):
+    pass
+
+
+# =============================================================================
+class PpBarracudaSyncApp(PpLdapApplication):
+    """Class for the 'barracuda-sync' application to ensure a synchronisation
+        of all existing aliases and virtual aliases in Postfix with the
+        LDAP entries used by Barracuda to ensure the existence of aliases.
+    """
+
+    default_barracuda_base_dn = 'ou=barracuda,ou=Applications, o=Pixelpark,o=isp'
+    postfix_config_dir = os.sep + os.path.join('etc', 'postfix')
+    postfix_maps_dir = os.path.join(postfix_config_dir, 'maps')
+
+    default_aliases_files = [
+        os.path.join(postfix_maps_dir, 'aliases'),
+    ]
+
+    default_virtaliases_files = [
+        os.path.join(postfix_maps_dir, 'virtual-aliases'),
+    ]
+
+    default_origin = 'pixelpark.com'
+
+    re_aliases_line = re.compile(r'^([^#\s:]+):', re.MULTILINE)
+    re_virtaliases_line = re.compile(r'^([^#\s:]+)\s', re.MULTILINE)
+
+    # -------------------------------------------------------------------------
+    def __init__(self, appname=None, version=__version__):
+
+        self.barracuda_base_dn = self.default_barracuda_base_dn
+        self.aliases_files = copy.copy(self.default_aliases_files)
+        self.virtaliases_files = copy.copy(self.default_virtaliases_files)
+        self.origin = self.default_origin
+
+        self.existing_aliases = []
+        self.ldap_aliases = []
+        self.aliases_to_create = []
+        self.aliases_to_remove = []
+
+        self._show_simulate_opt = True
+
+        description = textwrap.dedent('''\
+            Synchronization of existing aliases and virtual aliases
+            with alias definitions in LDAP for Barracuda.
+            ''').strip()
+
+        super(PpBarracudaSyncApp, self).__init__(
+            appname=appname, version=version, description=description,
+            cfg_stems='barracuda-sync'
+        )
+
+        self.initialized = True
+
+    # -------------------------------------------------------------------------
+    def pre_run(self):
+        """
+        Dummy function to run before the main routine.
+        Could be overwritten by descendant classes.
+
+        """
+
+        super(PpBarracudaSyncApp, self).pre_run()
+
+    # -------------------------------------------------------------------------
+    def _run(self):
+
+        LOG.info("Starting ...")
+
+# =============================================================================
+
+if __name__ == "__main__":
+
+    pass
+
+# =============================================================================
+
+# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 list