ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilVirusScannerSetupConfig.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2019 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
5 use ILIAS\Setup;
7 
8 class ilVirusScannerSetupConfig implements Setup\Config
9 {
10  const VIRUS_SCANNER_NONE = "none";
11  const VIRUS_SCANNER_SOPHOS = "sophos";
12  const VIRUS_SCANNER_ANTIVIR = "antivir";
13  const VIRUS_SCANNER_CLAMAV = "clamav";
14 
18  protected $virus_scanner;
19 
23  protected $path_to_scan;
24 
28  protected $path_to_clean;
29 
30  public function __construct(
31  string $virus_scanner,
32  ?string $path_to_scan,
33  ?string $path_to_clean
34  ) {
35  $scanners = [
36  self::VIRUS_SCANNER_NONE,
37  self::VIRUS_SCANNER_SOPHOS,
38  self::VIRUS_SCANNER_ANTIVIR,
39  self::VIRUS_SCANNER_CLAMAV
40  ];
41  if (!in_array($virus_scanner, $scanners)) {
42  throw new \InvalidArgumentException(
43  "Unknown virus scanner: '$virus_scanner'"
44  );
45  }
46  if ($virus_scanner !== self::VIRUS_SCANNER_NONE && (!$path_to_scan || !$path_to_clean)) {
47  throw new \InvalidArgumentException(
48  "Missing path to scan and/or clean commands for virus scanner."
49  );
50  }
51  $this->virus_scanner = $virus_scanner;
52  $this->path_to_scan = $this->toLinuxConvention($path_to_scan);
53  $this->path_to_clean = $this->toLinuxConvention($path_to_clean);
54  }
55 
56  protected function toLinuxConvention(?string $p) : ?string
57  {
58  if (!$p) {
59  return null;
60  }
61  return preg_replace("/\\\\/", "/", $p);
62  }
63 
64  public function getVirusScanner() : string
65  {
66  return $this->virus_scanner;
67  }
68 
69  public function getPathToScan() : ?string
70  {
71  return $this->path_to_scan;
72  }
73 
74  public function getPathToClean() : ?string
75  {
76  return $this->path_to_clean;
77  }
78 }
__construct(string $virus_scanner, ?string $path_to_scan, ?string $path_to_clean)