Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00180
00181
00182
00183
00184
00185
00186
00187
00188
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
00225
00226
00227
00228
00229
00230
00231
00232
00233
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 ?>