[4020] | 1 | <?php |
---|
[4029] | 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
| 5 | // | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org | |
---|
| 6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
| 7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
| 8 | // +-----------------------------------------------------------------------+ |
---|
| 9 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 10 | // | it under the terms of the GNU General Public License as published by | |
---|
| 11 | // | the Free Software Foundation | |
---|
| 12 | // | | |
---|
| 13 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 16 | // | General Public License for more details. | |
---|
| 17 | // | | |
---|
| 18 | // | You should have received a copy of the GNU General Public License | |
---|
| 19 | // | along with this program; if not, write to the Free Software | |
---|
| 20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 21 | // | USA. | |
---|
| 22 | // +-----------------------------------------------------------------------+ |
---|
| 23 | |
---|
[4020] | 24 | /* |
---|
| 25 | Plugin Name: Mail supervisor |
---|
[4051] | 26 | Version: 1.1.5 |
---|
[4020] | 27 | Description: Mail supervisor surveille l'envoie des mails. |
---|
[4023] | 28 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=315 |
---|
[4020] | 29 | Author: cljosse |
---|
| 30 | Author URI:http://cljosse.e3b.org |
---|
| 31 | */ |
---|
| 32 | |
---|
| 33 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
[4029] | 34 | |
---|
[4051] | 35 | if (!defined('MAIL_SUPERV_DIR')) define('MAIL_SUPERV_DIR' , basename(dirname(__FILE__))); |
---|
[4041] | 36 | if (!defined('MAIL_SUPERV_PATH')) define('MAIL_SUPERV_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
| 37 | |
---|
[4020] | 38 | include_once (MAIL_SUPERV_PATH.'include/constants.php'); |
---|
| 39 | include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); |
---|
| 40 | |
---|
| 41 | /* |
---|
| 42 | EVENT_HANDLER_PRIORITY_NEUTRAL */ |
---|
| 43 | |
---|
| 44 | add_event_handler('send_mail', 'clj_mail',EVENT_HANDLER_PRIORITY_NEUTRAL - 1 , 6); |
---|
| 45 | |
---|
| 46 | function clj_mail($result, $mailto, $subject, $content, $headers, $args) |
---|
| 47 | { |
---|
[4029] | 48 | global $conf, $user, $lang_info, $conf_mail,$mails_options,$mails_données , $template,$page ,$erreur_message,$infos_message; |
---|
[4020] | 49 | // lecture config table ------------- |
---|
| 50 | |
---|
[4029] | 51 | |
---|
| 52 | $mails_options = explode("," , $conf['mail_superv']); |
---|
| 53 | $message =""; |
---|
[4040] | 54 | if (!isset($infos_message)) |
---|
| 55 | { |
---|
| 56 | $infos_message = ""; |
---|
| 57 | } |
---|
| 58 | if (!isset($erreur_message)) |
---|
| 59 | { |
---|
| 60 | $erreur_message = ''; |
---|
| 61 | } |
---|
[4020] | 62 | // lecture données ------------- |
---|
| 63 | $mails_données = Get_Datas(); |
---|
[4029] | 64 | |
---|
[4020] | 65 | |
---|
| 66 | $nb_mails = $mails_données['nb_mails'] ; |
---|
| 67 | $next_day = $mails_données['date_mail'] ; |
---|
| 68 | |
---|
| 69 | $reste = $mails_données['reste'] ; |
---|
| 70 | |
---|
[4029] | 71 | |
---|
| 72 | $rest_mail = $mails_données['rest_mail'] ; |
---|
| 73 | if ($rest_mail <=0 || $mails_données['nb_mails'] ==0 ){ |
---|
| 74 | $mails_données['nb_mails'] =0 ; |
---|
| 75 | $mails_données['date_mail'] = time(); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | $rest_spam = $mails_données['rest_spam'] ; |
---|
| 79 | if ($rest_spam <=0 || $mails_données['nb_spams'] ==0 ){ |
---|
| 80 | $mails_données['nb_spams'] =0 ; |
---|
| 81 | $mails_données['date_spam'] = time(); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | $alerte = ( $mails_données['reste'] >0 ) ? true : false ; |
---|
| 85 | |
---|
[4040] | 86 | $alerte_mail = ( $mails_données['nb_mails'] > $mails_données['nb_mails_maxi']-1 ) ? true : false ; |
---|
| 87 | $alerte_spam = ( $mails_données['nb_spams'] > $mails_données['nb_spams_maxi']-1 ) ? true : false ; |
---|
[4029] | 88 | |
---|
[4020] | 89 | |
---|
[4029] | 90 | if ( ( !$alerte && !$alerte_spam && !$alerte_mail ) ) |
---|
| 91 | { |
---|
| 92 | |
---|
[4020] | 93 | $nb_destinataires=0; |
---|
[4045] | 94 | if ($mails_options[0] == 'on') { |
---|
| 95 | if ($mailto == "" ) $mailto = $conf_mail['email_webmaster']; |
---|
| 96 | } |
---|
| 97 | if ($mailto<>"" ) $nb_destinataires +=1; |
---|
[4049] | 98 | |
---|
| 99 | if (!empty($args['Bcc'])) { |
---|
| 100 | $nb_destinataires += count($args['Bcc']); |
---|
| 101 | } |
---|
| 102 | if (!empty($args['Cc'])) { |
---|
| 103 | $nb_destinataires += count($args['Cc']); |
---|
| 104 | } |
---|
[4020] | 105 | //================= réécriture de l'entête =============================== |
---|
[4045] | 106 | if ( $nb_destinataires == 1 ) |
---|
| 107 | { |
---|
| 108 | if ($mailto == "" ) |
---|
| 109 | { |
---|
[4049] | 110 | if (!empty($args['Cc']) and count($args['Cc']) > 0 ) $mailto = get_strict_email_list(implode(',', $args['Cc'])) ; |
---|
| 111 | if (!empty($args['Bcc']) and count($args['Bcc']) > 0 ) $mailto = get_strict_email_list(implode(',', $args['Bcc'])) ; |
---|
| 112 | |
---|
[4045] | 113 | $headers = preg_replace('/.*Bcc(.*).\n/i', '', $headers); |
---|
| 114 | $headers = preg_replace('/.*Cc(.*).\n/i', '', $headers); |
---|
[4049] | 115 | |
---|
[4045] | 116 | } |
---|
| 117 | }else{ |
---|
| 118 | |
---|
| 119 | if (!empty($args['Cc'])) |
---|
| 120 | { |
---|
[4050] | 121 | $headers= corrige_header('Cc',$headers); |
---|
| 122 | |
---|
[4045] | 123 | } |
---|
[4020] | 124 | if (!empty($args['Bcc'])) |
---|
[4045] | 125 | { |
---|
[4050] | 126 | $headers = corrige_header('Bcc',$headers); |
---|
[4045] | 127 | } |
---|
[4020] | 128 | |
---|
[4045] | 129 | |
---|
| 130 | } |
---|
[4020] | 131 | |
---|
| 132 | if ($mails_options[2]=='on') { |
---|
| 133 | |
---|
| 134 | $texte = "This is a multi-part message in MIME format.\n"; |
---|
| 135 | |
---|
| 136 | $texte .= "-----=".$conf_mail['boundary_key']."\n"; |
---|
| 137 | $texte .= "Ceci est un message est au format MIME.\n"; |
---|
| 138 | $texte .= 'Content-Type: text/plain; charset="UTF-8"'."\n"; |
---|
| 139 | $texte .= 'Content-Transfer-Encoding: 8bit'."\n\n"; |
---|
| 140 | $texte .= $mails_données['header_text']; // A voir texte brut... |
---|
| 141 | |
---|
| 142 | $texte .= "\n\n"; |
---|
| 143 | |
---|
| 144 | $content =$texte .$content ; |
---|
| 145 | } |
---|
[4029] | 146 | |
---|
[4020] | 147 | $ret=false; |
---|
[4030] | 148 | |
---|
[4029] | 149 | //======== Non mise en quarantaine ============= |
---|
[4020] | 150 | ob_start(); |
---|
[4029] | 151 | $ret = false; |
---|
| 152 | if ($nb_destinataires > 0) { |
---|
[4045] | 153 | $ret = mail($mailto, $subject, $content, $headers); |
---|
[4049] | 154 | /* <br /> |
---|
| 155 | <b>Warning</b>: mail() [<a href='function.mail'>function.mail</a>]: Trop de spam. Fonction mail() bloque. |
---|
| 156 | in <b>/mnt/102/sdb/9/5/cl.josse/Galerie/plugins/mail_supervisor/main.inc.php</b> on line <b>132</b><br /> |
---|
| 157 | */ |
---|
[4029] | 158 | }else{ |
---|
| 159 | $message .='Nombre de destinataires = 0'; |
---|
| 160 | } |
---|
| 161 | $message .= ob_get_contents(); |
---|
| 162 | ob_end_clean(); |
---|
| 163 | $mails_données['message']=$message; |
---|
| 164 | Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto); |
---|
[4020] | 165 | |
---|
[4029] | 166 | |
---|
[4020] | 167 | |
---|
[4029] | 168 | } else { |
---|
[4020] | 169 | |
---|
[4029] | 170 | //================== Est en quarantaine ======================= |
---|
| 171 | $erreur_message .= l10n('To_day_is')."<br />"; |
---|
| 172 | if ($alerte_spam ) { |
---|
| 173 | $type="Spams"; |
---|
[4045] | 174 | |
---|
[4040] | 175 | $d1=$mails_données['nb_spams'] . ' \\ ' . $mails_données['nb_spams_maxi']; |
---|
[4045] | 176 | $d2=$mails_données['nb_spams']; |
---|
[4029] | 177 | $d3= $mails_données['rest_spam']; |
---|
| 178 | $d4=time()+$d3 ; |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | if ($alerte_mail) { |
---|
| 182 | $type="Mails"; |
---|
| 183 | |
---|
[4040] | 184 | $d1=$mails_données['nb_mails']. ' \\ ' . $mails_données['nb_mails_maxi'];; |
---|
[4029] | 185 | $d2=$mails_données['date_mail']; |
---|
| 186 | $d3= $mails_données['rest_mail']; |
---|
| 187 | $d4=time()+$d3 ; |
---|
[4040] | 188 | |
---|
| 189 | |
---|
[4029] | 190 | } |
---|
| 191 | if ($alerte) { |
---|
| 192 | $type="Spams(Quarantaine)"; |
---|
[4040] | 193 | $d1=$mails_données['nb_spams'] . ' \\ ' . $mails_données['nb_spams_maxi']; |
---|
[4029] | 194 | $d2=$mails_données['date_quarantaine']; |
---|
| 195 | $d3= $mails_données['reste']; |
---|
| 196 | $d4=time()+$d3 ; |
---|
[4040] | 197 | } |
---|
[4020] | 198 | |
---|
[4029] | 199 | |
---|
| 200 | $d2=date(l10n('formatdate'),$d2); |
---|
| 201 | $d3=int_to_heure($d3) ; |
---|
| 202 | $d4=date(l10n('formatdate'),$d4); |
---|
| 203 | |
---|
[4040] | 204 | if ($alerte_mail) { |
---|
| 205 | $erreur_message .='<br />'.sprintf(l10n('alerte_mail %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />'; |
---|
| 206 | }else{ |
---|
| 207 | $erreur_message .='<br />'.sprintf(l10n('mise_en_quarantaine %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />'; |
---|
| 208 | |
---|
| 209 | } |
---|
| 210 | $infos_message = l10n('mail_not_send'); |
---|
| 211 | |
---|
[4029] | 212 | } |
---|
| 213 | sauve_données(); |
---|
| 214 | return true ; |
---|
| 215 | } |
---|
| 216 | //=========================================================================================== |
---|
| 217 | function Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto) |
---|
| 218 | { |
---|
| 219 | global $conf, $user, $lang_info, $conf_mail,$mails_options,$mails_données , $template,$page ,$infos_message,$erreur_message,$args; |
---|
| 220 | $match=array("<",">"); |
---|
| 221 | $string=array("<",">") ; |
---|
| 222 | |
---|
| 223 | |
---|
| 224 | $est_un_spam =!(strpos(strtolower($message), 'spam') === false); |
---|
| 225 | $headers=str_replace( $match,$string, $headers); |
---|
| 226 | |
---|
| 227 | if ( ($ret==false) || ($est_un_spam==true) || ($nb_destinataires == 0) ) { |
---|
| 228 | ; // Bad recipient address syntax |
---|
| 229 | $pos1 = strpos(strtolower($message), 'bad recipient address syntax'); |
---|
| 230 | if ( !($pos1 === false) ){ |
---|
| 231 | $erreur_message .='Détection de : Bad recipient address syntax .'; |
---|
| 232 | $erreur_message .='Vérifiez les destinataires: (Bcc,Cc,To)<br />'; |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | $erreur_message .= sprintf(l10n('debug_message %s %s %s %s %s'),($ret==true)? "true" : "false",$message,$mailto,$headers,$nb_destinataires); |
---|
| 236 | //=============== La fonction mail à retournéeune erreur ========================= |
---|
| 237 | |
---|
[4020] | 238 | |
---|
[4029] | 239 | } |
---|
| 240 | |
---|
| 241 | if ($est_un_spam == false) |
---|
| 242 | { |
---|
| 243 | if ($mails_données['nb_mails']==0) { $mails_données['date_mail'] = time(); } |
---|
| 244 | $mails_données['nb_mails'] += $nb_destinataires; |
---|
[4020] | 245 | } |
---|
| 246 | else |
---|
| 247 | { |
---|
[4029] | 248 | $mails_données['nb_spams'] += $nb_destinataires; |
---|
| 249 | //--- Détection de spam ------------------ |
---|
| 250 | if ($mails_données['nb_spams']==0) {$mails_données['date_spam'] = time(); } |
---|
| 251 | |
---|
| 252 | $trop_de_spam =!(strpos(strtolower($message), 'trop de spam') === false); |
---|
| 253 | if ( $trop_de_spam ) { |
---|
| 254 | $mails_données['nb_spams_maxi']=$mails_données['nb_spams']; |
---|
[4045] | 255 | |
---|
[4029] | 256 | $mails_données['date_quarantaine']= time() ; |
---|
| 257 | $mails_données['quarantaine']= true ; |
---|
[4040] | 258 | $infos_message .=memo_var($mails_données); |
---|
[4029] | 259 | } |
---|
| 260 | |
---|
[4020] | 261 | } |
---|
| 262 | |
---|
| 263 | |
---|
[4029] | 264 | |
---|
[4020] | 265 | |
---|
[4029] | 266 | |
---|
[4020] | 267 | $ret=true; |
---|
| 268 | return $ret ; |
---|
| 269 | |
---|
| 270 | } |
---|
| 271 | |
---|
| 272 | //========================================================================================== |
---|
| 273 | function admin_menu($menu) |
---|
| 274 | { |
---|
| 275 | array_push($menu, array('NAME' => 'Mail_Superv', |
---|
| 276 | 'URL' => get_admin_plugin_menu_link(MAIL_SUPERV_PATH . 'admin/mail_superv_admin.php'))); |
---|
| 277 | return $menu; |
---|
| 278 | } |
---|
| 279 | |
---|
| 280 | |
---|
| 281 | add_event_handler('get_admin_plugin_menu_links', 'admin_menu'); |
---|
| 282 | //add_event_handler('loc_end_page_tail', 'affiche_message'); |
---|
| 283 | add_event_handler('loc_after_page_header', 'affiche_message'); |
---|
| 284 | |
---|
| 285 | ?> |
---|