C0ML: parameter email server, improve check for sendmail

This commit is contained in:
sparkyx 2026-05-08 12:04:24 +02:00
parent f406064cdb
commit c6a34abb3e
5 changed files with 90 additions and 7 deletions

View file

@ -4946,7 +4946,15 @@ Noalyss.prototype.save_config_smtp = function ()
reconnect();
return;
}
let json = req.evalJSON();
let json = req.responseJSON;
try {
let json=req.responseJSON;
if (json['status']=='NOK') {
smoke.alert(json['error']);
}
}catch (e) {
console.error(e)
}
}
@ -4963,9 +4971,11 @@ Noalyss.prototype.parameter_display_smtp = function ()
if ($F("smtp_type") == 'smtp') {
$("smtp_config_div").style.display = "grid";
$('btn_save1').hide();
$('info_snd').hide();
} else {
$("smtp_config_div").hide();
$('btn_save1').show();
$('info_snd').show();
}
};

View file

@ -75,10 +75,11 @@ if ( $op2 == "save_config_smtp")
);
$mail_parameter->from_post();
$mail_parameter->save();
echo 'OK';
echo json_response(["status"=>"OK"]) ;
} catch (Exception $exc) {
\record_log($exc);
echo 'NOK';
echo json_response(["status"=>"NOK","error"=>$exc->getMessage()]) ;
}
return;
}

View file

@ -137,6 +137,31 @@ class Mail_Parameter
*/
function save()
{
if ( $this->smtp_replyto!="" && filter_var($this->smtp_replyto, FILTER_VALIDATE_EMAIL) == false)
{
throw new \Exception (_("adresse réponse invalide"),140); ;
}
if ( $this->smtp_from!="" && filter_var($this->smtp_from, FILTER_VALIDATE_EMAIL) == false)
{
throw new \Exception (_("adresse expéditeur invalide"),146);
}
if ( $this->smtp_type=="sendmail" && defined("ALLOWED_EMAIL_DOMAIN"))
{
$a_allowed=explode(",", ALLOWED_EMAIL_DOMAIN);
if ($this->smtp_replyto !="" ) {
list($m,$domain)=explode("@",$this->smtp_replyto);
if (!in_array($domain, $a_allowed)) {
throw new \Exception (_("adresse réponse invalide"),153);
}
}
if ($this->smtp_from !="" ) {
list($m,$domain)=explode("@",$this->smtp_from);
if (!in_array($domain, $a_allowed)) {
throw new \Exception (_("adresse expéditeur invalide"),160);
}
}
}
foreach (self::PARAMETER as $key)
{
$id = $this->cn->get_value("select pe_id from parm_mail_server
@ -235,13 +260,17 @@ class Mail_Parameter
$this->smtp_auth=1;
}
public static function Factory(\Database $cnx,$reply_to="", $blind_copy="")
public static function Factory(\Database $cnx,$reply_to="", $blind_copy="",$mail_setting=MAIL_SETTING_NOALYSS)
{
$mail_parameter=new Mail_Parameter($cnx,MAIL_SETTING_NOALYSS);
if ( $mail_parameter->smtp_type=="sendmail") {
return new \Sendmail($mail_parameter->smtp_replyto,$mail_parameter->smtp_replyto);
$mail=new \Sendmail();
$mail->setReplyTo($reply_to)->setBlindCopy($blind_copy);
return $mail;
} elseif ($mail_parameter->smtp_type=="smtp") {
$phpmail= new SMTPMail($mail_parameter);
$phpmail->setReplyTo($reply_to)->setBlindCopy($blind_copy);
return $phpmail;
}

View file

@ -74,7 +74,40 @@ class Sendmail_Core
$this->afile=[];
}
public function getSupplemental_param()
public function getMailto()
{
return $this->mailto;
}
public function getBlindCopy()
{
return $this->blind_copy;
}
public function getReplyTo()
{
return $this->reply_to;
}
public function setMailto($mailto)
{
$this->mailto = $mailto;
return $this;
}
public function setBlindCopy($blind_copy)
{
$this->blind_copy = $blind_copy;
return $this;
}
public function setReplyTo($reply_to)
{
$this->reply_to = $reply_to;
return $this;
}
public function getSupplemental_param()
{
return $this->supplemental_param;
}

View file

@ -80,7 +80,17 @@ $show=($this->smtp_type=="sendmail")?"none":"grid";
value="sendmail">Sendmail</option>
</select>
</div>
<?php $show2=($this->smtp_type == 'sendmail') ? "none" : "block" ;?>
<p id="info_snd" style="display:<?=$show2?>" class="text-muted">
<?php
if ( defined('ALLOWED_EMAIL_DOMAIN') )
{
printf("Domaine accepté %s:",ALLOWED_EMAIL_DOMAIN);
}
?>
</p>
<div>
<label for="smtp_from"><?= _("adresse par défaut email de l'expéditeur") ?></label>
</div>