ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 @access 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 @access 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 @access public More...
 
 logCleanResult ()
 write the result of the last clean to the log @access 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 @access public.

Parameters
stringvirus scanner command

Reimplemented from ilVirusScanner.

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.

33 {
34 return $this->scanCommand.' '.self::ADD_SCAN_PARAMS.' '.$file;
35 }
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file

References $file.

Referenced by processBufferScan(), and scanFile().

+ Here is the caller graph for this function:

◆ hasDetections()

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

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

113 {
114 return preg_match("/FOUND/", $detectionReport);
115 }

Referenced by processBufferScan(), and scanFile().

+ Here is the caller graph for this function:

◆ isBufferScanPossible()

ilVirusScannerClamAV::isBufferScanPossible ( )
protected
Returns
bool $isBufferScanSupported

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

41 {
42 $functions = array('proc_open', 'proc_close');
43
44 foreach($functions as $func)
45 {
46 if( function_exists($func) )
47 {
48 continue;
49 }
50
51 return false;
52 }
53
54 return true;
55 }

Referenced by scanBuffer().

+ Here is the caller graph for this function:

◆ processBufferScan()

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

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

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

References buildScanCommand(), and hasDetections().

Referenced by scanBuffer().

+ 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

Reimplemented from ilVirusScanner.

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

62 {
63 if( !$this->isBufferScanPossible() )
64 {
65 return $this->scanFileFromBuffer($buffer);
66 }
67
68 return $this->processBufferScan($buffer);
69 }

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

+ 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) @access public

Reimplemented from ilVirusScanner.

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

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

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

+ 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: