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