changeset 445:a71176d858be

surge protection: specialcase AttachFile, fix no cache exists case imported from: moin--main--1.5--patch-449
author Thomas Waldmann <tw@waldmann-edv.de>
date Thu, 16 Feb 2006 22:08:06 +0000
parents 918c58dcc275
children 4c984229abb9
files ChangeLog MoinMoin/multiconfig.py MoinMoin/request.py
diffstat 3 files changed, 43 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Feb 16 17:43:13 2006 +0000
+++ b/ChangeLog	Thu Feb 16 22:08:06 2006 +0000
@@ -2,6 +2,20 @@
 # arch-tag: automatic-ChangeLog--arch@arch.thinkmo.de--2003-archives/moin--main--1.5
 #
 
+2006-02-16 23:08:06 GMT	Thomas Waldmann <tw@waldmann-edv.de>	patch-449
+
+    Summary:
+      surge protection: specialcase AttachFile, fix no cache exists case
+    Revision:
+      moin--main--1.5--patch-449
+
+    surge protection: specialcase AttachFile, fix no cache exists case
+    
+
+    modified files:
+     ChangeLog MoinMoin/multiconfig.py MoinMoin/request.py
+
+
 2006-02-16 18:43:13 GMT	Alexander Schremmer <alex@alexanderweb.de.tla>	patch-448
 
     Summary:
--- a/MoinMoin/multiconfig.py	Thu Feb 16 17:43:13 2006 +0000
+++ b/MoinMoin/multiconfig.py	Thu Feb 16 22:08:06 2006 +0000
@@ -300,11 +300,11 @@
     
     surge_action_limits = { # allow max. <count> <action> requests per <dt> secs
         # action: (count, dt)
-        'all': (20, 30),
-        'show': (20, 60),
+        'all': (30, 30),
+        'show': (30, 60),
         'recall': (5, 60),
         'raw': (20, 40),  # some people use this for css
-        'AttachFile': (60, 60),
+        'AttachFile': (90, 60),
         'diff': (30, 60),
         'fullsearch': (5, 60),
         'edit': (10, 120),
--- a/MoinMoin/request.py	Thu Feb 16 17:43:13 2006 +0000
+++ b/MoinMoin/request.py	Thu Feb 16 22:08:06 2006 +0000
@@ -185,20 +185,21 @@
         
         try:
             cache = caching.CacheEntry(self, 'surgeprotect', 'surge-log')
-            data = cache.content()
-            data = data.split("\n")
-            for line in data:
-                try:
-                    id, t, action, surge_indicator = line.split("\t")
-                    t = int(t)
-                    maxnum, dt = limits.get(action, default_limit)
-                    if t >= now - dt:
-                        events = surgedict.setdefault(id, copy.copy({}))
-                        timestamps = events.setdefault(action, copy.copy([]))
-                        timestamps.append((t, surge_indicator))
-                except StandardError, err:
-                    pass
-        
+            if cache.exists():
+                data = cache.content()
+                data = data.split("\n")
+                for line in data:
+                    try:
+                        id, t, action, surge_indicator = line.split("\t")
+                        t = int(t)
+                        maxnum, dt = limits.get(action, default_limit)
+                        if t >= now - dt:
+                            events = surgedict.setdefault(id, copy.copy({}))
+                            timestamps = events.setdefault(action, copy.copy([]))
+                            timestamps.append((t, surge_indicator))
+                    except StandardError, err:
+                        pass
+                
             maxnum, dt = limits.get(current_action, default_limit)
             events = surgedict.setdefault(current_id, copy.copy({}))
             timestamps = events.setdefault(current_action, copy.copy([]))
@@ -210,17 +211,18 @@
                 if len(timestamps) < maxnum*2:
                     timestamps.append((now + self.cfg.surge_lockout_time, surge_indicator)) # continue like that and get locked out
         
-            current_action = 'all' # put a total limit on user's requests
-            maxnum, dt = limits.get(current_action, default_limit)
-            events = surgedict.setdefault(current_id, copy.copy({}))
-            timestamps = events.setdefault(current_action, copy.copy([]))
-            surge_detected = surge_detected or len(timestamps) > maxnum
+            if current_action != 'AttachFile': # don't add AttachFile accesses to all or picture galleries will trigger SP
+                current_action = 'all' # put a total limit on user's requests
+                maxnum, dt = limits.get(current_action, default_limit)
+                events = surgedict.setdefault(current_id, copy.copy({}))
+                timestamps = events.setdefault(current_action, copy.copy([]))
+                surge_detected = surge_detected or len(timestamps) > maxnum
             
-            surge_indicator = surge_detected and "!" or ""
-            timestamps.append((now, surge_indicator))
-            if surge_detected:
-                if len(timestamps) < maxnum*2:
-                    timestamps.append((now + self.cfg.surge_lockout_time, surge_indicator)) # continue like that and get locked out
+                surge_indicator = surge_detected and "!" or ""
+                timestamps.append((now, surge_indicator))
+                if surge_detected:
+                    if len(timestamps) < maxnum*2:
+                        timestamps.append((now + self.cfg.surge_lockout_time, surge_indicator)) # continue like that and get locked out
         
             data = []
             for id, events in surgedict.items():