[4020] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: Mail supervisor |
---|
[9702] | 4 | Version: auto |
---|
[4225] | 5 | Description: Mail supervisor surveille l'envoie des mails. |
---|
[4023] | 6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=315 |
---|
[4020] | 7 | Author: cljosse |
---|
[4199] | 8 | Author URI:http://cljosse.free.fr |
---|
[4020] | 9 | */ |
---|
| 10 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
[9702] | 11 | if (!defined('mail_superv_DIR')) define('mail_superv_DIR' , basename(dirname(__FILE__))); |
---|
[4041] | 12 | if (!defined('MAIL_SUPERV_PATH')) define('MAIL_SUPERV_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
[10385] | 13 | |
---|
| 14 | $MAIL_SUPERV_PATH_ABS = str_replace('\\','/',dirname(__FILE__) ); |
---|
[9702] | 15 | if (!defined('MAIL_SUPERV_PATH_ABS')) define( 'MAIL_SUPERV_PATH_ABS', $MAIL_SUPERV_PATH_ABS."/"); |
---|
[10385] | 16 | |
---|
[9702] | 17 | global $conf,$mails_options ; |
---|
[10419] | 18 | include_once (MAIL_SUPERV_PATH.'include/constants.php'); |
---|
[9702] | 19 | include_once(MAIL_SUPERV_PATH.'mail_super.inc.php'); |
---|
[10385] | 20 | |
---|
[9702] | 21 | $mail_supervisor = new mail_supervisor(); |
---|
| 22 | add_event_handler('get_admin_plugin_menu_links', array(&$mail_supervisor,'admin_menu') ); |
---|
[4020] | 23 | |
---|
[9702] | 24 | $mails_options = mail_supervisor::Get_Options($mails_options,"mail_superv"); |
---|
[10419] | 25 | /* EVENT_HANDLER_PRIORITY_NEUTRAL */ |
---|
[9702] | 26 | // |
---|
| 27 | // |
---|
[10385] | 28 | include_once (PHPWG_ROOT_PATH.'include/functions_mail.inc.php' ); |
---|
[10419] | 29 | include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); |
---|
[10564] | 30 | //===============loc_begin_index====loc_begin_page_header==========loc_after_page_header============================================================= |
---|
| 31 | add_event_handler('loc_after_page_header', array(&$mail_supervisor,'init') ); |
---|
[9702] | 32 | add_event_handler('loc_begin_page_tail', array(&$mail_supervisor,'affiche_message') ); |
---|
[4020] | 33 | |
---|
[9702] | 34 | //========================================================================================== |
---|
| 35 | add_event_handler('send_mail', 'clj_mail',EVENT_HANDLER_PRIORITY_NEUTRAL - 10, 6); |
---|
| 36 | function clj_mail($result, $mailto, $subject, $content, $headers, $args) { |
---|
[10419] | 37 | global $conf, $user, $lang_info; |
---|
[10385] | 38 | global $conf_mail,$mails_options,$mails_donnees ; |
---|
[10419] | 39 | global $template,$page ,$erreur_message,$infos_message, $lang; |
---|
[10385] | 40 | global $errors; |
---|
| 41 | // lecture config table ------------- |
---|
[10419] | 42 | include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); |
---|
| 43 | load_language('plugin.lang', MAIL_SUPERV_PATH); |
---|
| 44 | trigger_event('cl_begin_send_mail'); |
---|
| 45 | |
---|
| 46 | // remove_event_handler('send_mail', 'pwg_send_mail'); |
---|
| 47 | $message =""; |
---|
| 48 | if (!isset($infos_message)) { $infos_message = ""; } |
---|
| 49 | if (!isset($erreur_message)) { $erreur_message = ''; } |
---|
| 50 | |
---|
[10385] | 51 | // $mails_options = explode("," , $conf['mail_superv']); |
---|
| 52 | $envoie_ok=true ; |
---|
| 53 | //======== verification si envoie de mail ou blocage connexion ===================== |
---|
[9702] | 54 | |
---|
[10419] | 55 | if ($mails_options['no_mail_list']=='on' || $mails_options['no_connect'] == 'on' ) { |
---|
| 56 | if (kill_list()) { |
---|
[9702] | 57 | $nb_destinataires=0; ; |
---|
| 58 | $envoie_ok= false ; |
---|
| 59 | $erreur_message .= "<BR />".l10n('Sv_is_a_spam') ; |
---|
[10419] | 60 | $infos_message = l10n('Sv_mail_not_send')."<BR />"; |
---|
[10385] | 61 | if ($mails_options['no_connect'] == 'on' ){ |
---|
[10419] | 62 | if ($user['status'] == 'webmaster'){ |
---|
| 63 | //---------- continuer si web master ---------- |
---|
| 64 | }else{ |
---|
| 65 | if (!isset($_GET['admin'])) { |
---|
| 66 | die('Blacklist : <br />' .$erreur_message. '<br /> Hacking attempt!'); |
---|
| 67 | }elseif ($_GET['admin'] != 'piwigo') |
---|
| 68 | { |
---|
| 69 | die('blacklist Hacking attempt!'); |
---|
| 70 | } |
---|
| 71 | } |
---|
[10385] | 72 | } |
---|
[10419] | 73 | trigger_event('cl_kill_send_mail', $ip); |
---|
| 74 | return true; |
---|
| 75 | } |
---|
| 76 | } |
---|
[10385] | 77 | // lecture donnees ------------- |
---|
[10419] | 78 | $mails_donnees = mail_supervisor::Get_Datas(); |
---|
| 79 | $nb_mails = $mails_donnees['nb_mails'] ; |
---|
| 80 | $next_day = $mails_donnees['date_mail'] ; |
---|
| 81 | $reste = $mails_donnees['reste'] ; |
---|
| 82 | $rest_mail = $mails_donnees['rest_mail'] ; |
---|
| 83 | if ($rest_mail <=0 || $mails_donnees['nb_mails'] ==0 ){ |
---|
| 84 | $mails_donnees['nb_mails'] =0 ; |
---|
| 85 | $mails_donnees['date_mail'] = time(); |
---|
| 86 | } |
---|
| 87 | $rest_spam = $mails_donnees['rest_spam'] ; |
---|
| 88 | if ($rest_spam <=0 || $mails_donnees['nb_spams'] ==0 ){ |
---|
| 89 | $mails_donnees['nb_spams'] =0 ; |
---|
| 90 | $mails_donnees['date_spam'] = time(); |
---|
| 91 | } |
---|
| 92 | $alerte = ( $mails_donnees['reste'] >0 ) ? true : false ; |
---|
| 93 | $alerte_mail = ( $mails_donnees['nb_mails'] > $mails_donnees['nb_mails_maxi']-1 ) ? true : false ; |
---|
| 94 | $alerte_spam = ( $mails_donnees['nb_spams'] > $mails_donnees['nb_spams_maxi']-1 ) ? true : false ; |
---|
[4049] | 95 | |
---|
[10419] | 96 | if ( ( !$alerte && !$alerte_spam && !$alerte_mail ) ) { |
---|
| 97 | $nb_destinataires=0; |
---|
[10385] | 98 | //==================================================== |
---|
[10419] | 99 | $match_email = $conf_mail['email_webmaster']; |
---|
| 100 | |
---|
[10385] | 101 | $new_args=array(); |
---|
[10388] | 102 | if( isset($args['Bcc'])) |
---|
[10419] | 103 | foreach($args['Bcc'] as $key => $val){ |
---|
| 104 | if (!preg_match('/'. $match_email.'/', $val)){ |
---|
[10385] | 105 | array_push($new_args, $val); |
---|
| 106 | }else{ |
---|
[10419] | 107 | $mailto = $match_email; |
---|
[10385] | 108 | } |
---|
| 109 | } |
---|
| 110 | $args['Bcc']=$new_args; |
---|
| 111 | //======================================================================= |
---|
| 112 | $nb_destinataires=0; |
---|
[10419] | 113 | if ($mailto<>"" ) $nb_destinataires +=1; |
---|
| 114 | if (!empty($args['Cc'])) { |
---|
| 115 | $nb_destinataires += count($args['Cc']); |
---|
| 116 | |
---|
| 117 | } |
---|
| 118 | if (!empty($args['Bcc'])) { |
---|
| 119 | $nb_destinataires += count($args['Bcc']); |
---|
| 120 | } |
---|
| 121 | if ($mailto == "" && $nb_destinataires==0 ) { |
---|
[10385] | 122 | $mailto = $conf_mail['email_webmaster']; |
---|
| 123 | $nb_destinataires ++; |
---|
| 124 | } |
---|
[8917] | 125 | |
---|
[10419] | 126 | if ($mails_options['check_mailto'] == 'on') { |
---|
| 127 | if ($mailto == "" && $nb_destinataires > 1 ) $mailto = $conf_mail['email_webmaster']; |
---|
| 128 | } |
---|
[8917] | 129 | |
---|
[10419] | 130 | $infos_message .= "nb_destinataires : $nb_destinataires Theme :" . ($args['theme'] ) ."{". $lang_info['language_name'] ."}"."<br />"; |
---|
[10385] | 131 | //================= réecriture de l'entete =============================== |
---|
| 132 | $match=array("<",">"); |
---|
[10419] | 133 | $string=array("<",">") ; |
---|
| 134 | if ( $nb_destinataires == 1 ) { |
---|
| 135 | if ($mailto == "" ) { |
---|
| 136 | if (!empty($args['Bcc'])){ |
---|
[10385] | 137 | $mailto = get_strict_email_list(implode(',', $args['Bcc'])); |
---|
| 138 | $args['Bcc']=array(); |
---|
[10419] | 139 | }else{ |
---|
[10385] | 140 | if (!empty($args['Cc']) ){ $mailto=get_strict_email_list(implode(',', $args['Cc'])); |
---|
| 141 | $args['Cc']=array(); |
---|
| 142 | }; |
---|
| 143 | } |
---|
| 144 | } |
---|
| 145 | if ($mailto == "" ) {$nb_destinataires = 0 ;} |
---|
| 146 | $mailto = $mailto ." \n" ; |
---|
| 147 | $headers = preg_replace('/.*Bcc(.*).\n/i', '', $headers); |
---|
| 148 | $headers = preg_replace('/.*Cc(.*).\n/i', '', $headers); |
---|
| 149 | $infos_message .="Destinataire:" .$mailto ; |
---|
| 150 | //============================================================================= |
---|
[10419] | 151 | |
---|
[10385] | 152 | }else{ |
---|
| 153 | //=== plusieurs destinataires =========== |
---|
| 154 | $cl_list_mail=""; |
---|
[10419] | 155 | if ($mailto !="") $infos_message .="To: " . $mailto . " "."<br />" ; |
---|
[10385] | 156 | if (!empty($args['Cc'])) { |
---|
| 157 | $ret= corrige_header('Cc',$headers,$args,$cl_list_mail,$mailto); |
---|
| 158 | $headers = $ret->headers; |
---|
| 159 | if($ret->list_mail!="") $infos_message .="Cc: " . ( $ret->list_mail)." <br />" ; |
---|
[10419] | 160 | |
---|
[10385] | 161 | } |
---|
[10419] | 162 | if (!empty($args['Bcc'])){ |
---|
| 163 | $ret = corrige_header('Bcc',$headers,$args,$cl_list_mail,$mailto); |
---|
[10385] | 164 | $headers = $ret->headers ; |
---|
| 165 | if($ret->list_mail!="") $infos_message .="Bcc: " . ( $ret->list_mail) ." <br />"; |
---|
[10419] | 166 | |
---|
| 167 | } |
---|
| 168 | $infos_message .= " " ; |
---|
[10385] | 169 | } |
---|
[10419] | 170 | |
---|
| 171 | |
---|
[9702] | 172 | //============================================================================= |
---|
| 173 | if ($mails_options['check_header_text']=='on') { |
---|
[10419] | 174 | $texte = "This is a multi-part message in MIME format.\n"; |
---|
| 175 | $texte .= "-----=".$conf_mail['boundary_key']."\n"; |
---|
| 176 | $texte .= "Ceci est un message est au format MIME.\n"; |
---|
| 177 | $texte .= 'Content-Type: text/plain; charset="UTF-8"'."\n"; |
---|
| 178 | $texte .= 'Content-Transfer-Encoding: 8bit'."\n\n"; |
---|
| 179 | $texte .= $mails_donnees['header_text']; // A voir texte brut... |
---|
| 180 | $texte .= "\n\n"; |
---|
[9702] | 181 | $content =$texte .$content ; |
---|
[10419] | 182 | } |
---|
[10385] | 183 | // corrige erreur 'mail dropped, bare LF found' |
---|
[10419] | 184 | /* if ( preg_match('/\n\./',$content)){ |
---|
[10385] | 185 | $content=preg_replace('/\n\./', '/\n\.\./', $content); |
---|
| 186 | |
---|
| 187 | // $infos_message .= $content ; |
---|
| 188 | } |
---|
| 189 | $content = str_replace("\n.", "\n/./.", $content); |
---|
[10419] | 190 | $headers = str_replace("\n.", "\n..", $headers); |
---|
[10385] | 191 | $subject = str_replace("\n.", "\n..", $subject); |
---|
| 192 | $mailto = str_replace("\n.", "\n..", $mailto); |
---|
| 193 | */ |
---|
| 194 | |
---|
[10419] | 195 | $ret=false; |
---|
| 196 | //======== Non mise en quarantaine ============= |
---|
| 197 | |
---|
| 198 | |
---|
| 199 | ob_start(); |
---|
| 200 | if ($nb_destinataires > 0) { |
---|
| 201 | |
---|
| 202 | if( $envoie_ok) $ret = mail($mailto, $subject,$content, $headers); |
---|
| 203 | |
---|
[10385] | 204 | }else{ |
---|
| 205 | $message .= l10n('Sv_no_receiver_available'); |
---|
| 206 | } |
---|
| 207 | $message .= ob_get_contents(); |
---|
| 208 | ob_end_clean(); |
---|
[10419] | 209 | $mails_donnees['message']=$message; |
---|
[10385] | 210 | Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto); |
---|
[9702] | 211 | } else { |
---|
[10419] | 212 | //================== Est en quarantaine ======================= |
---|
| 213 | $erreur_message .= l10n('Sv_To_day_is')."<br />"; |
---|
| 214 | if ($alerte_spam ) { |
---|
| 215 | $type="Spams"; |
---|
| 216 | $d1=$mails_donnees['nb_spams'] . ' \\ ' . $mails_donnees['nb_spams_maxi']; |
---|
| 217 | $d2=$mails_donnees['nb_spams']; |
---|
| 218 | $d3= $mails_donnees['rest_spam']; |
---|
| 219 | $d4=time()+$d3 ; |
---|
| 220 | } |
---|
| 221 | if ($alerte_mail) { |
---|
| 222 | $type="Mails"; |
---|
[9702] | 223 | $d1=$mails_donnees['nb_mails']. ' \\ ' . $mails_donnees['nb_mails_maxi'];; |
---|
| 224 | $d2=$mails_donnees['date_mail']; |
---|
| 225 | $d3= $mails_donnees['rest_mail']; |
---|
| 226 | $d4=time()+$d3 ; |
---|
[10419] | 227 | } |
---|
| 228 | if ($alerte) { |
---|
| 229 | $type="Spams(Quarantaine)"; |
---|
| 230 | $d1=$mails_donnees['nb_spams'] . ' \\ ' . $mails_donnees['nb_spams_maxi']; |
---|
| 231 | $d2=$mails_donnees['date_quarantaine']; |
---|
| 232 | $d3= $mails_donnees['reste']; |
---|
| 233 | $d4=time()+$d3 ; |
---|
| 234 | } |
---|
[9702] | 235 | $d2=date(l10n('Sv_formatdate'),$d2); |
---|
| 236 | $d3=int_to_heure($d3) ; |
---|
| 237 | $d4=date(l10n('Sv_formatdate'),$d4); |
---|
| 238 | if ($alerte_mail) { |
---|
[10419] | 239 | $erreur_message .='<br />'.sprintf(l10n('Sv_alerte_mail %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />'; |
---|
[9702] | 240 | }else{ |
---|
[10419] | 241 | $erreur_message .='<br />'.sprintf(l10n('Sv_mise_en_quarantaine %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />'; |
---|
[9702] | 242 | } |
---|
[10419] | 243 | $infos_message .= l10n('Sv_mail_not_send'); |
---|
| 244 | } |
---|
| 245 | $infos_message .= "<hr>"; |
---|
[9702] | 246 | mail_supervisor::sauve_donnees(); |
---|
| 247 | mail_supervisor::affiche_message(); |
---|
| 248 | return true ; |
---|
[4029] | 249 | } |
---|
[10419] | 250 | //=========================================================================================== |
---|
| 251 | function Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto){ |
---|
| 252 | global $conf, $user, $conf_mail,$mails_options,$mails_donnees , $template,$page ,$infos_message,$erreur_message,$args,$lang, $lang_info; |
---|
[9702] | 253 | $match=array("<",">"); |
---|
[10419] | 254 | $string=array("<",">") ; |
---|
| 255 | //Warning: mail() has been disabled for security reasons |
---|
[4029] | 256 | |
---|
[10419] | 257 | $est_un_spam =!(strpos(strtolower($message), 'spam') === false); |
---|
| 258 | $headers=str_replace( $match,$string, $headers); |
---|
[4045] | 259 | |
---|
[10419] | 260 | if ( ($ret==false) || ($est_un_spam==true) || ($nb_destinataires == 0) ) { |
---|
| 261 | ; // Bad recipient address syntax |
---|
| 262 | $pos1 = strpos(strtolower($message), 'bad recipient address syntax'); |
---|
| 263 | if ( !($pos1 === false) ){ |
---|
| 264 | $erreur_message .= l10n('Sv_detection_de').' Bad recipient address syntax .'; |
---|
| 265 | $erreur_message .= l10n('Sv_verifiez_les_destinataires').' (Bcc,Cc,To)<br />'; |
---|
| 266 | } |
---|
| 267 | |
---|
| 268 | $erreur_message .= sprintf(l10n('Sv_debug_message'), |
---|
| 269 | ($ret==true)? "true" : "false", |
---|
| 270 | $message , |
---|
| 271 | $mailto , |
---|
| 272 | $headers , |
---|
| 273 | $nb_destinataires ); |
---|
| 274 | //=============== La fonction mail retourne une erreur ========================= |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | if ($est_un_spam == false) |
---|
| 278 | { |
---|
| 279 | if ($mails_donnees['nb_mails']==0) { $mails_donnees['date_mail'] = time(); } |
---|
| 280 | $mails_donnees['nb_mails'] += $nb_destinataires; |
---|
| 281 | } |
---|
| 282 | else |
---|
| 283 | { |
---|
| 284 | $mails_donnees['nb_spams'] += $nb_destinataires; |
---|
| 285 | //--- Detection de spam ------------------ |
---|
| 286 | if ($mails_donnees['nb_spams']==0) {$mails_donnees['date_spam'] = time(); } |
---|
| 287 | |
---|
| 288 | $trop_de_spam =!(strpos(strtolower($message), 'trop de spam') === false); |
---|
| 289 | if ( $trop_de_spam ) { |
---|
| 290 | $mails_donnees['nb_spams_maxi']=$mails_donnees['nb_spams']; |
---|
| 291 | |
---|
| 292 | $mails_donnees['date_quarantaine']= time() ; |
---|
| 293 | $mails_donnees['quarantaine']= true ; |
---|
| 294 | $infos_message .= mail_supervisor::Memo_Var($mails_donnees); |
---|
| 295 | } |
---|
| 296 | } |
---|
[4020] | 297 | $ret=true; |
---|
[10419] | 298 | return $ret ; |
---|
[4020] | 299 | } |
---|
[4888] | 300 | ?> |
---|