ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 @access 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 @access 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 @access public More...
 
 logCleanResult ()
 write the result of the last clean to the log @access 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 @access public.

Parameters
stringvirus scanner command

Reimplemented from ilVirusScanner.

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 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References ILIAS\GlobalScreen\Provider\__construct().

+ Here is the call graph for this function:

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) @access public

Reimplemented from ilVirusScanner.

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

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 }
logCleanResult()
write the result of the last clean to the log @access public
$ret
Definition: parser.php:6

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

+ 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) @access public

Reimplemented from ilVirusScanner.

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

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") . " "
99 . $this->scanResult,
100 $this->ilias->error_obj->WARNING
101 );
102 }
103 }
static escapeShellArg($a_arg)
static escapeShellCmd($a_arg)
escape shell cmd
logScanResult()
write the result of the last scan to the log @access public
redirection script todo: (a better solution should control the processing via a xml file)

References $out, $ret, ilVirusScanner\$scanResult, ilUtil\escapeShellArg(), ilUtil\escapeShellCmd(), and ilVirusScanner\logScanResult().

+ Here is the call graph for this function:

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