ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 @access public. More...
 
 scanBuffer ($buffer)
 
 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
 

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

Reimplemented in ilVirusScannerSophos.

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

243 {
244 // This function needs to be redefined in child classes
245 // It should:
246 // - call the external cleaner
247 // - set cleanFilePath to a_filepath
248 // - set cleanFileOrigName to a_origname
249 // - set cleanFileIsCleaned according the clean result
250 // - set cleanResult to the cleaner output message
251 // - call logCleanResult in any case
252 // - return the output message, if file is cleaned
253 // - return an empty string, if file is not cleaned
254
255 $this->cleanFilePath = $a_filepath;
256 $this->cleanFileOrigName = $a_origname;
257
258 if ($a_origname == "cleanable.txt")
259 {
260 $this->cleanFileIsCleaned = true;
261 $this->cleanResult =
262 "FILE CLEANED: [". $a_filepath. "] (VIRUS: simulated)";
263 $this->logCleanResult();
264 return $this->cleanResult;
265 }
266 else
267 {
268 $this->cleanFileIsCleaned = false;
269 $this->cleanResult =
270 "FILE NOT CLEANED: [". $a_filepath. "] (VIRUS: simulated)";
271 $this->logCleanResult();
272 return "";
273 }
274 }
logCleanResult()
write the result of the last clean to the log

References $cleanResult, and logCleanResult().

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

171 {
172 $bufferFile = ilUtil::ilTempnam();
173 file_put_contents($bufferFile, $buffer);
174 return $bufferFile;
175 }
static ilTempnam($a_temp_path=null)
Create a temporary file in an ILIAS writable directory.

References ilUtil\ilTempnam().

Referenced by scanFileFromBuffer().

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

282 {
284 }

References $cleanFileIsCleaned.

◆ getCleanMessage()

ilVirusScanner::getCleanMessage ( )

get a located message with the result from the last clean

Returns
string @access public

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

376 {
377 if ($this->cleanFileIsCleaned)
378 {
379 $ret = sprintf($this->lng->txt("virus_cleaned"), $this->cleanFileOrigName);
380 }
381 else
382 {
383 $ret = sprintf($this->lng->txt("virus_not_cleaned"),$this->cleanFileOrigName);
384 }
385
386 if ($this->cleanResult)
387 {
388 $ret .= " ". $this->lng->txt("virus_clean_message")
389 . "<br />"
390 . str_replace($this->cleanFilePath, $this->cleanFileOrigName,
391 nl2br($this->cleanResult));
392 }
393 return $ret;
394 }

References $ret.

◆ getCleanResult()

ilVirusScanner::getCleanResult ( )

get the pure output of the external scan

Returns
string @access public

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

338 {
339 return $this->cleanResult;
340 }

References $cleanResult.

◆ getScanMessage()

ilVirusScanner::getScanMessage ( )

get a located message with the result from the last scan

Returns
string @access public

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

349 {
350 if ($this->scanFileIsInfected)
351 {
352 $ret = sprintf($this->lng->txt("virus_infected"), $this->scanFileOrigName);
353 }
354 else
355 {
356 $ret = sprintf($this->lng->txt("virus_not_infected"),$this->scanFileOrigName);
357 }
358
359 if ($this->scanResult)
360 {
361 $ret .= " ". $this->lng->txt("virus_scan_message")
362 . "<br />"
363 . str_replace($this->scanFilePath, $this->scanFileOrigName,
364 nl2br($this->scanResult));
365 }
366 return $ret;
367 }

References $ret.

◆ getScanResult()

ilVirusScanner::getScanResult ( )

get the pure output of the external scan

Returns
string @access public

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

327 {
328 return $this->scanResult;
329 }

References $scanResult.

◆ getScanZipFiles()

ilVirusScanner::getScanZipFiles ( )

get info if class can scan ZIP files

Returns
boolean @access public

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

403 {
404 return $this->scanZipFiles;
405 }

References $scanZipFiles.

◆ ilVirusScanner()

ilVirusScanner::ilVirusScanner (   $a_scancommand,
  $a_cleancommand 
)

Constructor @access public.

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

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)

References $ilias, $lng, and $log.

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

+ Here is the caller graph for this function:

◆ logCleanResult()

ilVirusScanner::logCleanResult ( )

write the result of the last clean to the log

@access public

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

309 {
310 $mess = "Virus Cleaner (". $this->type. ")";
311 if ($this->cleanFileOrigName)
312 {
313 $mess .= " (File ". $this->cleanFileOrigName. ")";
314 }
315 $mess .= ": " . ereg_replace("(\r|\n)+", "; ", $this->cleanResult);
316
317 $this->log->write($mess);
318 }

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

+ Here is the caller graph for this function:

◆ logScanResult()

ilVirusScanner::logScanResult ( )

write the result of the last scan to the log

@access public

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

292 {
293 $mess = "Virus Scanner (". $this->type. ")";
294 if ($this->scanFileOrigName)
295 {
296 $mess .= " (File " . $this->scanFileOrigName . ")";
297 }
298 $mess .= ": " . ereg_replace("(\r|\n)+", "; ", $this->scanResult);
299
300 $this->log->write($mess);
301 }

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

+ Here is the caller graph for this function:

◆ removeBufferFile()

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

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

181 {
182 unlink($bufferFile);
183 }

Referenced by scanFileFromBuffer().

+ Here is the caller graph for this function:

◆ scanBuffer()

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

Reimplemented in ilVirusScannerClamAV.

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

150 {
151 return $this->scanFileFromBuffer($buffer);
152 }

References scanFileFromBuffer().

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

Reimplemented in ilVirusScannerAntiVir, ilVirusScannerClamAV, and ilVirusScannerSophos.

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

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

References $scanResult, and logScanResult().

Referenced by scanFileFromBuffer().

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

159 {
160 $bufferFile = $this->createBufferFile($buffer);
161 $isInfected = $this->scanFile($bufferFile);
162 $this->removeBufferFile($bufferFile);
163 return $isInfected;
164 }
scanFile($a_filepath, $a_origname="")
scan a file for viruses
removeBufferFile($bufferFile)

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

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

+ Here is the call graph for this function:
+ Here is the caller 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.

◆ $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.

◆ $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: