Skip to content

Commit

Permalink
send empty quarantine reports over user_manager; fixes 1054
Browse files Browse the repository at this point in the history
  • Loading branch information
Skywalker-11 authored and endelwar committed Apr 18, 2018
1 parent 0e310c2 commit f3c5c94
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 24 deletions.
1 change: 1 addition & 0 deletions mailscanner/languages/de.php
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,7 @@
'message61' => 'Die Variable %s ist leer, bitte setzen Sie einen Wert in conf.php.',
'text611' => 'Quarantäne-Bericht für %s',
'text612' => 'In den letzten %s Tagen wurden %s empfangene E-Mails in die Quarantäne verschoben, die unten aufgeführt sind. Alle Nachrichten in der Quarantäne werden automatisch nach %s Tagen nach deren Empfang gelöscht.',
'text613' => 'In den letzten %s Tagen wurden keine empfangene E-Mails in die Quarantäne verschoben.',
'release61' => 'Freigabe',
'virus61' => 'Virus',
'badcontent61' => 'Schlechter Inhalt',
Expand Down
1 change: 1 addition & 0 deletions mailscanner/languages/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,7 @@
'message61' => 'The variable %s is empty, please set a value in conf.php.',
'text611' => 'Quarantine Report for %s',
'text612' => 'In the last %s day(s) you have received %s e-mails that have been quarantined and are listed below. All messages in the quarantine are automatically deleted %s days after the date that they were received.',
'text613' => 'In the last %s day(s) you have received no e-mails that have been quarantined.',
'release61' => 'Release',
'virus61' => 'Virus',
'badcontent61' => 'Bad Content',
Expand Down
1 change: 1 addition & 0 deletions mailscanner/languages/fr.php
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,7 @@
'message61' => 'La variable %s est vide. Veuillez définir cette variable dans conf.php.',
'text611' => 'Rapport de Quarantaine pour %s',
'text612' => 'Durant le(s) %s dernier(s) jour(s) vous avez reçu %s messages qui ont été mis en Quarantaine et dont vous retrouverez la liste ci-dessous. Les messages en Quarantaine sont automatiquement effacés %s jours après la date à laquelle ils ont été reçus.',
'text613' => 'In the last %s day(s) you have received no e-mails that have been quarantined.',
'release61' => 'Libérer',
'virus61' => 'Virus',
'badcontent61' => 'Contenu dangereux',
Expand Down
1 change: 1 addition & 0 deletions mailscanner/languages/it.php
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,7 @@
'message61' => 'The variable %s is empty, please set a value in conf.php.',
'text611' => 'Quarantine Report for %s',
'text612' => 'In the last %s day(s) you have received %s e-mails that have been quarantined and are listed below. All messages in the quarantine are automatically deleted %s days after the date that they were received.',
'text613' => 'In the last %s day(s) you have received no e-mails that have been quarantined.',
'release61' => 'Release',
'virus61' => 'Virus',
'badcontent61' => 'Bad Content',
Expand Down
1 change: 1 addition & 0 deletions mailscanner/languages/ja.php
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@
'message61' => '変数 %s は空です。conf.php に値を設定してください。',
'text611' => '%sの検疫レポート',
'text612' => '最後の %s 日に隔離されたメールを受信しました。そのメールは以下のとおりです。隔離されたすべてのメールは、受信日から %s 日後に自動的に削除されます。 ',
'text613' => 'In the last %s day(s) you have received no e-mails that have been quarantined.',
'release61' => 'リリース',
'virus61' => 'ウイルス',
'badcontent61' => '悪いコンテンツ',
Expand Down
1 change: 1 addition & 0 deletions mailscanner/languages/nl.php
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,7 @@
'message61' => 'The variable %s is empty, please set a value in conf.php.',
'text611' => 'Quarantine Report for %s',
'text612' => 'In the last %s day(s) you have received %s e-mails that have been quarantined and are listed below. All messages in the quarantine are automatically deleted %s days after the date that they were received.',
'text613' => 'In the last %s day(s) you have received no e-mails that have been quarantined.',
'release61' => 'Release',
'virus61' => 'Virus',
'badcontent61' => 'Bad Content',
Expand Down
1 change: 1 addition & 0 deletions mailscanner/languages/pt_br.php
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,7 @@
'message61' => 'The variable %s is empty, please set a value in conf.php.',
'text611' => 'Quarantine Report for %s',
'text612' => 'In the last %s day(s) you have received %s e-mails that have been quarantined and are listed below. All messages in the quarantine are automatically deleted %s days after the date that they were received.',
'text613' => 'In the last %s day(s) you have received no e-mails that have been quarantined.',
'release61' => 'Release',
'virus61' => 'Virus',
'badcontent61' => 'Bad Content',
Expand Down
64 changes: 44 additions & 20 deletions mailscanner/quarantine_report.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static function check_quarantine_report_requirements()
return $required_constant_missing;
}

private static function get_html_template()
private static function get_html_template($empty=false)
{
return '<!DOCTYPE html>
<html>
Expand All @@ -84,12 +84,14 @@ private static function get_html_template()
<td><img src="' . MW_LOGO . '"/></td>
<td align="center" valign="middle">
<h2>' . __('text611') . '</h2>
' . __('text612') . '
' . ($empty ? __('text613') : __('text612')) . '
</td>
</tr>
'. ($empty ? '' : '
<tr>
<td colspan="2">%s</td>
</tr>
') . '
</table>
</body>
</html>';
Expand Down Expand Up @@ -126,6 +128,10 @@ private static function get_html_table()
%s';

private static $text_template_empty = 'Quarantine Report for %s
In the last %s day(s) you have received no e-mails that have been quarantined.';


private static $text_content = 'Received: %s
From: %s
Expand Down Expand Up @@ -245,7 +251,7 @@ private static function get_report_sql()
* @param array $usersForReport array containing users for which the reports should be send; if empty reports are send for all users
* @return false|array if requirements not met; else an associative array counting successfull and failed reports for users
*/
public function send_quarantine_reports($usersForReport = array())
public function send_quarantine_reports($usersForReport = array(), $sendEmptyReports = false)
{
if (self::check_quarantine_report_requirements() !== true) {
return false;
Expand Down Expand Up @@ -278,6 +284,7 @@ public function send_quarantine_reports($usersForReport = array())
$rows = $result->num_rows;
$num_successfull_reports = 0;
$num_failed_reports = 0;
$num_empty_reports = 0;
if ($rows > 0) {
while ($user = $result->fetch_object()) {
self::dbg("\n === Generating report for " . stripslashes($user->username) . ' type=' . $user->type);
Expand Down Expand Up @@ -312,8 +319,10 @@ public function send_quarantine_reports($usersForReport = array())
}
// Make sure we have a destination address
if (!empty($email) && false !== $email) {
$sendResult = self::send_reports_for_user($user->username, $user->type, $email, $to_address, $to_domain);
if ($sendResult) {
$sendResult = self::send_reports_for_user($user->username, $user->type, $email, $to_address, $to_domain, $sendEmptyReports);
if ($sendResult === 0) {
$num_empty_reports++;
} elseif ($sendResult) {
$num_successfull_reports++;
} else {
$num_failed_reports++;
Expand All @@ -322,11 +331,14 @@ public function send_quarantine_reports($usersForReport = array())
self::dbg(' ==== ' . $user->username . ' has empty e-mail recipient address, skipping...');
}
}
} else {
return -2;
}

return array(
'succ' => $num_successfull_reports,
'failed' => $num_failed_reports
'failed' => $num_failed_reports,
'empty' => $num_empty_reports
);
}

Expand All @@ -338,7 +350,7 @@ public function send_quarantine_reports($usersForReport = array())
* @param string $to_domain
* @return true if all reports were send successfully; false if one or more reports could not be send
*/
private static function send_reports_for_user($username, $type, $email, $to_address, $to_domain)
private static function send_reports_for_user($username, $type, $email, $to_address, $to_domain, $sendEmptyReports = false)
{
self::dbg(" ==== Recipient e-mail address is $email");
// Get any additional reports required
Expand All @@ -358,7 +370,7 @@ private static function send_reports_for_user($username, $type, $email, $to_addr
$quarantined = self::return_quarantine_list_array($filter, $filter_domain);

self::dbg(' ==== Found ' . count($quarantined) . ' quarantined e-mails');
if (count($quarantined) > 0) {
if (count($quarantined) > 0 || $sendEmptyReports) {
$sendResult = self::send_quarantine_email($email, $list_for, $quarantined);
}
unset($quarantined);
Expand Down Expand Up @@ -389,10 +401,14 @@ private static function send_reports_for_user($username, $type, $email, $to_addr
$quarantined[] = $tmp_quarantined;
}
}
$quarantined = call_user_func_array('array_merge', $quarantined);
if (count($quarantined) > 0) {
$quarantined = call_user_func_array('array_merge', $quarantined);
}
if (count($quarantined) > 0 || $sendEmptyReports) {
$list = implode(', ', $quarantine_list);
return self::send_quarantine_email($email, $list, self::quarantine_sort($quarantined));
} else {
return 0;
}
unset($quarantined, $quarantine_list);

Expand Down Expand Up @@ -558,18 +574,26 @@ private static function send_quarantine_email($email, $filter, $quarantined)
$qitem['reason']
);
}
if (count($quarantined) > 0) {
// HTML
$h2 = sprintf(self::get_html_table(), $h1);
$html_report = sprintf(self::get_html_template(), $filter, QUARANTINE_REPORT_DAYS, count($quarantined), QUARANTINE_DAYS_TO_KEEP, $h2);
if (DEBUG === true) {
echo '<pre>' . $html_report . '</pre>';
}

// HTML
$h2 = sprintf(self::get_html_table(), $h1);
$html_report = sprintf(self::get_html_template(), $filter, QUARANTINE_REPORT_DAYS, count($quarantined), QUARANTINE_DAYS_TO_KEEP, $h2);
if (DEBUG === true) {
echo '<pre>' . $html_report . '</pre>';
}

// Text
$text_report = sprintf(self::$text_template, $filter, QUARANTINE_REPORT_DAYS, count($quarantined), QUARANTINE_DAYS_TO_KEEP, $t1);
if (DEBUG === true) {
echo "<pre>$text_report</pre>\n";
// Text
$text_report = sprintf(self::$text_template, $filter, QUARANTINE_REPORT_DAYS, count($quarantined), QUARANTINE_DAYS_TO_KEEP, $t1);
if (DEBUG === true) {
echo "<pre>$text_report</pre>\n";
}
} else {
$html_report = sprintf(self::get_html_template(true), $filter, QUARANTINE_REPORT_DAYS);
$text_report = sprintf(self::$text_template_empty, $filter, QUARANTINE_REPORT_DAYS);
if (DEBUG === true) {
echo "<pre>$html_report</pre>\n";
echo "<pre>$text_report</pre>\n";
}
}

// Send e-mail
Expand Down
10 changes: 6 additions & 4 deletions mailscanner/user_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,11 +504,13 @@ function sendReport()
}

$quarantine_report = new Quarantine_Report();
$reportResult = $quarantine_report->send_quarantine_reports(array($user->username));
if ($reportResult['succ'] >= 0) {
$reportResult = $quarantine_report->send_quarantine_reports(array($user->username), true);
if ($reportResult == -2) {
return getHtmlMessage(__('noReportsEnabled12'), 'error');
} elseif ($reportResult['succ'] > 0) {
return getHtmlMessage(__('quarantineReportSend12'), 'success');
} else {
return getHtmlMessage(__('quarantineReportFailed12'), 'success');
return getHtmlMessage(__('quarantineReportFailed12'), 'error');
}
}

Expand Down Expand Up @@ -769,7 +771,7 @@ function logout_user(id, name) {
if ($requirementsCheck !== true) {
echo getHtmlMessage(__('checkReportRequirementsFailed12'), 'error');
error_log('Requirements for sending quarantine reports not met: ' . $requirementsCheck);
} elseif (!isset($_POST['quarantine_report'])) {
} elseif (!isset($_POST['quarantine_report']) || $_POST['quarantine_report'] !== 'on') {
echo getHtmlMessage(__('noReportsEnabled12'), 'error');
} else {
$quarantine_report = new Quarantine_Report();
Expand Down

0 comments on commit f3c5c94

Please sign in to comment.