quick search:
 

restricting user agents

Submitted by: zxc
Last Edited: 2001-08-09

Category: Python(Script)

Average rating is: 4.25 out of 5 (4 ratings)

Description:
This little but nice script shows how you can restrict a specific user agent from accesing any zope object.

It's very usefull for restricting download accelerators, like DownloadAccelerator, GetRight, etc


Source (Text):
user_agent = context.REQUEST.HTTP_USER_AGENT
denied_agents = 'DA', 'GetRight', 'FlashGet', 'Mass'

for denied_agent in denied_agents:
   chars = len(denied_agent)
   if user_agent[:chars] == denied_agent:
      raise "UserAgentError", "We don't allow download accelerators"

Explanation:
just create a python (script) called 'user_agents' on the folder
you want to restrict access to the user agents.

then add a 'Set Access Rule' object. in 'Rule Id' type 'user_agents'

and that's it, be aware that creating an access rule can be dangerous.
test the python script before converting it to an access rule.






Comments:

Just know it's easily bypassed by SmileyChris - 2001-08-07
Some download managers (FlashGet for example) can be set so they show up as IE simply by selecting a checkbox...
But yea, this'll stop most people who don't play around with program settings :)


But why? by peterbe - 2001-08-09
Why would one want to dissallow download accelerators?
 
Re: But why? by zxc - 2001-08-09
Short answer:
I have a limited upstream bandwidth, and a single user was stealing all of it. 

Download accelerators are EVIL, they download a single file in 
multiple simultaneous connections, pulling their bandwidth, and 
yours, to the max. 

Some users hit pause/resume (or cancel/resume) constantly. 
So if the accelerator uses 10 simultaneous connections, 
each cancel/resume will hit your webserver 10 times. 
making your logfiles grow a lot more than usual. 
(in my particular case, I've found 89 requests from a single 
user downloading a 5mb file with DA 5.0)

So, this is why I wrote this access rule. :)