• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

classes/class.ilVirusScanner.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00039 class ilVirusScanner
00040 {
00047         var $type;
00048         
00055         var $scanZipFiles;
00056 
00062         var $scanCommand;
00063 
00069         var $cleanCommand;
00070 
00076         var $scanFilePath;
00077 
00083         var $scanFileOrigName;
00084 
00090         var $cleanFilePath;
00091 
00097         var $cleanFileOrigName;
00098 
00104         var $scanFileIsInfected;
00105 
00111         var $cleanFileIsCleaned;
00112 
00118         var $scanResult;
00119         
00125         var $cleanResult;
00126         
00132         var $ilias;
00133 
00139         var $lng;
00140 
00146         var $log;
00147 
00152         function ilVirusScanner($a_scancommand, $a_cleancommand)
00153         {
00154                 global $ilias, $lng, $log;
00155 
00156                 $this->ilias = & $ilias;
00157                 $this->lng = & $lng;
00158                 $this->log = & $log;
00159                 $this->scanCommand = $a_scancommand;
00160                 $this->cleanCommand = $a_cleancommand;
00161                 
00162                 $this->type = "simulate";
00163                 $this->scanZipFiles = false;
00164         }
00165 
00178         function scanFile($a_filepath, $a_origname = "")
00179         {
00180                 // This function needs to be redefined in child classes.
00181                 // It should:
00182                 // - call the external scanner for a_filepath
00183                 // - set scanFilePath to a_filepath
00184                 // - set scanFileOrigName to a_origname
00185                 // - set scanFileIsInfected according the scan result
00186                 // - set scanResult to the scanner output message
00187                 // - call logScanResult() if file is infected
00188                 // - return the output message, if file is infected
00189                 // - return an empty string, if file is not infected
00190                 
00191                 $this->scanFilePath = $a_filepath;
00192                 $this->scanFileOrigName = $a_origname;
00193                 
00194                 if ($a_origname == "infected.txt" or $a_origname == "cleanable.txt")
00195                 {
00196                         $this->scanFileIsInfected = true;
00197                         $this->scanResult =
00198                                 "FILE INFECTED: [". $a_filepath. "] (VIRUS: simulated)";
00199                         $this->logScanResult();
00200                         return $this->scanResult;
00201                 }
00202                 else
00203                 {
00204                         $this->scanFileIsInfected = false;
00205                         $this->scanResult = "";
00206                         return "";
00207                 }
00208         }
00209         
00210         
00223         function cleanFile($a_filepath, $a_origname = "")
00224         {
00225                 // This function needs to be redefined in child classes
00226                 // It should:
00227                 // - call the external cleaner
00228                 // - set cleanFilePath to a_filepath
00229                 // - set cleanFileOrigName to a_origname
00230                 // - set cleanFileIsCleaned according the clean result
00231                 // - set cleanResult to the cleaner output message
00232                 // - call logCleanResult in any case
00233                 // - return the output message, if file is cleaned
00234                 // - return an empty string, if file is not cleaned
00235 
00236                 $this->cleanFilePath = $a_filepath;
00237                 $this->cleanFileOrigName = $a_origname;
00238 
00239                 if ($a_origname == "cleanable.txt")
00240                 {
00241                         $this->cleanFileIsCleaned = true;
00242                         $this->cleanResult =
00243                                 "FILE CLEANED: [". $a_filepath. "] (VIRUS: simulated)";
00244                         $this->logCleanResult();
00245                         return $this->cleanResult;
00246                 }
00247                 else
00248                 {
00249                         $this->cleanFileIsCleaned = false;
00250                         $this->cleanResult =
00251                                 "FILE NOT CLEANED: [". $a_filepath. "] (VIRUS: simulated)";
00252                         $this->logCleanResult();
00253                         return "";
00254                 }
00255         }
00256         
00262         function fileCleaned()
00263         {
00264                 return $this->cleanFileIsCleaned;
00265         }
00266         
00272         function logScanResult()
00273         {
00274                 $mess = "Virus Scanner (". $this->type. ")";
00275                 if ($this->scanFileOrigName)
00276                 {
00277                         $mess .= " (File " . $this->scanFileOrigName . ")";
00278                 }
00279                 $mess .= ": " . ereg_replace("(\r|\n)+", "; ", $this->scanResult);
00280 
00281                 $this->log->write($mess);
00282         }
00283         
00289         function logCleanResult()
00290         {
00291                 $mess = "Virus Cleaner (". $this->type. ")";
00292                 if ($this->cleanFileOrigName)
00293                 {
00294                         $mess .= " (File ". $this->cleanFileOrigName. ")";
00295                 }
00296                 $mess .= ": " . ereg_replace("(\r|\n)+", "; ", $this->cleanResult);
00297 
00298                 $this->log->write($mess);
00299         }
00300 
00307         function getScanResult()
00308         {
00309                 return $this->scanResult;
00310         }
00311         
00318         function getCleanResult()
00319         {
00320                 return $this->cleanResult;
00321         }
00322 
00329         function getScanMessage()
00330         {
00331                 if ($this->scanFileIsInfected)
00332                 {
00333                         $ret = sprintf($this->lng->txt("virus_infected"), $this->scanFileOrigName);
00334                 }
00335                 else
00336                 {
00337                         $ret = sprintf($this->lng->txt("virus_not_infected"),$this->scanFileOrigName);
00338                 }
00339                 
00340                 if ($this->scanResult)
00341                 {
00342                         $ret .= " ". $this->lng->txt("virus_scan_message")
00343                                  . "<br />"
00344                                  . str_replace($this->scanFilePath, $this->scanFileOrigName,
00345                                                                 nl2br($this->scanResult));
00346                 }
00347                 return $ret;
00348         }
00349 
00356         function getCleanMessage()
00357         {
00358                 if ($this->cleanFileIsCleaned)
00359                 {
00360                         $ret = sprintf($this->lng->txt("virus_cleaned"), $this->cleanFileOrigName);
00361                 }
00362                 else
00363                 {
00364                         $ret = sprintf($this->lng->txt("virus_not_cleaned"),$this->cleanFileOrigName);
00365                 }
00366 
00367                 if ($this->cleanResult)
00368                 {
00369                         $ret .= " ". $this->lng->txt("virus_clean_message")
00370                                  . "<br />"
00371                                  . str_replace($this->cleanFilePath, $this->cleanFileOrigName,
00372                                                                 nl2br($this->cleanResult));
00373                 }
00374                 return $ret;
00375         }
00376         
00383         function getScanZipFiles()
00384         {
00385                 return $this->scanZipFiles;
00386         }
00387 }
00388 ?>

Generated on Fri Dec 13 2013 09:06:35 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1