ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 $ilias, $lng, and $log.

128  {
129  global $ilias, $lng, $log;
130 
131  $this->ilias = $ilias;
132  $this->lng = $lng;
133  $this->log = $log;
134  $this->scanCommand = $a_scancommand;
135  $this->cleanCommand = $a_cleancommand;
136 
137  $this->type = "simulate";
138  $this->scanZipFiles = false;
139  }
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  {
251  $this->cleanFileIsCleaned = true;
252  $this->cleanResult =
253  "FILE CLEANED: [" . $a_filepath . "] (VIRUS: simulated)";
254  $this->logCleanResult();
255  return $this->cleanResult;
256  }
257  else
258  {
259  $this->cleanFileIsCleaned = false;
260  $this->cleanResult =
261  "FILE NOT CLEANED: [" . $a_filepath . "] (VIRUS: simulated)";
262  $this->logCleanResult();
263  return "";
264  }
265  }
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 166 of file class.ilVirusScanner.php.

References ilUtil\ilTempnam().

Referenced by scanFileFromBuffer().

167  {
168  $bufferFile = ilUtil::ilTempnam();
169  file_put_contents($bufferFile, $buffer);
170  return $bufferFile;
171  }
static ilTempnam($a_temp_path=null)
Create a temporary file in an ILIAS writable 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 271 of file class.ilVirusScanner.php.

References $cleanFileIsCleaned.

272  {
274  }

◆ getCleanMessage()

ilVirusScanner::getCleanMessage ( )

get a located message with the result from the last clean

Returns
string public

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

References $cleanFileOrigName, and $ret.

360  {
361  if($this->cleanFileIsCleaned)
362  {
363  $ret = sprintf($this->lng->txt("virus_cleaned"), $this->cleanFileOrigName);
364  }
365  else
366  {
367  $ret = sprintf($this->lng->txt("virus_not_cleaned"), $this->cleanFileOrigName);
368  }
369 
370  if($this->cleanResult)
371  {
372  $ret .= " " . $this->lng->txt("virus_clean_message")
373  . "<br />"
374  . str_replace($this->cleanFilePath, $this->cleanFileOrigName,
375  nl2br($this->cleanResult));
376  }
377  return $ret;
378  }
$ret
Definition: parser.php:6

◆ getCleanResult()

ilVirusScanner::getCleanResult ( )

get the pure output of the external scan

Returns
string public

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

References $cleanResult.

324  {
325  return $this->cleanResult;
326  }

◆ getScanMessage()

ilVirusScanner::getScanMessage ( )

get a located message with the result from the last scan

Returns
string public

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

References $ret, and $scanFileOrigName.

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

◆ getScanResult()

ilVirusScanner::getScanResult ( )

get the pure output of the external scan

Returns
string public

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

References $scanResult.

314  {
315  return $this->scanResult;
316  }

◆ getScanZipFiles()

ilVirusScanner::getScanZipFiles ( )

get info if class can scan ZIP files

Returns
boolean public

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

References $scanZipFiles.

386  {
387  return $this->scanZipFiles;
388  }

◆ logCleanResult()

ilVirusScanner::logCleanResult ( )

write the result of the last clean to the log public

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

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

297  {
298  $mess = "Virus Cleaner (" . $this->type . ")";
299  if($this->cleanFileOrigName)
300  {
301  $mess .= " (File " . $this->cleanFileOrigName . ")";
302  }
303  $mess .= ": " . preg_replace('/[\r\n]+/', "; ", $this->cleanResult);
304 
305  $this->log->write($mess);
306  }
+ 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 280 of file class.ilVirusScanner.php.

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

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

◆ removeBufferFile()

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

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

Referenced by scanFileFromBuffer().

177  {
178  unlink($bufferFile);
179  }
+ Here is the caller graph for this function:

◆ scanBuffer()

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

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

References scanFileFromBuffer().

146  {
147  return $this->scanFileFromBuffer($buffer);
148  }
+ 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 191 of file class.ilVirusScanner.php.

References $scanResult, and logScanResult().

Referenced by scanFileFromBuffer().

192  {
193  // This function needs to be redefined in child classes.
194  // It should:
195  // - call the external scanner for a_filepath
196  // - set scanFilePath to a_filepath
197  // - set scanFileOrigName to a_origname
198  // - set scanFileIsInfected according the scan result
199  // - set scanResult to the scanner output message
200  // - call logScanResult() if file is infected
201  // - return the output message, if file is infected
202  // - return an empty string, if file is not infected
203 
204  $this->scanFilePath = $a_filepath;
205  $this->scanFileOrigName = $a_origname;
206 
207  if($a_origname == "infected.txt" or $a_origname == "cleanable.txt")
208  {
209  $this->scanFileIsInfected = true;
210  $this->scanResult =
211  "FILE INFECTED: [" . $a_filepath . "] (VIRUS: simulated)";
212  $this->logScanResult();
213  return $this->scanResult;
214  }
215  else
216  {
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 154 of file class.ilVirusScanner.php.

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

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

155  {
156  $bufferFile = $this->createBufferFile($buffer);
157  $isInfected = $this->scanFile($bufferFile);
158  $this->removeBufferFile($bufferFile);
159  return $isInfected;
160  }
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: