fix: Validate email addresses used in alerting (#7830)

* fix: Validate email addresses used in alerting

* Whitespace
This commit is contained in:
Neil Lathwood
2017-12-01 05:27:04 +00:00
committed by Tony Murray
parent e3082873f6
commit edf26c1106

View File

@@ -233,6 +233,7 @@ function RunRules($device)
function GetContacts($results) function GetContacts($results)
{ {
global $config, $authorizer; global $config, $authorizer;
if (sizeof($results) == 0) { if (sizeof($results) == 0) {
return array(); return array();
} }
@@ -306,6 +307,16 @@ function GetContacts($results)
} }
} }
if (!empty($tmp_contacts)) {
// Validate contacts so we can fall back to default if configured.
$mail = new PHPMailer();
foreach ($tmp_contacts as $tmp_email => $tmp_name) {
if ($mail->validateAddress($tmp_email) != true) {
unset($tmp_contacts[$tmp_email]);
}
}
}
# Send email to default contact if no other contact found # Send email to default contact if no other contact found
if ((count($tmp_contacts) == 0) && ($config['alert']['default_if_none']) && (!empty($config['alert']['default_mail']))) { if ((count($tmp_contacts) == 0) && ($config['alert']['default_if_none']) && (!empty($config['alert']['default_mail']))) {
$tmp_contacts[$config['alert']['default_mail']] = 'NOC'; $tmp_contacts[$config['alert']['default_mail']] = 'NOC';