19 declare(strict_types=1);
53 public function __construct(
string $scan_command,
string $clean_command)
56 $error = $DIC[
'ilErr'];
57 $lng = $DIC->language();
58 $log = $DIC->logger()->root();
63 $this->scanCommand = $scan_command;
64 $this->cleanCommand = $clean_command;
66 $this->type =
'simulate';
67 $this->scanZipFiles =
false;
73 public static function virusHandling(
string $a_file,
string $a_orig_name =
'',
bool $a_clean =
true): array
77 $lng = $DIC->language();
79 if ((defined(
'IL_VIRUS_SCANNER') && IL_VIRUS_SCANNER !==
'None') || (defined(
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)) !==
'') {
92 nl2br($vs_txt) .
'<br />' . $lng->
txt(
'repeat_scan_failed') .
'<br />' . nl2br($vs2_txt)
96 return [
true, nl2br($vs_txt) .
'<br />' . $lng->
txt(
'repeat_scan_succeded')];
99 return [
false, nl2br($vs_txt) .
'<br />' . $lng->
txt(
'cleaning_failed')];
102 return [
false, nl2br($vs_txt)];
117 $infection = $this->
scanFile($bufferFile);
119 return $infection !==
'';
125 file_put_contents($bufferFile, $buffer);
129 public function scanFile(
string $file_path,
string $org_name =
''): string
131 $this->scanFilePath = $file_path;
132 $this->scanFileOrigName = $org_name;
134 if ($org_name ===
'infected.txt' || $org_name ===
'cleanable.txt') {
135 $this->scanFileIsInfected =
true;
137 'FILE INFECTED: [' . $file_path .
'] (VIRUS: simulated)';
142 $this->scanFileIsInfected =
false;
143 $this->scanResult =
'';
149 $mess =
'Virus Scanner (' . $this->type .
')';
150 if ($this->scanFileOrigName) {
151 $mess .=
' (File ' . $this->scanFileOrigName .
')';
153 $mess .=
': ' . preg_replace(
'/[\r\n]+/',
'; ', $this->scanResult);
155 $this->log->write($mess);
163 public function cleanFile(
string $file_path,
string $org_name =
''): string
165 $this->cleanFilePath = $file_path;
166 $this->cleanFileOrigName = $org_name;
168 if ($org_name ===
'cleanable.txt') {
169 $this->cleanFileIsCleaned =
true;
171 'FILE CLEANED: [' . $file_path .
'] (VIRUS: simulated)';
176 $this->cleanFileIsCleaned =
false;
178 'FILE NOT CLEANED: [' . $file_path .
'] (VIRUS: simulated)';
185 $mess =
'Virus Cleaner (' . $this->type .
')';
186 if ($this->cleanFileOrigName) {
187 $mess .=
' (File ' . $this->cleanFileOrigName .
')';
189 $mess .=
': ' . preg_replace(
'/[\r\n]+/',
'; ', $this->cleanResult);
191 $this->log->write($mess);
211 if ($this->scanFileIsInfected) {
217 if ($this->scanResult) {
218 $ret .=
' ' . $this->
lng->txt(
'virus_scan_message')
222 $this->scanFileOrigName,
223 nl2br($this->scanResult)
231 if ($this->cleanFileIsCleaned) {
237 if ($this->cleanResult) {
238 $ret .=
' ' . $this->
lng->txt(
'virus_clean_message')
241 $this->cleanFilePath,
242 $this->cleanFileOrigName,
243 nl2br($this->cleanResult)
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...
static virusHandling(string $a_file, string $a_orig_name='', bool $a_clean=true)
removeBufferFile(string $bufferFile)
cleanFile(string $file_path, string $org_name='')
__construct(string $scan_command, string $clean_command)
scanBuffer(string $buffer)
scanFileFromBuffer(string $buffer)
scanFile(string $file_path, string $org_name='')
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
createBufferFile(string $buffer)
string $cleanFileOrigName