ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilVirusScannerClamAV Class Reference
+ Inheritance diagram for ilVirusScannerClamAV:
+ Collaboration diagram for ilVirusScannerClamAV:

Public Member Functions

 __construct (string $scan_command, string $clean_command)
 
 scanBuffer (string $buffer)
 
 scanFile (string $file_path, string $org_name='')
 
- Public Member Functions inherited from ilVirusScanner
 __construct (string $scan_command, string $clean_command)
 
 scanBuffer (string $buffer)
 
 scanFile (string $file_path, string $org_name='')
 
 logScanResult ()
 
 cleanFile (string $file_path, string $org_name='')
 
 logCleanResult ()
 
 fileCleaned ()
 
 getScanResult ()
 
 getCleanResult ()
 
 getScanMessage ()
 
 getCleanMessage ()
 
 getScanZipFiles ()
 

Protected Member Functions

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

Private Attributes

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

Additional Inherited Members

- Static Public Member Functions inherited from ilVirusScanner
static virusHandling (string $a_file, string $a_orig_name='', bool $a_clean=true)
 
- Data Fields inherited from ilVirusScanner
string $type
 
bool $scanZipFiles
 
string $scanCommand
 
string $cleanCommand
 
string $scanFilePath
 
string $scanFileOrigName
 
string $cleanFilePath
 
string $cleanFileOrigName
 
bool $scanFileIsInfected
 
bool $cleanFileIsCleaned
 
string $scanResult
 
string $cleanResult
 
ilErrorHandling $error
 
ilLanguage $lng
 
ilLogger $log
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilVirusScannerClamAV::__construct ( string  $scan_command,
string  $clean_command 
)

Reimplemented from ilVirusScanner.

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

26 {
27 parent::__construct($scan_command, $clean_command);
28 $this->type = 'clamav';
29 $this->scanZipFiles = true;
30 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References ILIAS\GlobalScreen\Provider\__construct().

+ Here is the call graph for this function:

Member Function Documentation

◆ buildScanCommand()

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

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

88 : string
89 {
90 return $this->scanCommand . ' ' . self::ADD_SCAN_PARAMS . ' ' . $file;
91 }

Referenced by processBufferScan().

+ Here is the caller graph for this function:

◆ buildScanCommandArguments()

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

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

96 {
97 return ' ' . self::ADD_SCAN_PARAMS . ' ' . $file;
98 }

Referenced by scanFile().

+ Here is the caller graph for this function:

◆ hasDetections()

ilVirusScannerClamAV::hasDetections ( string  $detectionReport)
protected

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

101 : int
102 {
103 return preg_match('/FOUND/', $detectionReport);
104 }

Referenced by processBufferScan(), and scanFile().

+ Here is the caller graph for this function:

◆ isBufferScanPossible()

ilVirusScannerClamAV::isBufferScanPossible ( )
protected

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

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

Referenced by scanBuffer().

+ Here is the caller graph for this function:

◆ processBufferScan()

ilVirusScannerClamAV::processBufferScan ( string  $buffer)
protected

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

56 : bool
57 {
58 $descriptor_spec = [
59 0 => ['pipe', 'r'], // stdin is a pipe that the child will read from
60 1 => ['pipe', 'w'], // stdout is a pipe that the child will write to
61 2 => ['pipe', 'w'] // stderr for the child
62 ];
63
64 $pipes = []; // will look like follows after passing
65 // 0 => writeable handle connected to child stdin
66 // 1 => readable handle connected to child stdout
67
68 $process = proc_open($this->buildScanCommand(), $descriptor_spec, $pipes);
69
70 if (!is_resource($process)) {
71 return false; // no scan, no virus detected
72 }
73
74 fwrite($pipes[0], $buffer);
75 fclose($pipes[0]);
76
77 $detectionReport = stream_get_contents($pipes[1]);
78 fclose($pipes[1]);
79
80 $errorReport = stream_get_contents($pipes[2]);
81 fclose($pipes[2]);
82
83 $return = proc_close($process);
84
85 return (bool) $this->hasDetections($detectionReport);
86 }
hasDetections(string $detectionReport)

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 ( string  $buffer)

Reimplemented from ilVirusScanner.

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

32 : bool
33 {
34 if (!$this->isBufferScanPossible()) {
35 return $this->scanFileFromBuffer($buffer);
36 }
37
38 return $this->processBufferScan($buffer);
39 }
scanFileFromBuffer(string $buffer)

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

+ Here is the call graph for this function:

◆ scanFile()

ilVirusScannerClamAV::scanFile ( string  $file_path,
string  $org_name = '' 
)

Reimplemented from ilVirusScanner.

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

106 : string
107 {
108 $this->scanFilePath = $file_path;
109 $this->scanFileOrigName = $org_name;
110 // Make group readable for clamdscan
111 $currentPermission = fileperms($file_path);
112 $perm = $currentPermission | 0640;
113 chmod($file_path, $perm);
114
115 $a_filepath = realpath($file_path);
116 if (file_exists($file_path)) {
117 $args = ilShellUtil::escapeShellArg($file_path);
118 $arguments = $this->buildScanCommandArguments($args) . ' 2>&1';
119 $cmd = ilShellUtil::escapeShellCmd($this->scanCommand);
120 $out = ilShellUtil::execQuoted($cmd, $arguments);
121 $this->scanResult = implode("\n", $out);
122
123 if ($perm != $currentPermission) {
124 chmod($a_filepath, $currentPermission);
125 }
126
127 if ($this->hasDetections($this->scanResult)) {
128 $this->scanFileIsInfected = true;
129 $this->logScanResult();
130 return $this->scanResult;
131 } else {
132 $this->scanFileIsInfected = false;
133 return '';
134 }
135 }
136
137 $return_error = 'ERROR (Virus Scanner failed): '
138 . $this->scanResult
139 . '; Path=' . $a_filepath;
140 $this->log->write($return_error);
141 return $return_error;
142 }
$out
Definition: buildRTE.php:24
static escapeShellArg(string $a_arg)
static escapeShellCmd(string $a_arg)
static execQuoted(string $cmd, ?string $args=null)

References $out, ilVirusScanner\$scanResult, buildScanCommandArguments(), ilShellUtil\escapeShellArg(), ilShellUtil\escapeShellCmd(), ilShellUtil\execQuoted(), 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'
private

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


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