ILIAS  release_8 Revision v8.24
class.ilVirusScannerSophos.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 public function __construct(string $scan_command, string $clean_command)
24 {
25 parent::__construct($scan_command, $clean_command);
26 $this->type = "sophos";
27 $this->scanZipFiles = true;
28 }
29
30 public function scanFile(string $file_path, string $org_name = ""): string
31 {
32 $this->scanFilePath = $file_path;
33 $this->scanFileOrigName = $org_name;
34
35 // Call of scan_file from Sophie (www.vanja.com/tools/sophie)
36 // sophie must run as a process
37 $a_filepath = realpath($file_path);
38 $cmd = ilShellUtil::escapeShellCmd($this->scanCommand);
39 $args = ilShellUtil::escapeShellArg(" " . $a_filepath . " ");
40 $cmd = $cmd . " " . $args . " 2>&1";
41 exec($cmd, $out, $ret);
42 $this->scanResult = implode("\n", $out);
43
44 // sophie could be called
45 if ((int) $ret === 0) {
46 if (preg_match("/FILE INFECTED/", $this->scanResult)) {
47 $this->scanFileIsInfected = true;
48 $this->logScanResult();
49 return $this->scanResult;
50 }
51
52 $this->scanFileIsInfected = false;
53 return "";
54 }
55
56 // sophie has failed (probably the daemon doesn't run)
57 $this->log->write("ERROR (Virus Scanner failed): "
58 . $this->scanResult
59 . "; COMMAMD=" . $cmd);
60
61 // try fallback: scan by cleaner command (sweep)
62 // -ss: Don't display anything except on error or virus
63 // -archive: sweep inside archives
64 unset($out, $ret);
65 $cmd = $this->cleanCommand . " -ss -archive " . $file_path . " 2>&1";
66 exec($cmd, $out, $ret);
67 $this->scanResult = implode("\n", $out) . " [" . $ret . "]";
68
69 // error codes from sweep:
70 // 0 If no errors are encountered and no viruses are found.
71 // 1 If the user interrupts SWEEP (usually by pressing control-C) or kills the process.
72 // 2 If some error preventing further execution is discovered.
73 // 3 If viruses or virus fragments are discovered.
74 if ((int) $ret === 0) {
75 $this->cleanFileIsCleaned = false;
76 return "";
77 } elseif ((int) $ret === 3) {
78 $this->scanFileIsInfected = true;
79 $this->logScanResult();
80 return $this->scanResult;
81 }
82
83 $this->error->raiseError(
84 $this->lng->txt("virus_scan_error") . " "
85 . $this->lng->txt("virus_scan_message") . " "
86 . $this->scanResult,
87 $this->error->WARNING
88 );
89 }
90
91 public function cleanFile(string $file_path, string $org_name = ""): string
92 {
93 $this->cleanFilePath = $file_path;
94 $this->cleanFileOrigName = $org_name;
95
96 // Call of sweep from Sophos (www.sophos.com)
97 // -di: Disinfect infected items
98 // -nc: Don't ask for confirmation before disinfection/deletion
99 // -ss: Don't display anything except on error or virus
100 // -eec: Use extended error codes
101 // -archive: sweep inside archives
102
103 $cmd = $this->cleanCommand . " -di -nc -ss -eec -archive " . $file_path . " 2>&1";
104 exec($cmd, $out, $ret);
105 $this->cleanResult = implode("\n", $out) . " [" . $ret . "]";
106
107 // always log the result from a clean attempt
108 $this->logCleanResult();
109
110 // Extended error codes from sweep:
111 // 0 If no errors are encountered and no viruses are found.
112 // 8 If survivable errors have occurred.
113 // 12 If compressed files have been found and decompressed.
114 // 16 If compressed files have been found and not decompressed.
115 // 20 If viruses have been found and disinfected.
116 // 24 If viruses have been found and not disinfected.
117 // 28 If viruses have been found in memory.
118 // 32 If there has been an integrity check failure.
119 // 36 If unsurvivable errors have occurred.
120 // 40 If execution has been interrupted.
121 if ((int) $ret === 20) {
122 $this->cleanFileIsCleaned = true;
123 return $this->cleanResult;
124 }
125
126 $this->cleanFileIsCleaned = false;
127 return "";
128 }
129}
$out
Definition: buildRTE.php:24
error(string $a_errmsg)
static escapeShellArg(string $a_arg)
static escapeShellCmd(string $a_arg)
scanFile(string $file_path, string $org_name="")
cleanFile(string $file_path, string $org_name="")
__construct(string $scan_command, string $clean_command)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc