ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilVirusScanner.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 
19 {
26  var $type;
27 
35 
42 
49 
56 
63 
70 
77 
84 
91 
98 
105 
111  var $ilias;
112 
118  var $lng;
119 
125  var $log;
126 
131  function ilVirusScanner($a_scancommand, $a_cleancommand)
132  {
133  global $ilias, $lng, $log;
134 
135  $this->ilias = & $ilias;
136  $this->lng = & $lng;
137  $this->log = & $log;
138  $this->scanCommand = $a_scancommand;
139  $this->cleanCommand = $a_cleancommand;
140 
141  $this->type = "simulate";
142  $this->scanZipFiles = false;
143  }
144 
157  function scanFile($a_filepath, $a_origname = "")
158  {
159  // This function needs to be redefined in child classes.
160  // It should:
161  // - call the external scanner for a_filepath
162  // - set scanFilePath to a_filepath
163  // - set scanFileOrigName to a_origname
164  // - set scanFileIsInfected according the scan result
165  // - set scanResult to the scanner output message
166  // - call logScanResult() if file is infected
167  // - return the output message, if file is infected
168  // - return an empty string, if file is not infected
169 
170  $this->scanFilePath = $a_filepath;
171  $this->scanFileOrigName = $a_origname;
172 
173  if ($a_origname == "infected.txt" or $a_origname == "cleanable.txt")
174  {
175  $this->scanFileIsInfected = true;
176  $this->scanResult =
177  "FILE INFECTED: [". $a_filepath. "] (VIRUS: simulated)";
178  $this->logScanResult();
179  return $this->scanResult;
180  }
181  else
182  {
183  $this->scanFileIsInfected = false;
184  $this->scanResult = "";
185  return "";
186  }
187  }
188 
189 
202  function cleanFile($a_filepath, $a_origname = "")
203  {
204  // This function needs to be redefined in child classes
205  // It should:
206  // - call the external cleaner
207  // - set cleanFilePath to a_filepath
208  // - set cleanFileOrigName to a_origname
209  // - set cleanFileIsCleaned according the clean result
210  // - set cleanResult to the cleaner output message
211  // - call logCleanResult in any case
212  // - return the output message, if file is cleaned
213  // - return an empty string, if file is not cleaned
214 
215  $this->cleanFilePath = $a_filepath;
216  $this->cleanFileOrigName = $a_origname;
217 
218  if ($a_origname == "cleanable.txt")
219  {
220  $this->cleanFileIsCleaned = true;
221  $this->cleanResult =
222  "FILE CLEANED: [". $a_filepath. "] (VIRUS: simulated)";
223  $this->logCleanResult();
224  return $this->cleanResult;
225  }
226  else
227  {
228  $this->cleanFileIsCleaned = false;
229  $this->cleanResult =
230  "FILE NOT CLEANED: [". $a_filepath. "] (VIRUS: simulated)";
231  $this->logCleanResult();
232  return "";
233  }
234  }
235 
241  function fileCleaned()
242  {
244  }
245 
251  function logScanResult()
252  {
253  $mess = "Virus Scanner (". $this->type. ")";
254  if ($this->scanFileOrigName)
255  {
256  $mess .= " (File " . $this->scanFileOrigName . ")";
257  }
258  $mess .= ": " . ereg_replace("(\r|\n)+", "; ", $this->scanResult);
259 
260  $this->log->write($mess);
261  }
262 
268  function logCleanResult()
269  {
270  $mess = "Virus Cleaner (". $this->type. ")";
271  if ($this->cleanFileOrigName)
272  {
273  $mess .= " (File ". $this->cleanFileOrigName. ")";
274  }
275  $mess .= ": " . ereg_replace("(\r|\n)+", "; ", $this->cleanResult);
276 
277  $this->log->write($mess);
278  }
279 
286  function getScanResult()
287  {
288  return $this->scanResult;
289  }
290 
297  function getCleanResult()
298  {
299  return $this->cleanResult;
300  }
301 
308  function getScanMessage()
309  {
310  if ($this->scanFileIsInfected)
311  {
312  $ret = sprintf($this->lng->txt("virus_infected"), $this->scanFileOrigName);
313  }
314  else
315  {
316  $ret = sprintf($this->lng->txt("virus_not_infected"),$this->scanFileOrigName);
317  }
318 
319  if ($this->scanResult)
320  {
321  $ret .= " ". $this->lng->txt("virus_scan_message")
322  . "<br />"
323  . str_replace($this->scanFilePath, $this->scanFileOrigName,
324  nl2br($this->scanResult));
325  }
326  return $ret;
327  }
328 
335  function getCleanMessage()
336  {
337  if ($this->cleanFileIsCleaned)
338  {
339  $ret = sprintf($this->lng->txt("virus_cleaned"), $this->cleanFileOrigName);
340  }
341  else
342  {
343  $ret = sprintf($this->lng->txt("virus_not_cleaned"),$this->cleanFileOrigName);
344  }
345 
346  if ($this->cleanResult)
347  {
348  $ret .= " ". $this->lng->txt("virus_clean_message")
349  . "<br />"
350  . str_replace($this->cleanFilePath, $this->cleanFileOrigName,
351  nl2br($this->cleanResult));
352  }
353  return $ret;
354  }
355 
362  function getScanZipFiles()
363  {
364  return $this->scanZipFiles;
365  }
366 }
367 ?>