[4020] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: Mail supervisor |
---|
[4225] | 4 | Version: 1.2.6.a |
---|
| 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!'); |
---|
[4051] | 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__)).'/'); |
---|
[4020] | 13 | include_once (MAIL_SUPERV_PATH.'include/constants.php'); |
---|
| 14 | |
---|
[4199] | 15 | /* EVENT_HANDLER_PRIORITY_NEUTRAL */ |
---|
[4020] | 16 | |
---|
[4180] | 17 | |
---|
[4220] | 18 | |
---|
| 19 | global $superv_champs , $superv_type ,$superv_bl_champs , $superv_bl_type ; |
---|
| 20 | $superv_champs = array( |
---|
| 21 | "id", |
---|
| 22 | "nb_mails", |
---|
| 23 | "date_mail", |
---|
| 24 | "nb_mails_maxi", |
---|
| 25 | "nb_mails_periode", |
---|
| 26 | "nb_spams", |
---|
| 27 | "date_spam", |
---|
| 28 | "nb_spams_maxi", |
---|
| 29 | "nb_spams_periode", |
---|
| 30 | "quarantaine", |
---|
| 31 | "date_quarantaine", |
---|
| 32 | "quarantaine_periode", |
---|
| 33 | "message", |
---|
| 34 | "message_test", |
---|
| 35 | "header_text", |
---|
| 36 | |
---|
| 37 | ); |
---|
| 38 | |
---|
| 39 | $superv_type = array( |
---|
| 40 | " SMALLINT( 5 ) NOT NULL DEFAULT '0'" , |
---|
| 41 | "INT NOT NULL DEFAULT '0'" , |
---|
| 42 | "INT NOT NULL DEFAULT '0'" , |
---|
| 43 | "INT NOT NULL DEFAULT '2000'", |
---|
| 44 | "TEXT" , |
---|
| 45 | "INT NOT NULL DEFAULT '0'", |
---|
| 46 | "INT NOT NULL DEFAULT '0'", |
---|
| 47 | "INT NOT NULL DEFAULT '10'", |
---|
| 48 | "TEXT" , |
---|
| 49 | "TEXT" , |
---|
| 50 | "INT NOT NULL DEFAULT '0'", |
---|
| 51 | "TEXT" , |
---|
| 52 | "TEXT" , |
---|
| 53 | "TEXT" , |
---|
| 54 | "TEXT" , |
---|
| 55 | |
---|
| 56 | ); |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | $superv_bl_champs = array( |
---|
| 60 | "id", |
---|
| 61 | "ip", |
---|
| 62 | "pays", |
---|
| 63 | "region", |
---|
| 64 | "ville", |
---|
| 65 | "adresse", |
---|
| 66 | "fai", |
---|
| 67 | "nb" |
---|
| 68 | ); |
---|
| 69 | |
---|
| 70 | $superv_bl_type = array( |
---|
| 71 | " smallint(5) UNSIGNED NOT NULL auto_increment ", |
---|
| 72 | "TEXT" , |
---|
| 73 | "TEXT" , |
---|
| 74 | "TEXT" , |
---|
| 75 | "TEXT" , |
---|
| 76 | "TEXT" , |
---|
| 77 | "TEXT" , |
---|
| 78 | " smallint(5) UNSIGNED " |
---|
| 79 | ); |
---|
| 80 | |
---|
| 81 | |
---|
[4020] | 82 | add_event_handler('send_mail', 'clj_mail',EVENT_HANDLER_PRIORITY_NEUTRAL - 1 , 6); |
---|
| 83 | |
---|
| 84 | function clj_mail($result, $mailto, $subject, $content, $headers, $args) |
---|
| 85 | { |
---|
[4053] | 86 | global $conf, $user, $lang_info, $conf_mail,$mails_options,$mails_données , $template,$page ,$erreur_message,$infos_message, $lang; |
---|
[4020] | 87 | // lecture config table ------------- |
---|
[4053] | 88 | load_language('plugin.lang', MAIL_SUPERV_PATH); |
---|
[4206] | 89 | |
---|
[4029] | 90 | $mails_options = explode("," , $conf['mail_superv']); |
---|
[4156] | 91 | |
---|
| 92 | if ($mails_options[3]=='on') |
---|
| 93 | { |
---|
| 94 | if (kill_list()) |
---|
| 95 | { |
---|
| 96 | $erreur_message .= l10n('is_a_spam') ; |
---|
| 97 | return true; |
---|
| 98 | } |
---|
| 99 | } |
---|
| 100 | |
---|
[4029] | 101 | $message =""; |
---|
[4040] | 102 | if (!isset($infos_message)) |
---|
| 103 | { |
---|
| 104 | $infos_message = ""; |
---|
| 105 | } |
---|
| 106 | if (!isset($erreur_message)) |
---|
| 107 | { |
---|
| 108 | $erreur_message = ''; |
---|
| 109 | } |
---|
[4020] | 110 | // lecture données ------------- |
---|
| 111 | $mails_données = Get_Datas(); |
---|
[4029] | 112 | |
---|
[4020] | 113 | |
---|
| 114 | $nb_mails = $mails_données['nb_mails'] ; |
---|
| 115 | $next_day = $mails_données['date_mail'] ; |
---|
| 116 | |
---|
| 117 | $reste = $mails_données['reste'] ; |
---|
| 118 | |
---|
[4029] | 119 | |
---|
| 120 | $rest_mail = $mails_données['rest_mail'] ; |
---|
| 121 | if ($rest_mail <=0 || $mails_données['nb_mails'] ==0 ){ |
---|
| 122 | $mails_données['nb_mails'] =0 ; |
---|
| 123 | $mails_données['date_mail'] = time(); |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | $rest_spam = $mails_données['rest_spam'] ; |
---|
| 127 | if ($rest_spam <=0 || $mails_données['nb_spams'] ==0 ){ |
---|
| 128 | $mails_données['nb_spams'] =0 ; |
---|
| 129 | $mails_données['date_spam'] = time(); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | $alerte = ( $mails_données['reste'] >0 ) ? true : false ; |
---|
| 133 | |
---|
[4040] | 134 | $alerte_mail = ( $mails_données['nb_mails'] > $mails_données['nb_mails_maxi']-1 ) ? true : false ; |
---|
| 135 | $alerte_spam = ( $mails_données['nb_spams'] > $mails_données['nb_spams_maxi']-1 ) ? true : false ; |
---|
[4029] | 136 | |
---|
[4020] | 137 | |
---|
[4029] | 138 | if ( ( !$alerte && !$alerte_spam && !$alerte_mail ) ) |
---|
| 139 | { |
---|
| 140 | |
---|
[4020] | 141 | $nb_destinataires=0; |
---|
[4045] | 142 | if ($mails_options[0] == 'on') { |
---|
| 143 | if ($mailto == "" ) $mailto = $conf_mail['email_webmaster']; |
---|
| 144 | } |
---|
| 145 | if ($mailto<>"" ) $nb_destinataires +=1; |
---|
[4049] | 146 | |
---|
| 147 | if (!empty($args['Bcc'])) { |
---|
| 148 | $nb_destinataires += count($args['Bcc']); |
---|
| 149 | } |
---|
| 150 | if (!empty($args['Cc'])) { |
---|
| 151 | $nb_destinataires += count($args['Cc']); |
---|
| 152 | } |
---|
[4020] | 153 | //================= réécriture de l'entête =============================== |
---|
[4045] | 154 | if ( $nb_destinataires == 1 ) |
---|
| 155 | { |
---|
| 156 | if ($mailto == "" ) |
---|
| 157 | { |
---|
[4049] | 158 | if (!empty($args['Cc']) and count($args['Cc']) > 0 ) $mailto = get_strict_email_list(implode(',', $args['Cc'])) ; |
---|
| 159 | if (!empty($args['Bcc']) and count($args['Bcc']) > 0 ) $mailto = get_strict_email_list(implode(',', $args['Bcc'])) ; |
---|
| 160 | |
---|
[4045] | 161 | $headers = preg_replace('/.*Bcc(.*).\n/i', '', $headers); |
---|
| 162 | $headers = preg_replace('/.*Cc(.*).\n/i', '', $headers); |
---|
[4049] | 163 | |
---|
[4045] | 164 | } |
---|
| 165 | }else{ |
---|
| 166 | |
---|
[4054] | 167 | |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | //============================================================================= |
---|
| 171 | if (!empty($args['Cc'])) |
---|
[4045] | 172 | { |
---|
[4054] | 173 | $headers= corrige_header('Cc',$headers,$args); |
---|
[4045] | 174 | } |
---|
[4020] | 175 | if (!empty($args['Bcc'])) |
---|
[4045] | 176 | { |
---|
[4054] | 177 | $headers = corrige_header('Bcc',$headers,$args); |
---|
[4045] | 178 | } |
---|
[4054] | 179 | //============================================================================= |
---|
[4020] | 180 | if ($mails_options[2]=='on') { |
---|
| 181 | |
---|
| 182 | $texte = "This is a multi-part message in MIME format.\n"; |
---|
| 183 | |
---|
| 184 | $texte .= "-----=".$conf_mail['boundary_key']."\n"; |
---|
| 185 | $texte .= "Ceci est un message est au format MIME.\n"; |
---|
| 186 | $texte .= 'Content-Type: text/plain; charset="UTF-8"'."\n"; |
---|
| 187 | $texte .= 'Content-Transfer-Encoding: 8bit'."\n\n"; |
---|
| 188 | $texte .= $mails_données['header_text']; // A voir texte brut... |
---|
| 189 | |
---|
| 190 | $texte .= "\n\n"; |
---|
| 191 | |
---|
| 192 | $content =$texte .$content ; |
---|
| 193 | } |
---|
[4029] | 194 | |
---|
[4020] | 195 | $ret=false; |
---|
[4030] | 196 | |
---|
[4029] | 197 | //======== Non mise en quarantaine ============= |
---|
[4020] | 198 | ob_start(); |
---|
[4029] | 199 | $ret = false; |
---|
| 200 | if ($nb_destinataires > 0) { |
---|
[4045] | 201 | $ret = mail($mailto, $subject, $content, $headers); |
---|
[4054] | 202 | |
---|
[4029] | 203 | }else{ |
---|
[4156] | 204 | $message .= l10n('no_receiver_available'); |
---|
[4029] | 205 | } |
---|
| 206 | $message .= ob_get_contents(); |
---|
| 207 | ob_end_clean(); |
---|
| 208 | $mails_données['message']=$message; |
---|
| 209 | Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto); |
---|
[4020] | 210 | |
---|
[4029] | 211 | |
---|
[4020] | 212 | |
---|
[4029] | 213 | } else { |
---|
[4020] | 214 | |
---|
[4029] | 215 | //================== Est en quarantaine ======================= |
---|
| 216 | $erreur_message .= l10n('To_day_is')."<br />"; |
---|
| 217 | if ($alerte_spam ) { |
---|
| 218 | $type="Spams"; |
---|
[4045] | 219 | |
---|
[4040] | 220 | $d1=$mails_données['nb_spams'] . ' \\ ' . $mails_données['nb_spams_maxi']; |
---|
[4045] | 221 | $d2=$mails_données['nb_spams']; |
---|
[4029] | 222 | $d3= $mails_données['rest_spam']; |
---|
| 223 | $d4=time()+$d3 ; |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | if ($alerte_mail) { |
---|
| 227 | $type="Mails"; |
---|
| 228 | |
---|
[4040] | 229 | $d1=$mails_données['nb_mails']. ' \\ ' . $mails_données['nb_mails_maxi'];; |
---|
[4029] | 230 | $d2=$mails_données['date_mail']; |
---|
| 231 | $d3= $mails_données['rest_mail']; |
---|
| 232 | $d4=time()+$d3 ; |
---|
[4040] | 233 | |
---|
| 234 | |
---|
[4029] | 235 | } |
---|
| 236 | if ($alerte) { |
---|
| 237 | $type="Spams(Quarantaine)"; |
---|
[4040] | 238 | $d1=$mails_données['nb_spams'] . ' \\ ' . $mails_données['nb_spams_maxi']; |
---|
[4029] | 239 | $d2=$mails_données['date_quarantaine']; |
---|
| 240 | $d3= $mails_données['reste']; |
---|
| 241 | $d4=time()+$d3 ; |
---|
[4040] | 242 | } |
---|
[4020] | 243 | |
---|
[4029] | 244 | |
---|
| 245 | $d2=date(l10n('formatdate'),$d2); |
---|
| 246 | $d3=int_to_heure($d3) ; |
---|
| 247 | $d4=date(l10n('formatdate'),$d4); |
---|
| 248 | |
---|
[4040] | 249 | if ($alerte_mail) { |
---|
| 250 | $erreur_message .='<br />'.sprintf(l10n('alerte_mail %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />'; |
---|
| 251 | }else{ |
---|
| 252 | $erreur_message .='<br />'.sprintf(l10n('mise_en_quarantaine %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />'; |
---|
| 253 | |
---|
| 254 | } |
---|
| 255 | $infos_message = l10n('mail_not_send'); |
---|
| 256 | |
---|
[4029] | 257 | } |
---|
| 258 | sauve_données(); |
---|
| 259 | return true ; |
---|
| 260 | } |
---|
| 261 | //=========================================================================================== |
---|
| 262 | function Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto) |
---|
| 263 | { |
---|
[4156] | 264 | global $conf, $user, $conf_mail,$mails_options,$mails_données , $template,$page ,$infos_message,$erreur_message,$args,$lang, $lang_info; |
---|
| 265 | |
---|
| 266 | |
---|
| 267 | |
---|
[4029] | 268 | $match=array("<",">"); |
---|
| 269 | $string=array("<",">") ; |
---|
| 270 | |
---|
[4059] | 271 | //Warning: mail() has been disabled for security reasons |
---|
[4029] | 272 | |
---|
| 273 | $est_un_spam =!(strpos(strtolower($message), 'spam') === false); |
---|
| 274 | $headers=str_replace( $match,$string, $headers); |
---|
| 275 | |
---|
| 276 | if ( ($ret==false) || ($est_un_spam==true) || ($nb_destinataires == 0) ) { |
---|
| 277 | ; // Bad recipient address syntax |
---|
| 278 | $pos1 = strpos(strtolower($message), 'bad recipient address syntax'); |
---|
| 279 | if ( !($pos1 === false) ){ |
---|
[4156] | 280 | $erreur_message .= l10n('detection_de').' : Bad recipient address syntax .'; |
---|
| 281 | $erreur_message .= l10n('verifiez_les_destinataires').' (Bcc,Cc,To)<br />'; |
---|
[4029] | 282 | } |
---|
| 283 | |
---|
| 284 | $erreur_message .= sprintf(l10n('debug_message %s %s %s %s %s'),($ret==true)? "true" : "false",$message,$mailto,$headers,$nb_destinataires); |
---|
| 285 | //=============== La fonction mail à retournéeune erreur ========================= |
---|
| 286 | |
---|
[4020] | 287 | |
---|
[4029] | 288 | } |
---|
| 289 | |
---|
| 290 | if ($est_un_spam == false) |
---|
| 291 | { |
---|
| 292 | if ($mails_données['nb_mails']==0) { $mails_données['date_mail'] = time(); } |
---|
| 293 | $mails_données['nb_mails'] += $nb_destinataires; |
---|
[4020] | 294 | } |
---|
| 295 | else |
---|
| 296 | { |
---|
[4029] | 297 | $mails_données['nb_spams'] += $nb_destinataires; |
---|
| 298 | //--- Détection de spam ------------------ |
---|
| 299 | if ($mails_données['nb_spams']==0) {$mails_données['date_spam'] = time(); } |
---|
| 300 | |
---|
| 301 | $trop_de_spam =!(strpos(strtolower($message), 'trop de spam') === false); |
---|
| 302 | if ( $trop_de_spam ) { |
---|
| 303 | $mails_données['nb_spams_maxi']=$mails_données['nb_spams']; |
---|
[4045] | 304 | |
---|
[4029] | 305 | $mails_données['date_quarantaine']= time() ; |
---|
| 306 | $mails_données['quarantaine']= true ; |
---|
[4040] | 307 | $infos_message .=memo_var($mails_données); |
---|
[4029] | 308 | } |
---|
| 309 | |
---|
[4020] | 310 | } |
---|
| 311 | |
---|
[4029] | 312 | |
---|
[4020] | 313 | |
---|
[4029] | 314 | |
---|
[4020] | 315 | $ret=true; |
---|
| 316 | return $ret ; |
---|
| 317 | |
---|
| 318 | } |
---|
| 319 | |
---|
| 320 | //========================================================================================== |
---|
| 321 | function admin_menu($menu) |
---|
| 322 | { |
---|
| 323 | array_push($menu, array('NAME' => 'Mail_Superv', |
---|
| 324 | 'URL' => get_admin_plugin_menu_link(MAIL_SUPERV_PATH . 'admin/mail_superv_admin.php'))); |
---|
| 325 | return $menu; |
---|
| 326 | } |
---|
| 327 | |
---|
[4199] | 328 | function affiche_spam () |
---|
[4020] | 329 | |
---|
[4199] | 330 | { |
---|
| 331 | include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); |
---|
| 332 | |
---|
| 333 | affiche_message(); |
---|
| 334 | } |
---|
[4020] | 335 | add_event_handler('get_admin_plugin_menu_links', 'admin_menu'); |
---|
[4199] | 336 | add_event_handler('loc_after_page_header','affiche_spam' ); |
---|
[4156] | 337 | |
---|
[4020] | 338 | ?> |
---|