ILIAS  release_7 Revision v7.30-3-g800a261c036
ilVirusScannerICapClient Class Reference

Interface to the ClamAV virus protector. More...

+ Inheritance diagram for ilVirusScannerICapClient:
+ Collaboration diagram for ilVirusScannerICapClient:

Public Member Functions

 __construct ($a_scancommand, $a_cleancommand)
 ilVirusScannerICapClient constructor. More...
 
 scanFile ($a_filepath, $a_origname="")
 
- Public Member Functions inherited from ilVirusScanner
 __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

const HEADER_INFECTION_FOUND = 'X-Infection-Found'
 
- Data Fields inherited from ilVirusScanner
 $type
 
 $scanZipFiles
 
 $scanCommand
 
 $cleanCommand
 
 $scanFilePath
 
 $scanFileOrigName
 
 $cleanFilePath
 
 $cleanFileOrigName
 
 $scanFileIsInfected
 
 $cleanFileIsCleaned
 
 $scanResult
 
 $cleanResult
 
 $ilias
 
 $lng
 
 $log
 

Protected Member Functions

 buildScanCommandArguments ($file='-')
 
- Protected Member Functions inherited from ilVirusScanner
 scanFileFromBuffer ($buffer)
 
 createBufferFile ($buffer)
 
 removeBufferFile ($bufferFile)
 

Detailed Description

Interface to the ClamAV virus protector.

Author
Ralf Schenk rs@da.nosp@m.taba.nosp@m.y.de
Version
$Id$

Definition at line 13 of file class.ilVirusScannerICapClient.php.

Constructor & Destructor Documentation

◆ __construct()

ilVirusScannerICapClient::__construct (   $a_scancommand,
  $a_cleancommand 
)

ilVirusScannerICapClient constructor.

Parameters
$a_scancommand
$a_cleancommand

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

References ILIAS\GlobalScreen\Provider\__construct().

24  {
25  parent::__construct($a_scancommand, $a_cleancommand);
26  $this->scanCommand = IL_ICAP_CLIENT;
27  }
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

Member Function Documentation

◆ buildScanCommandArguments()

ilVirusScannerICapClient::buildScanCommandArguments (   $file = '-')
protected
Parameters
string$file
Returns
string

Definition at line 33 of file class.ilVirusScannerICapClient.php.

Referenced by scanFile().

34  {
35  return ' -i ' . IL_ICAP_HOST . ' -p ' . IL_ICAP_PORT . ' -v -s ' . IL_ICAP_AV_COMMAND . ' -f ' . $file;
36  }
+ Here is the caller graph for this function:

◆ scanFile()

ilVirusScannerICapClient::scanFile (   $a_filepath,
  $a_origname = "" 
)
Parameters
$a_filepath
string$a_origname
Returns
bool|string

Definition at line 43 of file class.ilVirusScannerICapClient.php.

References $out, buildScanCommandArguments(), ilUtil\escapeShellArg(), ilUtil\escapeShellCmd(), and ilUtil\execQuoted().

44  {
45  $return_string = '';
46  if (file_exists($a_filepath)) {
47  if (is_readable($a_filepath)) {
48  $a_filepath = realpath($a_filepath);
49  $args = ilUtil::escapeShellArg($a_filepath);
50  $arguments = $this->buildScanCommandArguments($args) . " 2>&1";
51  $cmd = ilUtil::escapeShellCmd($this->scanCommand);
52  $out = ilUtil::execQuoted($cmd, $arguments);
53  $timeout = preg_grep('/failed\/timedout.*/', $out);
54  $virus_detected = preg_grep('/' . self::HEADER_INFECTION_FOUND . '.*/', $out);
55  if (is_array($virus_detected) && count($virus_detected) > 0) {
56  $return_string = sprintf('Virus detected in %s', $a_filepath);
57  $this->log->warning($return_string);
58 
59  } elseif (is_array($timeout) && count($timeout) > 0) {
60  $return_string = 'Cannot connect to icap server.';
61  $this->log->warning($return_string);
62  }
63  $this->scanResult = implode("\n", $out);
64  } else {
65  $return_string = sprintf('File "%s" not readable.', $a_filepath);
66  $this->log->info($return_string);
67  }
68  } else {
69  $return_string = sprintf('File "%s" not found.', $a_filepath);
70  $this->log->info($return_string);
71  }
72  $this->log->info(sprintf('No virus found in file "%s".', $a_filepath));
73  return $return_string;
74  }
static escapeShellCmd($a_arg)
escape shell cmd
static execQuoted($cmd, $args=null)
exec command and fix spaces on windows
static escapeShellArg($a_arg)
+ Here is the call graph for this function:

Field Documentation

◆ HEADER_INFECTION_FOUND

const ilVirusScannerICapClient::HEADER_INFECTION_FOUND = 'X-Infection-Found'

Definition at line 16 of file class.ilVirusScannerICapClient.php.


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