[prev in list] [next in list] [prev in thread] [next in thread] 

List:       calendarserver-changes
Subject:    [CalendarServer-changes] [2356]
From:       source_changes () macosforge ! org
Date:       2008-04-26 2:38:18
Message-ID: 20080426023818.586A215EB990 () beta ! macosforge ! org
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Revision: 2356
          http://trac.macosforge.org/projects/calendarserver/changeset/2356
Author:   wsanchez@apple.com
Date:     2008-04-25 19:38:17 -0700 (Fri, 25 Apr 2008)

Log Message:
-----------
Add accounting stuff, modeled roughly after Cyrus' loggig branch.

Modified Paths:
--------------
    CalendarServer/branches/users/wsanchez/logging/conf/caldavd-test.plist
    CalendarServer/branches/users/wsanchez/logging/twistedcaldav/config.py
    CalendarServer/branches/users/wsanchez/logging/twistedcaldav/schedule.py

Added Paths:
-----------
    CalendarServer/branches/users/wsanchez/logging/twistedcaldav/accounting.py

Modified: CalendarServer/branches/users/wsanchez/logging/conf/caldavd-test.plist
===================================================================
--- CalendarServer/branches/users/wsanchez/logging/conf/caldavd-test.plist	2008-04-26 \
                02:21:28 UTC (rev 2355)
+++ CalendarServer/branches/users/wsanchez/logging/conf/caldavd-test.plist	2008-04-26 \
02:38:17 UTC (rev 2356) @@ -184,7 +184,7 @@
   <!-- Principals with "DAV:all" access (relative URLs) -->
   <key>AdminPrincipals</key>
   <array>
-    <string>/principals/__uids__/admin/</string>
+    <string>/principals/users/admin/</string>
   </array>
 
   <!-- Principals that can pose as other principals -->
@@ -258,6 +258,17 @@
   <dict>
   </dict>
 
+  <!-- Accounting -->
+  <key>AccountingCategories</key>
+  <dict>
+    <key>iTIP</key><false/>
+  </dict>
+
+  <key>AccountingPrincipals</key>
+  <array>
+    <!--<string>/principals/users/foo/</string>-->
+  </array>
+
   <!-- Server statistics file -->
   <key>ServerStatsFile</key>
   <string>logs/stats.plist</string>

Added: CalendarServer/branches/users/wsanchez/logging/twistedcaldav/accounting.py
===================================================================
--- CalendarServer/branches/users/wsanchez/logging/twistedcaldav/accounting.py	       \
                (rev 0)
+++ CalendarServer/branches/users/wsanchez/logging/twistedcaldav/accounting.py	2008-04-26 \
02:38:17 UTC (rev 2356) @@ -0,0 +1,107 @@
+##
+# Copyright (c) 2006-2007 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.
+##
+
+"""
+Extended account-specific logging.
+Allows different sub-systems to log data on a per-principal basis.
+"""
+
+__all__ = [
+    "accountingEnabled",
+    "emitAccounting",
+]
+
+import datetime
+import os
+
+from twistedcaldav.config import config
+from twistedcaldav.log import Logger
+
+log = Logger()
+
+def accountingEnabled(category, principal):
+    """
+    Determine if accounting is enabled for the given category and principal.
+    """
+    return (
+        accountingEnabledForCategory(category) and
+        accountingEnabledForPrincipal(principal)
+    )
+
+def accountingEnabledForCategory(category):
+    """
+    Determine if accounting is enabled for the given category.
+    """
+    return config.AccountingCategories.get(category, False)
+
+def accountingEnabledForPrincipal(principal):
+    """
+    Determine if accounting is enabled for the given principal.
+    """
+    enabledPrincipalURIs = config.AccountingPrincipals
+
+    if principal.principalURL() in enabledPrincipalURIs:
+        return True
+
+    if principal.alternateURIs() in enabledPrincipalURIs:
+        return True
+
+    return False
+
+def emitAccounting(category, principal, data):
+    """
+    Write the supplied data to the appropriate location for the given
+    category and principal.
+
+    @param principal: the principal for whom a log entry is to be created.
+    @type principal: L{DirectoryPrincipalResource}
+    @param category: accounting category
+    @type category: C{tuple}
+    @param data: data to write.
+    @type data: C{str}
+    """    
+    if not accountingEnabled(category, principal):
+        return
+
+    #
+    # Obtain the accounting log file name
+    #
+    logRoot = config.AccountingLogRoot
+    logDirectory = os.path.join(logRoot, principal.record.recordType, \
principal.record.shortName, category) +    logFilename = os.path.join(logDirectory, \
datetime.datetime.now().isoformat()) +
+    if not os.path.isdir(logDirectory):
+        os.makedirs(logDirectory)
+        logFilename = "%s-01" % (logFilename,)
+    else:
+        index = 1
+        while True:
+            path = "%s-%02d" % (logFilename, index)
+            if not os.path.isfile(path):
+                logFilename = path
+                break
+            if index == 1000:
+                log.error("Too many %s accounting files for %s" % (category, \
principal)) +                return
+
+    #
+    # Now write out the data to the log file
+    #
+    logFile = open(logFilename, "a")
+    try:
+        logFile.write(data)
+    finally:
+        logFile.close()

Modified: CalendarServer/branches/users/wsanchez/logging/twistedcaldav/config.py
===================================================================
--- CalendarServer/branches/users/wsanchez/logging/twistedcaldav/config.py	2008-04-26 \
                02:21:28 UTC (rev 2355)
+++ CalendarServer/branches/users/wsanchez/logging/twistedcaldav/config.py	2008-04-26 \
02:38:17 UTC (rev 2356) @@ -113,8 +113,13 @@
     "ServerStatsFile": "/var/run/caldavd/stats.plist",
     "PIDFile"        : "/var/run/caldavd.pid",
     "RotateAccessLog": False,
-    "DefaultLogLevel": None,
+    "DefaultLogLevel": "",
     "LogLevels": {},
+    "AccountingCategories": {
+        "iTIP": False,
+    },
+    "AccountingPrincipals": (),
+    "AccountingLogRoot": "/var/log/caldavd/accounting",
 
     #
     # SSL/TLS

Modified: CalendarServer/branches/users/wsanchez/logging/twistedcaldav/schedule.py
===================================================================
--- CalendarServer/branches/users/wsanchez/logging/twistedcaldav/schedule.py	2008-04-26 \
                02:21:28 UTC (rev 2355)
+++ CalendarServer/branches/users/wsanchez/logging/twistedcaldav/schedule.py	2008-04-26 \
02:38:17 UTC (rev 2356) @@ -40,6 +40,7 @@
 from twistedcaldav import caldavxml
 from twistedcaldav import itip
 from twistedcaldav.log import LoggingMixIn
+from twistedcaldav.accounting import accountingEnabled, emitAccounting
 from twistedcaldav.resource import CalDAVResource
 from twistedcaldav.caldavxml import caldav_namespace, TimeRange
 from twistedcaldav.config import config
@@ -338,6 +339,21 @@
             # Do regular invite (fan-out)
             freebusy = False
 
+        #
+        # Accounting
+        #
+        # Note that we associate logging with the organizer, not the
+        # originator, which is good for looking for why something
+        # shows up in a given principal's calendars, rather than
+        # tracking the activities of a specific user.
+        #
+        if accountingEnabled("iTIP", organizerPrincipal):
+            emitAccounting(
+                "iTIP", organizerPrincipal,
+                "Originator: %s\nRecipients: %s\n\n%s"
+                % (originator, ", ".join(recipients), str(calendar))
+            )
+
         # Prepare for multiple responses
         responses = ScheduleResponseQueue("POST", responsecode.OK)
     


[Attachment #5 (text/html)]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style \
type="text/css"><!-- #msg dl { border: 1px #006 solid; background: #369; padding: \
6px; color: #fff; } #msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: \
verdana,arial,helvetica,sans-serif; font-size: 10pt;  } #msg dl a { font-weight: \
bold} #msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: \
bold; } #msg pre, #msg p { overflow: auto; background: #ffc; border: 1px #fc0 solid; \
padding: 6px; } #msg ul { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: \
6px; } #patch { width: 100%; }
#patch h4 {font-family: \
verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
 #patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, \
#patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch ins \
{background:#dfd;text-decoration:none;display:block;padding:0 10px;} #patch del \
{background:#fdd;text-decoration:none;display:block;padding:0 10px;} #patch .lines, \
                .info {color:#888;background:#fff;}
--></style>
<title>[2356] CalendarServer/branches/users/wsanchez/logging</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a \
href="http://trac.macosforge.org/projects/calendarserver/changeset/2356">2356</a></dd>
 <dt>Author</dt> <dd>wsanchez@apple.com</dd>
<dt>Date</dt> <dd>2008-04-25 19:38:17 -0700 (Fri, 25 Apr 2008)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add accounting stuff, modeled roughly after Cyrus' loggig branch.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesuserswsanchezloggingconfcaldavdtestplist">CalendarServer/branches/users/wsanchez/logging/conf/caldavd-test.plist</a></li>
 <li><a href="#CalendarServerbranchesuserswsanchezloggingtwistedcaldavconfigpy">CalendarServer/branches/users/wsanchez/logging/twistedcaldav/config.py</a></li>
 <li><a href="#CalendarServerbranchesuserswsanchezloggingtwistedcaldavschedulepy">CalendarServer/branches/users/wsanchez/logging/twistedcaldav/schedule.py</a></li>
 </ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesuserswsanchezloggingtwistedcaldavaccountingpy">CalendarServer/branches/users/wsanchez/logging/twistedcaldav/accounting.py</a></li>
 </ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServerbranchesuserswsanchezloggingconfcaldavdtestplist"></a>
<div class="modfile"><h4>Modified: \
CalendarServer/branches/users/wsanchez/logging/conf/caldavd-test.plist (2355 => \
2356)</h4> <pre class="diff"><span>
<span class="info">--- \
CalendarServer/branches/users/wsanchez/logging/conf/caldavd-test.plist	2008-04-26 \
                02:21:28 UTC (rev 2355)
+++ CalendarServer/branches/users/wsanchez/logging/conf/caldavd-test.plist	2008-04-26 \
02:38:17 UTC (rev 2356) </span><span class="lines">@@ -184,7 +184,7 @@
</span><span class="cx">   &lt;!-- Principals with &quot;DAV:all&quot; access \
(relative URLs) --&gt; </span><span class="cx">   \
&lt;key&gt;AdminPrincipals&lt;/key&gt; </span><span class="cx">   &lt;array&gt;
</span><del>-    &lt;string&gt;/principals/__uids__/admin/&lt;/string&gt;
</del><ins>+    &lt;string&gt;/principals/users/admin/&lt;/string&gt;
</ins><span class="cx">   &lt;/array&gt;
</span><span class="cx"> 
</span><span class="cx">   &lt;!-- Principals that can pose as other principals \
--&gt; </span><span class="lines">@@ -258,6 +258,17 @@
</span><span class="cx">   &lt;dict&gt;
</span><span class="cx">   &lt;/dict&gt;
</span><span class="cx"> 
</span><ins>+  &lt;!-- Accounting --&gt;
+  &lt;key&gt;AccountingCategories&lt;/key&gt;
+  &lt;dict&gt;
+    &lt;key&gt;iTIP&lt;/key&gt;&lt;false/&gt;
+  &lt;/dict&gt;
+
+  &lt;key&gt;AccountingPrincipals&lt;/key&gt;
+  &lt;array&gt;
+    &lt;!--&lt;string&gt;/principals/users/foo/&lt;/string&gt;--&gt;
+  &lt;/array&gt;
+
</ins><span class="cx">   &lt;!-- Server statistics file --&gt;
</span><span class="cx">   &lt;key&gt;ServerStatsFile&lt;/key&gt;
</span><span class="cx">   &lt;string&gt;logs/stats.plist&lt;/string&gt;
</span></span></pre></div>
<a id="CalendarServerbranchesuserswsanchezloggingtwistedcaldavaccountingpy"></a>
<div class="addfile"><h4>Added: \
CalendarServer/branches/users/wsanchez/logging/twistedcaldav/accounting.py (0 => \
2356)</h4> <pre class="diff"><span>
<span class="info">--- \
CalendarServer/branches/users/wsanchez/logging/twistedcaldav/accounting.py	           \
                (rev 0)
+++ CalendarServer/branches/users/wsanchez/logging/twistedcaldav/accounting.py	2008-04-26 \
02:38:17 UTC (rev 2356) </span><span class="lines">@@ -0,0 +1,107 @@
</span><ins>+##
+# Copyright (c) 2006-2007 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
+# 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 &quot;AS IS&quot; 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.
+##
+
+&quot;&quot;&quot;
+Extended account-specific logging.
+Allows different sub-systems to log data on a per-principal basis.
+&quot;&quot;&quot;
+
+__all__ = [
+    &quot;accountingEnabled&quot;,
+    &quot;emitAccounting&quot;,
+]
+
+import datetime
+import os
+
+from twistedcaldav.config import config
+from twistedcaldav.log import Logger
+
+log = Logger()
+
+def accountingEnabled(category, principal):
+    &quot;&quot;&quot;
+    Determine if accounting is enabled for the given category and principal.
+    &quot;&quot;&quot;
+    return (
+        accountingEnabledForCategory(category) and
+        accountingEnabledForPrincipal(principal)
+    )
+
+def accountingEnabledForCategory(category):
+    &quot;&quot;&quot;
+    Determine if accounting is enabled for the given category.
+    &quot;&quot;&quot;
+    return config.AccountingCategories.get(category, False)
+
+def accountingEnabledForPrincipal(principal):
+    &quot;&quot;&quot;
+    Determine if accounting is enabled for the given principal.
+    &quot;&quot;&quot;
+    enabledPrincipalURIs = config.AccountingPrincipals
+
+    if principal.principalURL() in enabledPrincipalURIs:
+        return True
+
+    if principal.alternateURIs() in enabledPrincipalURIs:
+        return True
+
+    return False
+
+def emitAccounting(category, principal, data):
+    &quot;&quot;&quot;
+    Write the supplied data to the appropriate location for the given
+    category and principal.
+
+    @param principal: the principal for whom a log entry is to be created.
+    @type principal: L{DirectoryPrincipalResource}
+    @param category: accounting category
+    @type category: C{tuple}
+    @param data: data to write.
+    @type data: C{str}
+    &quot;&quot;&quot;    
+    if not accountingEnabled(category, principal):
+        return
+
+    #
+    # Obtain the accounting log file name
+    #
+    logRoot = config.AccountingLogRoot
+    logDirectory = os.path.join(logRoot, principal.record.recordType, \
principal.record.shortName, category) +    logFilename = os.path.join(logDirectory, \
datetime.datetime.now().isoformat()) +
+    if not os.path.isdir(logDirectory):
+        os.makedirs(logDirectory)
+        logFilename = &quot;%s-01&quot; % (logFilename,)
+    else:
+        index = 1
+        while True:
+            path = &quot;%s-%02d&quot; % (logFilename, index)
+            if not os.path.isfile(path):
+                logFilename = path
+                break
+            if index == 1000:
+                log.error(&quot;Too many %s accounting files for %s&quot; % \
(category, principal)) +                return
+
+    #
+    # Now write out the data to the log file
+    #
+    logFile = open(logFilename, &quot;a&quot;)
+    try:
+        logFile.write(data)
+    finally:
+        logFile.close()
</ins></span></pre></div>
<a id="CalendarServerbranchesuserswsanchezloggingtwistedcaldavconfigpy"></a>
<div class="modfile"><h4>Modified: \
CalendarServer/branches/users/wsanchez/logging/twistedcaldav/config.py (2355 => \
2356)</h4> <pre class="diff"><span>
<span class="info">--- \
CalendarServer/branches/users/wsanchez/logging/twistedcaldav/config.py	2008-04-26 \
                02:21:28 UTC (rev 2355)
+++ CalendarServer/branches/users/wsanchez/logging/twistedcaldav/config.py	2008-04-26 \
02:38:17 UTC (rev 2356) </span><span class="lines">@@ -113,8 +113,13 @@
</span><span class="cx">     &quot;ServerStatsFile&quot;: \
&quot;/var/run/caldavd/stats.plist&quot;, </span><span class="cx">     \
&quot;PIDFile&quot;        : &quot;/var/run/caldavd.pid&quot;, </span><span \
class="cx">     &quot;RotateAccessLog&quot;: False, </span><del>-    \
&quot;DefaultLogLevel&quot;: None, </del><ins>+    &quot;DefaultLogLevel&quot;: \
&quot;&quot;, </ins><span class="cx">     &quot;LogLevels&quot;: {},
</span><ins>+    &quot;AccountingCategories&quot;: {
+        &quot;iTIP&quot;: False,
+    },
+    &quot;AccountingPrincipals&quot;: (),
+    &quot;AccountingLogRoot&quot;: &quot;/var/log/caldavd/accounting&quot;,
</ins><span class="cx"> 
</span><span class="cx">     #
</span><span class="cx">     # SSL/TLS
</span></span></pre></div>
<a id="CalendarServerbranchesuserswsanchezloggingtwistedcaldavschedulepy"></a>
<div class="modfile"><h4>Modified: \
CalendarServer/branches/users/wsanchez/logging/twistedcaldav/schedule.py (2355 => \
2356)</h4> <pre class="diff"><span>
<span class="info">--- \
CalendarServer/branches/users/wsanchez/logging/twistedcaldav/schedule.py	2008-04-26 \
                02:21:28 UTC (rev 2355)
+++ CalendarServer/branches/users/wsanchez/logging/twistedcaldav/schedule.py	2008-04-26 \
02:38:17 UTC (rev 2356) </span><span class="lines">@@ -40,6 +40,7 @@
</span><span class="cx"> from twistedcaldav import caldavxml
</span><span class="cx"> from twistedcaldav import itip
</span><span class="cx"> from twistedcaldav.log import LoggingMixIn
</span><ins>+from twistedcaldav.accounting import accountingEnabled, emitAccounting
</ins><span class="cx"> from twistedcaldav.resource import CalDAVResource
</span><span class="cx"> from twistedcaldav.caldavxml import caldav_namespace, \
TimeRange </span><span class="cx"> from twistedcaldav.config import config
</span><span class="lines">@@ -338,6 +339,21 @@
</span><span class="cx">             # Do regular invite (fan-out)
</span><span class="cx">             freebusy = False
</span><span class="cx"> 
</span><ins>+        #
+        # Accounting
+        #
+        # Note that we associate logging with the organizer, not the
+        # originator, which is good for looking for why something
+        # shows up in a given principal's calendars, rather than
+        # tracking the activities of a specific user.
+        #
+        if accountingEnabled(&quot;iTIP&quot;, organizerPrincipal):
+            emitAccounting(
+                &quot;iTIP&quot;, organizerPrincipal,
+                &quot;Originator: %s\nRecipients: %s\n\n%s&quot;
+                % (originator, &quot;, &quot;.join(recipients), str(calendar))
+            )
+
</ins><span class="cx">         # Prepare for multiple responses
</span><span class="cx">         responses = ScheduleResponseQueue(&quot;POST&quot;, \
responsecode.OK) </span><span class="cx">     
</span></span></pre>
</div>
</div>

</body>
</html>



_______________________________________________
calendarserver-changes mailing list
calendarserver-changes@lists.macosforge.org
http://lists.macosforge.org/mailman/listinfo/calendarserver-changes


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic