示例#1
0
文件: fields.py 项目: visitorone/yats
    def clean(self, data, initial=None):
        f = super(yatsFileField, self).clean(initial or data)
        if f is None:
            return None
        elif not data and initial:
            return initial

        if settings.FILE_UPLOAD_VIRUS_SCAN:
            # virus scan
            try:
                pyclamd.init_network_socket('localhost', 3310)

                # We need to get a file object for clamav. We might have a path or we might
                # have to read the data into memory.
                if hasattr(data, 'temporary_file_path'):
                    chmod(data.temporary_file_path(), 0664)
                    result = pyclamd.scan_file(data.temporary_file_path())
                else:
                    if hasattr(data, 'read'):
                        result = pyclamd.scan_stream(data.read())
                    else:
                        result = pyclamd.scan_stream(data['content'])
            except:
                from socket import gethostname
                raise ValidationError(
                    self.error_messages['virus_engine_error'] % gethostname())

            if result:
                raise ValidationError(self.error_messages['virus_found'] %
                                      result[result.keys()[0]])

        return f
示例#2
0
 def clean(self, data, initial=None):
     f = super(yatsFileField, self).clean(initial or data)
     if f is None:
         return None
     elif not data and initial:
         return initial
     
     if settings.FILE_UPLOAD_VIRUS_SCAN:
         # virus scan
         try:
             pyclamd.init_network_socket('localhost', 3310)
     
             # We need to get a file object for clamav. We might have a path or we might
             # have to read the data into memory.
             if hasattr(data, 'temporary_file_path'):
                 chmod(data.temporary_file_path(), 0664)
                 result = pyclamd.scan_file(data.temporary_file_path())
             else:
                 if hasattr(data, 'read'):
                     result = pyclamd.scan_stream(data.read())
                 else:
                     result = pyclamd.scan_stream(data['content'])
         except:
             from socket import gethostname
             raise ValidationError(self.error_messages['virus_engine_error'] % gethostname())
         
         if result:
             raise ValidationError(self.error_messages['virus_found'] % result[result.keys()[0]])
     
     return f
示例#3
0
文件: clamdscan.py 项目: vertrex/DFF
 def scan(self, node):
     if not (node.size() > 0 and node.size() < 30 * 1024 * 1024):
         return None
     try:
         vfile = node.open()
         data = vfile.read()
         ret = pyclamd.scan_stream(data)
         if ret:
             return ret["stream"]
     except:
         return None
示例#4
0
 def receive_data_chunk(self, raw_data, start):
     if self.virus_found:
         # If a virus was already found, there's no need to
         # run it through the virus scanner a second time.
         return None
     try:
         if pyclamd.scan_stream(raw_data):
             # A virus was found, so the file should
             # be removed from the input stream.
             raise uploadhandler.SkipFile()
     except pylamd.ScanError:
         # Clam AV couldn't be contacted, so the file wasn't scanned.
         # Since we can't guarantee the safety of any files,
         # no other files should be processed either.
         raise uploadhander.StopUpload()
     # If everything went fine, pass the data along
     return raw_data
示例#5
0
 def receive_data_chunk(self, raw_data, start):
     if self.virus_found:
         # If a virus was already found, there's no need to
         # run it through the virus scanner a second time.
         return None
     try:
         if pyclamd.scan_stream(raw_data):
             # A virus was found, so the file should
             # be removed from the input stream.
             raise uploadhandler.SkipFile()
     except pylamd.ScanError:
         # Clam AV couldn't be contacted, so the file wasn't scanned.
         # Since we can't guarantee the safety of any files,
         # no other files should be processed either.
         raise uploadhander.StopUpload()
     # If everything went fine, pass the data along
     return raw_data
示例#6
0
文件: clamav.py 项目: moepnse/phoenix
    def _scan_stream(self):
        """Scans the Stream for Viruses"""

        try:
            ret = pyclamd.scan_stream(self._part)

            if self._email_message.__getitem__(
                    self._x_virus) != YES and ret == None:
                self._virus = False
            elif ret != None:
                self._virus = True
                self._viruses.append(ret["stream"])

        #except pyclamd.ScanError, err:
        #    log("%s [ClamAV] Error: %s" % (self._message_id, err), STD_ERR)
        #    raise BreakScanning()
        except Exception, err:
            if self._email_message.__getitem__(self._x_virus) != YES:
                self._virus = None
            log("%s [ClamAV] Unexpected error: %s" % (self._message_id, err),
                STD_ERR)
            raise BreakScanning()
示例#7
0
文件: amqpav.py 项目: dvoraka/amqpav
    def check_stream(self, data):
        
        result = pyclamd.scan_stream(data)

        return result
示例#8
0
文件: amqpav.py 项目: iSC-Labs/amqpav
    def check_stream(self, data):

        result = pyclamd.scan_stream(data)

        return result
示例#9
0
 def _scan(self):
     log.debug("Scanning message {0}".format(self))
     result = pyclamd.scan_stream(self._message.as_string())
     log.debug("Scanned message {0}, result {1}".format(self, result))
     if result:
         self.signature = result["stream"]
示例#10
0
文件: clamav.py 项目: iSC-Labs/amqpav
#! /usr/bin/env python

import pyclamd

print('pyclamd version: {}'.format(pyclamd.__version__))

pyclamd.init_unix_socket('/var/run/clamav/clamd.ctl')
if pyclamd.ping():
    print('Connection to Unix socket established.')
    print('ClamAV version: {}'.format(pyclamd.version()))

# test scan
result = pyclamd.scan_stream(pyclamd.EICAR)
print('Scan result: {}'.format(result))