From c208597ce1987cfce335ac9d06d68d30b9c3595b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Carretero?= <frederic.carretero@veremes.com> Date: Fri, 30 Nov 2018 16:46:28 +0100 Subject: [PATCH] =?UTF-8?q?Demande=20de=20Licence=20:=20message=20si=20le?= =?UTF-8?q?=20serveur=20SMTP=20n'est=20pas=20configur=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/module_gtf/module/lang/lang-en.json | 3 +- src/module_gtf/module/lang/lang-fr.json | 3 +- .../web_service/ws/License.class.inc | 128 ++++++++++-------- 3 files changed, 78 insertions(+), 56 deletions(-) diff --git a/src/module_gtf/module/lang/lang-en.json b/src/module_gtf/module/lang/lang-en.json index 7adda049..7f928e10 100755 --- a/src/module_gtf/module/lang/lang-en.json +++ b/src/module_gtf/module/lang/lang-en.json @@ -433,6 +433,7 @@ "SEND_MAIL_SUCCESS_CONFIGURATION_CONFIGURATION_GTF_LICENSE" : "Mail sent successfully", "LICENSE_FILE_INSTALL_ERROR_CONFIGURATION_CONFIGURATION_GTF_LICENSE" : "Error while installing the license file.", "LICENSE_FILE_INSTALL_SUCCESS_CONFIGURATION_CONFIGURATION_GTF_LICENSE" : "License file successfully installed", + "SMTP_SERVER_PARAMETERS_CONFIGURATION_CONFIGURATION_GTF_LICENSE" : "Please enter the settings of your SMTP server", "" : "", "FORM_NAME_ENGINE_GTF_ENGINE" : "Name", "FORM_SERVER_ENGINE_GTF_ENGINE" : "Server", @@ -502,4 +503,4 @@ "FORM_WIDGET_NOTIFICATIONS_OPTIONAL_PUBLICATION_WORKSPACE_EDIT_WIDGET" : "Email (Optional)", "EXPIRED_WIDGET_TOKEN_ERROR_TITLE": "Session timed out", "INVALID_WIDGET_TOKEN_ERROR_TITLE": "Invalid Session" -} \ No newline at end of file +} diff --git a/src/module_gtf/module/lang/lang-fr.json b/src/module_gtf/module/lang/lang-fr.json index 2073cf66..9af2c0a1 100755 --- a/src/module_gtf/module/lang/lang-fr.json +++ b/src/module_gtf/module/lang/lang-fr.json @@ -386,7 +386,7 @@ "FORM_GTF_SCHEMA_CONFIGURATION_CONFIGURATION_GTF_CONFIG" : "Schéma de GTF", "FORM_GTF_HOME_CONFIGURATION_CONFIGURATION_GTF_CONFIG" : "Répertoire de GTF", "FORM_NOT_COMPRESSED_EXTENSION_CONFIGURATION_CONFIGURATION_GTF_CONFIG" : "Extensions des fichiers à ne pas compresser", - + "FORM_NBR_ORDER_MAX_CONFIGURATION_CONFIGURATION_GTF_CONFIG" : "Nombre maximum de demandes traitées simultanément", "FORM_MAX_ATTEMPT_CONFIGURATION_CONFIGURATION_GTF_CONFIG" : "Nombre maximum de tentatives", "FORM_RADIO_TRUE_CONFIGURATION_CONFIGURATION_GTF_CONFIG" : "Oui", @@ -434,6 +434,7 @@ "SEND_MAIL_SUCCESS_CONFIGURATION_CONFIGURATION_GTF_LICENSE" : "Mail envoyé avec succés", "LICENSE_FILE_INSTALL_ERROR_CONFIGURATION_CONFIGURATION_GTF_LICENSE" : "Erreur pendant l'installation du fichier de licence.", "LICENSE_FILE_INSTALL_SUCCESS_CONFIGURATION_CONFIGURATION_GTF_LICENSE" : "Fichier de licence installé avec succés", + "SMTP_SERVER_PARAMETERS_CONFIGURATION_CONFIGURATION_GTF_LICENSE" : "Veuillez renseigner les paramètres de votre serveur SMTP.", "" : "", "FORM_NAME_ENGINE_GTF_ENGINE" : "Nom", "FORM_SERVER_ENGINE_GTF_ENGINE" : "Serveur", diff --git a/src/module_gtf/web_service/ws/License.class.inc b/src/module_gtf/web_service/ws/License.class.inc index 8f1e63df..68da1fe2 100755 --- a/src/module_gtf/web_service/ws/License.class.inc +++ b/src/module_gtf/web_service/ws/License.class.inc @@ -170,64 +170,84 @@ class License extends GTF { } } } else if ($this->aValues["action"] == 'ask') { - $mail = new PHPMailer; - - $mail->isSMTP(); // Set mailer to use SMTP - //$mail->SMTPDebug = 3; // debugger level (3 all with connection) - $mail->Debugoutput = function($str, $level) {error_log("debug level $level; message: $str");}; - $mail->Host = $this->aProperties["smtp_host"]; // Specify main and backup SMTP servers - $mail->Port = $this->aProperties["smtp_port"]; // TCP port to connect to - $mail->SMTPAuth = $this->aProperties["smtp_authentification"]; // Enable SMTP authentication - // if authentication add parameter to connect SMTP - if ($this->aProperties["smtp_authentification"] === true){ - $mail->AuthType = 'LOGIN'; - $mail->Username = $this->aProperties["smtp_login"]; // SMTP username - $mail->Password = $this->aProperties["smtp_password"]; // SMTP password - $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted (deprecated) - } - $sTo = 'codes@veremes.com'; - $mail->AddAddress($sTo); - $mail->SetFrom($this->aProperties['mail_sender'], $this->aProperties['nickname_sender']); - $mail->AddReplyTo($this->aValues['reply_to']); - $mail->IsHTML(true); // Set email format to HTML - $mail->CharSet = 'UTF-8'; - $mail->Subject = $this->aValues['subject'] . $this->aValues['license_number']; - $mail->Body = /*utf8_decode*/('<html><body>' . $this->aValues['message'] . '</body></html>'); - $mail->AddCC($this->aValues['reply_to']); - - // Depuis PHP 5.6 -> vérification du certificat SSL. - if (!$this->aProperties['proxy_check_ssl']) { - $mail->SMTPOptions = array( - 'ssl' => array( - 'verify_peer' => false, - 'verify_peer_name' => false, - 'allow_self_signed' => true - ) - ); + // Vérification des paramètres du serveur smtp (vides ou par défaut -> erreur). + $aSmtpDefault = array( + 'smtp_host' => 'smtp.domaine.com', + 'smtp_port' => 26, + 'smtp_authentification' => true, + 'smtp_login' => 'login@domaine.com', + 'smtp_password' => 'password' + ); + $iSmtpCount = 0; + foreach ($aSmtpDefault as $sSmtpKey => $sSmtpValue) { + if (empty($this->aProperties[$sSmtpKey]) || $this->aProperties[$sSmtpKey] == $sSmtpValue) + $iSmtpCount++; } - - // - if (!$mail->send()) { - writeToErrorLog(ERROR_0023 . $sTo . '.'); - writeToErrorLog("Error message : " . $mail->ErrorInfo); - writeToLog("|WARN|PHP|Failed sending email to the following address : " . $sTo . ' and copy to : ' . $this->aValues['reply_to'], $this->aProperties['mail_log_file']); - $oError = new VitisError(1, 'SEND_MAIL_ERROR_CONFIGURATION_CONFIGURATION_GTF_LICENSE'); + if ($iSmtpCount == count($aSmtpDefault)) { + writeToErrorLog('the SMTP server is not configured'); + $oError = new VitisError(1, 'SMTP_SERVER_PARAMETERS_CONFIGURATION_CONFIGURATION_GTF_LICENSE'); $aXmlRacineAttribute['status'] = 0; $sMessage = $oError->asDocument('', 'vitis', $this->aValues['sEncoding'], True, $aXmlRacineAttribute, $this->aValues['sSourceEncoding'], $this->aValues['output']); - //$sErrorMessage = $sMail->getMessage(); - } else { - writeToLog("|INFORM|PHP| An email has been sent to the following address : " . $sTo . ' and copy to : ' . $this->aValues['reply_to'], $this->aProperties['mail_log_file']); - if(!empty($this->aProperties['SaveSentMail']) && $this->aProperties['SaveSentMail'] === true){ - $imap = new Imap($this->aProperties['imapBotSender_host'], $this->aProperties['imapBotSender_port'], $this->aProperties['imapBotSender_login'], $this->aProperties['imapBotSender_pwd'], $this->aProperties['imapBotSender_encrypt']); - if($imap->isConnected()===false) - writeToLog("|WARN|PHP| can't connect to the IMAP at hostname : " . $this->aProperties['imapBotSender_host'], $this->aProperties['mail_log_file']); - else{ - $imap->selectFolder("Sent"); - $imap->saveMessageInSent($mail->getSentMIMEMessage(), ""); + } + else { + $mail = new PHPMailer; + $mail->isSMTP(); // Set mailer to use SMTP + //$mail->SMTPDebug = 3; // debugger level (3 all with connection) + $mail->Debugoutput = function($str, $level) {error_log("debug level $level; message: $str");}; + $mail->Host = $this->aProperties["smtp_host"]; // Specify main and backup SMTP servers + $mail->Port = $this->aProperties["smtp_port"]; // TCP port to connect to + $mail->SMTPAuth = $this->aProperties["smtp_authentification"]; // Enable SMTP authentication + // if authentication add parameter to connect SMTP + if ($this->aProperties["smtp_authentification"] === true){ + $mail->AuthType = 'LOGIN'; + $mail->Username = $this->aProperties["smtp_login"]; // SMTP username + $mail->Password = $this->aProperties["smtp_password"]; // SMTP password + $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted (deprecated) + } + $sTo = 'codes@veremes.com'; + $mail->AddAddress($sTo); + $mail->SetFrom($this->aProperties['mail_sender'], $this->aProperties['nickname_sender']); + $mail->AddReplyTo($this->aValues['reply_to']); + $mail->IsHTML(true); // Set email format to HTML + $mail->CharSet = 'UTF-8'; + $mail->Subject = $this->aValues['subject'] . $this->aValues['license_number']; + $mail->Body = /*utf8_decode*/('<html><body>' . $this->aValues['message'] . '</body></html>'); + $mail->AddCC($this->aValues['reply_to']); + + // Depuis PHP 5.6 -> vérification du certificat SSL. + if (!$this->aProperties['proxy_check_ssl']) { + $mail->SMTPOptions = array( + 'ssl' => array( + 'verify_peer' => false, + 'verify_peer_name' => false, + 'allow_self_signed' => true + ) + ); + } + + // + if (!$mail->send()) { + writeToErrorLog(ERROR_0023 . $sTo . '.'); + writeToErrorLog("Error message : " . $mail->ErrorInfo); + writeToLog("|WARN|PHP|Failed sending email to the following address : " . $sTo . ' and copy to : ' . $this->aValues['reply_to'], $this->aProperties['mail_log_file']); + $oError = new VitisError(1, 'SEND_MAIL_ERROR_CONFIGURATION_CONFIGURATION_GTF_LICENSE'); + $aXmlRacineAttribute['status'] = 0; + $sMessage = $oError->asDocument('', 'vitis', $this->aValues['sEncoding'], True, $aXmlRacineAttribute, $this->aValues['sSourceEncoding'], $this->aValues['output']); + //$sErrorMessage = $sMail->getMessage(); + } else { + writeToLog("|INFORM|PHP| An email has been sent to the following address : " . $sTo . ' and copy to : ' . $this->aValues['reply_to'], $this->aProperties['mail_log_file']); + if(!empty($this->aProperties['SaveSentMail']) && $this->aProperties['SaveSentMail'] === true){ + $imap = new Imap($this->aProperties['imapBotSender_host'], $this->aProperties['imapBotSender_port'], $this->aProperties['imapBotSender_login'], $this->aProperties['imapBotSender_pwd'], $this->aProperties['imapBotSender_encrypt']); + if($imap->isConnected()===false) + writeToLog("|WARN|PHP| can't connect to the IMAP at hostname : " . $this->aProperties['imapBotSender_host'], $this->aProperties['mail_log_file']); + else{ + $imap->selectFolder("Sent"); + $imap->saveMessageInSent($mail->getSentMIMEMessage(), ""); + } } + $aXmlRacineAttribute['status'] = 1; + $sMessage = $this->asDocument('', 'vitis', $this->aValues['sEncoding'], True, $aXmlRacineAttribute, $this->aValues['sSourceEncoding'], $this->aValues['output']); } - $aXmlRacineAttribute['status'] = 1; - $sMessage = $this->asDocument('', 'vitis', $this->aValues['sEncoding'], True, $aXmlRacineAttribute, $this->aValues['sSourceEncoding'], $this->aValues['output']); } } return $sMessage; @@ -235,4 +255,4 @@ class License extends GTF { } -?> \ No newline at end of file +?> -- GitLab