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
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
00181
00182
00183
00184
00185
00186
00187
00188
00189
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
00226
00227
00228
00229
00230
00231
00232
00233
00234
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 ?>