Merge branch 'SMTP'

This commit is contained in:
Fred Tempez 2020-05-12 09:19:30 +02:00
commit 67d2155569
8 changed files with 1566 additions and 30 deletions

View File

@ -7,6 +7,7 @@ class autoload {
require_once 'core/class/SitemapGenerator.class.php';
require_once 'core/class/phpmailer/PHPMailer.class.php';
require_once 'core/class/phpmailer/Exception.class.php';
require_once 'core/class/phpmailer/SMTP.class.php';
require_once "core/class/jsondb/Dot.class.php";
require_once "core/class/jsondb/JsonDb.class.php";
}

View File

@ -445,4 +445,27 @@ class helper {
return $text;
}
/**
* Cryptation
* @param string $key la clé d'encryptage
* @param string $payload la chaine à coder
* @return string
*/
public static function encrypt($key, $payload) {
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
$encrypted = openssl_encrypt($payload, 'aes-256-cbc', $key, 0, $iv);
return base64_encode($encrypted . '::' . $iv);
}
/**
* Décryptation
* @param string $key la clé d'encryptage
* @param string $garble la chaine à décoder
* @return string
*/
public static function decrypt($key, $garble) {
list($encrypted_data, $iv) = explode('::', base64_decode($garble), 2);
return openssl_decrypt($encrypted_data, 'aes-256-cbc', $key, 0, $iv);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -845,25 +845,45 @@ class common {
* @return bool
*/
public function sendMail($to, $subject, $content, $replyTo = null) {
// Utilisation de PHPMailer version 6.0.6
//require_once "core/vendor/phpmailer/phpmailer.php";
//require_once "core/vendor/phpmailer/exception.php";
// Layout
ob_start();
include 'core/layout/mail.php';
include 'core/layout/mail.php';
$layout = ob_get_clean();
$mail = new PHPMailer\PHPMailer\PHPMailer;
$mail->CharSet = 'UTF-8';
// Mail
try{
$mail = new PHPMailer\PHPMailer\PHPMailer;
$mail->CharSet = 'UTF-8';
$host = str_replace('www.', '', $_SERVER['HTTP_HOST']);
$mail->setFrom('no-reply@' . $host, $this->getData(['config', 'title']));
if (is_null($replyTo)) {
$mail->addReplyTo('no-reply@' . $host, $this->getData(['config', 'title']));
// Paramètres SMTP
if ($this->getdata(['config','smtp','enable'])) {
//$mail->SMTPDebug = PHPMailer\PHPMailer\SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->SMTPAutoTLS = false;
$mail->Host = $this->getdata(['config','smtp','host']);
$mail->Port = (int) $this->getdata(['config','smtp','port']);
if ($this->getData(['config','smtp','auth'])) {
$mail->Username = $this->getData(['config','smtp','username']);
$mail->Password = helper::decrypt($this->getData(['config','smtp','username']),$this->getData(['config','smtp','password']));
$mail->SMTPAuth = $this->getData(['config','smtp','auth']);
$mail->SMTPSecure = $this->getData(['config','smtp','secure']);
$mail->setFrom($this->getData(['config','smtp','username']));
if (is_null($replyTo)) {
$mail->addReplyTo($this->getData(['config','smtp','username']));
} else {
$mail->addReplyTo($replyTo);
}
}
// Fin SMTP
} else {
$mail->addReplyTo($replyTo);
}
$host = str_replace('www.', '', $_SERVER['HTTP_HOST']);
$mail->setFrom('no-reply@' . $host, $this->getData(['config', 'title']));
if (is_null($replyTo)) {
$mail->addReplyTo('no-reply@' . $host, $this->getData(['config', 'title']));
} else {
$mail->addReplyTo($replyTo);
}
}
if(is_array($to)) {
foreach($to as $userMail) {
$mail->addAddress($userMail);
@ -903,8 +923,6 @@ class common {
//Retourne une chaine contenant le dossier à créer
$folder = $this->dirData ($keys[0],'fr');
// Constructeur JsonDB
//require_once "core/vendor/jsondb/Dot.php";
//require_once "core/vendor/jsondb/JsonDb.php";
$db = new \Prowebcraft\JsonDb([
'name' => $keys[0] . '.json',
'dir' => $folder,
@ -1439,6 +1457,7 @@ class core extends common {
* @param string $className Nom de la classe à charger
*/
public static function autoload($className) {
$classPath = strtolower($className) . '/' . strtolower($className) . '.php';
// Module du coeur
if(is_readable('core/module/' . $classPath)) {

View File

@ -148,11 +148,22 @@ class config extends common {
15 => '15 articles',
20 => '20 articles'
];
// Type de proxy
public static $proxyType = [
'tcp://' => 'TCP',
'http://' => 'HTTP'
];
// Type de proxy
public static $proxyType = [
'tcp://' => 'TCP',
'http://' => 'HTTP'
];
// Authentification SMTP
public static $SMTPauth = [
true => 'Oui',
false => 'Non'
];
// Encryptation SMTP
public static $SMTPEnc = [
'' => 'Aucune',
'tls' => 'START TLS',
'ssl' => 'SSL/TLS'
];
public function generateFiles() {
@ -419,10 +430,20 @@ class config extends common {
: $this->getInput('configAutoUpdate', helper::FILTER_BOOLEAN),
'proxyType' => $this->getInput('configProxyType'),
'proxyUrl' => $this->getInput('configProxyUrl'),
'proxyPort' => $this->getInput('configProxyPort',helper::FILTER_INT)
'proxyPort' => $this->getInput('configProxyPort',helper::FILTER_INT),
'smtp' => [
'enable' => $this->getInput('configSmtpEnable',helper::FILTER_BOOLEAN),
'host' => $this->getInput('configSmtpHost',helper::FILTER_STRING_SHORT),
'port' => $this->getInput('configSmtpPort',helper::FILTER_INT),
'auth' => $this->getInput('configSmtpAuth',helper::FILTER_BOOLEAN),
'secure' => $this->getInput('configSmtpSecure'),
'username' => $this->getInput('configSmtpUsername',helper::FILTER_STRING_SHORT),
'password' =>helper::encrypt($this->getData(['config','smtp','username']),$this->getInput('configSmtpPassword')),
'sender' => $this->getInput('configSmtpSender',helper::FILTER_MAIL)
]
]
]);
if(self::$inputNotices === []) {
// Ecrire les fichiers de script
file_put_contents(self::DATA_DIR . 'head.inc.html',$this->getInput('configScriptHead',null));

View File

@ -10,16 +10,54 @@
* @link http://zwiicms.com/
*/
$( document).ready(function() {
/**
* Afficher et masquer options SMTP
*/
if ($("input[name=configSmtpEnable]").is(':checked')) {
$("#configSmtpParam").addClass("disabled");
$("#configSmtpParam").slideDown();
} else {
$("#configSmtpParam").removeClass("disabled");
$("#configSmtpParam").slideUp();
}
/**
* Afficher et masquer options Auth
*/
if ($("select[name=configSmtpAuth]").val() == true) {
$("#configSmtpAuthParam").addClass("disabled");
$("#configSmtpAuthParam").slideDown();
} else {
$("#configSmtpAuthParam").removeClass("disabled");
$("#configSmtpAuthParam").slideUp();
}
});
/**
* Modification de l'affichage de l'icône de langues
* Afficher et masquer options SMTP
*/
$("input[name=configSmtpEnable]").on("change", function() {
if ($("input[name=configSmtpEnable]").is(':checked')) {
$("#configSmtpParam").addClass("disabled");
$("#configSmtpParam").slideDown();
} else {
$("#configSmtpParam").removeClass("disabled");
$("#configSmtpParam").slideUp();
}
});
/**
* Afficher et masquer options Auth
*/
var configdisablei18nDOM = $("#configdisablei18n");
configdisablei18nDOM.on("change", function() {
if ($("input[name=configdisablei18n]").is(':checked')) {
$(".zwiico-flag").css('display','none');
} else {
$(".zwiico-flag").css('display','block');
$("select[name=configSmtpAuth]").on("change", function() {
if ($("select[name=configSmtpAuth]").val() == true) {
$("#configSmtpAuthParam").addClass("disabled");
$("#configSmtpAuthParam").slideDown();
} else {
$("#configSmtpAuthParam").removeClass("disabled");
$("#configSmtpAuthParam").slideUp();
}
});
});

View File

@ -323,6 +323,68 @@
</div>
</div>
</div>
<div class="row">
<div class="col12">
<div class="block">
<h4>Paramètres de messagerie SMTP</h4>
<div class="row">
<div class="col12">
<?php echo template::checkbox('configSmtpEnable', true, 'Activer STMP', [
'checked' => $this->getData(['config', 'smtp','enable']),
'help' => 'Paramètres à utiliser lorsque votre hébergeur ne propose pas la fonctionnalité d\'envoi de mail.'
]); ?>
</div>
</div>
<div id="configSmtpParam">
<div class="row">
<div class="col8">
<?php echo template::text('configSmtpHost', [
'label' => 'Adresse SMTP',
'placeholder' => 'smtp.fr',
'value' => $this->getData(['config', 'smtp','host'])
]); ?>
</div>
<div class="col2">
<?php echo template::text('configSmtpPort', [
'label' => 'Port SMTP',
'placeholder' => '589',
'value' => $this->getData(['config', 'smtp','port'])
]); ?>
</div>
<div class="col2">
<?php echo template::select('configSmtpAuth', $module::$SMTPauth, [
'label' => 'Authentification',
'selected' => $this->getData(['config', 'smtp','auth'])
]); ?>
</div>
</div>
<div id="configSmtpAuthParam">
<div class="row">
<div class="col5">
<?php echo template::text('configSmtpUsername', [
'label' => 'Nom utilisateur',
'value' => $this->getData(['config', 'smtp','username' ])
]); ?>
</div>
<div class="col5">
<?php echo template::password('configSmtpPassword', [
'label' => 'Mot de passe',
'autocomplete' => 'off',
'value' => $this->getData(['config','smtp','password'])
]); ?>
</div>
<div class="col2">
<?php echo template::select('configSmtpSecure', $module::$SMTPEnc , [
'label' => 'Sécurité',
'selected' => $this->getData(['config', 'smtp','secure'])
]); ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col12">
<div class="block">

View File

@ -30,6 +30,7 @@ setlocale (LC_TIME, 'fra_FRA', 'french');
*/
session_start();
// Chargement des classes
require 'core/class/autoload.php';
autoload::autoloader();
// Chargement du coeur