ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilVirusScannerICapRemoteAvClient.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 private const HEADER = 'headers';
24 private const HEADER_VIOLATION_FOUND = 'X-Violations-Found';
25 private const HEADER_INFECTION_FOUND = 'X-Infection-Found';
26
27 public function __construct(string $scan_command, string $clean_command)
28 {
29 parent::__construct($scan_command, $clean_command);
30 $this->options(IL_ICAP_AV_COMMAND);
31 }
32
33 public function scanFile(string $file_path, string $org_name = ''): string
34 {
35 $return_string = '';
36 $file_path = realpath($file_path);
37 if (is_readable($file_path)) {
38 $results = ($this->reqmod(
39 'avscan',
40 [
41 'req-hdr' => "POST /test HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n",
42 'req-body' => file_get_contents($file_path) //Todo: find a better way
43 ]
44 ));
45 if ($this->analyseHeader($results)) {
46 $return_string = sprintf('Virus found in file "%s"!', $file_path);
47 $this->log->warning($return_string);
48 }
49 } else {
50 $return_string = sprintf('File "%s" not found or not readable.', $file_path);
51 $this->log->warning($return_string);
52 }
53 $this->log->info(sprintf('No virus found in file "%s".', $file_path));
54 return $return_string;
55 }
56
57 protected function analyseHeader(array $header): bool
58 {
59 $virus_found = false;
60 if (array_key_exists(self::HEADER, $header)) {
61 $header = $header[self::HEADER];
62 if (array_key_exists(self::HEADER_VIOLATION_FOUND, $header) && $header[self::HEADER_VIOLATION_FOUND] > 0) {
63 $virus_found = true;
64 }
65 if (array_key_exists(
66 self::HEADER_INFECTION_FOUND,
67 $header
68 ) && $header[self::HEADER_INFECTION_FOUND] !== '') {
69 $infection_split = explode(';', $header[self::HEADER_INFECTION_FOUND]);
70 foreach ($infection_split as $infection) {
71 $parts = explode('=', $infection);
72 if ($parts !== false &&
73 is_array($parts) &&
74 count($parts) > 0 &&
75 $parts[0] !== '') {
76 $this->log->warning(trim($parts[0]) . ': ' . trim($parts[1]));
77 }
78 }
79 $virus_found = true;
80 }
81 }
82
83 return $virus_found;
84 }
85}
__construct(string $scan_command, string $clean_command)
scanFile(string $file_path, string $org_name='')
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$results