PageRenderTime 23ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/README.rst

https://github.com/benjaoming/django-stopforumspam
ReStructuredText | 126 lines | 74 code | 52 blank | 0 comment | 0 complexity | 9923945dd8d360065970260de70d0e28 MD5 | raw file
  1. django stopforumspam middleware
  2. ===============================
  3. Tired of comment spam, form spam and dumb crawlers? A django application
  4. that provides middleware for blocking IPs listed in stopforumspam.com's
  5. database. It only reacts on POST requests, so don't worry about a huge
  6. table of rules having to be passed at every request. It's quite
  7. painless.
  8. A simple management command is provided for updating the database from
  9. stopforumspam.com:
  10. ::
  11. manage.py sfsupdate [--force]
  12. Using this command, all IPs are stored in Django models, and using
  13. django-admin, it's possible to add your own extra IP addresses on a
  14. permanent database.
  15. Compatibility
  16. -------------
  17. - Django 1.7 - 4.x
  18. - Python 2.7 and 3+
  19. Installation
  20. ------------
  21. 1. Install the latest release from pypi::
  22. sudo pip install stopforumspam
  23. 2. Add this to ``settings.MIDDLEWARE_CLASSES``::
  24. 'stopforumspam.middleware.StopForumSpamMiddleware'
  25. 3. Then add this to ``INSTALLED_APPS``::
  26. 'stopforumspam'
  27. 4. And run::
  28. python manage.py migrate
  29. 5. To insert all the IPs run this command, which you should make a
  30. cronjob (run it every 24h)::
  31. python manage.py sfsupdate
  32. Configuration
  33. -------------
  34. The following options exist for your project's settings.py file:
  35. To check ALL POST requests::
  36. SFS_ALL_POST_REQUESTS = True
  37. To ignore some URLS::
  38. SFS_URLS_IGNORE = ["url_name", "/url/path"]
  39. To only include some URLS (only works if ``SFS_ALL_POST_REQUEST=False``)::
  40. SFS_URLS_INCLUDE = ["url_name", "/url/path"]
  41. If your application is behind a set of proxy, you can use a specific
  42. HTTP Header as a source of the client IP::
  43. SFS_HTTP_HEADER = "X-Forwarded-For"
  44. Synching with stopforumspam.com
  45. -------------------------------
  46. Be nice to their servers and remember that they have strict enforcements
  47. on the files that they offer. So before you start testing, you could
  48. consider using a local file as a test.
  49. To configure where to download the file from (you can MAX download 2
  50. times a day) - see http://www.stopforumspam.com for more resources::
  51. SFS_SOURCE_ZIP = "http://www.stopforumspam.com/downloads/listed_ip_7.zip"
  52. But you should really use a local file if you have more than 1 Django
  53. project with stopforumspam running from the same IP address. To do this,
  54. use a local protocol::
  55. SFS_SOURCE_ZIP = "file:///path/to/listed_ip_7.zip"
  56. You can control how often at most the update should be performed::
  57. SFS_CACHE_EXPIRE = 1 #day
  58. ...and how long back the log should remember the rejection of POSTS and
  59. IPs::
  60. SFS_LOG_EXPIRE = 1 #days
  61. Remember to configure this as well -- it's the name of the file inside
  62. the .zip file::
  63. SFS_ZIP_FILENAME = "listed_ip_7.txt"
  64. For testing you can force all requests to be checked::
  65. SFS_FORCE_ALL_REQUESTS = True
  66. Cron Jobs
  67. ---------
  68. You probably want to automatically update the list of blocked IP
  69. addresses every 24 hours or 48 hours. To do that, you can insert a line
  70. in crontab::
  71. 0 2 * * * python /your/project/path/manage.py sfsupdate -q
  72. The above would update at 2 AM every night. If you have several projects
  73. and sync them with a local file, you can add::
  74. 0 2 * * * wget -O /tmp/listed_ip_7.zip http://www.stopforumspam.com/downloads/listed_ip_7.zip ; python /your/project/path/manage.py sfsupdate -q