Skip to content

Commit

Permalink
Added infectedAction option 'Mark and log', which marks (renames) 'in…
Browse files Browse the repository at this point in the history
…fected' files. This patch can easily used to move 'infected' files into a quarantain folder. Translations are incomplete.

Signed-off-by: tx0h <tx0h@icf.de>
  • Loading branch information
thomax authored and tx0h committed Oct 19, 2023
1 parent 55cf56a commit eada776
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions l10n/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ OC.L10N.register(
"When infected files are found during a background scan" : "Wenn infizierte Dateien während eines Hintergrund-Scans gefunden werden",
"Only log" : "Nur loggen",
"Delete file" : "Datei löschen",
"Mark and log" : "Markieren und loggen",
"Save" : "Speichern",
"Advanced" : "Erweitert",
"Rules" : "Regeln",
Expand Down
3 changes: 2 additions & 1 deletion l10n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"When infected files are found during a background scan" : "Wenn infizierte Dateien während eines Hintergrund-Scans gefunden werden",
"Only log" : "Nur loggen",
"Delete file" : "Datei löschen",
"Mark and log" : "Markieren und loggen",
"Save" : "Speichern",
"Advanced" : "Erweitert",
"Rules" : "Regeln",
Expand All @@ -61,4 +62,4 @@
"Mark as" : "Markieren als",
"Add a rule" : "Eine Regel hinzufügen"
},"pluralForm" :"nplurals=2; plural=(n != 1);"
}
}
1 change: 1 addition & 0 deletions l10n/de_DE.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ OC.L10N.register(
"When infected files are found during a background scan" : "Wenn infizierte Dateien während eines Hintergrund-Scans gefunden werden",
"Only log" : "Nur protokollieren",
"Delete file" : "Datei löschen",
"Mark and log" : "Markieren und loggen",
"Save" : "Speichern",
"Advanced" : "Erweitert",
"Rules" : "Regeln",
Expand Down
3 changes: 2 additions & 1 deletion l10n/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"When infected files are found during a background scan" : "Wenn infizierte Dateien während eines Hintergrund-Scans gefunden werden",
"Only log" : "Nur protokollieren",
"Delete file" : "Datei löschen",
"Mark and log" : "Markieren und loggen",
"Save" : "Speichern",
"Advanced" : "Erweitert",
"Rules" : "Regeln",
Expand All @@ -62,4 +63,4 @@
"Mark as" : "Markieren als",
"Add a rule" : "Eine Regel hinzufügen"
},"pluralForm" :"nplurals=2; plural=(n != 1);"
}
}
1 change: 1 addition & 0 deletions l10n/en_GB.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ OC.L10N.register(
"When infected files are found during a background scan" : "When infected files are found during a background scan",
"Only log" : "Only log",
"Delete file" : "Delete file",
"Mark and log" : "Mark and log",
"Save" : "Save",
"Advanced" : "Advanced",
"Rules" : "Rules",
Expand Down
3 changes: 2 additions & 1 deletion l10n/en_GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"When infected files are found during a background scan" : "When infected files are found during a background scan",
"Only log" : "Only log",
"Delete file" : "Delete file",
"Mark and log" : "Mark and log",
"Save" : "Save",
"Advanced" : "Advanced",
"Rules" : "Rules",
Expand All @@ -62,4 +63,4 @@
"Mark as" : "Mark as",
"Add a rule" : "Add a rule"
},"pluralForm" :"nplurals=2; plural=(n != 1);"
}
}
20 changes: 19 additions & 1 deletion lib/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ public function processInfected(Status $status): void {
$infectedAction = $this->config->getAvInfectedAction();

$shouldDelete = $infectedAction === 'delete';
$shouldMarkAndLog = $infectedAction === 'mark_and_log';

$message = $shouldDelete ? Provider::MESSAGE_FILE_DELETED : '';
$message = $shouldMarkAndLog ? 'Infected file marked and logged' : '';

$userFolder = $this->rootFolder->getUserFolder($this->file->getOwner()->getUID());
$path = $userFolder->getRelativePath($this->file->getPath());
Expand All @@ -107,7 +109,6 @@ public function processInfected(Status $status): void {
->setAffectedUser($this->file->getOwner()->getUID())
->setType(Provider::TYPE_VIRUS_DETECTED);
$this->activityManager->publish($activity);

if ($shouldDelete) {
if ($this->isCron) {
$msg = 'Infected file deleted (during background scan)';
Expand All @@ -116,6 +117,16 @@ public function processInfected(Status $status): void {
}
$this->logError($msg . ' ' . $status->getDetails());
$this->deleteFile();
} else if ($shouldMarkAndLog) {
if ($this->isCron) {
$msg = 'Infected file found (during background scan)';
} else {
$msg = 'Infected file found.';
}
$this->logError('mark and log');
$this->logError($msg . ' ' . $status->getDetails());
$this->markFile();
$this->updateCheckTime($this->clock->getTime());
} else {
if ($this->isCron) {
$msg = 'Infected file found (during background scan)';
Expand Down Expand Up @@ -222,6 +233,13 @@ private function deleteFile(): void {
}
}

/**
* * Mark infected file
*/
private function markFile(): void {
$this->file->move($this->file->getPath() . " [\u{2623} VIRUS DETECTED \u{2620}]");
}

private function generateExtraInfo(): string {
$owner = $this->file->getOwner();

Expand Down
2 changes: 1 addition & 1 deletion templates/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
</tr>
<tr class="infected_action">
<td><label for="av_infected_action"><?php p($l->t('When infected files are found during a background scan'));?></label></td>
<td><select id="av_infected_action" name="avInfectedAction"><?php print_unescaped(html_select_options(['only_log' => $l->t('Only log'), 'delete' => $l->t('Delete file')], $_['avInfectedAction'])) ?></select></td>
<td><select id="av_infected_action" name="avInfectedAction"><?php print_unescaped(html_select_options(['only_log' => $l->t('Only log'), 'delete' => $l->t('Delete file'), 'mark_and_log' => $l->t('Mark and log')], $_['avInfectedAction'])) ?></select></td>
<td></td>
</tr>
</table>
Expand Down

0 comments on commit eada776

Please sign in to comment.