[CalendarServer-changes] [2660] CalendarServer/branches/users/cdaboo/admin-page-2658

source_changes at macosforge.org source_changes at macosforge.org
Mon Jul 7 08:23:18 PDT 2008


Revision: 2660
          http://trac.macosforge.org/projects/calendarserver/changeset/2660
Author:   cdaboo at apple.com
Date:     2008-07-07 08:23:17 -0700 (Mon, 07 Jul 2008)
Log Message:
-----------
Very crude beginning of a webservice for administering the server. Currently just displays some basic stats.

Modified Paths:
--------------
    CalendarServer/branches/users/cdaboo/admin-page-2658/conf/caldavd-test.plist
    CalendarServer/branches/users/cdaboo/admin-page-2658/conf/caldavd.plist
    CalendarServer/branches/users/cdaboo/admin-page-2658/twistedcaldav/config.py
    CalendarServer/branches/users/cdaboo/admin-page-2658/twistedcaldav/customxml.py
    CalendarServer/branches/users/cdaboo/admin-page-2658/twistedcaldav/static.py
    CalendarServer/branches/users/cdaboo/admin-page-2658/twistedcaldav/tap.py

Added Paths:
-----------
    CalendarServer/branches/users/cdaboo/admin-page-2658/twistedcaldav/admin/resource.py

Modified: CalendarServer/branches/users/cdaboo/admin-page-2658/conf/caldavd-test.plist
===================================================================
--- CalendarServer/branches/users/cdaboo/admin-page-2658/conf/caldavd-test.plist	2008-07-07 14:29:41 UTC (rev 2659)
+++ CalendarServer/branches/users/cdaboo/admin-page-2658/conf/caldavd-test.plist	2008-07-07 15:23:17 UTC (rev 2660)
@@ -375,7 +375,11 @@
   <key>EnableTimezoneService</key>
   <true/>
 
+  <!-- Admin Service -->
+  <key>EnableAdminService</key>
+  <true/>
 
+
   <!--
     Twisted
   -->

Modified: CalendarServer/branches/users/cdaboo/admin-page-2658/conf/caldavd.plist
===================================================================
--- CalendarServer/branches/users/cdaboo/admin-page-2658/conf/caldavd.plist	2008-07-07 14:29:41 UTC (rev 2659)
+++ CalendarServer/branches/users/cdaboo/admin-page-2658/conf/caldavd.plist	2008-07-07 15:23:17 UTC (rev 2660)
@@ -301,6 +301,10 @@
   <key>EnableTimezoneService</key>
   <true/>
 
+  <!-- Admin Service -->
+  <key>EnableAdminService</key>
+  <true/>
 
+
 </dict>
 </plist>

Added: CalendarServer/branches/users/cdaboo/admin-page-2658/twistedcaldav/admin/resource.py
===================================================================
--- CalendarServer/branches/users/cdaboo/admin-page-2658/twistedcaldav/admin/resource.py	                        (rev 0)
+++ CalendarServer/branches/users/cdaboo/admin-page-2658/twistedcaldav/admin/resource.py	2008-07-07 15:23:17 UTC (rev 2660)
@@ -0,0 +1,167 @@
+##
+# Copyright (c) 2008 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+"""
+Admin page resource.
+"""
+
+__all__ = [
+    "AdminServiceResource",
+]
+
+from twisted.internet.defer import inlineCallbacks, returnValue
+from twisted.web2.dav import davxml
+from twisted.web2.http import Response
+from twisted.web2.http_headers import MimeType
+
+from twistedcaldav.config import config
+from twistedcaldav.directory.directory import DirectoryService
+from twistedcaldav.resource import CalDAVResource
+
+class AdminServiceResource (CalDAVResource):
+    """
+    Timezone Service resource.
+
+    Extends L{DAVResource} to provide timezone service functionality.
+    """
+
+    def __init__(self, parent):
+        """
+        @param parent: the parent resource of this one.
+        """
+        assert parent is not None
+
+        CalDAVResource.__init__(self, principalCollections=parent.principalCollections())
+
+        self.parent = parent
+        self.cache = {}
+
+    def defaultAccessControlList(self):
+        return config.AdminOnlyResourceACL
+
+    def resourceType(self):
+        return davxml.ResourceType.admin
+
+    def isCollection(self):
+        return False
+
+    def isCalendarCollection(self):
+        return False
+
+    def isPseudoCalendarCollection(self):
+        return False
+
+    def render(self, request):
+        output = """<html>
+<head>
+<title>Admin Resource</title>
+</head>
+<body>
+<h1>Calendar Server Administration Interface.</h1>
+<table>
+
+<tr>
+<td><b>Accounts</b></td>
+<td>%(accounts)s</td>
+</tr>
+
+<tr>
+<td><b>Calendars</b></td>
+<td>%(calendars)s</td>
+</tr>
+
+<tr>
+<td><b>Groups</b></td>
+<td>%(groups)s</td>
+</tr>
+
+<tr>
+<td><b>Locations</b></td>
+<td>%(locations)s</td>
+</tr>
+
+<tr>
+<td><b>Resources</b></td>
+<td>%(resources)s</td>
+</tr>
+
+<tr>
+<td><b>Events</b></td>
+<td>%(events)s</td>
+</tr>
+
+<tr>
+<td><b>Todos</b></td>
+<td>%(todos)s</td>
+</tr>
+
+</table>
+</body
+</html>""" % self.stats
+
+        response = Response(200, {}, output)
+        response.headers.setHeader("content-type", MimeType("text", "html"))
+        return response
+
+    @inlineCallbacks
+    def http_GET(self, request):
+        """
+        The admin service GET method.
+        """
+        
+        # Check authentication and access controls
+        yield self.authorize(request, (davxml.Read(),))
+        
+        # Collect the stats
+        self.stats = {}
+        
+        # Accounts - number of individuals principals
+        self.stats["accounts"] = 0
+
+        # Calendars - number of calendars of principals
+        self.stats["calendars"] = 0
+
+        # Groups - number of group principals
+        self.stats["groups"] = 0
+
+        # Resources - number of resource principals
+        self.stats["resources"] = 0
+
+        # Locations - number of location principals
+        self.stats["locations"] = 0
+
+        # Events - number of events
+        self.stats["events"] = 0
+
+        # Todos - number of todos principals
+        self.stats["todos"] = 0
+
+        # Collect principal collection details
+        for collection in self.principalCollections():
+            for child in collection.listChildren():
+                child = collection.getChild(child)
+                if child.recordType == DirectoryService.recordType_users:
+                    self.stats["accounts"] += len(tuple(child.directory.listRecords(child.recordType)))
+                elif child.recordType == DirectoryService.recordType_groups:
+                    self.stats["groups"] += len(tuple(child.directory.listRecords(child.recordType)))
+                elif child.recordType == DirectoryService.recordType_resources:
+                    self.stats["resources"] += len(tuple(child.directory.listRecords(child.recordType)))
+                elif child.recordType == DirectoryService.recordType_locations:
+                    self.stats["locations"] += len(tuple(child.directory.listRecords(child.recordType)))
+
+        # Do normal GET behavior
+        response = yield self.render(request)
+        returnValue(response)

Modified: CalendarServer/branches/users/cdaboo/admin-page-2658/twistedcaldav/config.py
===================================================================
--- CalendarServer/branches/users/cdaboo/admin-page-2658/twistedcaldav/config.py	2008-07-07 14:29:41 UTC (rev 2659)
+++ CalendarServer/branches/users/cdaboo/admin-page-2658/twistedcaldav/config.py	2008-07-07 15:23:17 UTC (rev 2660)
@@ -173,6 +173,7 @@
     "EnableDropBox"         : False, # Calendar Drop Box
     "EnablePrivateEvents"   : False, # Private Events
     "EnableTimezoneService" : False, # Timezone service
+    "EnableAdminService"    : False, # Admin service
 
     #
     # Implementation details
@@ -337,6 +338,13 @@
             for principal in config.ReadPrincipals
         )
 
+        self.AdminOnlyResourceACL = davxml.ACL(
+            # Add inheritable all access for admins
+            *self.AdminACEs
+        )
+
+        log.debug("Admin Only ACL: %s" % (self.AdminOnlyResourceACL.toxml(),))
+
         self.RootResourceACL = davxml.ACL(
             # Read-only for anon or authenticated, depending on config
             readOnlyACE(self.EnableAnonymousReadRoot),

Modified: CalendarServer/branches/users/cdaboo/admin-page-2658/twistedcaldav/customxml.py
===================================================================
--- CalendarServer/branches/users/cdaboo/admin-page-2658/twistedcaldav/customxml.py	2008-07-07 14:29:41 UTC (rev 2659)
+++ CalendarServer/branches/users/cdaboo/admin-page-2658/twistedcaldav/customxml.py	2008-07-07 15:23:17 UTC (rev 2660)
@@ -244,6 +244,14 @@
     namespace = calendarserver_namespace
     name = "utc-offset"
 
+class Administer (davxml.WebDAVEmptyElement):
+    """
+    Denotes an admin service resource.
+    (Apple Extension to CalDAV)
+    """
+    namespace = calendarserver_namespace
+    name = "administer"
+
 ##
 # Extensions to davxml.ResourceType
 ##
@@ -253,3 +261,4 @@
 davxml.ResourceType.calendarproxyread = davxml.ResourceType(davxml.Principal(), davxml.Collection(), CalendarProxyRead())
 davxml.ResourceType.calendarproxywrite = davxml.ResourceType(davxml.Principal(), davxml.Collection(), CalendarProxyWrite())
 davxml.ResourceType.timezones = davxml.ResourceType(Timezones())
+davxml.ResourceType.admin = davxml.ResourceType(Administer())

Modified: CalendarServer/branches/users/cdaboo/admin-page-2658/twistedcaldav/static.py
===================================================================
--- CalendarServer/branches/users/cdaboo/admin-page-2658/twistedcaldav/static.py	2008-07-07 14:29:41 UTC (rev 2659)
+++ CalendarServer/branches/users/cdaboo/admin-page-2658/twistedcaldav/static.py	2008-07-07 15:23:17 UTC (rev 2660)
@@ -52,6 +52,7 @@
 
 from twistedcaldav import caldavxml
 from twistedcaldav import customxml
+from twistedcaldav.admin.resource import AdminServiceResource
 from twistedcaldav.caldavxml import caldav_namespace
 from twistedcaldav.config import config
 from twistedcaldav.extensions import DAVFile
@@ -749,6 +750,32 @@
             (caldav_namespace, "calendar-collection-location-ok")
         )
 
+class AdminServiceFile (AdminServiceResource, CalDAVFile):
+    def __init__(self, path, parent):
+        CalDAVFile.__init__(self, path, principalCollections=parent.principalCollections())
+        AdminServiceResource.__init__(self, parent)
+
+        assert self.fp.isfile() or not self.fp.exists()
+
+    def createSimilarFile(self, path):
+        if path == self.fp.path:
+            return self
+        else:
+            return responsecode.NOT_FOUND
+
+    def http_POST       (self, request): return responsecode.FORBIDDEN
+    def http_PUT        (self, request): return responsecode.FORBIDDEN
+    def http_COPY       (self, request): return responsecode.FORBIDDEN
+    def http_MOVE       (self, request): return responsecode.FORBIDDEN
+    def http_DELETE     (self, request): return responsecode.FORBIDDEN
+    def http_MKCOL      (self, request): return responsecode.FORBIDDEN
+
+    def http_MKCALENDAR(self, request):
+        return ErrorResponse(
+            responsecode.FORBIDDEN,
+            (caldav_namespace, "calendar-collection-location-ok")
+        )
+
 ##
 # Utilities
 ##

Modified: CalendarServer/branches/users/cdaboo/admin-page-2658/twistedcaldav/tap.py
===================================================================
--- CalendarServer/branches/users/cdaboo/admin-page-2658/twistedcaldav/tap.py	2008-07-07 14:29:41 UTC (rev 2659)
+++ CalendarServer/branches/users/cdaboo/admin-page-2658/twistedcaldav/tap.py	2008-07-07 15:23:17 UTC (rev 2660)
@@ -50,6 +50,7 @@
 from twistedcaldav.directory.principal import DirectoryPrincipalProvisioningResource
 from twistedcaldav.directory.aggregate import AggregateDirectoryService
 from twistedcaldav.directory.sudo import SudoDirectoryService
+from twistedcaldav.static import AdminServiceFile
 from twistedcaldav.static import CalendarHomeProvisioningFile
 from twistedcaldav.static import TimezoneServiceFile
 from twistedcaldav.timezones import TimezoneCache
@@ -435,6 +436,7 @@
     principalResourceClass       = DirectoryPrincipalProvisioningResource
     calendarResourceClass        = CalendarHomeProvisioningFile
     timezoneServiceResourceClass = TimezoneServiceFile
+    adminServiceResourceClass    = AdminServiceFile
 
     def makeService_Slave(self, options):
         #
@@ -524,6 +526,14 @@
             )
             root.putChild('timezones', timezoneService)
 
+        # Admin service is optional
+        if config.EnableAdminService:
+            adminService = self.adminServiceResourceClass(
+                os.path.join(config.DocumentRoot, "admin"),
+                root
+            )
+            root.putChild('admin', adminService)
+
         #
         # Configure ancillary data
         #
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080707/f6387858/attachment-0001.html 


More information about the calendarserver-changes mailing list