ILIAS  release_4-4 Revision
ilVirusScanner Class Reference

Base class for the interface to an external virus scanner. More...

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

Public Member Functions

 ilVirusScanner ($a_scancommand, $a_cleancommand)
 Constructor public. More...
 
 scanFile ($a_filepath, $a_origname="")
 scan a file for viruses More...
 
 cleanFile ($a_filepath, $a_origname="")
 clean an infected file More...
 
 fileCleaned ()
 returns wether file has been cleaned successfully or not More...
 
 logScanResult ()
 write the result of the last scan to the log More...
 
 logCleanResult ()
 write the result of the last clean to the log 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
 

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 18 of file class.ilVirusScanner.php.

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 202 of file class.ilVirusScanner.php.

References $cleanResult, and logCleanResult().

203  {
204  // This function needs to be redefined in child classes
205  // It should:
206  // - call the external cleaner
207  // - set cleanFilePath to a_filepath
208  // - set cleanFileOrigName to a_origname
209  // - set cleanFileIsCleaned according the clean result
210  // - set cleanResult to the cleaner output message
211  // - call logCleanResult in any case
212  // - return the output message, if file is cleaned
213  // - return an empty string, if file is not cleaned
214 
215  $this->cleanFilePath = $a_filepath;
216  $this->cleanFileOrigName = $a_origname;
217 
218  if ($a_origname == "cleanable.txt")
219  {
220  $this->cleanFileIsCleaned = true;
221  $this->cleanResult =
222  "FILE CLEANED: [". $a_filepath. "] (VIRUS: simulated)";
223  $this->logCleanResult();
224  return $this->cleanResult;
225  }
226  else
227  {
228  $this->cleanFileIsCleaned = false;
229  $this->cleanResult =
230  "FILE NOT CLEANED: [". $a_filepath. "] (VIRUS: simulated)";
231  $this->logCleanResult();
232  return "";
233  }
234  }
logCleanResult()
write the result of the last clean to the log
+ Here is the call 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 241 of file class.ilVirusScanner.php.

References $cleanFileIsCleaned.

242  {
244  }

◆ getCleanMessage()

ilVirusScanner::getCleanMessage ( )

get a located message with the result from the last clean

Returns
string public

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

References $cleanFileOrigName, and $ret.

336  {
337  if ($this->cleanFileIsCleaned)
338  {
339  $ret = sprintf($this->lng->txt("virus_cleaned"), $this->cleanFileOrigName);
340  }
341  else
342  {
343  $ret = sprintf($this->lng->txt("virus_not_cleaned"),$this->cleanFileOrigName);
344  }
345 
346  if ($this->cleanResult)
347  {
348  $ret .= " ". $this->lng->txt("virus_clean_message")
349  . "<br />"
350  . str_replace($this->cleanFilePath, $this->cleanFileOrigName,
351  nl2br($this->cleanResult));
352  }
353  return $ret;
354  }

◆ getCleanResult()

ilVirusScanner::getCleanResult ( )

get the pure output of the external scan

Returns
string public

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

References $cleanResult.

298  {
299  return $this->cleanResult;
300  }

◆ getScanMessage()

ilVirusScanner::getScanMessage ( )

get a located message with the result from the last scan

Returns
string public

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

References $ret, and $scanFileOrigName.

309  {
310  if ($this->scanFileIsInfected)
311  {
312  $ret = sprintf($this->lng->txt("virus_infected"), $this->scanFileOrigName);
313  }
314  else
315  {
316  $ret = sprintf($this->lng->txt("virus_not_infected"),$this->scanFileOrigName);
317  }
318 
319  if ($this->scanResult)
320  {
321  $ret .= " ". $this->lng->txt("virus_scan_message")
322  . "<br />"
323  . str_replace($this->scanFilePath, $this->scanFileOrigName,
324  nl2br($this->scanResult));
325  }
326  return $ret;
327  }

◆ getScanResult()

ilVirusScanner::getScanResult ( )

get the pure output of the external scan

Returns
string public

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

References $scanResult.

287  {
288  return $this->scanResult;
289  }

◆ getScanZipFiles()

ilVirusScanner::getScanZipFiles ( )

get info if class can scan ZIP files

Returns
boolean public

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

References $scanZipFiles.

363  {
364  return $this->scanZipFiles;
365  }

◆ ilVirusScanner()

ilVirusScanner::ilVirusScanner (   $a_scancommand,
  $a_cleancommand 
)

Constructor public.

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

References $ilias, $lng, and $log.

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

132  {
133  global $ilias, $lng, $log;
134 
135  $this->ilias = & $ilias;
136  $this->lng = & $lng;
137  $this->log = & $log;
138  $this->scanCommand = $a_scancommand;
139  $this->cleanCommand = $a_cleancommand;
140 
141  $this->type = "simulate";
142  $this->scanZipFiles = false;
143  }
redirection script todo: (a better solution should control the processing via a xml file) ...
+ Here is the caller graph for this function:

◆ logCleanResult()

ilVirusScanner::logCleanResult ( )

write the result of the last clean to the log

public

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

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

269  {
270  $mess = "Virus Cleaner (". $this->type. ")";
271  if ($this->cleanFileOrigName)
272  {
273  $mess .= " (File ". $this->cleanFileOrigName. ")";
274  }
275  $mess .= ": " . ereg_replace("(\r|\n)+", "; ", $this->cleanResult);
276 
277  $this->log->write($mess);
278  }
+ 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 251 of file class.ilVirusScanner.php.

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

252  {
253  $mess = "Virus Scanner (". $this->type. ")";
254  if ($this->scanFileOrigName)
255  {
256  $mess .= " (File " . $this->scanFileOrigName . ")";
257  }
258  $mess .= ": " . ereg_replace("(\r|\n)+", "; ", $this->scanResult);
259 
260  $this->log->write($mess);
261  }
+ Here is the caller 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 157 of file class.ilVirusScanner.php.

References $scanResult, and logScanResult().

158  {
159  // This function needs to be redefined in child classes.
160  // It should:
161  // - call the external scanner for a_filepath
162  // - set scanFilePath to a_filepath
163  // - set scanFileOrigName to a_origname
164  // - set scanFileIsInfected according the scan result
165  // - set scanResult to the scanner output message
166  // - call logScanResult() if file is infected
167  // - return the output message, if file is infected
168  // - return an empty string, if file is not infected
169 
170  $this->scanFilePath = $a_filepath;
171  $this->scanFileOrigName = $a_origname;
172 
173  if ($a_origname == "infected.txt" or $a_origname == "cleanable.txt")
174  {
175  $this->scanFileIsInfected = true;
176  $this->scanResult =
177  "FILE INFECTED: [". $a_filepath. "] (VIRUS: simulated)";
178  $this->logScanResult();
179  return $this->scanResult;
180  }
181  else
182  {
183  $this->scanFileIsInfected = false;
184  $this->scanResult = "";
185  return "";
186  }
187  }
logScanResult()
write the result of the last scan to the log
+ Here is the call graph for this function:

Field Documentation

◆ $cleanCommand

ilVirusScanner::$cleanCommand

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

◆ $cleanFileIsCleaned

ilVirusScanner::$cleanFileIsCleaned

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

Referenced by fileCleaned().

◆ $cleanFileOrigName

ilVirusScanner::$cleanFileOrigName

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

Referenced by getCleanMessage().

◆ $cleanFilePath

ilVirusScanner::$cleanFilePath

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

◆ $cleanResult

ilVirusScanner::$cleanResult

◆ $ilias

ilVirusScanner::$ilias

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

Referenced by ilVirusScanner().

◆ $lng

ilVirusScanner::$lng

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

Referenced by ilVirusScanner().

◆ $log

ilVirusScanner::$log

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

Referenced by ilVirusScanner().

◆ $scanCommand

ilVirusScanner::$scanCommand

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

◆ $scanFileIsInfected

ilVirusScanner::$scanFileIsInfected

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

◆ $scanFileOrigName

ilVirusScanner::$scanFileOrigName

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

Referenced by getScanMessage().

◆ $scanFilePath

ilVirusScanner::$scanFilePath

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

◆ $scanResult

◆ $scanZipFiles

ilVirusScanner::$scanZipFiles

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

Referenced by getScanZipFiles().

◆ $type

ilVirusScanner::$type

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


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