ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilVirusScannerSophos Class Reference

Interface to the sophos virus protector. More...

+ Inheritance diagram for ilVirusScannerSophos:
+ Collaboration diagram for ilVirusScannerSophos:

Public Member Functions

 __construct ($a_scancommand, $a_cleancommand)
 Constructor public. More...
 
 scanFile ($a_filepath, $a_origname="")
 scan a file for viruses More...
 
 cleanFile ($a_filepath, $a_origname="")
 clean an infected file More...
 
- Public Member Functions inherited from ilVirusScanner
 __construct ($a_scancommand, $a_cleancommand)
 Constructor public. More...
 
 scanBuffer ($buffer)
 
 scanFile ($a_filepath, $a_origname="")
 scan a file for viruses needs to be redefined in child classes here it simulates a scan "infected.txt" or "cleanable.txt" are expected to be infected More...
 
 cleanFile ($a_filepath, $a_origname="")
 clean an infected file needs to be redefined in child classes here it simulates a clean "cleanable.txt" is expected to be cleanable More...
 
 fileCleaned ()
 returns wether file has been cleaned successfully or not More...
 
 logScanResult ()
 write the result of the last scan to the log public More...
 
 logCleanResult ()
 write the result of the last clean to the log public More...
 
 getScanResult ()
 get the pure output of the external scan More...
 
 getCleanResult ()
 get the pure output of the external scan More...
 
 getScanMessage ()
 get a located message with the result from the last scan More...
 
 getCleanMessage ()
 get a located message with the result from the last clean More...
 
 getScanZipFiles ()
 get info if class can scan ZIP files More...
 

Additional Inherited Members

- Data Fields inherited from ilVirusScanner
 $type
 
 $scanZipFiles
 
 $scanCommand
 
 $cleanCommand
 
 $scanFilePath
 
 $scanFileOrigName
 
 $cleanFilePath
 
 $cleanFileOrigName
 
 $scanFileIsInfected
 
 $cleanFileIsCleaned
 
 $scanResult
 
 $cleanResult
 
 $ilias
 
 $lng
 
 $log
 
- Protected Member Functions inherited from ilVirusScanner
 scanFileFromBuffer ($buffer)
 
 createBufferFile ($buffer)
 
 removeBufferFile ($bufferFile)
 

Detailed Description

Interface to the sophos virus protector.

Author
Fred Neumann fred..nosp@m.neum.nosp@m.ann@f.nosp@m.im.u.nosp@m.ni-er.nosp@m.lang.nosp@m.en.de
Version
$Id$

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

Constructor & Destructor Documentation

◆ __construct()

ilVirusScannerSophos::__construct (   $a_scancommand,
  $a_cleancommand 
)

Constructor public.

Parameters
stringvirus scanner command

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

21  {
22  parent::__construct($a_scancommand, $a_cleancommand);
23  $this->type = "sophos";
24  $this->scanZipFiles = true;
25  }

Member Function Documentation

◆ cleanFile()

ilVirusScannerSophos::cleanFile (   $a_filepath,
  $a_origname = "" 
)

clean an infected file

Parameters
stringpath of file to check
stringoriginal name of the file to check
Returns
string clean message (empty if not cleaned) public

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

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

117  {
118  // This function should:
119  // - call the external cleaner
120  // - set cleanFilePath to a_filepath
121  // - set cleanFileOrigName to a_origname
122  // - set cleanFileIsCleaned according the clean result
123  // - set cleanResult to the cleaner output message
124  // - call logCleanResult in any case
125  // - return the cleanResult, if file is cleaned
126  // - return an empty string, if file is not cleaned
127 
128  $this->cleanFilePath = $a_filepath;
129  $this->cleanFileOrigName = $a_origname;
130 
131  // Call of sweep from Sophos (www.sophos.com)
132  // -di: Disinfect infected items
133  // -nc: Don't ask for confirmation before disinfection/deletion
134  // -ss: Don't display anything except on error or virus
135  // -eec: Use extended error codes
136  // -archive: sweep inside archives
137 
138  $cmd = $this->cleanCommand . " -di -nc -ss -eec -archive " . $a_filepath . " 2>&1";
139  exec($cmd, $out, $ret);
140  $this->cleanResult = implode("\n", $out) . " [" . $ret . "]";
141 
142  // always log the result from a clean attempt
143  $this->logCleanResult();
144 
145  // Extended error codes from sweep:
146  // 0 If no errors are encountered and no viruses are found.
147  // 8 If survivable errors have occurred.
148  // 12 If compressed files have been found and decompressed.
149  // 16 If compressed files have been found and not decompressed.
150  // 20 If viruses have been found and disinfected.
151  // 24 If viruses have been found and not disinfected.
152  // 28 If viruses have been found in memory.
153  // 32 If there has been an integrity check failure.
154  // 36 If unsurvivable errors have occurred.
155  // 40 If execution has been interrupted.
156  if($ret == 20)
157  {
158  $this->cleanFileIsCleaned = true;
159  return $this->cleanResult;
160  }
161  else
162  {
163  $this->cleanFileIsCleaned = false;
164  return "";
165  }
166  }
$cmd
Definition: sahs_server.php:35
logCleanResult()
write the result of the last clean to the log public
$ret
Definition: parser.php:6
+ Here is the call graph for this function:

◆ scanFile()

ilVirusScannerSophos::scanFile (   $a_filepath,
  $a_origname = "" 
)

scan a file for viruses

Parameters
stringpath of file to check
stringoriginal name of the file to ckeck
Returns
string virus message (empty if not infected) public

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

References $cmd, $out, $ret, ilVirusScanner\$scanResult, and ilVirusScanner\logScanResult().

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  $cmd = $this->scanCommand . " " . $a_filepath . " 2>&1";
52  exec($cmd, $out, $ret);
53  $this->scanResult = implode("\n", $out);
54 
55  // sophie could be called
56  if($ret == 0)
57  {
58  if(preg_match("/FILE INFECTED/", $this->scanResult))
59  {
60  $this->scanFileIsInfected = true;
61  $this->logScanResult();
62  return $this->scanResult;
63  }
64  else
65  {
66  $this->scanFileIsInfected = false;
67  return "";
68  }
69  }
70 
71  // sophie has failed (probably the daemon doesn't run)
72  $this->log->write("ERROR (Virus Scanner failed): "
73  . $this->scanResult
74  . "; COMMAMD=" . $cmd);
75 
76  // try fallback: scan by cleaner command (sweep)
77  // -ss: Don't display anything except on error or virus
78  // -archive: sweep inside archives
79  unset($out, $ret);
80  $cmd = $this->cleanCommand . " -ss -archive " . $a_filepath . " 2>&1";
81  exec($cmd, $out, $ret);
82  $this->scanResult = implode("\n", $out) . " [" . $ret . "]";
83 
84  // error codes from sweep:
85  // 0 If no errors are encountered and no viruses are found.
86  // 1 If the user interrupts SWEEP (usually by pressing control-C) or kills the process.
87  // 2 If some error preventing further execution is discovered.
88  // 3 If viruses or virus fragments are discovered.
89  if($ret == 0)
90  {
91  $this->scanFileIsCleaned = false;
92  return "";
93  }
94  else if($ret == 3)
95  {
96  $this->scanFileIsInfected = true;
97  $this->logScanResult();
98  return $this->scanResult;
99  }
100  else
101  {
102  $this->ilias->raiseError($this->lng->txt("virus_scan_error") . " "
103  . $this->lng->txt("virus_scan_message") . " "
105  $this->ilias->error_obj->WARNING);
106  }
107  }
$cmd
Definition: sahs_server.php:35
logScanResult()
write the result of the last scan to the log public
redirection script todo: (a better solution should control the processing via a xml file) ...
$ret
Definition: parser.php:6
+ Here is the call graph for this function:

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