This project integrates python-clamd with Django for easy scanning files for viruses on upload
From PyPi with pip:
pip install django-clamdor
easy_install django-clamdYou can also install development version directly from GitHub:
pip install git+https://github.com/vstoykov/django-clamd.gitAdditionally if you want translations to work you need to add it to installed apps.
INSTALLED_APPS= (
...
'django_clamd',
...
)Additionally if you are using Ubuntu, in order for django-clamd to work install clamav-daemon.
sudo apt-get install clamav-daemonYou can use it in forms:
fromdjangoimportformsfromdjango_clamd.validatorsimportvalidate_file_infectionclassUploadForm(forms.Form):
upload_file=forms.FileField(validators=[validate_file_infection])Or you can add it as validator directly in your model:
fromdjango.dbimportmodelsfromdjango_clamd.validatorsimportvalidate_file_infectionclassFileModel(models.Model):
document=models.FileField(validators=[validate_file_infection])You will have automatically scanning of upladed files in Django Admin and also when create ModelForm's for that model.
By default django-clamd tries to be smart and with good defaults.
You can still configure how to connect to Clamd. Default values are:
CLAMD_SOCKET='/var/run/clamav/clamd.ctl'CLAMD_USE_TCP=FalseCLAMD_TCP_SOCKET=3310CLAMD_TCP_ADDR='127.0.0.1'Note: When you are running on Fedora or CentOS and clamav-scanner
package is installed then default value for CLAMD_SOCKET is:
CLAMD_SOCKET='/var/run/clamd.scan/clamd.sock'By default, this package will allow a file if ClamD cannot be contacted or
if the scan fails. If you want validation to fail in these instances, change
CLAMD_FAIL_BY_DEFAULT
CLAMD_FAIL_BY_DEFAULT=TrueYou also can disable virus scanning for development with:
CLAMD_ENABLED=FalseNote: This is primary for make it easy to run a project on development without the need of installing Clamd on devlopment machine.
django-clamd is released as open-source software under the LGPL license.