ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilVirusScannerICapRemoteAvClient.php
Go to the documentation of this file.
1 <?php
2 //hsuhh-patch: begin
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
6 {
7  const HEADER = 'headers';
8  const HEADER_VIOLATION_FOUND = 'X-Violations-Found';
9  const HEADER_INFECTION_FOUND = 'X-Infection-Found';
10 
16  public function __construct($a_scancommand, $a_cleancommand)
17  {
18  parent::__construct($a_scancommand, $a_cleancommand);
19  $this->options(IL_ICAP_AV_COMMAND);
20  }
21 
27  public function scanFile($a_filepath, $a_origname = "")
28  {
29  $return_string = '';
30  if (file_exists($a_filepath)) {
31  if (is_readable($a_filepath)) {
32  $a_filepath = realpath($a_filepath);
33  $results = ($this->reqmod(
34  'avscan',
35  [
36  'req-hdr' => "POST /test HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n",
37  'req-body' => file_get_contents($a_filepath) //Todo: find a better way
38  ]
39  ));
40  if ($this->analyseHeader($results)) {
41  $return_string = sprintf('Virus found in file "%s"!', $a_filepath);
42  $this->log->warning($return_string);
43  }
44  } else {
45  $return_string = sprintf('File "%s" not readable.', $a_filepath);
46  $this->log->warning($return_string);
47  }
48  } else {
49  $return_string = sprintf('File "%s" not found.', $a_filepath);
50  $this->log->warning($return_string);
51  }
52  $this->log->info(sprintf('No virus found in file "%s".', $a_filepath));
53  return $return_string;
54  }
55 
60  protected function analyseHeader($header)
61  {
62  $virus_found = false;
63  if (array_key_exists(self::HEADER, $header)) {
64  $header = $header[self::HEADER];
65  if (array_key_exists(self::HEADER_VIOLATION_FOUND, $header)) {
66  if ($header[self::HEADER_VIOLATION_FOUND] > 0) {
67  $virus_found = true;
68  }
69  }
70  if (array_key_exists(self::HEADER_INFECTION_FOUND, $header)) {
71  if (strlen($header[self::HEADER_INFECTION_FOUND]) > 0) {
72  $infection_split = preg_split('/;/', $header[self::HEADER_INFECTION_FOUND]);
73  foreach ($infection_split as $infection) {
74  $parts = preg_split('/=/', $infection);
75  if ($parts !== false &&
76  is_array($parts) &&
77  count($parts) > 0 &&
78  strlen($parts[0]) > 0) {
79  $this->log->warning(trim($parts[0]) . ': ' . trim($parts[1]));
80  }
81  }
82  $virus_found = true;
83  }
84  }
85  }
86  return $virus_found;
87  }
88 }
89 //hsuhh-patch: end
__construct($a_scancommand, $a_cleancommand)
ilVirusScannerICapAvClient constructor.
Interface to the ClamAV virus protector.
$results
__construct(Container $dic, ilPlugin $plugin)