ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
ilVirusScannerClamAV Class Reference

Interface to the ClamAV virus protector. More...

+ Inheritance diagram for ilVirusScannerClamAV:
+ Collaboration diagram for ilVirusScannerClamAV:

Public Member Functions

 ilVirusScannerClamAV ($a_scancommand, $a_cleancommand)
 Constructor public. More...
 
 scanBuffer ($buffer)
 
 scanFile ($a_filepath, $a_origname="")
 scan a file for viruses More...
 
- Public Member Functions inherited from ilVirusScanner
 ilVirusScanner ($a_scancommand, $a_cleancommand)
 Constructor public. More...
 
 scanBuffer ($buffer)
 
 scanFile ($a_filepath, $a_origname="")
 scan a file for viruses More...
 
 cleanFile ($a_filepath, $a_origname="")
 clean an infected file More...
 
 fileCleaned ()
 returns wether file has been cleaned successfully or not More...
 
 logScanResult ()
 write the result of the last scan to the log More...
 
 logCleanResult ()
 write the result of the last clean to the log More...
 
 getScanResult ()
 get the pure output of the external scan More...
 
 getCleanResult ()
 get the pure output of the external scan More...
 
 getScanMessage ()
 get a located message with the result from the last scan More...
 
 getCleanMessage ()
 get a located message with the result from the last clean More...
 
 getScanZipFiles ()
 get info if class can scan ZIP files More...
 

Data Fields

const ADD_SCAN_PARAMS = '--no-summary -i'
 
- Data Fields inherited from ilVirusScanner
 $type
 
 $scanZipFiles
 
 $scanCommand
 
 $cleanCommand
 
 $scanFilePath
 
 $scanFileOrigName
 
 $cleanFilePath
 
 $cleanFileOrigName
 
 $scanFileIsInfected
 
 $cleanFileIsCleaned
 
 $scanResult
 
 $cleanResult
 
 $ilias
 
 $lng
 
 $log
 

Protected Member Functions

 buildScanCommand ($file='-')
 
 isBufferScanPossible ()
 
 processBufferScan ($buffer)
 
 hasDetections ($detectionReport)
 
- Protected Member Functions inherited from ilVirusScanner
 scanFileFromBuffer ($buffer)
 
 createBufferFile ($buffer)
 
 removeBufferFile ($bufferFile)
 

Detailed Description

Interface to the ClamAV virus protector.

Author
Ralf Schenk rs@da.nosp@m.taba.nosp@m.y.de
Version
$Id$

Definition at line 15 of file class.ilVirusScannerClamAV.php.

Member Function Documentation

◆ buildScanCommand()

ilVirusScannerClamAV::buildScanCommand (   $file = '-')
protected
Returns
string $scanCommand

Definition at line 34 of file class.ilVirusScannerClamAV.php.

References $file.

Referenced by processBufferScan(), and scanFile().

35  {
36  return $this->scanCommand.' '.self::ADD_SCAN_PARAMS.' '.$file;
37  }
print $file
+ Here is the caller graph for this function:

◆ hasDetections()

ilVirusScannerClamAV::hasDetections (   $detectionReport)
protected
Parameters
$detectionReport
Returns
int

Definition at line 114 of file class.ilVirusScannerClamAV.php.

Referenced by processBufferScan(), and scanFile().

115  {
116  return preg_match("/FOUND/", $detectionReport);
117  }
+ Here is the caller graph for this function:

◆ ilVirusScannerClamAV()

ilVirusScannerClamAV::ilVirusScannerClamAV (   $a_scancommand,
  $a_cleancommand 
)

Constructor public.

Parameters
stringvirus scanner command

Definition at line 24 of file class.ilVirusScannerClamAV.php.

References ilVirusScanner\ilVirusScanner().

25  {
26  $this->ilVirusScanner($a_scancommand, $a_cleancommand);
27  $this->type = "clamav";
28  $this->scanZipFiles = true;
29  }
ilVirusScanner($a_scancommand, $a_cleancommand)
Constructor public.
+ Here is the call graph for this function:

◆ isBufferScanPossible()

ilVirusScannerClamAV::isBufferScanPossible ( )
protected
Returns
bool $isBufferScanSupported

Definition at line 42 of file class.ilVirusScannerClamAV.php.

Referenced by scanBuffer().

43  {
44  $functions = array('proc_open', 'proc_close');
45 
46  foreach($functions as $func)
47  {
48  if( function_exists($func) )
49  {
50  continue;
51  }
52 
53  return false;
54  }
55 
56  return true;
57  }
+ Here is the caller graph for this function:

◆ processBufferScan()

ilVirusScannerClamAV::processBufferScan (   $buffer)
protected
Parameters
string$buffer(any data, binary)
Returns
bool

Definition at line 77 of file class.ilVirusScannerClamAV.php.

References buildScanCommand(), and hasDetections().

Referenced by scanBuffer().

78  {
79  $descriptorspec = array(
80  0 => array("pipe", "r"), // stdin is a pipe that the child will read from
81  1 => array("pipe", "w"), // stdout is a pipe that the child will write to
82  2 => array("pipe", "w") // stderr for the child
83  );
84 
85  $pipes = array(); // will look like follows after passing
86  // 0 => writeable handle connected to child stdin
87  // 1 => readable handle connected to child stdout
88 
89  $process = proc_open($this->buildScanCommand(), $descriptorspec, $pipes);
90 
91  if( !is_resource($process) )
92  {
93  return false; // no scan, no virus detected
94  }
95 
96  fwrite($pipes[0], $buffer);
97  fclose($pipes[0]);
98 
99  $detectionReport = stream_get_contents($pipes[1]);
100  fclose($pipes[1]);
101 
102  $errorReport = stream_get_contents($pipes[2]);
103  fclose($pipes[2]);
104 
105  $return = proc_close($process);
106 
107  return $this->hasDetections($detectionReport);
108  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ scanBuffer()

ilVirusScannerClamAV::scanBuffer (   $buffer)
Parameters
string$buffer(any data, binary)
Returns
bool $infected

Definition at line 63 of file class.ilVirusScannerClamAV.php.

References isBufferScanPossible(), processBufferScan(), and ilVirusScanner\scanFileFromBuffer().

64  {
65  if( !$this->isBufferScanPossible() )
66  {
67  return $this->scanFileFromBuffer($buffer);
68  }
69 
70  return $this->processBufferScan($buffer);
71  }
+ Here is the call graph for this function:

◆ scanFile()

ilVirusScannerClamAV::scanFile (   $a_filepath,
  $a_origname = "" 
)

scan a file for viruses

Parameters
stringpath of file to check
stringoriginal name of the file to ckeck
Returns
string virus message (empty if not infected) public

Definition at line 127 of file class.ilVirusScannerClamAV.php.

References $cmd, $out, $ret, ilVirusScanner\$scanResult, buildScanCommand(), hasDetections(), and ilVirusScanner\logScanResult().

128  {
129  // This function should:
130  // - call the external scanner for a_filepath
131  // - set scanFilePath to a_filepath
132  // - set scanFileOrigName to a_origname
133  // - set scanFileIsInfected according the scan result
134  // - set scanResult to the scanner output message
135  // - call logScanResult() if file is infected
136  // - return the scanResult, if file is infected
137  // - return an empty string, if file is not infected
138 
139  $this->scanFilePath = $a_filepath;
140  $this->scanFileOrigName = $a_origname;
141 
142  // Call of antivir command
143  $cmd = $this->buildScanCommand($a_filepath)." 2>&1";
144  exec($cmd, $out, $ret);
145  $this->scanResult = implode("\n", $out);
146 
147  // sophie could be called
148  if( $this->hasDetections($this->scanResult) )
149  {
150  $this->scanFileIsInfected = true;
151  $this->logScanResult();
152  return $this->scanResult;
153  }
154  else
155  {
156  $this->scanFileIsInfected = false;
157  return "";
158  }
159 
160  // antivir has failed (todo)
161  $this->log->write("ERROR (Virus Scanner failed): "
162  . $this->scanResult
163  . "; COMMAMD=" . $cmd);
164 
165  }
$cmd
Definition: sahs_server.php:35
logScanResult()
write the result of the last scan to the log
+ Here is the call graph for this function:

Field Documentation

◆ ADD_SCAN_PARAMS

const ilVirusScannerClamAV::ADD_SCAN_PARAMS = '--no-summary -i'

Definition at line 17 of file class.ilVirusScannerClamAV.php.


The documentation for this class was generated from the following file: