weblog.mattdorn.com

Generously funded by Matt Dorn

Getting AWStats to show Plone-authenticated users

without comments

I’m using AWStats to track usage on a Plone site that’s essentially a portal for collaborative document translation. That means that most users of the site need to login to do anything useful, and I want to see who’s logging in along with the rest of the stats on my site.

For hosting the site, I’m using the recommended setup which uses Zope’s Virtual Host Monser to route requests and responses between Apache and the Zope application server appropriately. I.e., I include the following two key lines in my Apache directive:

RewriteEngine On
RewriteRule ^/(.*) http://localhost:8080/VirtualHostBase/http/%{SERVER_NAME}:80/MyApp/VirtualHostRoot/$1 [NC,P,L]

Since I’m going thru Apache, I can record requests in log files as with any other site. Unfortunately, Zope/Plone does not pass information about the users who authenticate via its own system to the HTTP headers. Taking a cue from this thread, I came up with the following solution. It’s tested on Plone 2.1.3, but probably won’t work on Plone 2.5, given the latter’s use of Pluggable Authentication Service.

First, I found a place in the Plone page rendering mechanism that gets executed on each page view. I suppose the place that I chose was somewhat arbitrary, but in the "authenticate" method of the file GroupUserFolder/GroupUserFolder.py, I set a header called X-PloneUser, as shown in the following patch, available for your use:

1020,1022d1019
<         # PATCH FOR TRACKING AUTH USER IN APACHE LOGS --mdorn:
<         if name is not None:
<             request.RESPONSE.setHeader('X-PloneUser', name)

In my Apache configuration, I had to change LogFormat from "combined" to something more specific, and reference the label in the CustomLog:

LogFormat "%h %l %{X-Ploneuser}o %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" plone
CustomLog "|/usr/local/sbin/cronolog /home/httpd/MYDOMAIN/logs/%m-%Y/access_log" plone

To see authenticated users in your AWStats configuration file, you’ll need to change the default value for that setting:

ShowAuthenticatedUsers=1

That’s it. Next time AWStats processes your logs, assuming you had visits from authenticated users, you’ll now see them in the appropriate location on your AWStats report.

Written by mdorn

October 15th, 2006 at 7:12 pm

Posted in technology

Tagged with , , ,

Leave a Reply