ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
11require_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 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 $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") . " "
104 . $this->scanResult,
105 $this->ilias->error_obj->WARNING);
106 }
107 }
108
116 function cleanFile($a_filepath, $a_origname = "")
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 }
167}
An exception for terminatinating execution or to throw for unit testing.
Interface to the sophos virus protector.
__construct($a_scancommand, $a_cleancommand)
Constructor @access public.
cleanFile($a_filepath, $a_origname="")
clean an infected 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...
logScanResult()
write the result of the last scan to the log @access public
logCleanResult()
write the result of the last clean to the log @access public
redirection script todo: (a better solution should control the processing via a xml file)
$ret
Definition: parser.php:6
$cmd
Definition: sahs_server.php:35