ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilVirusScannerICapClient.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11require_once "./Services/VirusScanner/classes/class.ilVirusScanner.php";
12
14{
15
16 const HEADER_INFECTION_FOUND = 'X-Infection-Found';
17
23 public function __construct($a_scancommand, $a_cleancommand)
24 {
25 parent::__construct($a_scancommand, $a_cleancommand);
26 $this->scanCommand = IL_ICAP_CLIENT;
27 }
28
33 protected function buildScanCommandArguments($file = '-') // default means piping
34 {
35 return ' -i ' . IL_ICAP_HOST . ' -p ' . IL_ICAP_PORT . ' -v -s ' . IL_ICAP_AV_COMMAND . ' -f ' . $file;
36 }
37
43 function scanFile($a_filepath, $a_origname = "")
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 }
75}
An exception for terminatinating execution or to throw for unit testing.
static execQuoted($cmd, $args=null)
exec command and fix spaces on windows
static escapeShellArg($a_arg)
static escapeShellCmd($a_arg)
escape shell cmd
Interface to the ClamAV virus protector.
scanFile($a_filepath, $a_origname="")
__construct($a_scancommand, $a_cleancommand)
ilVirusScannerICapClient constructor.
Base class for the interface to an external virus scanner This class is abstract and needs to be exte...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc