• Main Page
  • Related Pages
  • Modules
  • 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 
00038 class ilVirusScanner
00039 {
00046         var $type;
00047         
00054         var $scanZipFiles;
00055 
00061         var $scanCommand;
00062 
00068         var $cleanCommand;
00069 
00075         var $scanFilePath;
00076 
00082         var $scanFileOrigName;
00083 
00089         var $cleanFilePath;
00090 
00096         var $cleanFileOrigName;
00097 
00103         var $scanFileIsInfected;
00104 
00110         var $cleanFileIsCleaned;
00111 
00117         var $scanResult;
00118         
00124         var $cleanResult;
00125         
00131         var $ilias;
00132 
00138         var $lng;
00139 
00145         var $log;
00146 
00151         function ilVirusScanner($a_scancommand, $a_cleancommand)
00152         {
00153                 global $ilias, $lng, $log;
00154 
00155                 $this->ilias = & $ilias;
00156                 $this->lng = & $lng;
00157                 $this->log = & $log;
00158                 $this->scanCommand = $a_scancommand;
00159                 $this->cleanCommand = $a_cleancommand;
00160                 
00161                 $this->type = "simulate";
00162                 $this->scanZipFiles = false;
00163         }
00164 
00177         function scanFile($a_filepath, $a_origname = "")
00178         {
00179                 // This function needs to be redefined in child classes.
00180                 // It should:
00181                 // - call the external scanner for a_filepath
00182                 // - set scanFilePath to a_filepath
00183                 // - set scanFileOrigName to a_origname
00184                 // - set scanFileIsInfected according the scan result
00185                 // - set scanResult to the scanner output message
00186                 // - call logScanResult() if file is infected
00187                 // - return the output message, if file is infected
00188                 // - return an empty string, if file is not infected
00189                 
00190                 $this->scanFilePath = $a_filepath;
00191                 $this->scanFileOrigName = $a_origname;
00192                 
00193                 if ($a_origname == "infected.txt" or $a_origname == "cleanable.txt")
00194                 {
00195                         $this->scanFileIsInfected = true;
00196                         $this->scanResult =
00197                                 "FILE INFECTED: [". $a_filepath. "] (VIRUS: simulated)";
00198                         $this->logScanResult();
00199                         return $this->scanResult;
00200                 }
00201                 else
00202                 {
00203                         $this->scanFileIsInfected = false;
00204                         $this->scanResult = "";
00205                         return "";
00206                 }
00207         }
00208         
00209         
00222         function cleanFile($a_filepath, $a_origname = "")
00223         {
00224                 // This function needs to be redefined in child classes
00225                 // It should:
00226                 // - call the external cleaner
00227                 // - set cleanFilePath to a_filepath
00228                 // - set cleanFileOrigName to a_origname
00229                 // - set cleanFileIsCleaned according the clean result
00230                 // - set cleanResult to the cleaner output message
00231                 // - call logCleanResult in any case
00232                 // - return the output message, if file is cleaned
00233                 // - return an empty string, if file is not cleaned
00234 
00235                 $this->cleanFilePath = $a_filepath;
00236                 $this->cleanFileOrigName = $a_origname;
00237 
00238                 if ($a_origname == "cleanable.txt")
00239                 {
00240                         $this->cleanFileIsCleaned = true;
00241                         $this->cleanResult =
00242                                 "FILE CLEANED: [". $a_filepath. "] (VIRUS: simulated)";
00243                         $this->logCleanResult();
00244                         return $this->cleanResult;
00245                 }
00246                 else
00247                 {
00248                         $this->cleanFileIsCleaned = false;
00249                         $this->cleanResult =
00250                                 "FILE NOT CLEANED: [". $a_filepath. "] (VIRUS: simulated)";
00251                         $this->logCleanResult();
00252                         return "";
00253                 }
00254         }
00255         
00261         function fileCleaned()
00262         {
00263                 return $this->cleanFileIsCleaned;
00264         }
00265         
00271         function logScanResult()
00272         {
00273                 $mess = "Virus Scanner (". $this->type. ")";
00274                 if ($this->scanFileOrigName)
00275                 {
00276                         $mess .= " (File " . $this->scanFileOrigName . ")";
00277                 }
00278                 $mess .= ": " . ereg_replace("(\r|\n)+", "; ", $this->scanResult);
00279 
00280                 $this->log->write($mess);
00281         }
00282         
00288         function logCleanResult()
00289         {
00290                 $mess = "Virus Cleaner (". $this->type. ")";
00291                 if ($this->cleanFileOrigName)
00292                 {
00293                         $mess .= " (File ". $this->cleanFileOrigName. ")";
00294                 }
00295                 $mess .= ": " . ereg_replace("(\r|\n)+", "; ", $this->cleanResult);
00296 
00297                 $this->log->write($mess);
00298         }
00299 
00306         function getScanResult()
00307         {
00308                 return $this->scanResult;
00309         }
00310         
00317         function getCleanResult()
00318         {
00319                 return $this->cleanResult;
00320         }
00321 
00328         function getScanMessage()
00329         {
00330                 if ($this->scanFileIsInfected)
00331                 {
00332                         $ret = sprintf($this->lng->txt("virus_infected"), $this->scanFileOrigName);
00333                 }
00334                 else
00335                 {
00336                         $ret = sprintf($this->lng->txt("virus_not_infected"),$this->scanFileOrigName);
00337                 }
00338                 
00339                 if ($this->scanResult)
00340                 {
00341                         $ret .= " ". $this->lng->txt("virus_scan_message")
00342                                  . "<br />"
00343                                  . str_replace($this->scanFilePath, $this->scanFileOrigName,
00344                                                                 nl2br($this->scanResult));
00345                 }
00346                 return $ret;
00347         }
00348 
00355         function getCleanMessage()
00356         {
00357                 if ($this->cleanFileIsCleaned)
00358                 {
00359                         $ret = sprintf($this->lng->txt("virus_cleaned"), $this->cleanFileOrigName);
00360                 }
00361                 else
00362                 {
00363                         $ret = sprintf($this->lng->txt("virus_not_cleaned"),$this->cleanFileOrigName);
00364                 }
00365 
00366                 if ($this->cleanResult)
00367                 {
00368                         $ret .= " ". $this->lng->txt("virus_clean_message")
00369                                  . "<br />"
00370                                  . str_replace($this->cleanFilePath, $this->cleanFileOrigName,
00371                                                                 nl2br($this->cleanResult));
00372                 }
00373                 return $ret;
00374         }
00375         
00382         function getScanZipFiles()
00383         {
00384                 return $this->scanZipFiles;
00385         }
00386 }
00387 ?>

Generated on Fri Dec 13 2013 17:56:48 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1