[CalendarServer-changes] [2653] CalendarServer/trunk/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Wed Jul 2 10:20:31 PDT 2008


Revision: 2653
          http://trac.macosforge.org/projects/calendarserver/changeset/2653
Author:   wsanchez at apple.com
Date:     2008-07-02 10:20:30 -0700 (Wed, 02 Jul 2008)
Log Message:
-----------
Add config option for rejecting clients based on user-agent

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/config.py
    CalendarServer/trunk/twistedcaldav/resource.py

Modified: CalendarServer/trunk/twistedcaldav/config.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/config.py	2008-07-02 15:47:41 UTC (rev 2652)
+++ CalendarServer/trunk/twistedcaldav/config.py	2008-07-02 17:20:30 UTC (rev 2653)
@@ -16,6 +16,7 @@
 
 import os
 import copy
+import re
 
 from twisted.web2.dav import davxml
 from twisted.web2.dav.resource import TwistedACLInheritable
@@ -99,6 +100,11 @@
     "EnablePrincipalListings": True, # Allow listing of principal collections
 
     #
+    # Client controls
+    #
+    "RejectClients": [], # List of regexes for clients to disallow
+
+    #
     # Authentication
     #
     "Authentication": {
@@ -349,6 +355,14 @@
 
         self.updateLogLevels()
 
+        #
+        # Compile RejectClients expressions for speed
+        #
+        try:
+            self.RejectClients = [re.compile(x) for x in self.RejectClients if x]
+        except re.error, e:
+            raise ConfigurationError("Invalid regular expression in RejectClients: %s" % (e,))
+
     def updateLogLevels(self):
         clearLogLevels()
 

Modified: CalendarServer/trunk/twistedcaldav/resource.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/resource.py	2008-07-02 15:47:41 UTC (rev 2652)
+++ CalendarServer/trunk/twistedcaldav/resource.py	2008-07-02 17:20:30 UTC (rev 2653)
@@ -58,6 +58,7 @@
 from twistedcaldav.customxml import calendarserver_namespace
 from twistedcaldav.ical import allowedComponents
 from twistedcaldav.ical import Component as iComponent
+from twistedcaldav.log import LoggingMixIn
 
 if twistedcaldav.__version__:
     serverVersion = twisted.web2.server.VERSION + " TwistedCalDAV/" + twistedcaldav.__version__
@@ -91,7 +92,7 @@
     return fun
 
 
-class CalDAVResource (CalDAVComplianceMixIn, DAVResource):
+class CalDAVResource (CalDAVComplianceMixIn, DAVResource, LoggingMixIn):
     """
     CalDAV resource.
 
@@ -133,6 +134,19 @@
             return super(CalDAVResource, self).render(request)
 
     def renderHTTP(self, request):
+        if config.RejectClients:
+            #
+            # Filter out unsupported clients
+            #
+            agent = request.headers.getHeader("user-agent")
+            for reject in config.RejectClients:
+                if reject.search(agent) is not None:
+                    self.log_info("Rejecting user-agent: %s" % (agent,))
+                    raise HTTPError(StatusResponse(
+                        responsecode.FORBIDDEN,
+                        "Your client software (%s) is not allowed to access this service." % (agent,)
+                    ))
+
         response = maybeDeferred(super(CalDAVResource, self).renderHTTP, request)
 
         def setHeaders(response):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080702/5d23f83a/attachment-0001.html 


More information about the calendarserver-changes mailing list