1
from django.core.exceptions import ValidationError
2
from django.conf import settings
8
def virus_scan(uploaded_file):
9
'''Scan uploaded_file for viruses with clamav.'''
11
if settings.VIRUS_CHECK:
13
tmp_file_path = uploaded_file.temporary_file_path()
14
process_compl = subprocess.run(['/usr/bin/clamdscan',
18
if process_compl.returncode == 1:
19
raise ValidationError(
20
'This file seems to contain malicious code.'
22
if process_compl.returncode == 2:
23
raise ValidationError(
24
'Some error occured during virus scannning...'
26
except FileNotFoundError:
27
raise ValidationError(
28
'Please check the installation of clamav and make \
29
sure clamdscan is working.'