Added error control and email handler

This commit is contained in:
Arturo Gonzalez 2017-04-19 16:04:24 +02:00
parent bd30625532
commit 48f7fa50dd
4 changed files with 104 additions and 13 deletions

View File

@ -267,22 +267,42 @@ echo '<div id="ver_num">'.$pandora_version.(($develop_bypass == 1) ? ' '.__('Bui
echo '</div>';
if ($mail != "") {
echo '<div id="reset_correct" title="' . __('Password reset') . '">';
echo '<div class="content_alert">';
echo '<div class="icon_message_alert">';
echo html_print_image('images/icono_logo_pandora.png', true, array("alt" => __('Password reset'), "border" => 0));
echo '</div>';
echo '<div class="content_message_alert">';
echo '<div class="text_message_alert">';
echo '<h1>' . __('INFO') . '</h1>';
echo '<p>' . __('An email has been sent to the user\'s address') . '</p>';
if ($email_error_message == '') {
echo '<div id="reset_correct" title="' . __('Password reset') . '">';
echo '<div class="content_alert">';
echo '<div class="icon_message_alert">';
echo html_print_image('images/icono_logo_pandora.png', true, array("alt" => __('Password reset'), "border" => 0));
echo '</div>';
echo '<div class="button_message_alert">';
html_print_submit_button("Ok", 'reset_correct_button', false);
echo '<div class="content_message_alert">';
echo '<div class="text_message_alert">';
echo '<h1>' . __('INFO') . '</h1>';
echo '<p>' . __('An email has been sent to the user\'s address') . '</p>';
echo '</div>';
echo '<div class="button_message_alert">';
html_print_submit_button("Ok", 'reset_correct_button', false);
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div>';
}
else {
echo '<div id="reset_correct" title="' . __('Password reset') . '">';
echo '<div class="content_alert">';
echo '<div class="icon_message_alert">';
echo html_print_image('images/icono_stop.png', true, array("alt" => __('Password reset'), "border" => 0));
echo '</div>';
echo '<div class="content_message_alert">';
echo '<div class="text_message_alert">';
echo '<h1>' . __('ERROR') . '</h1>';
echo '<p>' . $email_error_message . '</p>';
echo '</div>';
echo '<div class="button_message_alert">';
html_print_submit_button("Ok", 'reset_correct_button', false);
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div>';
}
}
if (isset ($login_failed)) {

View File

@ -0,0 +1,20 @@
<?php
// ______ __ _______ _______ _______
//| __ \.---.-.-----.--| |.-----.----.---.-. | ___| | | __|
//| __/| _ | | _ || _ | _| _ | | ___| |__ |
//|___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
//
// ============================================================================
// Copyright (c) 2007-2010 Artica Soluciones Tecnologicas, http://www.artica.es
// This code is NOT free software. This code is NOT licenced under GPL2 licence
// You cannnot redistribute it without written permission of copyright holder.
// ============================================================================
//Please setup your config to send emails
$email_from = array('pandora@pandorafms.org' => 'Pandora FMS');
$email_smtpServer = '127.0.0.1';
$email_smtpPort = 25;
$email_username = '';
$email_password = '';
?>

View File

@ -2730,4 +2730,38 @@ function remove_right_zeros ($value) {
return $value;
}
}
function send_email_to_user ($to, $body, $subject) {
global $config;
require_once($config['homedir'] . '/include/swiftmailer/swift_required.php');
require_once($config['homedir'] . '/include/email_config_user.php');
$result = false;
try {
$transport = Swift_SmtpTransport::newInstance($email_smtpServer, $email_smtpPort);
$transport->setUsername($email_username);
$transport->setPassword($email_password);
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance($subject);
$message->setFrom($email_from);
$to = trim($to);
$message->setTo(array($to => $to));
$message->setBody($body, 'text/html');
ini_restore ('sendmail_from');
html_debug("AAAA", true);
$result = $mailer->send($message);
}
catch (Exception $e) {
error_log($e->getMessage());
db_pandora_audit("Pandora mail", $e->getMessage());
html_debug($e->getMessage(), true);
}
return $result;
}
?>

View File

@ -592,7 +592,24 @@ if (! isset ($config['id_user'])) {
require_once ('general/reset_pass.php');
}
else {
// MANDAR CORREO ELECTRÓNICO AL USUARIO Y VOLVER A LA PÁGINA DE INICIO
$subject = '[Pandora] '.__('Reset password');
$body = __('This is the automatic message');
$body .= ' "<strong>' . $user_reset_pass . '"</strong>';
$body .= '<p />';
$body .= __('Please, click in the link below to reset your password');
$body .= '<p />';
$body .= '<a href="">' . __('Reset your password') . '</a>';
$body .= '<p />';
$body .= 'Pandora FMS';
$body .= '<p />';
$body .= '<em>'.__('Please do not answer or reply to this email').'</em>';
$result = send_email_to_user($mail, $body, $subject);
$email_error_message = "";
if (!$result) {
$email_error_message = __('Error at sending the email');
}
require_once ('general/login_page.php');
}