ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilVirusScannerClamAV Class Reference

Interface to the ClamAV virus protector. More...

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

Public Member Functions

 __construct ($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
 __construct ($a_scancommand, $a_cleancommand)
 Constructor public. More...
 
 scanBuffer ($buffer)
 
 scanFile ($a_filepath, $a_origname="")
 scan a file for viruses needs to be redefined in child classes here it simulates a scan "infected.txt" or "cleanable.txt" are expected to be infected More...
 
 cleanFile ($a_filepath, $a_origname="")
 clean an infected file needs to be redefined in child classes here it simulates a clean "cleanable.txt" is expected to be cleanable More...
 
 fileCleaned ()
 returns wether file has been cleaned successfully or not More...
 
 logScanResult ()
 write the result of the last scan to the log public More...
 
 logCleanResult ()
 write the result of the last clean to the log public 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 13 of file class.ilVirusScannerClamAV.php.

Constructor & Destructor Documentation

◆ __construct()

ilVirusScannerClamAV::__construct (   $a_scancommand,
  $a_cleancommand 
)

Constructor public.

Parameters
stringvirus scanner command

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

23  {
24  parent::__construct($a_scancommand, $a_cleancommand);
25  $this->type = "clamav";
26  $this->scanZipFiles = true;
27  }

Member Function Documentation

◆ buildScanCommand()

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

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

Referenced by processBufferScan(), and scanFile().

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

◆ hasDetections()

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

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

Referenced by processBufferScan(), and scanFile().

109  {
110  return preg_match("/FOUND/", $detectionReport);
111  }
+ Here is the caller graph for this function:

◆ isBufferScanPossible()

ilVirusScannerClamAV::isBufferScanPossible ( )
protected
Returns
bool $isBufferScanSupported

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

Referenced by scanBuffer().

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

◆ processBufferScan()

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

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

References buildScanCommand(), and hasDetections().

Referenced by scanBuffer().

73  {
74  $descriptorspec = array(
75  0 => array("pipe", "r"), // stdin is a pipe that the child will read from
76  1 => array("pipe", "w"), // stdout is a pipe that the child will write to
77  2 => array("pipe", "w") // stderr for the child
78  );
79 
80  $pipes = array(); // will look like follows after passing
81  // 0 => writeable handle connected to child stdin
82  // 1 => readable handle connected to child stdout
83 
84  $process = proc_open($this->buildScanCommand(), $descriptorspec, $pipes);
85 
86  if (!is_resource($process)) {
87  return false; // no scan, no virus detected
88  }
89 
90  fwrite($pipes[0], $buffer);
91  fclose($pipes[0]);
92 
93  $detectionReport = stream_get_contents($pipes[1]);
94  fclose($pipes[1]);
95 
96  $errorReport = stream_get_contents($pipes[2]);
97  fclose($pipes[2]);
98 
99  $return = proc_close($process);
100 
101  return $this->hasDetections($detectionReport);
102  }
+ 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 59 of file class.ilVirusScannerClamAV.php.

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

60  {
61  if (!$this->isBufferScanPossible()) {
62  return $this->scanFileFromBuffer($buffer);
63  }
64 
65  return $this->processBufferScan($buffer);
66  }
+ 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 120 of file class.ilVirusScannerClamAV.php.

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

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

Field Documentation

◆ ADD_SCAN_PARAMS

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

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


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