1
0

fonctionnel sans mails en https

This commit is contained in:
Daniel Tartavel
2021-05-31 12:27:51 +02:00
parent 7e015a3d1b
commit 3c303efeb9
16 changed files with 564 additions and 135 deletions

View File

@@ -20,9 +20,12 @@ $site = "Avion Poème";
$dossier = "/www";
$basedir = dirname( $_SERVER['DOCUMENT_ROOT'] ) . $dossier;
$base_url = "http://avion-poe.me";
$base_url = "https://avion-poe.me";
$base_path = "/flex/storage/avion-poe.me/site/www/";
$url_admin = $base_url . "/gestion";
$accueil = $base_url . "/index.html";
if (empty( $_SERVER["PHP_AUTH_USER"]))
{
$_SERVER["PHP_AUTH_USER"] = 'script';
}
?>

View File

@@ -91,7 +91,7 @@ class db
$this->result = $this->connect->query( $string ) ;
if ( $this->connect->error ) log_error( "Échec de la commande query => " . $this->connect->error . "<br />" . __file__ . ' ligne ' . __line__ . "\n" . $string, true, true);
if ( $this->connect->error ) log_error( "Échec de la commande query => " . $this->connect->error . "<br />" . __file__ . ' ligne ' . __line__ . "\n" . $string, true, false);
//print_r( $this );
}
@@ -120,15 +120,15 @@ class db
$query .= "FROM_UNIXTIME(" . $this->protect($this->deliveryTimeServer) . "), '";
$query .= $this->protect($this->deliveryMethod) . "','";
$query .= "0')";
//print_r($this);
$this->query($query);
$this->uid = $this->connect->insert_id;
echo "{'uid':'" . $this->uid . "'}";
$this->startTimeRFC822 = formatteDate( $this->expeLang, $this->startTime, $this->startTZ);
$this->deliveryTimeRFC822 = formatteDate( $this->destLang, $this->deliveryTime, $this->deliveryTZ );
$this->urlAvion = $base_url . "/?avionpoeme=" . $this->uid;
courrielEnvoi($this);
$this->newPeripetie();
courrielEnvoi($this);
}
function getPlane($uid)

View File

@@ -12,8 +12,17 @@ function courrielEnvoi( $db )
// Message à l'expéditeur
$indexObjet = "Objet_" . $expediteurIndex;
$objetMail = replaceVariables($db, $dicoExpe[$indexObjet], $dicoExpe);
$mailText = replaceVariables($db, $dicoExpe[$expediteurIndex], $dicoExpe) .EOL .EOL ;
$result = replaceVariables($db, $dicoExpe[$indexObjet], $dicoExpe);
log_write("indexObjet" .EOLH . print_r($result, true));
$objetMail = $result['text'];
$result = replaceVariables($db, $dicoExpe[$expediteurIndex], $dicoExpe) ;
log_write("indexObjet" .EOLH . print_r($result, true));
$mailText = $result['text'];
$html = $result['html'];
if ( $html )
{
$mailText = "<html><head></head>\n<body>" . $mailText . "</body></html>";
}
if ( $db->expeKnown == false )
{
$destinataireIndex = "Notification_denvoi_Destinataire_ExpediteurConnu";
@@ -21,18 +30,25 @@ function courrielEnvoi( $db )
{
$destinataireIndex = "Notification_denvoi_Destinataire_ExpediteurAnonyme";
}
saveMail( $db, $db->expeMail, $objetMail, $mailText);
saveMail( $db, $db->expeMail, $objetMail, $mailText, $html);
// message au destinataire
$indexObjet = "Objet_" . $destinataireIndex;
$objetMail = replaceVariables($db, $dicoExpe[$indexObjet], $dicoDest);
$mailText = replaceVariables($db, $dicoDest[$destinataireIndex], $dicoDest) .EOL .EOL ;
saveMail( $db, $db->destMail, $objetMail, $mailText);
$result = replaceVariables($db, $dicoDest[$indexObjet], $dicoDest);
log_write("indexObjet" .EOLH . print_r($result, true));
$objetMail = $result['text'];
$result = replaceVariables($db, $dicoDest[$destinataireIndex], $dicoDest);
log_write("indexObjet" .EOLH . print_r($result, true));
$mailText = $result['text'];
$html = $result['html'];
if ( $html )
{
$message = "<html><head></head>\n<body>" . $message . "</body></html>";
}
saveMail( $db, $db->destMail, $objetMail, $mailText, $html);
}
function saveMail( $db, $destinataire, $objet, $text, $html=FALSE)
function saveMail( $db, $destinataire, $objet, $text, $html=false)
{
$query = "INSERT INTO courriels VALUES ('0', '" . $db->protect($destinataire) . "', '" . $db->protect($objet) . "', '" . $db->protect($text) . "', '" . (int)$html . "')";
$db->query($query);
@@ -44,20 +60,22 @@ function envoiMail($destinataire, $sujet, $text, $html=false, $cc='', $bcc='')
if ( !empty($cc)) $headers .= "Cc: " . $cc . LF;
if ( !empty($bcc)) $headers .= "Bcc: " . $bcc . LF;
if (empty($html))
{
$headers .= "Content-type: text/plain; charset=UTF-8" . LF;
}else
if ($html)
{
$headers .= "Content-type: text/html; charset=UTF-8" . LF;
nl2br($text);
}else
{
$headers .= "Content-type: text/plain; charset=UTF-8" . LF;
$text = str_replace("\n","\r\n", $text);
}
$headers .= "DATE: " . date( 'r' ) . LF . LF;
$destinataire = "dtux@free.fr";
log_write(__FILE__ . __LINE__ . " Envoi d'un courriel à " . $destinataire . "sujet:" . $sujet, INFO);
if( !mail($destinataire, $sujet, wordwrap($text, 70 , "\r\n"), $headers) ) //Sending mail
if( !mail($destinataire, $sujet, wordwrap($text, 1000 , "\r\n"), $headers) ) //Sending mail
{
log_write(__FILE__ . EOL . __LINE__ . EOL . "Le courriel n'est pas parti:" .$destinataire . EOL . $sujet, ERROR);
$error = error_get_last();
log_write(__FILE__ . EOL . __LINE__ . EOL . "Le courriel n'est pas parti:" .$destinataire . EOL . $sujet . EOL . print_r($error, true) . EOL . wordwrap($text, 1000 , "\r\n"), ERROR);
return false;
}else
{

View File

@@ -25,56 +25,76 @@ function getpost( $var )
{
return;
}
}
// MET LA PREMIÈRE LETTRE D'UN MOT EN MAJUSCULE ( utf8 compliant )
function mb_ucfirst($str) {
$char = mb_substr($str,0,1,"UTF8");
$str = mb_substr( $str, 1, NULL, "UTF8");
$char = mb_strtoupper( $char, "UTF8");
function mb_ucfirst($str)
{
$char = mb_substr($str,0,1,"UTF8");
$str = mb_substr( $str, 1, NULL, "UTF8");
$char = mb_strtoupper( $char, "UTF8");
return $char . $str;
}
}
function getLang( $lang )
function getLang( $lang, $gestion=false )
{
$dico = array();
if ( empty($lang) )
{
$dico = array();
if ( empty($lang) )
{
$lang="en";
}
if (($fh = fopen('lang/'.$lang, 'r') ))
{
$str = fgets($fh);
fclose($fh);
$dico = json_decode($str, true);
return $dico;
}
$lang="en";
}
$langPath ='lang/'.$lang;
if ($gestion)
$langPath = "../" . $langPath;
if (($fh = fopen($langPath, 'r') ))
{
$str = fgets($fh);
fclose($fh);
$dico = json_decode($str, true);
return $dico;
}else
{
return false;
}
}
function formatteDate($locale, $date, $tz)
{
$formatter = new IntlDateFormatter($locale, IntlDateFormatter::FULL, IntlDateFormatter::FULL, $tz, IntlDateFormatter::GREGORIAN );
if ($formatter == null)
{
log_write(InvalidConfigException(intl_get_error_message()));
log_write(__FILE__ . EOLH . __LINE__ . EOLH . "Formatter error : locale = " . $locale . "tz = " . $tz . "Formatter = " . print_r($formatter, true) . InvalidConfigException(intl_get_error_message()),ERROR);
}
return $formatter->format($date);
}
function replaceVariables($db, $text, $dico)
/* Remplace les variables dans les textes
*/
function replaceVariables($db, $text, $dico) :array
{
$variables = array( 'expediteur' => 'expeMail', 'destinataire' => 'destMail', 'date_depart' => 'startTimeRFC822', 'date_arrivee' => 'deliveryTimeRFC822', 'new_date_arrivee' => 'datePeripetie', 'message' => 'message', 'url_avion' => 'url_avion', 'onglet_apropos' => 'onglet_apropos', 'NB_avion_poeme' => 'avionJournalier', "url_avion" => "urlAvion");
$variables = array( 'expediteur' => 'expeMail', 'destinataire' => 'destMail', 'date_depart' => 'startTimeRFC822', 'date_arrivee' => 'deliveryTimeRFC822', 'new_date_arrivee' => 'datePeripetie', 'message' => 'message', 'onglet_apropos' => 'onglet_apropos', 'NB_avion_poeme' => 'avionJournalier', "url_avion" => "urlAvion");
$posVar = 0 ;
$x =0;
$result = array();
// si contient la variable '$message' alors le text est en html
if (strpos($text, '$message') === false)
{
$html = false;
}else
{
$html = true;
}
while( 1 )
{
// Recherche les variables dans le texte
$posVar = strpos( $text, "$", $posVar);
if ($posVar !== false)
{
if ($x++ >10 ) break;
// une variable a été trouvée
if ($x++ >10 ) break; // empêche une boucle sans fin, il n'y a pas plus de 10 variables par texte
$posEsp = strpos( $text, " ", $posVar);
if ($posEsp === false)
{
@@ -83,23 +103,33 @@ function replaceVariables($db, $text, $dico)
{
$var = substr($text, $posVar+1, $posEsp-$posVar-1);
}
$var = trim($var, " .\n\r");
$posVar = $posEsp+1;
$varReplace = "$" . $var;
$var = trim($var, " .\n\r");
$varReplace = "$" . $var;
if ( isset ($variables[$var]) )
{
$dbVar = $variables[$var];
$text = str_replace($varReplace, $db->$dbVar, $text);
$varText = $db->$dbVar;
//$text = str_replace($varReplace, $db->$dbVar, $text);
}elseif ( isset ($dico[$var]) )
{
$text = str_replace($varReplace, $dico[$var], $text);
$varText = $dico[$var];
//$text = str_replace($varReplace, $dico[$var], $text);
}else
{
log_error( "La variable => " . $var . "n'est pas reconnue<br />" . __file__ . ' ligne ' . __line__ . "\n" , true, false);
}
if ($html and (strpos($var, "url") !== false))
{
$varText = '<a href="' . $varText .'">' . $varText . "</a>";
}
$text = str_replace($varReplace, $varText, $text);
}else {
break;
}
}
return $text;
$result['html'] = $html;
$result['text'] = $text;
return $result;
}

View File

@@ -140,7 +140,7 @@ function affich_log( $nl, $np = 1, $level=0)
$query .= " WHERE niveau='" . $level . "'";
}
$query .= ' ORDER BY date DESC LIMIT ' . ( ( ( $np - 1 ) * $nl ) ) . ',' . $nl;
$query .= ' ORDER BY id_log DESC LIMIT ' . ( ( ( $np - 1 ) * $nl ) ) . ',' . $nl;
$db->query( $query );
echo "<table border='1' width='90%'><tr><td><b>date</b></td><td><b>auteur</b></td><td><b>log</b></td><td><b>niveau</b></td></tr>\n";
while ( ($donnees =$db->result->fetch_array()) )