NEW : Email configuration - Allow auto signed certificat when ssl activated

This commit is contained in:
kamel 2020-09-08 14:48:50 +02:00
parent f567d41055
commit ccff18e2a5
6 changed files with 127 additions and 10 deletions

View File

@ -77,6 +77,7 @@ if ($action == 'update' && empty($_POST["cancel"]))
dolibarr_set_const($db, "MAIN_MAIL_SMTPS_PW", GETPOST("MAIN_MAIL_SMTPS_PW", 'none'), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "MAIN_MAIL_EMAIL_TLS", GETPOST("MAIN_MAIL_EMAIL_TLS", 'int'), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "MAIN_MAIL_EMAIL_STARTTLS", GETPOST("MAIN_MAIL_EMAIL_STARTTLS", 'int'), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED", GETPOST("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED", 'int'), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_ENABLED", GETPOST("MAIN_MAIL_EMAIL_DKIM_ENABLED", 'int'), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_DOMAIN", GETPOST("MAIN_MAIL_EMAIL_DKIM_DOMAIN", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
@ -156,6 +157,8 @@ if ($action == 'edit')
jQuery("#MAIN_MAIL_EMAIL_TLS").prop("disabled", true);
jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val(0);
jQuery("#MAIN_MAIL_EMAIL_STARTTLS").prop("disabled", true);
jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").val(0);
jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").prop("disabled", true);
jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").val(0);
jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").prop("disabled", true);
jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").prop("disabled", true);
@ -187,6 +190,8 @@ if ($action == 'edit')
jQuery("#MAIN_MAIL_EMAIL_TLS").removeAttr("disabled");
jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS.');
jQuery("#MAIN_MAIL_EMAIL_STARTTLS").removeAttr("disabled");
jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").val('.$conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED.');
jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").removeAttr("disabled");
jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").val(0);
jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").prop("disabled", true);
jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").prop("disabled", true);
@ -211,6 +216,8 @@ if ($action == 'edit')
jQuery("#MAIN_MAIL_EMAIL_TLS").removeAttr("disabled");
jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS.');
jQuery("#MAIN_MAIL_EMAIL_STARTTLS").removeAttr("disabled");
jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").val('.$conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED.');
jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").removeAttr("disabled");
jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").val('.$conf->global->MAIN_MAIL_EMAIL_DKIM_ENABLED.');
jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").removeAttr("disabled");
jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").removeAttr("disabled");
@ -233,12 +240,16 @@ if ($action == 'edit')
initfields();
});
jQuery("#MAIN_MAIL_EMAIL_TLS").change(function() {
if (jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val() == 1)
if (jQuery("#MAIN_MAIL_EMAIL_TLS").val() == 1)
jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val(0);
else
jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").val(0);
});
jQuery("#MAIN_MAIL_EMAIL_STARTTLS").change(function() {
if (jQuery("#MAIN_MAIL_EMAIL_TLS").val() == 1)
if (jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val() == 1)
jQuery("#MAIN_MAIL_EMAIL_TLS").val(0);
else
jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").val(0);
});
})';
print '</script>'."\n";
@ -408,6 +419,17 @@ if ($action == 'edit')
} else print yn(0).' ('.$langs->trans("NotSupported").')';
print '</td></tr>';
// SMTP_ALLOW_SELF_SIGNED
print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").'</td><td>';
if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))))
{
if (function_exists('openssl_open'))
{
print $form->selectyesno('MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED', (!empty($conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED) ? $conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED : 0), 1);
} else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
} else print yn(0).' ('.$langs->trans("NotSupported").')';
print '</td></tr>';
// DKIM
print '<tr class="oddeven dkim"><td>'.$langs->trans("MAIN_MAIL_EMAIL_DKIM_ENABLED").'</td><td>';
if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('swiftmailer'))))
@ -561,6 +583,17 @@ if ($action == 'edit')
} else print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
print '</td></tr>';
// SMTP_ALLOW_SELF_SIGNED
print '<tr class="oddeven"><td>'.$langs->trans("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").'</td><td>';
if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer')))
{
if (function_exists('openssl_open'))
{
print yn($conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED);
} else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
} else print '<span class="opacitymedium">'.yn(0).' ('.$langs->trans("NotSupported").')</span>';
print '</td></tr>';
if ($conf->global->MAIN_MAIL_SENDMODE == 'swiftmailer')
{

View File

@ -68,6 +68,7 @@ if ($action == 'update' && empty($_POST["cancel"]))
dolibarr_set_const($db, "MAIN_MAIL_SMTPS_PW_EMAILING", GETPOST("MAIN_MAIL_SMTPS_PW_EMAILING"), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "MAIN_MAIL_EMAIL_TLS_EMAILING", GETPOST("MAIN_MAIL_EMAIL_TLS_EMAILING"), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "MAIN_MAIL_EMAIL_STARTTLS_EMAILING", GETPOST("MAIN_MAIL_EMAIL_STARTTLS_EMAILING"), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING", GETPOST("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING"), 'chaine', 0, '', $conf->entity);
header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
exit;
@ -147,6 +148,8 @@ if ($action == 'edit')
jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").prop("disabled", true);
jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val(0);
jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").prop("disabled", true);
jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val(0);
jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").prop("disabled", true);
';
if ($linuxlike)
{
@ -173,6 +176,8 @@ if ($action == 'edit')
jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").removeAttr("disabled");
jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING.');
jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").removeAttr("disabled");
jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING.');
jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").removeAttr("disabled");
jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").removeAttr("disabled");
jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").removeAttr("disabled");
jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").show();
@ -187,6 +192,8 @@ if ($action == 'edit')
jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").removeAttr("disabled");
jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING.');
jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").removeAttr("disabled");
jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING.');
jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").removeAttr("disabled");
jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").removeAttr("disabled");
jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").removeAttr("disabled");
jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").show();
@ -199,13 +206,17 @@ if ($action == 'edit')
jQuery("#MAIN_MAIL_SENDMODE_EMAILING").change(function() {
initfields();
});
jQuery("#MAIN_MAIL_EMAIL_TLS").change(function() {
if (jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val() == 1)
jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").change(function() {
if (jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val() == 1)
jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val(0);
else
jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val(0);
});
jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").change(function() {
if (jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val() == 1)
if (jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val() == 1)
jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val(0);
else
jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val(0);
});
})';
print '</script>'."\n";
@ -359,6 +370,18 @@ if ($action == 'edit')
} else print yn(0).' ('.$langs->trans("NotSupported").')';
print '</td></tr>';
// SMTP_ALLOW_SELF_SIGNED_EMAILING
print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").'</td><td>';
if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer'))))
{
if (function_exists('openssl_open'))
{
print $form->selectyesno('MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING', (!empty($conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING) ? $conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING : 0), 1);
} else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
} else print yn(0).' ('.$langs->trans("NotSupported").')';
print '</td></tr>';
print '</table>';
dol_fiche_end();
@ -437,6 +460,17 @@ if ($action == 'edit')
} else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
} else print yn(0).' ('.$langs->trans("NotSupported").')';
print '</td></tr>';
// SMTP_ALLOW_SELF_SIGNED_EMAILING
print '<tr class="oddeven hideifdefault"><td>'.$langs->trans("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").'</td><td>';
if (isset($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && in_array($conf->global->MAIN_MAIL_SENDMODE_EMAILING, array('smtps', 'swiftmailer')))
{
if (function_exists('openssl_open'))
{
print yn($conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING);
} else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
} else print yn(0).' ('.$langs->trans("NotSupported").')';
print '</td></tr>';
}
print '</table>';

View File

@ -294,6 +294,16 @@ class CMailFile
$addr_bcc .= ($addr_bcc ? ', ' : '').$conf->global->MAIN_MAIL_AUTOCOPY_TO;
}
$keyforsslseflsigned ='MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED';
if (!empty($this->sendcontext)) {
$smtpContextKey = strtoupper($this->sendcontext);
$keyForSMTPSendMode = 'MAIN_MAIL_SENDMODE_' . $smtpContextKey;
$smtpContextSendMode = $conf->global->{$keyForSMTPSendMode};
if (!empty($smtpContextSendMode) && $smtpContextSendMode != 'default') {
$keyforsslseflsigned ='MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_' . $smtpContextKey;
}
}
// We set all data according to choosed sending method.
// We also set a value for ->msgid
if ($this->sendmode == 'mail')
@ -404,6 +414,7 @@ class CMailFile
$smtps->setBCC($this->addr_bcc);
$smtps->setErrorsTo($this->errors_to);
$smtps->setDeliveryReceipt($this->deliveryreceipt);
if (!empty($conf->global->$keyforsslseflsigned)) $smtps->setOptions(array('ssl' => array('verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true)));
$host = dol_getprefix('email');
$this->msgid = time().'.SMTPs-dolibarr-'.$this->trackid.'@'.$host;
@ -639,6 +650,7 @@ class CMailFile
$keyforsmtppw = 'MAIN_MAIL_SMTPS_PW';
$keyfortls = 'MAIN_MAIL_EMAIL_TLS';
$keyforstarttls = 'MAIN_MAIL_EMAIL_STARTTLS';
$keyforsslseflsigned ='MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED';
if (!empty($this->sendcontext)) {
$smtpContextKey = strtoupper($this->sendcontext);
$keyForSMTPSendMode = 'MAIN_MAIL_SENDMODE_' . $smtpContextKey;
@ -650,6 +662,7 @@ class CMailFile
$keyforsmtppw = 'MAIN_MAIL_SMTPS_PW_' . $smtpContextKey;
$keyfortls = 'MAIN_MAIL_EMAIL_TLS_' . $smtpContextKey;
$keyforstarttls = 'MAIN_MAIL_EMAIL_STARTTLS_' . $smtpContextKey;
$keyforsslseflsigned ='MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_' . $smtpContextKey;
}
}
@ -846,6 +859,7 @@ class CMailFile
if (!empty($conf->global->$keyforsmtpid)) $this->transport->setUsername($conf->global->$keyforsmtpid);
if (!empty($conf->global->$keyforsmtppw)) $this->transport->setPassword($conf->global->$keyforsmtppw);
if (! empty($conf->global->$keyforsslseflsigned)) $this->transport->setStreamOptions(array('ssl' => array('allow_self_signed' => true, 'verify_peer' => false)));;
//$smtps->_msgReplyTo = 'reply@web.com';
// Switch content encoding to base64 - avoid the doubledot issue with quoted-printable

View File

@ -228,6 +228,21 @@ class SMTPs
private $_trackId = '';
private $_moreInHeader = '';
/**
* An array of options for stream_context_create()
*/
private $_options = [];
/**
* Set delivery receipt
*
* @param array $_options An array of options for stream_context_create()
* @return void
*/
public function setOptions($_options = [])
{
$this->_options = $_options;
}
/**
* Set delivery receipt
@ -372,15 +387,34 @@ class SMTPs
{
$this->_setErr(99, $host.' is either offline or is an invalid host name.');
$_retVal = false;
} else {
//See if we can connect to the SMTP server
if ($this->socket = @fsockopen(
preg_replace('@tls://@i', '', $this->getHost()), // Host to 'hit', IP or domain
}
else
{
if (function_exists('stream_socket_client')) {
$socket_context = stream_context_create($this->_options); // An array of options for stream_context_create()
set_error_handler([$this, 'errorHandler']);
$this->socket = @stream_socket_client(
$this->getHost() . // Host to 'hit', IP or domain
':' . $this->getPort(), // which Port number to use
$this->errno, // actual system level error
$this->errstr, // and any text that goes with the error
$this->_smtpTimeout, // timeout for reading/writing data over the socket
STREAM_CLIENT_CONNECT,
$socket_context // Options for connection
);
} else {
$this->socket = @fsockopen(
$this->getHost(), // Host to 'hit', IP or domain
$this->getPort(), // which Port number to use
$this->errno, // actual system level error
$this->errstr, // and any text that goes with the error
$this->_smtpTimeout // timeout for reading/writing data over the socket
)) {
);
}
//See if we can connect to the SMTP server
if (is_resource($this->socket))
{
// Fix from PHP SMTP class by 'Chris Ryan'
// Sometimes the SMTP server takes a little longer to respond
// so we will give it a longer timeout for the first read

View File

@ -289,6 +289,7 @@ MAIN_MAIL_SMTPS_ID=SMTP ID (if sending server requires authentication)
MAIN_MAIL_SMTPS_PW=SMTP Password (if sending server requires authentication)
MAIN_MAIL_EMAIL_TLS=Use TLS (SSL) encryption
MAIN_MAIL_EMAIL_STARTTLS=Use TLS (STARTTLS) encryption
MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED=Authorise les certificats auto-signés
MAIN_MAIL_EMAIL_DKIM_ENABLED=Use DKIM to generate email signature
MAIN_MAIL_EMAIL_DKIM_DOMAIN=Email Domain for use with dkim
MAIN_MAIL_EMAIL_DKIM_SELECTOR=Name of dkim selector

View File

@ -289,6 +289,7 @@ MAIN_MAIL_SMTPS_ID=ID SMTP (si le serveur d'envoi nécessite une authentificatio
MAIN_MAIL_SMTPS_PW=Mot de passe SMTP (si le serveur d'envoi nécessite une authentification)
MAIN_MAIL_EMAIL_TLS=Utilisation du chiffrement TLS (SSL)
MAIN_MAIL_EMAIL_STARTTLS=Utiliser le cryptage TTS (STARTTLS)
MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED=Authorise les certificats auto-signés
MAIN_MAIL_EMAIL_DKIM_ENABLED=Utiliser DKIM pour signer les emails
MAIN_MAIL_EMAIL_DKIM_DOMAIN=Nom de domaine pour la signature DKIM
MAIN_MAIL_EMAIL_DKIM_SELECTOR=Nom du sélecteur DKIM