]> Frank Brehm's Git Trees - my-stuff/py-logrotate.git/commitdiff
Mailzeugs in config getestet
authorFrank Brehm <frank@brehm-online.com>
Fri, 6 May 2011 21:00:57 +0000 (21:00 +0000)
committerFrank Brehm <frank@brehm-online.com>
Fri, 6 May 2011 21:00:57 +0000 (21:00 +0000)
git-svn-id: http://svn.brehm-online.com/svn/my-stuff/python/PyLogrotate/trunk@225 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa

LogRotateCommon.py
LogRotateConfig.py
test/apache2 [new file with mode: 0644]

index e51a0af3923c106649b234b8940dc0f6c5db05fb..8490ee06bcd59b0d8fed173374d427b13876c0de 100755 (executable)
@@ -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__":
index 085352c8b8729c4cfad80272f8fcd4c660db985d..6a5dbf4d8d63452004134251775dbefb5e462f82 100755 (executable)
@@ -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 (file)
index 0000000..1f24f14
--- /dev/null
@@ -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
+}
+