From: Frank Brehm Date: Thu, 11 Apr 2024 15:50:47 +0000 (+0200) Subject: Start evaluating results of bin/get-intern-used-from-addresses. X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=59b42e844644cf26230ad97d2995d61ae1f71af9;p=pixelpark%2Fpp-admin-tools.git Start evaluating results of bin/get-intern-used-from-addresses. --- diff --git a/lib/pp_admintools/app/get_from_addr.py b/lib/pp_admintools/app/get_from_addr.py index a98ce8d..5d28e5b 100644 --- a/lib/pp_admintools/app/get_from_addr.py +++ b/lib/pp_admintools/app/get_from_addr.py @@ -16,13 +16,14 @@ from pathlib import Path # Third party modules from fb_tools.common import pp +from fb_tools.mailaddress import MailAddress # Own modules from . import BaseDPXApplication from ..handler.pflogparse import PostfixLogfileParser from ..xlate import XLATOR -__version__ = '0.3.1' +__version__ = '0.4.0' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -40,6 +41,8 @@ class GetFromAddressesApp(BaseDPXApplication): default_logdir = Path('/var/log') default_logfile_pattern = 'maillog*' + re_mail_domain = re.compile(r'.*@') + local_networks = [ ipaddress.ip_network('10.0.0.0/8'), ipaddress.ip_network('172.16.0.0/12'), @@ -65,6 +68,8 @@ class GetFromAddressesApp(BaseDPXApplication): self.logfile_pattern = self.default_logfile_pattern self.logfiles = [] + self.per_domain = {} + self.show_address_results = False desc1 = _( @@ -121,7 +126,7 @@ class GetFromAddressesApp(BaseDPXApplication): self._eval_given_logfiles() else: self._eval_default_logfiles() - self._sort_sogfiles() + self._sort_logfiles() # ------------------------------------------------------------------------- def _eval_given_logfiles(self): @@ -161,7 +166,7 @@ class GetFromAddressesApp(BaseDPXApplication): LOG.warn(_('File {!r} is not a regular file.').format(str(f))) # ------------------------------------------------------------------------- - def _sort_sogfiles(self): + def _sort_logfiles(self): if self.verbose > 1: LOG.debug(_('Sorting logfiles ...')) @@ -184,6 +189,57 @@ class GetFromAddressesApp(BaseDPXApplication): for logfile in logfiles_left: self.logfiles.append(logfile) + # ------------------------------------------------------------------------- + def _collect_results(self): + + self.empty_line() + self.debug(_('Collecting results ...')) + + for postfix_id in self.pflogparser.chain: + + chain = self.pflogparser.chain[postfix_id] + + # Did not come from smtpd or pickup + if not chain.client_addr and not chain.pickup_from: + continue + + # No From-address - Bounce. Forget it + if not chain.from_address: + continue + + domain = '' + if isinstance(chain.from_address, MailAddress): + domain = chain.from_address.domain + else: + domain = self.re_mail_domain.sub('', chain.from_address) + + # No domain found + if not domain: + continue + + # Client address is not an ipaddress + if isinstance(chain.client_addr, ipaddress._BaseAddress): + continue + + local_client = False + if chain.client_addr: + for net in self.local_networks: + if chain.client_addr in net: + local_client = True + break + + if local_client: + for except_src in self.except_sources: + if chain.client_addr == except_src: + local_client = False + else: + # from pickup ... + local_client = True + + # Not from our network originating + if not local_client: + continue + # ------------------------------------------------------------------------- def _run(self):