diff --git a/README.md b/README.md index 0c44d8d..7cbdf98 100644 --- a/README.md +++ b/README.md @@ -74,8 +74,11 @@ More details about the sync workflow can be found in SyncWorkflow.md - `LINUXMUSTER_MAILCOW_DOMAIN_QUOTA` - total quota of one domain. CAUTION! If this is not enough to fit all mailboxes the import will fail!! - `LINUXMUSTER_MAILCOW_ENABLE_GAL` - whether to enable the global addressbook - **Optional** Only use these if you know what you are doing! They are not required for normal operation! - - `LDAP-MAILCOW_API_URI` - mailcow API uri. + - `LINUXMUSTER_MAILCOW_API_URI` - mailcow API uri. - `LINUXMUSTER_MAILCOW_DOCKERAPI_URI` - dockerapi API uri. + - `LINUXMUSTER_MAILCOW_LDAP_USER_FILTER` - users that get mail accounts, default is teachers and students, set to `"(sophomorixRole=teacher)"` to restrict to teachers + - `LINUXMUSTER_MAILCOW_LDAP_SOGO_USER_FILTER` - users that are allowed to use SOGo, defaults to teachers or students, set to `"(sophomorixRole='teacher')"` to restrict to teachers + 4. Start additional container: `docker compose up -d linuxmuster-mailcow` 5. Check logs `docker compose logs -f linuxmuster-mailcow` (quit with ctrl+c). Please note: Connection errors are normal after all containers are started with `docker compose up -d`. diff --git a/src/ldapHelper.py b/src/ldapHelper.py index adcb971..d95c213 100644 --- a/src/ldapHelper.py +++ b/src/ldapHelper.py @@ -9,6 +9,8 @@ def __init__(self, ldapUri, ldapBindDn, ldapBindPassword, ldapBaseDn): def bind(self): try: + # uncomment to disable CERT-Check on LDAP-Server + #ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER) self._ldapConnection = ldap.initialize(f"{self._uri}") self._ldapConnection.set_option(ldap.OPT_REFERRALS, 0) self._ldapConnection.simple_bind_s(self._bindDn, self._bindPassword) diff --git a/src/syncer.py b/src/syncer.py index 9754e27..116947c 100644 --- a/src/syncer.py +++ b/src/syncer.py @@ -78,7 +78,7 @@ def _sync(self): logging.info(" * Loading groups from AD") ret, adLists = self._ldap.search( self.ldapMailingListFilter, - ["mail", "proxyAddresses", "distinguishedName", + ["mail", "proxyAddresses", "distinguishedName", "description", "sophomorixMailList", "sAMAccountName"] ) @@ -133,6 +133,9 @@ def _sync(self): continue mail = mailingList["mail"] + if mail.startswith("p_"): + mail = mail[2:] + desc = mailingList["description"] maildomain = mail.split("@")[-1] ret, members = self._ldap.search( self.ldapMailingListMemberFilter.replace( @@ -150,13 +153,13 @@ def _sync(self): "mail": mail, "sophomorixStatus": "U", "sophomorixMailQuotaCalculated": 1, - "displayName": mailingList["sAMAccountName"] + " (list)" + "displayName": "Verteiler " + desc }, mailcowMailboxes) self._addAliasesFromProxyAddresses( mailingList, mail, mailcowAliases) self._addListFilter(mail, list( - map(lambda x: x["mail"], members)), mailcowFilters) + map(lambda x: x["mail"], members)), desc, mailcowFilters) if mailcowDomains.queuesAreEmpty() and mailcowMailboxes.queuesAreEmpty() and mailcowAliases.queuesAreEmpty() and mailcowFilters.queuesAreEmpty(): logging.info(" * Everything up-to-date!") @@ -262,9 +265,19 @@ def _addAlias(self, alias, goto, mailcowAliases): }, alias) pass - def _addListFilter(self, listAddress, memberAddresses, mailcowFilters): + def _addListFilter(self, listAddress, memberAddresses, description, mailcowFilters): scriptData = "### Auto-generated mailinglist filter by linuxmuster ###\r\n\r\n" - scriptData += "require \"copy\";\r\n\r\n" + scriptData += "require \"editheader\";\r\n" + scriptData += "require \"copy\";\r\n" + scriptData += "require \"variables\";\r\n" + scriptData += "set \"addendum\" \""+description+"\";\r\n" + scriptData += "# Match the entire subject ...\r\n" + scriptData += "if header :matches \"Subject\" \"*\" {\r\n" + scriptData += " # ... to get it in a match group that can then be stored in a variable:\r\n" + scriptData += " set \"subject\" \"${1}\";\r\n" + scriptData += " }\r\n" + scriptData += "deleteheader \"Subject\";\r\n" + scriptData += "addheader :last \"Subject\" \"[${addendum}] ${subject}\";\r\n" for memberAddress in memberAddresses: scriptData += f"redirect :copy \"{memberAddress}\";\r\n" scriptData += "\r\ndiscard;stop;" @@ -289,6 +302,8 @@ def _readConfig(self): ] allowedConfigKeys = [ + "LINUXMUSTER_MAILCOW_LDAP_SOGO_USER_FILTER", + "LINUXMUSTER_MAILCOW_LDAP_USER_FILTER", "LINUXMUSTER_MAILCOW_DOCKERAPI_URI", "LINUXMUSTER_MAILCOW_API_URI" ]