ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilVirusScanner.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
39 {
46  var $type;
47 
55 
62 
69 
76 
83 
90 
97 
104 
111 
118 
125 
131  var $ilias;
132 
138  var $lng;
139 
145  var $log;
146 
151  function ilVirusScanner($a_scancommand, $a_cleancommand)
152  {
153  global $ilias, $lng, $log;
154 
155  $this->ilias = & $ilias;
156  $this->lng = & $lng;
157  $this->log = & $log;
158  $this->scanCommand = $a_scancommand;
159  $this->cleanCommand = $a_cleancommand;
160 
161  $this->type = "simulate";
162  $this->scanZipFiles = false;
163  }
164 
177  function scanFile($a_filepath, $a_origname = "")
178  {
179  // This function needs to be redefined in child classes.
180  // It should:
181  // - call the external scanner for a_filepath
182  // - set scanFilePath to a_filepath
183  // - set scanFileOrigName to a_origname
184  // - set scanFileIsInfected according the scan result
185  // - set scanResult to the scanner output message
186  // - call logScanResult() if file is infected
187  // - return the output message, if file is infected
188  // - return an empty string, if file is not infected
189 
190  $this->scanFilePath = $a_filepath;
191  $this->scanFileOrigName = $a_origname;
192 
193  if ($a_origname == "infected.txt" or $a_origname == "cleanable.txt")
194  {
195  $this->scanFileIsInfected = true;
196  $this->scanResult =
197  "FILE INFECTED: [". $a_filepath. "] (VIRUS: simulated)";
198  $this->logScanResult();
199  return $this->scanResult;
200  }
201  else
202  {
203  $this->scanFileIsInfected = false;
204  $this->scanResult = "";
205  return "";
206  }
207  }
208 
209 
222  function cleanFile($a_filepath, $a_origname = "")
223  {
224  // This function needs to be redefined in child classes
225  // It should:
226  // - call the external cleaner
227  // - set cleanFilePath to a_filepath
228  // - set cleanFileOrigName to a_origname
229  // - set cleanFileIsCleaned according the clean result
230  // - set cleanResult to the cleaner output message
231  // - call logCleanResult in any case
232  // - return the output message, if file is cleaned
233  // - return an empty string, if file is not cleaned
234 
235  $this->cleanFilePath = $a_filepath;
236  $this->cleanFileOrigName = $a_origname;
237 
238  if ($a_origname == "cleanable.txt")
239  {
240  $this->cleanFileIsCleaned = true;
241  $this->cleanResult =
242  "FILE CLEANED: [". $a_filepath. "] (VIRUS: simulated)";
243  $this->logCleanResult();
244  return $this->cleanResult;
245  }
246  else
247  {
248  $this->cleanFileIsCleaned = false;
249  $this->cleanResult =
250  "FILE NOT CLEANED: [". $a_filepath. "] (VIRUS: simulated)";
251  $this->logCleanResult();
252  return "";
253  }
254  }
255 
261  function fileCleaned()
262  {
264  }
265 
271  function logScanResult()
272  {
273  $mess = "Virus Scanner (". $this->type. ")";
274  if ($this->scanFileOrigName)
275  {
276  $mess .= " (File " . $this->scanFileOrigName . ")";
277  }
278  $mess .= ": " . ereg_replace("(\r|\n)+", "; ", $this->scanResult);
279 
280  $this->log->write($mess);
281  }
282 
288  function logCleanResult()
289  {
290  $mess = "Virus Cleaner (". $this->type. ")";
291  if ($this->cleanFileOrigName)
292  {
293  $mess .= " (File ". $this->cleanFileOrigName. ")";
294  }
295  $mess .= ": " . ereg_replace("(\r|\n)+", "; ", $this->cleanResult);
296 
297  $this->log->write($mess);
298  }
299 
306  function getScanResult()
307  {
308  return $this->scanResult;
309  }
310 
317  function getCleanResult()
318  {
319  return $this->cleanResult;
320  }
321 
328  function getScanMessage()
329  {
330  if ($this->scanFileIsInfected)
331  {
332  $ret = sprintf($this->lng->txt("virus_infected"), $this->scanFileOrigName);
333  }
334  else
335  {
336  $ret = sprintf($this->lng->txt("virus_not_infected"),$this->scanFileOrigName);
337  }
338 
339  if ($this->scanResult)
340  {
341  $ret .= " ". $this->lng->txt("virus_scan_message")
342  . "<br />"
343  . str_replace($this->scanFilePath, $this->scanFileOrigName,
344  nl2br($this->scanResult));
345  }
346  return $ret;
347  }
348 
355  function getCleanMessage()
356  {
357  if ($this->cleanFileIsCleaned)
358  {
359  $ret = sprintf($this->lng->txt("virus_cleaned"), $this->cleanFileOrigName);
360  }
361  else
362  {
363  $ret = sprintf($this->lng->txt("virus_not_cleaned"),$this->cleanFileOrigName);
364  }
365 
366  if ($this->cleanResult)
367  {
368  $ret .= " ". $this->lng->txt("virus_clean_message")
369  . "<br />"
370  . str_replace($this->cleanFilePath, $this->cleanFileOrigName,
371  nl2br($this->cleanResult));
372  }
373  return $ret;
374  }
375 
382  function getScanZipFiles()
383  {
384  return $this->scanZipFiles;
385  }
386 }
387 ?>