| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | Plugin Name: Mail supervisor |
|---|
| 4 | Version: 1.3.3 |
|---|
| 5 | Description: Mail supervisor surveille l'envoie des mails. |
|---|
| 6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=315 |
|---|
| 7 | Author: cljosse |
|---|
| 8 | Author URI:http://cljosse.free.fr |
|---|
| 9 | */ |
|---|
| 10 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
|---|
| 11 | if (!defined('MAIL_SUPERV_DIR')) define('MAIL_SUPERV_DIR' , basename(dirname(__FILE__))); |
|---|
| 12 | if (!defined('MAIL_SUPERV_PATH')) define('MAIL_SUPERV_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
|---|
| 13 | include_once (MAIL_SUPERV_PATH.'include/constants.php'); |
|---|
| 14 | |
|---|
| 15 | /* EVENT_HANDLER_PRIORITY_NEUTRAL */ |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 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 | global $conf ; |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | add_event_handler('send_mail', 'clj_mail',EVENT_HANDLER_PRIORITY_NEUTRAL - 1 , 6); |
|---|
| 85 | |
|---|
| 86 | function clj_mail($result, $mailto, $subject, $content, $headers, $args) |
|---|
| 87 | { |
|---|
| 88 | global $conf, $user, $lang_info, $conf_mail,$mails_options,$mails_donn�es , $template,$page ,$erreur_message,$infos_message, $lang; |
|---|
| 89 | // lecture config table ------------- |
|---|
| 90 | include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); |
|---|
| 91 | load_language('plugin.lang', MAIL_SUPERV_PATH); |
|---|
| 92 | $mails_options = explode("," , $conf['mail_superv']); |
|---|
| 93 | //======== v�rification si envoie de mail ou blocage connexion ===================== |
|---|
| 94 | if ($mails_options[no_mail_list]=='on' || $mails_options[no_connect] == 'on' ) |
|---|
| 95 | { |
|---|
| 96 | if (kill_list()) |
|---|
| 97 | { |
|---|
| 98 | $erreur_message .= "<BR />".l10n('is_a_spam') ; |
|---|
| 99 | if ($mails_options[no_connect] == 'on' ){ |
|---|
| 100 | if ($user['status'] == 'webmaster' ) |
|---|
| 101 | { |
|---|
| 102 | //---------- continuer si web master ---------- |
|---|
| 103 | }else{ |
|---|
| 104 | if (!isset($_GET['admin'])) { |
|---|
| 105 | die('Blacklist : <br />' .$erreur_message. '<br /> Hacking attempt!'); |
|---|
| 106 | }elseif ($_GET['admin'] != 'piwigo') |
|---|
| 107 | { |
|---|
| 108 | die('blacklist Hacking attempt!'); |
|---|
| 109 | } |
|---|
| 110 | return true; |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | } |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | $message =""; |
|---|
| 119 | if (!isset($infos_message)) |
|---|
| 120 | { |
|---|
| 121 | $infos_message = ""; |
|---|
| 122 | } |
|---|
| 123 | if (!isset($erreur_message)) |
|---|
| 124 | { |
|---|
| 125 | $erreur_message = ''; |
|---|
| 126 | } |
|---|
| 127 | // lecture donn�es ------------- |
|---|
| 128 | $mails_donn�es = Get_Datas(); |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | $nb_mails = $mails_donn�es['nb_mails'] ; |
|---|
| 132 | $next_day = $mails_donn�es['date_mail'] ; |
|---|
| 133 | |
|---|
| 134 | $reste = $mails_donn�es['reste'] ; |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | $rest_mail = $mails_donn�es['rest_mail'] ; |
|---|
| 138 | if ($rest_mail <=0 || $mails_donn�es['nb_mails'] ==0 ){ |
|---|
| 139 | $mails_donn�es['nb_mails'] =0 ; |
|---|
| 140 | $mails_donn�es['date_mail'] = time(); |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | $rest_spam = $mails_donn�es['rest_spam'] ; |
|---|
| 144 | if ($rest_spam <=0 || $mails_donn�es['nb_spams'] ==0 ){ |
|---|
| 145 | $mails_donn�es['nb_spams'] =0 ; |
|---|
| 146 | $mails_donn�es['date_spam'] = time(); |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | $alerte = ( $mails_donn�es['reste'] >0 ) ? true : false ; |
|---|
| 150 | |
|---|
| 151 | $alerte_mail = ( $mails_donn�es['nb_mails'] > $mails_donn�es['nb_mails_maxi']-1 ) ? true : false ; |
|---|
| 152 | $alerte_spam = ( $mails_donn�es['nb_spams'] > $mails_donn�es['nb_spams_maxi']-1 ) ? true : false ; |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | if ( ( !$alerte && !$alerte_spam && !$alerte_mail ) ) |
|---|
| 156 | { |
|---|
| 157 | |
|---|
| 158 | $nb_destinataires=0; |
|---|
| 159 | if ($mails_options[check_mailto] == 'on') { |
|---|
| 160 | if ($mailto == "" ) $mailto = $conf_mail['email_webmaster']; |
|---|
| 161 | } |
|---|
| 162 | if ($mailto<>"" ) $nb_destinataires +=1; |
|---|
| 163 | |
|---|
| 164 | if (!empty($args['Bcc'])) { |
|---|
| 165 | $nb_destinataires += count($args['Bcc']); |
|---|
| 166 | } |
|---|
| 167 | if (!empty($args['Cc'])) { |
|---|
| 168 | $nb_destinataires += count($args['Cc']); |
|---|
| 169 | } |
|---|
| 170 | //================= r��criture de l'ent�te =============================== |
|---|
| 171 | if ( $nb_destinataires == 1 ) |
|---|
| 172 | { |
|---|
| 173 | if ($mailto == "" ) |
|---|
| 174 | { |
|---|
| 175 | if (!empty($args['Cc']) and count($args['Cc']) > 0 ) $mailto = get_strict_email_list(implode(',', $args['Cc'])) ; |
|---|
| 176 | if (!empty($args['Bcc']) and count($args['Bcc']) > 0 ) $mailto = get_strict_email_list(implode(',', $args['Bcc'])) ; |
|---|
| 177 | |
|---|
| 178 | $headers = preg_replace('/.*Bcc(.*).\n/i', '', $headers); |
|---|
| 179 | $headers = preg_replace('/.*Cc(.*).\n/i', '', $headers); |
|---|
| 180 | |
|---|
| 181 | } |
|---|
| 182 | }else{ |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | //============================================================================= |
|---|
| 188 | if (!empty($args['Cc'])) |
|---|
| 189 | { |
|---|
| 190 | $headers= corrige_header('Cc',$headers,$args); |
|---|
| 191 | } |
|---|
| 192 | if (!empty($args['Bcc'])) |
|---|
| 193 | { |
|---|
| 194 | $headers = corrige_header('Bcc',$headers,$args); |
|---|
| 195 | } |
|---|
| 196 | //============================================================================= |
|---|
| 197 | if ($mails_options[check_header_text]=='on') { |
|---|
| 198 | |
|---|
| 199 | $texte = "This is a multi-part message in MIME format.\n"; |
|---|
| 200 | |
|---|
| 201 | $texte .= "-----=".$conf_mail['boundary_key']."\n"; |
|---|
| 202 | $texte .= "Ceci est un message est au format MIME.\n"; |
|---|
| 203 | $texte .= 'Content-Type: text/plain; charset="UTF-8"'."\n"; |
|---|
| 204 | $texte .= 'Content-Transfer-Encoding: 8bit'."\n\n"; |
|---|
| 205 | $texte .= $mails_donn�es['header_text']; // A voir texte brut... |
|---|
| 206 | |
|---|
| 207 | $texte .= "\n\n"; |
|---|
| 208 | |
|---|
| 209 | $content =$texte .$content ; |
|---|
| 210 | } |
|---|
| 211 | |
|---|
| 212 | $ret=false; |
|---|
| 213 | |
|---|
| 214 | //======== Non mise en quarantaine ============= |
|---|
| 215 | ob_start(); |
|---|
| 216 | $ret = false; |
|---|
| 217 | if ($nb_destinataires > 0) { |
|---|
| 218 | $ret = mail($mailto, $subject, $content, $headers); |
|---|
| 219 | |
|---|
| 220 | }else{ |
|---|
| 221 | $message .= l10n('no_receiver_available'); |
|---|
| 222 | } |
|---|
| 223 | $message .= ob_get_contents(); |
|---|
| 224 | ob_end_clean(); |
|---|
| 225 | $mails_donn�es['message']=$message; |
|---|
| 226 | Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto); |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | } else { |
|---|
| 231 | |
|---|
| 232 | //================== Est en quarantaine ======================= |
|---|
| 233 | $erreur_message .= l10n('To_day_is')."<br />"; |
|---|
| 234 | if ($alerte_spam ) { |
|---|
| 235 | $type="Spams"; |
|---|
| 236 | |
|---|
| 237 | $d1=$mails_donn�es['nb_spams'] . ' \\ ' . $mails_donn�es['nb_spams_maxi']; |
|---|
| 238 | $d2=$mails_donn�es['nb_spams']; |
|---|
| 239 | $d3= $mails_donn�es['rest_spam']; |
|---|
| 240 | $d4=time()+$d3 ; |
|---|
| 241 | } |
|---|
| 242 | |
|---|
| 243 | if ($alerte_mail) { |
|---|
| 244 | $type="Mails"; |
|---|
| 245 | |
|---|
| 246 | $d1=$mails_donn�es['nb_mails']. ' \\ ' . $mails_donn�es['nb_mails_maxi'];; |
|---|
| 247 | $d2=$mails_donn�es['date_mail']; |
|---|
| 248 | $d3= $mails_donn�es['rest_mail']; |
|---|
| 249 | $d4=time()+$d3 ; |
|---|
| 250 | |
|---|
| 251 | |
|---|
| 252 | } |
|---|
| 253 | if ($alerte) { |
|---|
| 254 | $type="Spams(Quarantaine)"; |
|---|
| 255 | $d1=$mails_donn�es['nb_spams'] . ' \\ ' . $mails_donn�es['nb_spams_maxi']; |
|---|
| 256 | $d2=$mails_donn�es['date_quarantaine']; |
|---|
| 257 | $d3= $mails_donn�es['reste']; |
|---|
| 258 | $d4=time()+$d3 ; |
|---|
| 259 | } |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | $d2=date(l10n('formatdate'),$d2); |
|---|
| 263 | $d3=int_to_heure($d3) ; |
|---|
| 264 | $d4=date(l10n('formatdate'),$d4); |
|---|
| 265 | |
|---|
| 266 | if ($alerte_mail) { |
|---|
| 267 | $erreur_message .='<br />'.sprintf(l10n('alerte_mail %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />'; |
|---|
| 268 | }else{ |
|---|
| 269 | $erreur_message .='<br />'.sprintf(l10n('mise_en_quarantaine %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />'; |
|---|
| 270 | |
|---|
| 271 | } |
|---|
| 272 | $infos_message = l10n('mail_not_send'); |
|---|
| 273 | |
|---|
| 274 | } |
|---|
| 275 | sauve_donn�es(); |
|---|
| 276 | return true ; |
|---|
| 277 | } |
|---|
| 278 | //=========================================================================================== |
|---|
| 279 | function Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto) |
|---|
| 280 | { |
|---|
| 281 | global $conf, $user, $conf_mail,$mails_options,$mails_donn�es , $template,$page ,$infos_message,$erreur_message,$args,$lang, $lang_info; |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | $match=array("<",">"); |
|---|
| 286 | $string=array("<",">") ; |
|---|
| 287 | |
|---|
| 288 | //Warning: mail() has been disabled for security reasons |
|---|
| 289 | |
|---|
| 290 | $est_un_spam =!(strpos(strtolower($message), 'spam') === false); |
|---|
| 291 | $headers=str_replace( $match,$string, $headers); |
|---|
| 292 | |
|---|
| 293 | if ( ($ret==false) || ($est_un_spam==true) || ($nb_destinataires == 0) ) { |
|---|
| 294 | ; // Bad recipient address syntax |
|---|
| 295 | $pos1 = strpos(strtolower($message), 'bad recipient address syntax'); |
|---|
| 296 | if ( !($pos1 === false) ){ |
|---|
| 297 | $erreur_message .= l10n('detection_de').' : Bad recipient address syntax .'; |
|---|
| 298 | $erreur_message .= l10n('verifiez_les_destinataires').' (Bcc,Cc,To)<br />'; |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | $erreur_message .= sprintf(l10n('debug_message %s %s %s %s %s'),($ret==true)? "true" : "false",$message,$mailto,$headers,$nb_destinataires); |
|---|
| 302 | //=============== La fonction mail � retourn�eune erreur ========================= |
|---|
| 303 | |
|---|
| 304 | |
|---|
| 305 | } |
|---|
| 306 | |
|---|
| 307 | if ($est_un_spam == false) |
|---|
| 308 | { |
|---|
| 309 | if ($mails_donn�es['nb_mails']==0) { $mails_donn�es['date_mail'] = time(); } |
|---|
| 310 | $mails_donn�es['nb_mails'] += $nb_destinataires; |
|---|
| 311 | } |
|---|
| 312 | else |
|---|
| 313 | { |
|---|
| 314 | $mails_donn�es['nb_spams'] += $nb_destinataires; |
|---|
| 315 | //--- D�tection de spam ------------------ |
|---|
| 316 | if ($mails_donn�es['nb_spams']==0) {$mails_donn�es['date_spam'] = time(); } |
|---|
| 317 | |
|---|
| 318 | $trop_de_spam =!(strpos(strtolower($message), 'trop de spam') === false); |
|---|
| 319 | if ( $trop_de_spam ) { |
|---|
| 320 | $mails_donn�es['nb_spams_maxi']=$mails_donn�es['nb_spams']; |
|---|
| 321 | |
|---|
| 322 | $mails_donn�es['date_quarantaine']= time() ; |
|---|
| 323 | $mails_donn�es['quarantaine']= true ; |
|---|
| 324 | $infos_message .=memo_var($mails_donn�es); |
|---|
| 325 | } |
|---|
| 326 | |
|---|
| 327 | } |
|---|
| 328 | |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | |
|---|
| 332 | $ret=true; |
|---|
| 333 | return $ret ; |
|---|
| 334 | |
|---|
| 335 | } |
|---|
| 336 | |
|---|
| 337 | //========================================================================================== |
|---|
| 338 | add_event_handler('get_admin_plugin_menu_links', 'admin_menu'); |
|---|
| 339 | function admin_menu($menu) |
|---|
| 340 | { |
|---|
| 341 | array_push($menu, array('NAME' => 'Mail_Superv', |
|---|
| 342 | 'URL' => get_admin_plugin_menu_link(MAIL_SUPERV_PATH . 'admin/mail_superv_admin.php'))); |
|---|
| 343 | return $menu; |
|---|
| 344 | } |
|---|
| 345 | //========================================================================================== |
|---|
| 346 | add_event_handler('loc_after_page_header','affiche_spam' );// |
|---|
| 347 | function affiche_spam () |
|---|
| 348 | |
|---|
| 349 | { |
|---|
| 350 | include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); |
|---|
| 351 | |
|---|
| 352 | affiche_message(); |
|---|
| 353 | |
|---|
| 354 | } |
|---|
| 355 | include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); |
|---|
| 356 | $mails_options = explode("," , $conf['mail_superv']); |
|---|
| 357 | |
|---|
| 358 | //========================================================================================== |
|---|
| 359 | if ($mails_options[set_id]=='on' ) { |
|---|
| 360 | add_event_handler('register_user_check', 'Test_spam_g', EVENT_HANDLER_PRIORITY_NEUTRAL +2 , 2); |
|---|
| 361 | } |
|---|
| 362 | function Test_spam_g ($err, $user) |
|---|
| 363 | { |
|---|
| 364 | |
|---|
| 365 | if (count($err)!=0 ) return $err ; |
|---|
| 366 | if ( !isset($_POST['submit_add']) && !isset($_POST['submit']) ) return $err ; |
|---|
| 367 | //Liableelard |
|---|
| 368 | include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); |
|---|
| 369 | if ( isset($_POST['submit'])) { |
|---|
| 370 | $mail = $_POST['mail_address'] ; |
|---|
| 371 | $user_name = $_POST['login'] ; |
|---|
| 372 | }else{ |
|---|
| 373 | $mail = $user['email']; |
|---|
| 374 | $user_name = $user['username']; |
|---|
| 375 | } |
|---|
| 376 | $user_name =""; // suppression du test sur user name. |
|---|
| 377 | $ip='0'; |
|---|
| 378 | if (test_spam($ip,$user_name ,$mail )) |
|---|
| 379 | { |
|---|
| 380 | if (test_spam($ip,$user_name ,"" )) { |
|---|
| 381 | $err[] = $user_name . " ". l10n('is_a_login_spam') ; |
|---|
| 382 | }else |
|---|
| 383 | $err[] = $user_name . " : " .$mail . " ". l10n('is_a_spam') ; |
|---|
| 384 | } |
|---|
| 385 | |
|---|
| 386 | return $err ; |
|---|
| 387 | } |
|---|
| 388 | ?> |
|---|