ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilVirusScannerSophos.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
11 require_once "./Services/VirusScanner/classes/class.ilVirusScanner.php";
12 
14 {
20  public function __construct($a_scancommand, $a_cleancommand)
21  {
22  parent::__construct($a_scancommand, $a_cleancommand);
23  $this->type = "sophos";
24  $this->scanZipFiles = true;
25  }
26 
34  public function scanFile($a_filepath, $a_origname = "")
35  {
36  // This function should:
37  // - call the external scanner for a_filepath
38  // - set scanFilePath to a_filepath
39  // - set scanFileOrigName to a_origname
40  // - set scanFileIsInfected according the scan result
41  // - set scanResult to the scanner output message
42  // - call logScanResult() if file is infected
43  // - return the scanResult, if file is infected
44  // - return an empty string, if file is not infected
45 
46  $this->scanFilePath = $a_filepath;
47  $this->scanFileOrigName = $a_origname;
48 
49  // Call of scan_file from Sophie (www.vanja.com/tools/sophie)
50  // sophie must run as a process
51  $a_filepath = realpath($a_filepath);
52  $cmd = ilUtil::escapeShellCmd($this->scanCommand);
53  $args = ilUtil::escapeShellArg(" " . $a_filepath . " ");
54  $cmd = $cmd . " " . $args . " 2>&1";
55  exec($cmd, $out, $ret);
56  $this->scanResult = implode("\n", $out);
57 
58  // sophie could be called
59  if ($ret == 0) {
60  if (preg_match("/FILE INFECTED/", $this->scanResult)) {
61  $this->scanFileIsInfected = true;
62  $this->logScanResult();
63  return $this->scanResult;
64  } else {
65  $this->scanFileIsInfected = false;
66  return "";
67  }
68  }
69 
70  // sophie has failed (probably the daemon doesn't run)
71  $this->log->write("ERROR (Virus Scanner failed): "
72  . $this->scanResult
73  . "; COMMAMD=" . $cmd);
74 
75  // try fallback: scan by cleaner command (sweep)
76  // -ss: Don't display anything except on error or virus
77  // -archive: sweep inside archives
78  unset($out, $ret);
79  $cmd = $this->cleanCommand . " -ss -archive " . $a_filepath . " 2>&1";
80  exec($cmd, $out, $ret);
81  $this->scanResult = implode("\n", $out) . " [" . $ret . "]";
82 
83  // error codes from sweep:
84  // 0 If no errors are encountered and no viruses are found.
85  // 1 If the user interrupts SWEEP (usually by pressing control-C) or kills the process.
86  // 2 If some error preventing further execution is discovered.
87  // 3 If viruses or virus fragments are discovered.
88  if ($ret == 0) {
89  $this->scanFileIsCleaned = false;
90  return "";
91  } elseif ($ret == 3) {
92  $this->scanFileIsInfected = true;
93  $this->logScanResult();
94  return $this->scanResult;
95  } else {
96  $this->ilias->raiseError(
97  $this->lng->txt("virus_scan_error") . " "
98  . $this->lng->txt("virus_scan_message") . " "
100  $this->ilias->error_obj->WARNING
101  );
102  }
103  }
104 
112  public function cleanFile($a_filepath, $a_origname = "")
113  {
114  // This function should:
115  // - call the external cleaner
116  // - set cleanFilePath to a_filepath
117  // - set cleanFileOrigName to a_origname
118  // - set cleanFileIsCleaned according the clean result
119  // - set cleanResult to the cleaner output message
120  // - call logCleanResult in any case
121  // - return the cleanResult, if file is cleaned
122  // - return an empty string, if file is not cleaned
123 
124  $this->cleanFilePath = $a_filepath;
125  $this->cleanFileOrigName = $a_origname;
126 
127  // Call of sweep from Sophos (www.sophos.com)
128  // -di: Disinfect infected items
129  // -nc: Don't ask for confirmation before disinfection/deletion
130  // -ss: Don't display anything except on error or virus
131  // -eec: Use extended error codes
132  // -archive: sweep inside archives
133 
134  $a_filepath = realpath($a_filepath);
135  $cmd = $this->cleanCommand . " -di -nc -ss -eec -archive " . $a_filepath . " 2>&1";
136  exec($cmd, $out, $ret);
137  $this->cleanResult = implode("\n", $out) . " [" . $ret . "]";
138 
139  // always log the result from a clean attempt
140  $this->logCleanResult();
141 
142  // Extended error codes from sweep:
143  // 0 If no errors are encountered and no viruses are found.
144  // 8 If survivable errors have occurred.
145  // 12 If compressed files have been found and decompressed.
146  // 16 If compressed files have been found and not decompressed.
147  // 20 If viruses have been found and disinfected.
148  // 24 If viruses have been found and not disinfected.
149  // 28 If viruses have been found in memory.
150  // 32 If there has been an integrity check failure.
151  // 36 If unsurvivable errors have occurred.
152  // 40 If execution has been interrupted.
153  if ($ret == 20) {
154  $this->cleanFileIsCleaned = true;
155  return $this->cleanResult;
156  } else {
157  $this->cleanFileIsCleaned = false;
158  return "";
159  }
160  }
161 }
cleanFile($a_filepath, $a_origname="")
clean an infected file
logScanResult()
write the result of the last scan to the log public
__construct($a_scancommand, $a_cleancommand)
Constructor public.
static escapeShellCmd($a_arg)
escape shell cmd
logCleanResult()
write the result of the last clean to the log public
redirection script todo: (a better solution should control the processing via a xml file) ...
scanFile($a_filepath, $a_origname="")
scan a file for viruses
Base class for the interface to an external virus scanner This class is abstract and needs to be exte...
Interface to the sophos virus protector.
static escapeShellArg($a_arg)
__construct(Container $dic, ilPlugin $plugin)
$ret
Definition: parser.php:6