ILIAS  release_8 Revision v8.24
ilVirusScanner Class Reference
+ Inheritance diagram for ilVirusScanner:
+ Collaboration diagram for ilVirusScanner:

Public Member Functions

 __construct (string $scan_command, string $clean_command)
 
 scanBuffer (string $buffer)
 
 scanFile (string $file_path, string $org_name="")
 
 logScanResult ()
 
 cleanFile (string $file_path, string $org_name="")
 
 logCleanResult ()
 
 fileCleaned ()
 
 getScanResult ()
 
 getCleanResult ()
 
 getScanMessage ()
 
 getCleanMessage ()
 
 getScanZipFiles ()
 

Static Public Member Functions

static virusHandling (string $a_file, string $a_orig_name='', bool $a_clean=true)
 

Data Fields

string $type
 
bool $scanZipFiles
 
string $scanCommand
 
string $cleanCommand
 
string $scanFilePath
 
string $scanFileOrigName
 
string $cleanFilePath
 
string $cleanFileOrigName
 
bool $scanFileIsInfected
 
bool $cleanFileIsCleaned
 
string $scanResult
 
string $cleanResult
 
ilErrorHandling $error
 
ilLanguage $lng
 
ilLogger $log
 

Protected Member Functions

 scanFileFromBuffer (string $buffer)
 
 createBufferFile (string $buffer)
 
 removeBufferFile (string $bufferFile)
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilVirusScanner::__construct ( string  $scan_command,
string  $clean_command 
)

Reimplemented in ilVirusScannerAntiVir, ilVirusScannerClamAV, ilVirusScannerICapClient, ilVirusScannerICapRemote, ilVirusScannerICapRemoteAvClient, and ilVirusScannerSophos.

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

54 {
55 global $DIC;
56 $error = $DIC['ilErr'];
57 $lng = $DIC->language();
58 $log = $DIC->logger()->root();
59
60 $this->error = $error;
61 $this->lng = $lng;
62 $this->log = $log;
63 $this->scanCommand = $scan_command;
64 $this->cleanCommand = $clean_command;
65
66 $this->type = "simulate";
67 $this->scanZipFiles = false;
68 }
error(string $a_errmsg)
ilErrorHandling $error
global $DIC
Definition: feed.php:28

References $DIC, $error, $lng, $log, error(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

Member Function Documentation

◆ cleanFile()

ilVirusScanner::cleanFile ( string  $file_path,
string  $org_name = "" 
)

Reimplemented in ilVirusScannerSophos.

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

166 : string
167 {
168 $this->cleanFilePath = $file_path;
169 $this->cleanFileOrigName = $org_name;
170
171 if ($org_name === "cleanable.txt") {
172 $this->cleanFileIsCleaned = true;
173 $this->cleanResult =
174 "FILE CLEANED: [" . $file_path . "] (VIRUS: simulated)";
175 $this->logCleanResult();
176 return $this->cleanResult;
177 }
178
179 $this->cleanFileIsCleaned = false;
180 $this->cleanResult =
181 "FILE NOT CLEANED: [" . $file_path . "] (VIRUS: simulated)";
182 $this->logCleanResult();
183 return "";
184 }

References $cleanResult, and logCleanResult().

+ Here is the call graph for this function:

◆ createBufferFile()

ilVirusScanner::createBufferFile ( string  $buffer)
protected

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

125 : string
126 {
127 $bufferFile = ilFileUtils::ilTempnam();
128 file_put_contents($bufferFile, $buffer);
129 return $bufferFile;
130 }
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.

References ilFileUtils\ilTempnam().

Referenced by scanFileFromBuffer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fileCleaned()

ilVirusScanner::fileCleaned ( )

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

197 : bool
198 {
200 }

References $cleanFileIsCleaned.

◆ getCleanMessage()

ilVirusScanner::getCleanMessage ( )

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

232 : string
233 {
234 if ($this->cleanFileIsCleaned) {
235 $ret = sprintf($this->lng->txt("virus_cleaned"), $this->cleanFileOrigName);
236 } else {
237 $ret = sprintf($this->lng->txt("virus_not_cleaned"), $this->cleanFileOrigName);
238 }
239
240 if ($this->cleanResult) {
241 $ret .= " " . $this->lng->txt("virus_clean_message")
242 . "<br />"
243 . str_replace(
244 $this->cleanFilePath,
245 $this->cleanFileOrigName,
246 nl2br($this->cleanResult)
247 );
248 }
249 return $ret;
250 }

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getCleanResult()

ilVirusScanner::getCleanResult ( )

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

207 : string
208 {
209 return $this->cleanResult;
210 }

References $cleanResult.

◆ getScanMessage()

ilVirusScanner::getScanMessage ( )

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

212 : string
213 {
214 if ($this->scanFileIsInfected) {
215 $ret = sprintf($this->lng->txt("virus_infected"), $this->scanFileOrigName);
216 } else {
217 $ret = sprintf($this->lng->txt("virus_not_infected"), $this->scanFileOrigName);
218 }
219
220 if ($this->scanResult) {
221 $ret .= " " . $this->lng->txt("virus_scan_message")
222 . "<br />"
223 . str_replace(
224 $this->scanFilePath,
225 $this->scanFileOrigName,
226 nl2br($this->scanResult)
227 );
228 }
229 return $ret;
230 }

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getScanResult()

ilVirusScanner::getScanResult ( )

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

202 : string
203 {
204 return $this->scanResult;
205 }

References $scanResult.

◆ getScanZipFiles()

ilVirusScanner::getScanZipFiles ( )

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

252 : bool
253 {
254 return $this->scanZipFiles;
255 }

References $scanZipFiles.

◆ logCleanResult()

ilVirusScanner::logCleanResult ( )

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

186 : void
187 {
188 $mess = "Virus Cleaner (" . $this->type . ")";
189 if ($this->cleanFileOrigName) {
190 $mess .= " (File " . $this->cleanFileOrigName . ")";
191 }
192 $mess .= ": " . preg_replace('/[\r\n]+/', "; ", $this->cleanResult);
193
194 $this->log->write($mess);
195 }

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

+ Here is the caller graph for this function:

◆ logScanResult()

ilVirusScanner::logScanResult ( )

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

150 : void
151 {
152 $mess = "Virus Scanner (" . $this->type . ")";
153 if ($this->scanFileOrigName) {
154 $mess .= " (File " . $this->scanFileOrigName . ")";
155 }
156 $mess .= ": " . preg_replace('/[\r\n]+/', "; ", $this->scanResult);
157
158 $this->log->write($mess);
159 }

Referenced by scanFile(), ilVirusScannerAntiVir\scanFile(), ilVirusScannerClamAV\scanFile(), and ilVirusScannerSophos\scanFile().

+ Here is the caller graph for this function:

◆ removeBufferFile()

ilVirusScanner::removeBufferFile ( string  $bufferFile)
protected

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

161 : void
162 {
163 unlink($bufferFile);
164 }

Referenced by scanFileFromBuffer().

+ Here is the caller graph for this function:

◆ scanBuffer()

ilVirusScanner::scanBuffer ( string  $buffer)

Reimplemented in ilVirusScannerClamAV.

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

112 : bool
113 {
114 return $this->scanFileFromBuffer($buffer);
115 }
scanFileFromBuffer(string $buffer)

References scanFileFromBuffer().

+ Here is the call graph for this function:

◆ scanFile()

ilVirusScanner::scanFile ( string  $file_path,
string  $org_name = "" 
)

Reimplemented in ilVirusScannerAntiVir, ilVirusScannerClamAV, ilVirusScannerICapClient, ilVirusScannerICapRemoteAvClient, and ilVirusScannerSophos.

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

132 : string
133 {
134 $this->scanFilePath = $file_path;
135 $this->scanFileOrigName = $org_name;
136
137 if ($org_name === "infected.txt" || $org_name === "cleanable.txt") {
138 $this->scanFileIsInfected = true;
139 $this->scanResult =
140 "FILE INFECTED: [" . $file_path . "] (VIRUS: simulated)";
141 $this->logScanResult();
142 return $this->scanResult;
143 }
144
145 $this->scanFileIsInfected = false;
146 $this->scanResult = "";
147 return "";
148 }

References $scanResult, and logScanResult().

Referenced by scanFileFromBuffer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ scanFileFromBuffer()

ilVirusScanner::scanFileFromBuffer ( string  $buffer)
protected

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

117 : bool
118 {
119 $bufferFile = $this->createBufferFile($buffer);
120 $infection = $this->scanFile($bufferFile);
121 $this->removeBufferFile($bufferFile);
122 return $infection !== '';
123 }
createBufferFile(string $buffer)
scanFile(string $file_path, string $org_name="")
removeBufferFile(string $bufferFile)

References createBufferFile(), removeBufferFile(), and scanFile().

Referenced by scanBuffer(), and ilVirusScannerClamAV\scanBuffer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ virusHandling()

static ilVirusScanner::virusHandling ( string  $a_file,
string  $a_orig_name = '',
bool  $a_clean = true 
)
static
Parameters
string$a_file
string$a_orig_name
bool$a_clean
Returns
array{0: bool, 1: string}

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

76 : array
77 {
78 global $DIC;
79
80 $lng = $DIC->language();
81
82 if ((defined('IL_VIRUS_SCANNER') && IL_VIRUS_SCANNER !== 'None') || (defined(
83 'IL_ICAP_HOST'
84 ) && IL_ICAP_HOST !== '')) {
86 if (($vs_txt = $vs->scanFile($a_file, $a_orig_name)) !== '') {
87 if ($a_clean && defined('IL_VIRUS_CLEAN_COMMAND') && IL_VIRUS_CLEAN_COMMAND !== '') {
88 $clean_txt = $vs->cleanFile($a_file, $a_orig_name);
89 if ($vs->fileCleaned()) {
90 $vs_txt .= '<br />' . $lng->txt('cleaned_file') . '<br />' . $clean_txt;
91 $vs_txt .= '<br />' . $lng->txt('repeat_scan');
92 if (($vs2_txt = $vs->scanFile($a_file, $a_orig_name)) !== '') {
93 return [
94 false,
95 nl2br($vs_txt) . '<br />' . $lng->txt('repeat_scan_failed') . '<br />' . nl2br($vs2_txt)
96 ];
97 }
98
99 return [true, nl2br($vs_txt) . '<br />' . $lng->txt('repeat_scan_succeded')];
100 }
101
102 return [false, nl2br($vs_txt) . '<br />' . $lng->txt('cleaning_failed')];
103 }
104
105 return [false, nl2br($vs_txt)];
106 }
107 }
108
109 return [true, ''];
110 }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...

References $DIC, $lng, ilVirusScannerFactory\_getInstance(), and ilLanguage\txt().

Referenced by ilUploadFiles\_copyUploadFile(), ilImageWizardInputGUI\checkInput(), ilMatchingWizardInputGUI\checkInput(), ilMultipleChoiceWizardInputGUI\checkInput(), ilSingleChoiceWizardInputGUI\checkInput(), ilImagemapFileInputGUI\checkInput(), ilFileInputGUI\checkInput(), ilFileWizardInputGUI\checkInput(), assFileUpload\checkUpload(), ilKprimChoiceWizardInputGUI\checkUploads(), ilObjMediaPoolGUI\createMediaFromUploadDir(), and ilMultipleImagesInputGUI\onCheckInput().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $cleanCommand

string ilVirusScanner::$cleanCommand

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

◆ $cleanFileIsCleaned

bool ilVirusScanner::$cleanFileIsCleaned

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

Referenced by fileCleaned().

◆ $cleanFileOrigName

string ilVirusScanner::$cleanFileOrigName

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

◆ $cleanFilePath

string ilVirusScanner::$cleanFilePath

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

◆ $cleanResult

string ilVirusScanner::$cleanResult

◆ $error

ilErrorHandling ilVirusScanner::$error

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

Referenced by __construct().

◆ $lng

ilLanguage ilVirusScanner::$lng

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

Referenced by __construct(), and virusHandling().

◆ $log

ilLogger ilVirusScanner::$log

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

Referenced by __construct().

◆ $scanCommand

string ilVirusScanner::$scanCommand

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

◆ $scanFileIsInfected

bool ilVirusScanner::$scanFileIsInfected

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

◆ $scanFileOrigName

string ilVirusScanner::$scanFileOrigName

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

◆ $scanFilePath

string ilVirusScanner::$scanFilePath

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

◆ $scanResult

◆ $scanZipFiles

bool ilVirusScanner::$scanZipFiles

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

Referenced by getScanZipFiles().

◆ $type

string ilVirusScanner::$type

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

Referenced by ilVirusScannerICapRemote\getRequest().


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