Public Member Functions | Data Fields

ilVirusScanner Class Reference

Inheritance diagram for ilVirusScanner:

Public Member Functions

 ilVirusScanner ($a_scancommand, $a_cleancommand)
 Constructor public.
 scanFile ($a_filepath, $a_origname="")
 scan a file for viruses
 cleanFile ($a_filepath, $a_origname="")
 clean an infected file
 fileCleaned ()
 returns wether file has been cleaned successfully or not
 logScanResult ()
 write the result of the last scan to the log
 logCleanResult ()
 write the result of the last clean to the log
 getScanResult ()
 get the pure output of the external scan
 getCleanResult ()
 get the pure output of the external scan
 getScanMessage ()
 get a located message with the result from the last scan
 getCleanMessage ()
 get a located message with the result from the last clean
 getScanZipFiles ()
 get info if class can scan ZIP files

Data Fields

 $type
 $scanZipFiles
 $scanCommand
 $cleanCommand
 $scanFilePath
 $scanFileOrigName
 $cleanFilePath
 $cleanFileOrigName
 $scanFileIsInfected
 $cleanFileIsCleaned
 $scanResult
 $cleanResult
 $ilias
 $lng
 $log

Detailed Description

Definition at line 39 of file class.ilVirusScanner.php.


Member Function Documentation

ilVirusScanner::cleanFile ( a_filepath,
a_origname = "" 
)

clean an infected file

needs to be redefined in child classes here it simulates a clean "cleanable.txt" is expected to be cleanable

Parameters:
string path of file to check
string original name of the file to clean
Returns:
string clean message (empty if not cleaned) public

Reimplemented in ilVirusScannerSophos.

Definition at line 223 of file class.ilVirusScanner.php.

References logCleanResult().

        {
                // This function needs to be redefined in child classes
                // It should:
                // - call the external cleaner
                // - set cleanFilePath to a_filepath
                // - set cleanFileOrigName to a_origname
                // - set cleanFileIsCleaned according the clean result
                // - set cleanResult to the cleaner output message
                // - call logCleanResult in any case
                // - return the output message, if file is cleaned
                // - return an empty string, if file is not cleaned

                $this->cleanFilePath = $a_filepath;
                $this->cleanFileOrigName = $a_origname;

                if ($a_origname == "cleanable.txt")
                {
                        $this->cleanFileIsCleaned = true;
                        $this->cleanResult =
                                "FILE CLEANED: [". $a_filepath. "] (VIRUS: simulated)";
                        $this->logCleanResult();
                        return $this->cleanResult;
                }
                else
                {
                        $this->cleanFileIsCleaned = false;
                        $this->cleanResult =
                                "FILE NOT CLEANED: [". $a_filepath. "] (VIRUS: simulated)";
                        $this->logCleanResult();
                        return "";
                }
        }

Here is the call graph for this function:

ilVirusScanner::fileCleaned (  ) 

returns wether file has been cleaned successfully or not

Returns:
boolean true, if last clean operation has been successful

Definition at line 262 of file class.ilVirusScanner.php.

        {
                return $this->cleanFileIsCleaned;
        }

ilVirusScanner::getCleanMessage (  ) 

get a located message with the result from the last clean

Returns:
string public

Definition at line 356 of file class.ilVirusScanner.php.

        {
                if ($this->cleanFileIsCleaned)
                {
                        $ret = sprintf($this->lng->txt("virus_cleaned"), $this->cleanFileOrigName);
                }
                else
                {
                        $ret = sprintf($this->lng->txt("virus_not_cleaned"),$this->cleanFileOrigName);
                }

                if ($this->cleanResult)
                {
                        $ret .= " ". $this->lng->txt("virus_clean_message")
                                 . "<br />"
                                 . str_replace($this->cleanFilePath, $this->cleanFileOrigName,
                                                                nl2br($this->cleanResult));
                }
                return $ret;
        }

ilVirusScanner::getCleanResult (  ) 

get the pure output of the external scan

Returns:
string public

Definition at line 318 of file class.ilVirusScanner.php.

        {
                return $this->cleanResult;
        }

ilVirusScanner::getScanMessage (  ) 

get a located message with the result from the last scan

Returns:
string public

Definition at line 329 of file class.ilVirusScanner.php.

        {
                if ($this->scanFileIsInfected)
                {
                        $ret = sprintf($this->lng->txt("virus_infected"), $this->scanFileOrigName);
                }
                else
                {
                        $ret = sprintf($this->lng->txt("virus_not_infected"),$this->scanFileOrigName);
                }
                
                if ($this->scanResult)
                {
                        $ret .= " ". $this->lng->txt("virus_scan_message")
                                 . "<br />"
                                 . str_replace($this->scanFilePath, $this->scanFileOrigName,
                                                                nl2br($this->scanResult));
                }
                return $ret;
        }

ilVirusScanner::getScanResult (  ) 

get the pure output of the external scan

Returns:
string public

Definition at line 307 of file class.ilVirusScanner.php.

        {
                return $this->scanResult;
        }

ilVirusScanner::getScanZipFiles (  ) 

get info if class can scan ZIP files

Returns:
boolean public

Definition at line 383 of file class.ilVirusScanner.php.

        {
                return $this->scanZipFiles;
        }

ilVirusScanner::ilVirusScanner ( a_scancommand,
a_cleancommand 
)

Constructor public.

Definition at line 152 of file class.ilVirusScanner.php.

References $ilias, $lng, and $log.

Referenced by ilVirusScannerAntiVir::ilVirusScannerAntivir(), and ilVirusScannerSophos::ilVirusScannerSophos().

        {
                global $ilias, $lng, $log;

                $this->ilias = & $ilias;
                $this->lng = & $lng;
                $this->log = & $log;
                $this->scanCommand = $a_scancommand;
                $this->cleanCommand = $a_cleancommand;
                
                $this->type = "simulate";
                $this->scanZipFiles = false;
        }

Here is the caller graph for this function:

ilVirusScanner::logCleanResult (  ) 

write the result of the last clean to the log

public

Definition at line 289 of file class.ilVirusScanner.php.

Referenced by ilVirusScannerSophos::cleanFile(), and cleanFile().

        {
                $mess = "Virus Cleaner (". $this->type. ")";
                if ($this->cleanFileOrigName)
                {
                        $mess .= " (File ". $this->cleanFileOrigName. ")";
                }
                $mess .= ": " . ereg_replace("(\r|\n)+", "; ", $this->cleanResult);

                $this->log->write($mess);
        }

Here is the caller graph for this function:

ilVirusScanner::logScanResult (  ) 

write the result of the last scan to the log

public

Definition at line 272 of file class.ilVirusScanner.php.

Referenced by ilVirusScannerSophos::scanFile(), ilVirusScannerAntiVir::scanFile(), and scanFile().

        {
                $mess = "Virus Scanner (". $this->type. ")";
                if ($this->scanFileOrigName)
                {
                        $mess .= " (File " . $this->scanFileOrigName . ")";
                }
                $mess .= ": " . ereg_replace("(\r|\n)+", "; ", $this->scanResult);

                $this->log->write($mess);
        }

Here is the caller graph for this function:

ilVirusScanner::scanFile ( a_filepath,
a_origname = "" 
)

scan a file for viruses

needs to be redefined in child classes here it simulates a scan "infected.txt" or "cleanable.txt" are expected to be infected

Parameters:
string path of file to scan
string original name of the file to scan
Returns:
string virus message (empty if not infected) public

Reimplemented in ilVirusScannerAntiVir, and ilVirusScannerSophos.

Definition at line 178 of file class.ilVirusScanner.php.

References logScanResult().

        {
                // This function needs to be redefined in child classes.
                // It should:
                // - call the external scanner for a_filepath
                // - set scanFilePath to a_filepath
                // - set scanFileOrigName to a_origname
                // - set scanFileIsInfected according the scan result
                // - set scanResult to the scanner output message
                // - call logScanResult() if file is infected
                // - return the output message, if file is infected
                // - return an empty string, if file is not infected
                
                $this->scanFilePath = $a_filepath;
                $this->scanFileOrigName = $a_origname;
                
                if ($a_origname == "infected.txt" or $a_origname == "cleanable.txt")
                {
                        $this->scanFileIsInfected = true;
                        $this->scanResult =
                                "FILE INFECTED: [". $a_filepath. "] (VIRUS: simulated)";
                        $this->logScanResult();
                        return $this->scanResult;
                }
                else
                {
                        $this->scanFileIsInfected = false;
                        $this->scanResult = "";
                        return "";
                }
        }

Here is the call graph for this function:


Field Documentation

ilVirusScanner::$cleanCommand

Definition at line 69 of file class.ilVirusScanner.php.

ilVirusScanner::$cleanFileIsCleaned

Definition at line 111 of file class.ilVirusScanner.php.

ilVirusScanner::$cleanFileOrigName

Definition at line 97 of file class.ilVirusScanner.php.

ilVirusScanner::$cleanFilePath

Definition at line 90 of file class.ilVirusScanner.php.

ilVirusScanner::$cleanResult

Definition at line 125 of file class.ilVirusScanner.php.

ilVirusScanner::$ilias

Definition at line 132 of file class.ilVirusScanner.php.

Referenced by ilVirusScanner().

ilVirusScanner::$lng

Definition at line 139 of file class.ilVirusScanner.php.

Referenced by ilVirusScanner().

ilVirusScanner::$log

Definition at line 146 of file class.ilVirusScanner.php.

Referenced by ilVirusScanner().

ilVirusScanner::$scanCommand

Definition at line 62 of file class.ilVirusScanner.php.

ilVirusScanner::$scanFileIsInfected

Definition at line 104 of file class.ilVirusScanner.php.

ilVirusScanner::$scanFileOrigName

Definition at line 83 of file class.ilVirusScanner.php.

ilVirusScanner::$scanFilePath

Definition at line 76 of file class.ilVirusScanner.php.

ilVirusScanner::$scanResult

Definition at line 118 of file class.ilVirusScanner.php.

ilVirusScanner::$scanZipFiles

Definition at line 55 of file class.ilVirusScanner.php.

ilVirusScanner::$type

Definition at line 47 of file class.ilVirusScanner.php.


The documentation for this class was generated from the following file: