From: Frank Brehm Date: Fri, 6 May 2011 21:00:57 +0000 (+0000) Subject: Mailzeugs in config getestet X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=e84ad377396b3b51636a4bb038ef8d11763426d0;p=my-stuff%2Fpy-logrotate.git Mailzeugs in config getestet git-svn-id: http://svn.brehm-online.com/svn/my-stuff/python/PyLogrotate/trunk@225 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa --- diff --git a/LogRotateCommon.py b/LogRotateCommon.py index e51a0af..8490ee0 100755 --- a/LogRotateCommon.py +++ b/LogRotateCommon.py @@ -122,6 +122,32 @@ def split_parts( text, keep_quotes = False, raise_on_unbalanced = True): return chunks +#------------------------------------------------------------------------ + +def email_valid(address): + ''' + Simple Check for E-Mail addresses + + @param address: the mail address to check + @type address: str + + @return: Validity of the given mil address + @rtype: bool + ''' + + if address is None: + return False + + adr = str(address) + if adr is None or adr == '': + return False + + pattern = r'^[a-z0-9._%-+]+@[a-z0-9._%-]+.[a-z]{2,6}$' + if re.search(pattern, adr, re.IGNORECASE) is None: + return False + + return True + #======================================================================== if __name__ == "__main__": diff --git a/LogRotateConfig.py b/LogRotateConfig.py index 085352c..6a5dbf4 100755 --- a/LogRotateConfig.py +++ b/LogRotateConfig.py @@ -20,7 +20,7 @@ import pprint import os import os.path -from LogRotateCommon import split_parts +from LogRotateCommon import split_parts, email_valid revision = '$Revision$' revision = re.sub( r'\$', '', revision ) @@ -1005,6 +1005,52 @@ class LogrotateConfigurationReader(object): match = re.search(r'^(not?)?mail$', option, re.IGNORECASE) if match: negated = match.group(1) + if negated: + directive['mailaddress'] = None + if val is not None and val != '': + self.logger.warning( + ( _("Senseless option value »%s« after »%s«.") + % (val, option.lower()) + ) + ) + return False + return True + if not email_valid(val): + directive['mailaddress'] = None + self.logger.warning( ( _("Invalid Mail address »%s«.") % (val))) + return False + directive['mailaddress'] = val + if self.verbose > 4: + self.logger.debug( + ( _("Setting mail address to »%s«. (file »%s«, line %s)") + % (val, filename, linenr) + ) + ) + return True + + # Check for mailfirst/maillast + match = re.search(r'^mail(first|last)$', option, re.IGNORECASE) + if match: + when = match.group(1).lower() + option_value = False + if when == 'first': + option_value = True + directive['mailfirst'] = option_value + if self.verbose > 4: + self.logger.debug( + ( _("Setting mailfirst to »%s«. (file »%s«, line %s)") + % (str(option_value), filename, linenr) + ) + ) + if val is not None and val != '': + self.logger.warning( + ( _("Senseless option value »%s« after »%s«.") + % (val, option.lower()) + ) + ) + return False + return True + return True diff --git a/test/apache2 b/test/apache2 new file mode 100644 index 0000000..1f24f14 --- /dev/null +++ b/test/apache2 @@ -0,0 +1,21 @@ +# Apache2 logrotate snipet for Gentoo Linux +# Contributes by Chuck Short +# + +/var/log/apache2/access_log +/var/log/apache2/*.log +{ + missingok + notifempty + sharedscripts + rotate 10 + error bla + weekly + size 1m + mail test@uhu-banane.de + olddir /var/log/apache2/%Y-%m + postrotate + /etc/init.d/apache2 reload > /dev/null 2>&1 || true + endscript +} +