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

Base class for the interface to an external virus scanner This class is abstract and needs to be extended for actual scanners Only scanFile() and cleanFile() need to be redefined Child Constructors should call ilVirusScanner() Scan and Clean are independent and may work on different files Logging and message generation are generic. More...

+ Inheritance diagram for ilVirusScanner:
+ Collaboration diagram for ilVirusScanner:

Public Member Functions

 __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

 $type
 
 $scanZipFiles
 
 $scanCommand
 
 $cleanCommand
 
 $scanFilePath
 
 $scanFileOrigName
 
 $cleanFilePath
 
 $cleanFileOrigName
 
 $scanFileIsInfected
 
 $cleanFileIsCleaned
 
 $scanResult
 
 $cleanResult
 
 $ilias
 
 $lng
 
 $log
 

Protected Member Functions

 scanFileFromBuffer ($buffer)
 
 createBufferFile ($buffer)
 
 removeBufferFile ($bufferFile)
 

Detailed Description

Base class for the interface to an external virus scanner This class is abstract and needs to be extended for actual scanners Only scanFile() and cleanFile() need to be redefined Child Constructors should call ilVirusScanner() Scan and Clean are independent and may work on different files Logging and message generation are generic.

Author
Fred Neumann fred..nosp@m.neum.nosp@m.ann@f.nosp@m.im.u.nosp@m.ni-er.nosp@m.lang.nosp@m.en.de
Version
$Id$

Definition at line 14 of file class.ilVirusScanner.php.

Constructor & Destructor Documentation

◆ __construct()

ilVirusScanner::__construct (   $a_scancommand,
  $a_cleancommand 
)

Constructor public.

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

References $DIC, $ilias, $lng, and $log.

128  {
129  global $DIC;
130  $ilias = $DIC['ilias'];
131  $lng = $DIC['lng'];
132  $log = $DIC['log'];
133 
134  $this->ilias = $ilias;
135  $this->lng = $lng;
136  $this->log = $log;
137  $this->scanCommand = $a_scancommand;
138  $this->cleanCommand = $a_cleancommand;
139 
140  $this->type = "simulate";
141  $this->scanZipFiles = false;
142  }
global $DIC
Definition: saml.php:7
redirection script todo: (a better solution should control the processing via a xml file) ...

Member Function Documentation

◆ cleanFile()

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

Parameters
stringpath of file to check
stringoriginal name of the file to clean
Returns
string clean message (empty if not cleaned) public

Definition at line 233 of file class.ilVirusScanner.php.

References $cleanResult, and logCleanResult().

234  {
235  // This function needs to be redefined in child classes
236  // It should:
237  // - call the external cleaner
238  // - set cleanFilePath to a_filepath
239  // - set cleanFileOrigName to a_origname
240  // - set cleanFileIsCleaned according the clean result
241  // - set cleanResult to the cleaner output message
242  // - call logCleanResult in any case
243  // - return the output message, if file is cleaned
244  // - return an empty string, if file is not cleaned
245 
246  $this->cleanFilePath = $a_filepath;
247  $this->cleanFileOrigName = $a_origname;
248 
249  if ($a_origname == "cleanable.txt") {
250  $this->cleanFileIsCleaned = true;
251  $this->cleanResult =
252  "FILE CLEANED: [" . $a_filepath . "] (VIRUS: simulated)";
253  $this->logCleanResult();
254  return $this->cleanResult;
255  } else {
256  $this->cleanFileIsCleaned = false;
257  $this->cleanResult =
258  "FILE NOT CLEANED: [" . $a_filepath . "] (VIRUS: simulated)";
259  $this->logCleanResult();
260  return "";
261  }
262  }
logCleanResult()
write the result of the last clean to the log public
+ Here is the call graph for this function:

◆ createBufferFile()

ilVirusScanner::createBufferFile (   $buffer)
protected
Parameters
string$buffer(any data, binary)
Returns
string $bufferFile

Definition at line 169 of file class.ilVirusScanner.php.

References ilUtil\ilTempnam().

Referenced by scanFileFromBuffer().

170  {
171  $bufferFile = ilUtil::ilTempnam();
172  file_put_contents($bufferFile, $buffer);
173  return $bufferFile;
174  }
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fileCleaned()

ilVirusScanner::fileCleaned ( )

returns wether file has been cleaned successfully or not

Returns
boolean true, if last clean operation has been successful

Definition at line 268 of file class.ilVirusScanner.php.

References $cleanFileIsCleaned.

269  {
271  }

◆ getCleanMessage()

ilVirusScanner::getCleanMessage ( )

get a located message with the result from the last clean

Returns
string public

Definition at line 353 of file class.ilVirusScanner.php.

References $cleanFileOrigName, and $ret.

354  {
355  if ($this->cleanFileIsCleaned) {
356  $ret = sprintf($this->lng->txt("virus_cleaned"), $this->cleanFileOrigName);
357  } else {
358  $ret = sprintf($this->lng->txt("virus_not_cleaned"), $this->cleanFileOrigName);
359  }
360 
361  if ($this->cleanResult) {
362  $ret .= " " . $this->lng->txt("virus_clean_message")
363  . "<br />"
364  . str_replace(
365  $this->cleanFilePath,
366  $this->cleanFileOrigName,
367  nl2br($this->cleanResult)
368  );
369  }
370  return $ret;
371  }
$ret
Definition: parser.php:6

◆ getCleanResult()

ilVirusScanner::getCleanResult ( )

get the pure output of the external scan

Returns
string public

Definition at line 318 of file class.ilVirusScanner.php.

References $cleanResult.

319  {
320  return $this->cleanResult;
321  }

◆ getScanMessage()

ilVirusScanner::getScanMessage ( )

get a located message with the result from the last scan

Returns
string public

Definition at line 328 of file class.ilVirusScanner.php.

References $ret, and $scanFileOrigName.

329  {
330  if ($this->scanFileIsInfected) {
331  $ret = sprintf($this->lng->txt("virus_infected"), $this->scanFileOrigName);
332  } else {
333  $ret = sprintf($this->lng->txt("virus_not_infected"), $this->scanFileOrigName);
334  }
335 
336  if ($this->scanResult) {
337  $ret .= " " . $this->lng->txt("virus_scan_message")
338  . "<br />"
339  . str_replace(
340  $this->scanFilePath,
341  $this->scanFileOrigName,
342  nl2br($this->scanResult)
343  );
344  }
345  return $ret;
346  }
$ret
Definition: parser.php:6

◆ getScanResult()

ilVirusScanner::getScanResult ( )

get the pure output of the external scan

Returns
string public

Definition at line 308 of file class.ilVirusScanner.php.

References $scanResult.

309  {
310  return $this->scanResult;
311  }

◆ getScanZipFiles()

ilVirusScanner::getScanZipFiles ( )

get info if class can scan ZIP files

Returns
boolean public

Definition at line 378 of file class.ilVirusScanner.php.

References $scanZipFiles.

379  {
380  return $this->scanZipFiles;
381  }

◆ logCleanResult()

ilVirusScanner::logCleanResult ( )

write the result of the last clean to the log public

Definition at line 292 of file class.ilVirusScanner.php.

Referenced by ilVirusScannerSophos\cleanFile(), and cleanFile().

293  {
294  $mess = "Virus Cleaner (" . $this->type . ")";
295  if ($this->cleanFileOrigName) {
296  $mess .= " (File " . $this->cleanFileOrigName . ")";
297  }
298  $mess .= ": " . preg_replace('/[\r\n]+/', "; ", $this->cleanResult);
299 
300  $this->log->write($mess);
301  }
+ Here is the caller graph for this function:

◆ logScanResult()

ilVirusScanner::logScanResult ( )

write the result of the last scan to the log public

Definition at line 277 of file class.ilVirusScanner.php.

Referenced by ilVirusScannerAntiVir\scanFile(), ilVirusScannerSophos\scanFile(), ilVirusScannerClamAV\scanFile(), and scanFile().

278  {
279  $mess = "Virus Scanner (" . $this->type . ")";
280  if ($this->scanFileOrigName) {
281  $mess .= " (File " . $this->scanFileOrigName . ")";
282  }
283  $mess .= ": " . preg_replace('/[\r\n]+/', "; ", $this->scanResult);
284 
285  $this->log->write($mess);
286  }
+ Here is the caller graph for this function:

◆ removeBufferFile()

ilVirusScanner::removeBufferFile (   $bufferFile)
protected
Parameters
string$bufferFile

Definition at line 179 of file class.ilVirusScanner.php.

Referenced by scanFileFromBuffer().

180  {
181  unlink($bufferFile);
182  }
+ Here is the caller graph for this function:

◆ scanBuffer()

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

Definition at line 148 of file class.ilVirusScanner.php.

References scanFileFromBuffer().

149  {
150  return $this->scanFileFromBuffer($buffer);
151  }
+ Here is the call graph for this function:

◆ scanFile()

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

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

Definition at line 194 of file class.ilVirusScanner.php.

References $scanResult, and logScanResult().

Referenced by scanFileFromBuffer().

195  {
196  // This function needs to be redefined in child classes.
197  // It should:
198  // - call the external scanner for a_filepath
199  // - set scanFilePath to a_filepath
200  // - set scanFileOrigName to a_origname
201  // - set scanFileIsInfected according the scan result
202  // - set scanResult to the scanner output message
203  // - call logScanResult() if file is infected
204  // - return the output message, if file is infected
205  // - return an empty string, if file is not infected
206 
207  $this->scanFilePath = $a_filepath;
208  $this->scanFileOrigName = $a_origname;
209 
210  if ($a_origname == "infected.txt" or $a_origname == "cleanable.txt") {
211  $this->scanFileIsInfected = true;
212  $this->scanResult =
213  "FILE INFECTED: [" . $a_filepath . "] (VIRUS: simulated)";
214  $this->logScanResult();
215  return $this->scanResult;
216  } else {
217  $this->scanFileIsInfected = false;
218  $this->scanResult = "";
219  return "";
220  }
221  }
logScanResult()
write the result of the last scan to the log public
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ scanFileFromBuffer()

ilVirusScanner::scanFileFromBuffer (   $buffer)
protected
Parameters
string$buffer(any data, binary)
Returns
bool $infected

Definition at line 157 of file class.ilVirusScanner.php.

References createBufferFile(), removeBufferFile(), and scanFile().

Referenced by ilVirusScannerClamAV\scanBuffer(), and scanBuffer().

158  {
159  $bufferFile = $this->createBufferFile($buffer);
160  $isInfected = $this->scanFile($bufferFile);
161  $this->removeBufferFile($bufferFile);
162  return $isInfected;
163  }
removeBufferFile($bufferFile)
scanFile($a_filepath, $a_origname="")
scan a file for viruses needs to be redefined in child classes here it simulates a scan "infected...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $cleanCommand

ilVirusScanner::$cleanCommand

Definition at line 44 of file class.ilVirusScanner.php.

◆ $cleanFileIsCleaned

ilVirusScanner::$cleanFileIsCleaned

Definition at line 86 of file class.ilVirusScanner.php.

Referenced by fileCleaned().

◆ $cleanFileOrigName

ilVirusScanner::$cleanFileOrigName

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

Referenced by getCleanMessage().

◆ $cleanFilePath

ilVirusScanner::$cleanFilePath

Definition at line 65 of file class.ilVirusScanner.php.

◆ $cleanResult

ilVirusScanner::$cleanResult

◆ $ilias

ilVirusScanner::$ilias

Definition at line 107 of file class.ilVirusScanner.php.

Referenced by __construct().

◆ $lng

ilVirusScanner::$lng

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

Referenced by __construct().

◆ $log

ilVirusScanner::$log

Definition at line 121 of file class.ilVirusScanner.php.

Referenced by __construct().

◆ $scanCommand

ilVirusScanner::$scanCommand

Definition at line 37 of file class.ilVirusScanner.php.

◆ $scanFileIsInfected

ilVirusScanner::$scanFileIsInfected

Definition at line 79 of file class.ilVirusScanner.php.

◆ $scanFileOrigName

ilVirusScanner::$scanFileOrigName

Definition at line 58 of file class.ilVirusScanner.php.

Referenced by getScanMessage().

◆ $scanFilePath

ilVirusScanner::$scanFilePath

Definition at line 51 of file class.ilVirusScanner.php.

◆ $scanResult

◆ $scanZipFiles

ilVirusScanner::$scanZipFiles

Definition at line 30 of file class.ilVirusScanner.php.

Referenced by getScanZipFiles().

◆ $type

ilVirusScanner::$type

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


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