ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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: shib_login.php:26

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 163 of file class.ilVirusScanner.php.

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

References $cleanResult, and logCleanResult().

+ Here is the call graph for this function:

◆ createBufferFile()

ilVirusScanner::createBufferFile ( string  $buffer)
protected

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

122 : string
123 {
124 $bufferFile = ilFileUtils::ilTempnam();
125 file_put_contents($bufferFile, $buffer);
126 return $bufferFile;
127 }
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 194 of file class.ilVirusScanner.php.

194 : bool
195 {
197 }

References $cleanFileIsCleaned.

◆ getCleanMessage()

ilVirusScanner::getCleanMessage ( )

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

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

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getCleanResult()

ilVirusScanner::getCleanResult ( )

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

204 : string
205 {
206 return $this->cleanResult;
207 }

References $cleanResult.

◆ getScanMessage()

ilVirusScanner::getScanMessage ( )

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

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

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getScanResult()

ilVirusScanner::getScanResult ( )

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

199 : string
200 {
201 return $this->scanResult;
202 }

References $scanResult.

◆ getScanZipFiles()

ilVirusScanner::getScanZipFiles ( )

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

249 : bool
250 {
251 return $this->scanZipFiles;
252 }

References $scanZipFiles.

◆ logCleanResult()

ilVirusScanner::logCleanResult ( )

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

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

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

+ Here is the caller graph for this function:

◆ logScanResult()

ilVirusScanner::logScanResult ( )

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

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

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 158 of file class.ilVirusScanner.php.

158 : void
159 {
160 unlink($bufferFile);
161 }

Referenced by scanFileFromBuffer().

+ Here is the caller graph for this function:

◆ scanBuffer()

ilVirusScanner::scanBuffer ( string  $buffer)

Reimplemented in ilVirusScannerClamAV.

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

109 : bool
110 {
111 return $this->scanFileFromBuffer($buffer);
112 }
scanFileFromBuffer(string $buffer)

References scanFileFromBuffer().

+ Here is the call graph for this function:

◆ scanFile()

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

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

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

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

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 114 of file class.ilVirusScanner.php.

114 : bool
115 {
116 $bufferFile = $this->createBufferFile($buffer);
117 $infection = $this->scanFile($bufferFile);
118 $this->removeBufferFile($bufferFile);
119 return $infection !== '';
120 }
scanFile(string $file_path, string $org_name='')
createBufferFile(string $buffer)
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
Returns
array{0: bool, 1: string}

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

73 : array
74 {
75 global $DIC;
76
77 $lng = $DIC->language();
78
79 if ((defined('IL_VIRUS_SCANNER') && IL_VIRUS_SCANNER !== 'None') || (defined(
80 'IL_ICAP_HOST'
81 ) && IL_ICAP_HOST !== '')) {
83 if (($vs_txt = $vs->scanFile($a_file, $a_orig_name)) !== '') {
84 if ($a_clean && defined('IL_VIRUS_CLEAN_COMMAND') && IL_VIRUS_CLEAN_COMMAND !== '') {
85 $clean_txt = $vs->cleanFile($a_file, $a_orig_name);
86 if ($vs->fileCleaned()) {
87 $vs_txt .= '<br />' . $lng->txt('cleaned_file') . '<br />' . $clean_txt;
88 $vs_txt .= '<br />' . $lng->txt('repeat_scan');
89 if (($vs2_txt = $vs->scanFile($a_file, $a_orig_name)) !== '') {
90 return [
91 false,
92 nl2br($vs_txt) . '<br />' . $lng->txt('repeat_scan_failed') . '<br />' . nl2br($vs2_txt)
93 ];
94 }
95
96 return [true, nl2br($vs_txt) . '<br />' . $lng->txt('repeat_scan_succeded')];
97 }
98
99 return [false, nl2br($vs_txt) . '<br />' . $lng->txt('cleaning_failed')];
100 }
101
102 return [false, nl2br($vs_txt)];
103 }
104 }
105
106 return [true, ''];
107 }
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(), ilFileInputGUI\checkInput(), ilFileWizardInputGUI\checkInput(), ilMatchingWizardInputGUI\checkInput(), ilMultipleChoiceWizardInputGUI\checkInput(), ilSingleChoiceWizardInputGUI\checkInput(), ilImagemapFileInputGUI\checkInput(), ilKprimChoiceWizardInputGUI\checkUploads(), 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: