Package: crimson_antispam
================Crimson Anti-spam================Crimson Anit-spam is an anti-spam package for django framework.------------------------------------Requirements------------------------------------Crimson antispam supports python versions 2.7, 3.3, 3.4 and 3.5. Django 1.7,1.8 and 1.9 are supported out of the box. Crimson antispam requires djangomigrations hence it will not work on django versions prior to 1.7------------Installation------------Installation via pip--------------------pip is the recommended way of installing python packages. If you do not havepip installed on your system, please refer to to pip documentation forinformation on installing pip. Run the following command from a terminal toinstall the current version of crimson anti-spam.::pip install crimson_antispam --upgradeIt is possible to separately install crimson_antispam for python 2 and python3. Replace pip with pip2 or pip3 depending on your python version.Installing a development version from github--------------------------------------------If you need the latest development version, you can install it from github.Note that the development version is unstable and may contains bugs. Use thecommand below to install development version.::pip install git+https://github.com/tony-joseph/crimson_antispam.git@masterManual Installation-------------------If you want to download and install manually, you can download the latestversion from the following link.`<https://pypi.python.org/pypi/crimson_antispam/>`_Adding to django project------------------------Crimson antispam must be included in installed apps before using it in a djangoproject. Open your settings file and add 'antispam' to the list of installedapps.::INSTALLED_APPS = [……………'antispam',……………]You should run the migrations command to create database tables for antispam.::python manage.py migrate------------------------------Working With Spam IP Addresses------------------------------Crimson antispam uses a spam IP address database to identify spam. The modalfor this database is located at antispam.models.SpamIP. The antispam packagegives you helper functions to manage this database so that you will never haveto access the SpamIP model directly.Adding a new IP address to spam list------------------------------------Crimson antispam provides a convenient helper function to add an IP to spamlist. Import the add_spam_ip function from helpers.::from antispam.helpers import add_spam_ipThe add_spam_ip function takes an IPv4 or IPv6 IP address as its only argument.For example::add_spam_ip('192.168.0.1')The IP address will be added to the spam list if it is not already there. Noerror will be produced if it is already in spam list.Adding a list of addresses to spam list---------------------------------------Just like adding a single IP address to spam list, you could also add a list(or tuple) of IP addresses to spam list. The helpers module has abulk_add_spam_ip function for this purpose.::from antispam.helpers import bulk_add_spam_ipbulk_add_spam_ip(['192.168.0.1', '192.168.0.2', '192.168.0.3'])Checking an IP address is in spam list--------------------------------------The is_spam_ip function in helpers module checks the given IP address is inspam list or not. This function takes an IPv4  or IPv6 address as its onlyargument. It will return True if the IP address is in spam list and Falseotherwise.::from antispam.helpers import is_spam_ipis_spam_ip('192.168.0.1')Removing an IP address form spam list-------------------------------------You can remove an IP address from spam list using the remove_spam_ip functionin helpers module. It will remove the IP address if it exists. No error messagewill be produced if the IP address is not in the list.::from antispam.helpers import remove_spam_ipremove_spam_ip('192.168.0.1')Managing spam IP list using admin interface-------------------------------------------You can use the django admin interface to manage spam IPs. It will be locatedas 'Spam ips' under the antispam app.Importing and exporting spam IP addresses-----------------------------------------To export all the spam IP addresses into a csv file, run the following command::python manage.py exportspamipsYou can also import spam IP addresses from a csv file. Run the followingcommand to import IP addresses from csv file into database.::Python manage.py importspamips <csv_file>csv_file should be the absolute path to the csv file containing spam IPaddresses.-------------------------Restricting Spam Requests-------------------------Using crimson anti-spam you can block requests from known spam IP addresses andthrottle requests from an IP address if it exceeds the permitted requests persecond.Blocking spam IP addresses--------------------------Blocking using decorator````````````````````````Crimson anti-spam provides a block_spam_ip view decorator to block spam IPaddresses from accessing a particular view. Import it as follows::from antispam.decorators import block_spam_ipBlocking using middleware`````````````````````````To block all requests from known spam IP addresses, you can use theBlockSpamIPMiddleware middleware. Add this middleware to your middlewareclasses as follows::MIDDLEWARE_CLASSES = […………………………….'antispam.middlewares.BlockSpamIPMiddleware',…………………………….]Blocking in templates`````````````````````The crimson anti-spam provides an is_spam_ip template context variable if youadd the antispam_processor to your template context processors. The value ofthis variable will be true if the request IP addresses is in spam IP list. Addthe following line to your template context processor settings::'antispam.context_processors.antispam_processor'You can check spam ip address in template as follows.::{% if is_spam_ip %}You are spam{% else %}You are not spam{% endif %}Throttling requests-------------------With crimson anti-spam, you can restrict the number of requests from an IPaddress if the requests are happening in quick succession. The default timedifference required between two requests is 1000 milliseconds.  You canoverride it in your settings as follows::ANTISPAM_SETTINGS = {'REQUEST_INTERVAL': 1000,}For throttling requests, you can either use the view decorator or themiddleware.Throttling using view decorator```````````````````````````````To throttle requests to a particular view, you can use the throttle_requestsview decorator. Import it as follows::from antispam.decorators import  throttle_requestsThrottling using middleware```````````````````````````You can throttle requests to all views by adding the ThrottleRequestsMiddlewareto you middleware classes.::MIDDLEWARE_CLASSES = [……………………………'antispam.middlewares.ThrottleRequestsMiddleware',……………………………]