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