[4020] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: Mail supervisor |
---|
[8917] | 4 | Version: 1.4.4 Beta |
---|
[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!'); |
---|
[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 | |
---|
[4715] | 17 | global $conf ; |
---|
[4020] | 18 | add_event_handler('send_mail', 'clj_mail',EVENT_HANDLER_PRIORITY_NEUTRAL - 1 , 6); |
---|
| 19 | function clj_mail($result, $mailto, $subject, $content, $headers, $args) |
---|
| 20 | { |
---|
[7050] | 21 | global $conf, $user, $lang_info, $conf_mail,$mails_options,$mails_donnees , $template,$page ,$erreur_message,$infos_message, $lang; |
---|
[4020] | 22 | // lecture config table ------------- |
---|
[8917] | 23 | include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); |
---|
[4861] | 24 | load_language('plugin.lang', MAIL_SUPERV_PATH); |
---|
[8917] | 25 | |
---|
| 26 | if (isset($_POST["Submit"]) ) |
---|
| 27 | { |
---|
| 28 | if ($_POST["Submit"] != l10n('Sv_Envoyer') ) return true ; |
---|
| 29 | } |
---|
| 30 | $message =""; |
---|
| 31 | if (!isset($infos_message)) |
---|
| 32 | { |
---|
| 33 | $infos_message = ""; |
---|
| 34 | } |
---|
| 35 | if (!isset($erreur_message)) |
---|
| 36 | { |
---|
| 37 | $erreur_message = ''; |
---|
| 38 | } |
---|
[4861] | 39 | $mails_options = explode("," , $conf['mail_superv']); |
---|
[7050] | 40 | //======== verification si envoie de mail ou blocage connexion ===================== |
---|
[4861] | 41 | if ($mails_options[no_mail_list]=='on' || $mails_options[no_connect] == 'on' ) |
---|
[4156] | 42 | { |
---|
| 43 | if (kill_list()) |
---|
| 44 | { |
---|
[4879] | 45 | $erreur_message .= "<BR />".l10n('Sv_is_a_spam') ; |
---|
[4861] | 46 | if ($mails_options[no_connect] == 'on' ){ |
---|
| 47 | if ($user['status'] == 'webmaster' ) |
---|
| 48 | { |
---|
| 49 | //---------- continuer si web master ---------- |
---|
| 50 | }else{ |
---|
| 51 | if (!isset($_GET['admin'])) { |
---|
[4323] | 52 | die('Blacklist : <br />' .$erreur_message. '<br /> Hacking attempt!'); |
---|
[4861] | 53 | }elseif ($_GET['admin'] != 'piwigo') |
---|
| 54 | { |
---|
[4323] | 55 | die('blacklist Hacking attempt!'); |
---|
| 56 | } |
---|
[4861] | 57 | return true; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | } |
---|
| 61 | |
---|
[4156] | 62 | } |
---|
| 63 | } |
---|
| 64 | |
---|
[8917] | 65 | |
---|
[7050] | 66 | // lecture donnees ------------- |
---|
| 67 | $mails_donnees = Get_Datas(); |
---|
[4888] | 68 | |
---|
[7050] | 69 | $nb_mails = $mails_donnees['nb_mails'] ; |
---|
| 70 | $next_day = $mails_donnees['date_mail'] ; |
---|
[4020] | 71 | |
---|
[7050] | 72 | $reste = $mails_donnees['reste'] ; |
---|
[4020] | 73 | |
---|
[4029] | 74 | |
---|
[7050] | 75 | $rest_mail = $mails_donnees['rest_mail'] ; |
---|
| 76 | if ($rest_mail <=0 || $mails_donnees['nb_mails'] ==0 ){ |
---|
| 77 | $mails_donnees['nb_mails'] =0 ; |
---|
| 78 | $mails_donnees['date_mail'] = time(); |
---|
[4029] | 79 | } |
---|
| 80 | |
---|
[7050] | 81 | $rest_spam = $mails_donnees['rest_spam'] ; |
---|
| 82 | if ($rest_spam <=0 || $mails_donnees['nb_spams'] ==0 ){ |
---|
| 83 | $mails_donnees['nb_spams'] =0 ; |
---|
| 84 | $mails_donnees['date_spam'] = time(); |
---|
[4029] | 85 | } |
---|
| 86 | |
---|
[7050] | 87 | $alerte = ( $mails_donnees['reste'] >0 ) ? true : false ; |
---|
[4029] | 88 | |
---|
[7050] | 89 | $alerte_mail = ( $mails_donnees['nb_mails'] > $mails_donnees['nb_mails_maxi']-1 ) ? true : false ; |
---|
| 90 | $alerte_spam = ( $mails_donnees['nb_spams'] > $mails_donnees['nb_spams_maxi']-1 ) ? true : false ; |
---|
[4029] | 91 | |
---|
[4020] | 92 | |
---|
[4029] | 93 | if ( ( !$alerte && !$alerte_spam && !$alerte_mail ) ) |
---|
| 94 | { |
---|
| 95 | |
---|
[4020] | 96 | $nb_destinataires=0; |
---|
[4861] | 97 | if ($mails_options[check_mailto] == 'on') { |
---|
[4045] | 98 | if ($mailto == "" ) $mailto = $conf_mail['email_webmaster']; |
---|
| 99 | } |
---|
| 100 | if ($mailto<>"" ) $nb_destinataires +=1; |
---|
[4049] | 101 | |
---|
[8917] | 102 | if (!empty($args['Bcc'])) { $nb_destinataires += count($args['Bcc']); } |
---|
| 103 | if (!empty($args['Cc'])) { $nb_destinataires += count($args['Cc']); } |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | $infos_message .= "<hr> Theme :" . ($args['theme'] ) ."<br />"; |
---|
| 107 | $infos_message .="nombre de destinataire:".$nb_destinataires." <br />" ; |
---|
| 108 | |
---|
| 109 | //================= reecriture de l'entete =============================== |
---|
| 110 | $match=array("<",">"); |
---|
| 111 | $string=array("<",">") ; |
---|
| 112 | |
---|
| 113 | if ( $nb_destinataires == 1 && $mailto != "" ) |
---|
| 114 | { |
---|
| 115 | $infos_message .="--> Mailto: " . $mailto." \n" ; |
---|
| 116 | |
---|
| 117 | if ($mailto != "" ) |
---|
[4045] | 118 | { |
---|
[8917] | 119 | |
---|
| 120 | $mailto = $mailto ." \n" ; |
---|
| 121 | $headers = preg_replace('/.*Bcc(.*).\n/i', '', $headers); |
---|
| 122 | $headers = preg_replace('/.*Cc(.*).\n/i', '', $headers); |
---|
| 123 | |
---|
| 124 | |
---|
[4045] | 125 | } |
---|
[8917] | 126 | //============================================================================= |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | if (!empty($args['Bcc']) ) $infos_message .="Bcc: " . memo_var($args['Bcc']) ." \n"; |
---|
| 130 | if (!empty($args['Cc']) ) $infos_message .="Cc: " . memo_var($args['Cc'])." \n" ; |
---|
| 131 | $infos_message .="Mailto: [" . $mailto . "]"." \n".$headers; |
---|
| 132 | |
---|
[4045] | 133 | }else{ |
---|
[8917] | 134 | //=== plusieurs destinataires =========== |
---|
| 135 | $cl_list_mail=""; |
---|
[4054] | 136 | |
---|
[8917] | 137 | if ($mailto !="") $infos_message .="To: " . $mailto . " "." /n" ; |
---|
| 138 | if (!empty($args['Cc'])) { |
---|
| 139 | $ret= corrige_header('Cc',$headers,$args,$cl_list_mail); |
---|
| 140 | $headers = $ret->headers; |
---|
| 141 | $infos_message .="Cc: " . ( $ret->list_mail)." <br />" ; |
---|
| 142 | } |
---|
| 143 | if (!empty($args['Bcc'])){ |
---|
| 144 | $ret = corrige_header('Bcc',$headers,$args,$cl_list_mail); |
---|
| 145 | |
---|
| 146 | $headers = $ret->headers ; |
---|
| 147 | $infos_message .="Bcc: " . ( $ret->list_mail) ." <br />"; |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | $infos_message .= " " ; |
---|
| 151 | } |
---|
| 152 | // $infos_message .= $content ; |
---|
| 153 | //============================================================================= |
---|
[4861] | 154 | if ($mails_options[check_header_text]=='on') { |
---|
[4020] | 155 | |
---|
| 156 | $texte = "This is a multi-part message in MIME format.\n"; |
---|
| 157 | |
---|
| 158 | $texte .= "-----=".$conf_mail['boundary_key']."\n"; |
---|
| 159 | $texte .= "Ceci est un message est au format MIME.\n"; |
---|
| 160 | $texte .= 'Content-Type: text/plain; charset="UTF-8"'."\n"; |
---|
| 161 | $texte .= 'Content-Transfer-Encoding: 8bit'."\n\n"; |
---|
[7050] | 162 | $texte .= $mails_donnees['header_text']; // A voir texte brut... |
---|
[4020] | 163 | |
---|
| 164 | $texte .= "\n\n"; |
---|
| 165 | |
---|
| 166 | $content =$texte .$content ; |
---|
| 167 | } |
---|
[4029] | 168 | |
---|
[4020] | 169 | $ret=false; |
---|
[8917] | 170 | |
---|
[4029] | 171 | //======== Non mise en quarantaine ============= |
---|
[4020] | 172 | ob_start(); |
---|
[4029] | 173 | $ret = false; |
---|
| 174 | if ($nb_destinataires > 0) { |
---|
[8917] | 175 | // corrige erreur 'mail dropped, bare LF found' |
---|
| 176 | $content = str_replace("\n.", "\n..", $content); |
---|
| 177 | $headers = str_replace("\n.", "\n..", $headers); |
---|
| 178 | $subject = str_replace("\n.", "\n..", $subject); |
---|
| 179 | $mailto = str_replace("\n.", "\n..", $mailto); |
---|
| 180 | $ret = mail($mailto, $subject, $content, $headers); |
---|
| 181 | |
---|
[4029] | 182 | }else{ |
---|
[4879] | 183 | $message .= l10n('Sv_no_receiver_available'); |
---|
[4029] | 184 | } |
---|
| 185 | $message .= ob_get_contents(); |
---|
| 186 | ob_end_clean(); |
---|
[7050] | 187 | $mails_donnees['message']=$message; |
---|
[4029] | 188 | Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto); |
---|
[4020] | 189 | |
---|
[4029] | 190 | |
---|
[4020] | 191 | |
---|
[4029] | 192 | } else { |
---|
[4020] | 193 | |
---|
[4029] | 194 | //================== Est en quarantaine ======================= |
---|
[4879] | 195 | $erreur_message .= l10n('Sv_To_day_is')."<br />"; |
---|
[4029] | 196 | if ($alerte_spam ) { |
---|
| 197 | $type="Spams"; |
---|
[4045] | 198 | |
---|
[7050] | 199 | $d1=$mails_donnees['nb_spams'] . ' \\ ' . $mails_donnees['nb_spams_maxi']; |
---|
| 200 | $d2=$mails_donnees['nb_spams']; |
---|
| 201 | $d3= $mails_donnees['rest_spam']; |
---|
[4029] | 202 | $d4=time()+$d3 ; |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | if ($alerte_mail) { |
---|
| 206 | $type="Mails"; |
---|
| 207 | |
---|
[7050] | 208 | $d1=$mails_donnees['nb_mails']. ' \\ ' . $mails_donnees['nb_mails_maxi'];; |
---|
| 209 | $d2=$mails_donnees['date_mail']; |
---|
| 210 | $d3= $mails_donnees['rest_mail']; |
---|
[4029] | 211 | $d4=time()+$d3 ; |
---|
[4040] | 212 | |
---|
| 213 | |
---|
[4029] | 214 | } |
---|
| 215 | if ($alerte) { |
---|
| 216 | $type="Spams(Quarantaine)"; |
---|
[7050] | 217 | $d1=$mails_donnees['nb_spams'] . ' \\ ' . $mails_donnees['nb_spams_maxi']; |
---|
| 218 | $d2=$mails_donnees['date_quarantaine']; |
---|
| 219 | $d3= $mails_donnees['reste']; |
---|
[4029] | 220 | $d4=time()+$d3 ; |
---|
[4040] | 221 | } |
---|
[4020] | 222 | |
---|
[4029] | 223 | |
---|
[4879] | 224 | $d2=date(l10n('Sv_formatdate'),$d2); |
---|
[4029] | 225 | $d3=int_to_heure($d3) ; |
---|
[4879] | 226 | $d4=date(l10n('Sv_formatdate'),$d4); |
---|
[4029] | 227 | |
---|
[4040] | 228 | if ($alerte_mail) { |
---|
[4879] | 229 | $erreur_message .='<br />'.sprintf(l10n('Sv_alerte_mail %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />'; |
---|
[4040] | 230 | }else{ |
---|
[4879] | 231 | $erreur_message .='<br />'.sprintf(l10n('Sv_mise_en_quarantaine %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />'; |
---|
[4040] | 232 | |
---|
| 233 | } |
---|
[8917] | 234 | $infos_message .= l10n('Sv_mail_not_send'); |
---|
[4040] | 235 | |
---|
[4029] | 236 | } |
---|
[7050] | 237 | sauve_donnees(); |
---|
[4029] | 238 | return true ; |
---|
| 239 | } |
---|
| 240 | //=========================================================================================== |
---|
| 241 | function Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto) |
---|
| 242 | { |
---|
[7050] | 243 | global $conf, $user, $conf_mail,$mails_options,$mails_donnees , $template,$page ,$infos_message,$erreur_message,$args,$lang, $lang_info; |
---|
[4156] | 244 | |
---|
| 245 | |
---|
| 246 | |
---|
[4029] | 247 | $match=array("<",">"); |
---|
| 248 | $string=array("<",">") ; |
---|
[4059] | 249 | //Warning: mail() has been disabled for security reasons |
---|
[4029] | 250 | |
---|
| 251 | $est_un_spam =!(strpos(strtolower($message), 'spam') === false); |
---|
| 252 | $headers=str_replace( $match,$string, $headers); |
---|
| 253 | |
---|
| 254 | if ( ($ret==false) || ($est_un_spam==true) || ($nb_destinataires == 0) ) { |
---|
| 255 | ; // Bad recipient address syntax |
---|
| 256 | $pos1 = strpos(strtolower($message), 'bad recipient address syntax'); |
---|
| 257 | if ( !($pos1 === false) ){ |
---|
[8917] | 258 | $erreur_message .= l10n('Sv_detection_de').' Bad recipient address syntax .'; |
---|
[4879] | 259 | $erreur_message .= l10n('Sv_verifiez_les_destinataires').' (Bcc,Cc,To)<br />'; |
---|
[4029] | 260 | } |
---|
| 261 | |
---|
[8917] | 262 | $erreur_message .= sprintf(l10n('Sv_debug_message'), |
---|
| 263 | ($ret==true)? "true" : "false", |
---|
| 264 | $message , |
---|
| 265 | $mailto , |
---|
| 266 | $headers , |
---|
| 267 | $nb_destinataires ); |
---|
| 268 | //=============== La fonction mail retourneeune erreur ========================= |
---|
[4029] | 269 | |
---|
[4020] | 270 | |
---|
[4029] | 271 | } |
---|
| 272 | |
---|
| 273 | if ($est_un_spam == false) |
---|
| 274 | { |
---|
[7050] | 275 | if ($mails_donnees['nb_mails']==0) { $mails_donnees['date_mail'] = time(); } |
---|
| 276 | $mails_donnees['nb_mails'] += $nb_destinataires; |
---|
[4020] | 277 | } |
---|
| 278 | else |
---|
| 279 | { |
---|
[7050] | 280 | $mails_donnees['nb_spams'] += $nb_destinataires; |
---|
| 281 | //--- Detection de spam ------------------ |
---|
| 282 | if ($mails_donnees['nb_spams']==0) {$mails_donnees['date_spam'] = time(); } |
---|
[4029] | 283 | |
---|
| 284 | $trop_de_spam =!(strpos(strtolower($message), 'trop de spam') === false); |
---|
| 285 | if ( $trop_de_spam ) { |
---|
[7050] | 286 | $mails_donnees['nb_spams_maxi']=$mails_donnees['nb_spams']; |
---|
[4045] | 287 | |
---|
[7050] | 288 | $mails_donnees['date_quarantaine']= time() ; |
---|
| 289 | $mails_donnees['quarantaine']= true ; |
---|
| 290 | $infos_message .=memo_var($mails_donnees); |
---|
[4029] | 291 | } |
---|
| 292 | |
---|
[4020] | 293 | } |
---|
| 294 | $ret=true; |
---|
| 295 | return $ret ; |
---|
| 296 | |
---|
| 297 | } |
---|
| 298 | |
---|
| 299 | //========================================================================================== |
---|
[4323] | 300 | add_event_handler('get_admin_plugin_menu_links', 'admin_menu'); |
---|
[4020] | 301 | function admin_menu($menu) |
---|
| 302 | { |
---|
| 303 | array_push($menu, array('NAME' => 'Mail_Superv', |
---|
| 304 | 'URL' => get_admin_plugin_menu_link(MAIL_SUPERV_PATH . 'admin/mail_superv_admin.php'))); |
---|
| 305 | return $menu; |
---|
| 306 | } |
---|
[4323] | 307 | //========================================================================================== |
---|
| 308 | add_event_handler('loc_after_page_header','affiche_spam' );// |
---|
[4199] | 309 | function affiche_spam () |
---|
[4020] | 310 | |
---|
[4199] | 311 | { |
---|
| 312 | include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); |
---|
| 313 | |
---|
| 314 | affiche_message(); |
---|
[4323] | 315 | |
---|
[4199] | 316 | } |
---|
[4861] | 317 | include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); |
---|
[4715] | 318 | $mails_options = explode("," , $conf['mail_superv']); |
---|
[8917] | 319 | |
---|
[4323] | 320 | //========================================================================================== |
---|
[4861] | 321 | if ($mails_options[set_id]=='on' ) { |
---|
[4349] | 322 | add_event_handler('register_user_check', 'Test_spam_g', EVENT_HANDLER_PRIORITY_NEUTRAL +2 , 2); |
---|
[4715] | 323 | } |
---|
[4349] | 324 | function Test_spam_g ($err, $user) |
---|
[4323] | 325 | { |
---|
[4715] | 326 | |
---|
| 327 | if (count($err)!=0 ) return $err ; |
---|
[4349] | 328 | if ( !isset($_POST['submit_add']) && !isset($_POST['submit']) ) return $err ; |
---|
| 329 | //Liableelard |
---|
[4337] | 330 | include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); |
---|
[8917] | 331 | |
---|
[4349] | 332 | if ( isset($_POST['submit'])) { |
---|
| 333 | $mail = $_POST['mail_address'] ; |
---|
| 334 | $user_name = $_POST['login'] ; |
---|
| 335 | }else{ |
---|
| 336 | $mail = $user['email']; |
---|
| 337 | $user_name = $user['username']; |
---|
| 338 | } |
---|
[8917] | 339 | $user_name =""; // suppression du test sur user name. |
---|
[4349] | 340 | $ip='0'; |
---|
[8917] | 341 | |
---|
[4349] | 342 | if (test_spam($ip,$user_name ,$mail )) |
---|
| 343 | { |
---|
[8917] | 344 | //if (test_spam($ip,$user_name ,"" )) { |
---|
| 345 | // $err[] = $user_name . " ". l10n('Sv_is_a_login_spam') ; |
---|
| 346 | // }else |
---|
[4879] | 347 | $err[] = $user_name . " : " .$mail . " ". l10n('Sv_is_a_spam') ; |
---|
[4323] | 348 | } |
---|
[4715] | 349 | |
---|
[4349] | 350 | return $err ; |
---|
[4323] | 351 | } |
---|
[8917] | 352 | |
---|
| 353 | |
---|
[4888] | 354 | ?> |
---|