Diff
Modified: trunk/app/controllers/application.rb (1886 => 1887)
--- trunk/app/controllers/application.rb 2008-10-24 17:18:34 UTC (rev 1886)
+++ trunk/app/controllers/application.rb 2008-10-27 13:50:15 UTC (rev 1887)
@@ -22,6 +22,22 @@
request.host_with_port
end
+
+ def allow_statistics_logging
+ # check if the current viewing/download is to be logged
+ # (i.e. request is sent not by a bot and is legitimate)
+ allow_logging = true
+ BOT_IGNORE_LIST.each do |pattern|
+ if request.env['HTTP_USER_AGENT'].match(pattern)
+ allow_logging = false
+ break
+ end
+ end
+
+ return allow_logging
+ end
+
+
def can_manage_pages?
return admin? # from authenticated_system
end
Modified: trunk/app/controllers/blobs_controller.rb (1886 => 1887)
--- trunk/app/controllers/blobs_controller.rb 2008-10-24 17:18:34 UTC (rev 1886)
+++ trunk/app/controllers/blobs_controller.rb 2008-10-27 13:50:15 UTC (rev 1887)
@@ -37,7 +37,9 @@
# GET /files/1;download
def download
- @download = Download.create(:contribution => @blob.contribution, :user => (logged_in? ? current_user : nil))
+ if allow_statistics_logging
+ @download = Download.create(:contribution => @blob.contribution, :user => (logged_in? ? current_user : nil))
+ end
send_data(@blob.content_blob.data, :filename => @blob.local_name, :type => @blob.content_type)
@@ -71,7 +73,9 @@
# GET /files/1
def show
- @viewing = Viewing.create(:contribution => @blob.contribution, :user => (logged_in? ? current_user : nil))
+ if allow_statistics_logging
+ @viewing = Viewing.create(:contribution => @blob.contribution, :user => (logged_in? ? current_user : nil))
+ end
respond_to do |format|
format.html # show.rhtml
Modified: trunk/app/controllers/packs_controller.rb (1886 => 1887)
--- trunk/app/controllers/packs_controller.rb 2008-10-24 17:18:34 UTC (rev 1886)
+++ trunk/app/controllers/packs_controller.rb 2008-10-27 13:50:15 UTC (rev 1887)
@@ -48,7 +48,9 @@
# GET /packs/1
def show
- @viewing = Viewing.create(:contribution => @pack.contribution, :user => (logged_in? ? current_user : nil))
+ if allow_statistics_logging
+ @viewing = Viewing.create(:contribution => @pack.contribution, :user => (logged_in? ? current_user : nil))
+ end
respond_to do |format|
format.html # show.rhtml
@@ -73,6 +75,10 @@
@pack.create_zip(current_user, image_hash)
+ if allow_statistics_logging
+ @download = Download.create(:contribution => @pack.contribution, :user => (logged_in? ? current_user : nil))
+ end
+
send_file @pack.archive_file_path, :disposition => 'attachment'
end
Modified: trunk/app/controllers/workflows_controller.rb (1886 => 1887)
--- trunk/app/controllers/workflows_controller.rb 2008-10-24 17:18:34 UTC (rev 1886)
+++ trunk/app/controllers/workflows_controller.rb 2008-10-27 13:50:15 UTC (rev 1887)
@@ -157,7 +157,9 @@
# GET /workflows/1;download
def download
- @download = Download.create(:contribution => @workflow.contribution, :user => (logged_in? ? current_user : nil))
+ if allow_statistics_logging
+ @download = Download.create(:contribution => @workflow.contribution, :user => (logged_in? ? current_user : nil))
+ end
send_data(@viewing_version.content_blob.data, :filename => @workflow.filename(@viewing_version_number), :type => @workflow.content_type)
end
@@ -225,7 +227,9 @@
# GET /workflows/1
def show
- @viewing = Viewing.create(:contribution => @workflow.contribution, :user => (logged_in? ? current_user : nil))
+ if allow_statistics_logging
+ @viewing = Viewing.create(:contribution => @workflow.contribution, :user => (logged_in? ? current_user : nil))
+ end
respond_to do |format|
format.html # show.rhtml
Modified: trunk/config/environment_private.rb.pre (1886 => 1887)
--- trunk/config/environment_private.rb.pre 2008-10-24 17:18:34 UTC (rev 1886)
+++ trunk/config/environment_private.rb.pre 2008-10-27 13:50:15 UTC (rev 1887)
@@ -71,4 +71,14 @@
INVITATION_EMAIL_LIMIT = 10
# The maximum file size allowed for workflows
-WORKFLOW_UPLOAD_MAX_BYTES = 20971520
\ No newline at end of file
+WORKFLOW_UPLOAD_MAX_BYTES = 20971520
+
+
+# =========== Settings for Download and Viewing Logging ===========
+
+# Patterns in this list will be used to be checked against "user-agent" in http request headers
+# to filter out bots from usage statistics.
+#
+# It is essential to put patterns into the ignore list in a single quotes - this will enable the
+# patterns to be treated as regular expressions, not just strings
+BOT_IGNORE_LIST = ['Googlebot', 'Slurp', 'msnbot', 'crawler', 'bot', 'heritrix']
\ No newline at end of file