ILIAS  release_8 Revision v8.23
ilVirusScannerSophos Class Reference
+ Inheritance diagram for ilVirusScannerSophos:
+ Collaboration diagram for ilVirusScannerSophos:

Public Member Functions

 __construct (string $scan_command, string $clean_command)
 
 scanFile (string $file_path, string $org_name="")
 
 cleanFile (string $file_path, string $org_name="")
 
- Public Member Functions inherited from ilVirusScanner
 __construct (string $scan_command, string $clean_command)
 
 scanBuffer (string $buffer)
 
 scanFile (string $file_path, string $org_name="")
 
 logScanResult ()
 
 cleanFile (string $file_path, string $org_name="")
 
 logCleanResult ()
 
 fileCleaned ()
 
 getScanResult ()
 
 getCleanResult ()
 
 getScanMessage ()
 
 getCleanMessage ()
 
 getScanZipFiles ()
 

Additional Inherited Members

- Static Public Member Functions inherited from ilVirusScanner
static virusHandling (string $a_file, string $a_orig_name='', bool $a_clean=true)
 
- Data Fields inherited from ilVirusScanner
string $type
 
bool $scanZipFiles
 
string $scanCommand
 
string $cleanCommand
 
string $scanFilePath
 
string $scanFileOrigName
 
string $cleanFilePath
 
string $cleanFileOrigName
 
bool $scanFileIsInfected
 
bool $cleanFileIsCleaned
 
string $scanResult
 
string $cleanResult
 
ilErrorHandling $error
 
ilLanguage $lng
 
ilLogger $log
 
- Protected Member Functions inherited from ilVirusScanner
 scanFileFromBuffer (string $buffer)
 
 createBufferFile (string $buffer)
 
 removeBufferFile (string $bufferFile)
 

Detailed Description

Definition at line 21 of file class.ilVirusScannerSophos.php.

Constructor & Destructor Documentation

◆ __construct()

ilVirusScannerSophos::__construct ( string  $scan_command,
string  $clean_command 
)

Definition at line 23 of file class.ilVirusScannerSophos.php.

References ILIAS\GlobalScreen\Provider\__construct().

24  {
25  parent::__construct($scan_command, $clean_command);
26  $this->type = "sophos";
27  $this->scanZipFiles = true;
28  }
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

Member Function Documentation

◆ cleanFile()

ilVirusScannerSophos::cleanFile ( string  $file_path,
string  $org_name = "" 
)

Definition at line 91 of file class.ilVirusScannerSophos.php.

References ilVirusScanner\$cleanResult, $out, and ilVirusScanner\logCleanResult().

91  : 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  }
$out
Definition: buildRTE.php:24
+ Here is the call graph for this function:

◆ scanFile()

ilVirusScannerSophos::scanFile ( string  $file_path,
string  $org_name = "" 
)

Definition at line 30 of file class.ilVirusScannerSophos.php.

References $out, ilVirusScanner\$scanResult, ilShellUtil\escapeShellArg(), ilShellUtil\escapeShellCmd(), ILIAS\Repository\lng(), and ilVirusScanner\logScanResult().

30  : 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") . " "
87  $this->error->WARNING
88  );
89  }
static escapeShellArg(string $a_arg)
$out
Definition: buildRTE.php:24
static escapeShellCmd(string $a_arg)
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: