ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
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 93 of file class.ilVirusScannerSophos.php.

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

93  : string
94  {
95  $this->cleanFilePath = $file_path;
96  $this->cleanFileOrigName = $org_name;
97 
98  // Call of sweep from Sophos (www.sophos.com)
99  // -di: Disinfect infected items
100  // -nc: Don't ask for confirmation before disinfection/deletion
101  // -ss: Don't display anything except on error or virus
102  // -eec: Use extended error codes
103  // -archive: sweep inside archives
104 
105  $cmd = $this->cleanCommand . ' -di -nc -ss -eec -archive ' . $file_path . ' 2>&1';
106  exec($cmd, $out, $ret);
107  $this->cleanResult = implode("\n", $out) . ' [' . $ret . ']';
108 
109  // always log the result from a clean attempt
110  $this->logCleanResult();
111 
112  // Extended error codes from sweep:
113  // 0 If no errors are encountered and no viruses are found.
114  // 8 If survivable errors have occurred.
115  // 12 If compressed files have been found and decompressed.
116  // 16 If compressed files have been found and not decompressed.
117  // 20 If viruses have been found and disinfected.
118  // 24 If viruses have been found and not disinfected.
119  // 28 If viruses have been found in memory.
120  // 32 If there has been an integrity check failure.
121  // 36 If unsurvivable errors have occurred.
122  // 40 If execution has been interrupted.
123  if ((int) $ret === 20) {
124  $this->cleanFileIsCleaned = true;
125  return $this->cleanResult;
126  }
127 
128  $this->cleanFileIsCleaned = false;
129  return '';
130  }
$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 .= ' ' . $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(
58  'ERROR (Virus Scanner failed): '
59  . $this->scanResult
60  . '; COMMAMD=' . $cmd
61  );
62 
63  // try fallback: scan by cleaner command (sweep)
64  // -ss: Don't display anything except on error or virus
65  // -archive: sweep inside archives
66  unset($out, $ret);
67  $cmd = $this->cleanCommand . ' -ss -archive ' . $file_path . ' 2>&1';
68  exec($cmd, $out, $ret);
69  $this->scanResult = implode("\n", $out) . ' [' . $ret . ']';
70 
71  // error codes from sweep:
72  // 0 If no errors are encountered and no viruses are found.
73  // 1 If the user interrupts SWEEP (usually by pressing control-C) or kills the process.
74  // 2 If some error preventing further execution is discovered.
75  // 3 If viruses or virus fragments are discovered.
76  if ((int) $ret === 0) {
77  $this->cleanFileIsCleaned = false;
78  return '';
79  } elseif ((int) $ret === 3) {
80  $this->scanFileIsInfected = true;
81  $this->logScanResult();
82  return $this->scanResult;
83  }
84 
85  $this->error->raiseError(
86  $this->lng->txt('virus_scan_error') . ' '
87  . $this->lng->txt('virus_scan_message') . ' '
89  $this->error->WARNING
90  );
91  }
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: