| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | Plugin Name: Mail supervisor |
|---|
| 4 | Version: 1.3.6 |
|---|
| 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 | global $conf ; |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | add_event_handler('send_mail', 'clj_mail',EVENT_HANDLER_PRIORITY_NEUTRAL - 1 , 6); |
|---|
| 21 | function clj_mail($result, $mailto, $subject, $content, $headers, $args) |
|---|
| 22 | { |
|---|
| 23 | global $conf, $user, $lang_info, $conf_mail,$mails_options,$mails_donn�es , $template,$page ,$erreur_message,$infos_message, $lang; |
|---|
| 24 | // lecture config table ------------- |
|---|
| 25 | include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); |
|---|
| 26 | load_language('plugin.lang', MAIL_SUPERV_PATH); |
|---|
| 27 | $mails_options = explode("," , $conf['mail_superv']); |
|---|
| 28 | //======== v�rification si envoie de mail ou blocage connexion ===================== |
|---|
| 29 | if ($mails_options[no_mail_list]=='on' || $mails_options[no_connect] == 'on' ) |
|---|
| 30 | { |
|---|
| 31 | if (kill_list()) |
|---|
| 32 | { |
|---|
| 33 | $erreur_message .= "<BR />".l10n('Sv_is_a_spam') ; |
|---|
| 34 | if ($mails_options[no_connect] == 'on' ){ |
|---|
| 35 | if ($user['status'] == 'webmaster' ) |
|---|
| 36 | { |
|---|
| 37 | //---------- continuer si web master ---------- |
|---|
| 38 | }else{ |
|---|
| 39 | if (!isset($_GET['admin'])) { |
|---|
| 40 | die('Blacklist : <br />' .$erreur_message. '<br /> Hacking attempt!'); |
|---|
| 41 | }elseif ($_GET['admin'] != 'piwigo') |
|---|
| 42 | { |
|---|
| 43 | die('blacklist Hacking attempt!'); |
|---|
| 44 | } |
|---|
| 45 | return true; |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | } |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | $message =""; |
|---|
| 54 | if (!isset($infos_message)) |
|---|
| 55 | { |
|---|
| 56 | $infos_message = ""; |
|---|
| 57 | } |
|---|
| 58 | if (!isset($erreur_message)) |
|---|
| 59 | { |
|---|
| 60 | $erreur_message = ''; |
|---|
| 61 | } |
|---|
| 62 | // lecture donn�es ------------- |
|---|
| 63 | $mails_donn�es = Get_Datas(); |
|---|
| 64 | |
|---|
| 65 | $nb_mails = $mails_donn�es['nb_mails'] ; |
|---|
| 66 | $next_day = $mails_donn�es['date_mail'] ; |
|---|
| 67 | |
|---|
| 68 | $reste = $mails_donn�es['reste'] ; |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | $rest_mail = $mails_donn�es['rest_mail'] ; |
|---|
| 72 | if ($rest_mail <=0 || $mails_donn�es['nb_mails'] ==0 ){ |
|---|
| 73 | $mails_donn�es['nb_mails'] =0 ; |
|---|
| 74 | $mails_donn�es['date_mail'] = time(); |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | $rest_spam = $mails_donn�es['rest_spam'] ; |
|---|
| 78 | if ($rest_spam <=0 || $mails_donn�es['nb_spams'] ==0 ){ |
|---|
| 79 | $mails_donn�es['nb_spams'] =0 ; |
|---|
| 80 | $mails_donn�es['date_spam'] = time(); |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | $alerte = ( $mails_donn�es['reste'] >0 ) ? true : false ; |
|---|
| 84 | |
|---|
| 85 | $alerte_mail = ( $mails_donn�es['nb_mails'] > $mails_donn�es['nb_mails_maxi']-1 ) ? true : false ; |
|---|
| 86 | $alerte_spam = ( $mails_donn�es['nb_spams'] > $mails_donn�es['nb_spams_maxi']-1 ) ? true : false ; |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | if ( ( !$alerte && !$alerte_spam && !$alerte_mail ) ) |
|---|
| 90 | { |
|---|
| 91 | |
|---|
| 92 | $nb_destinataires=0; |
|---|
| 93 | if ($mails_options[check_mailto] == 'on') { |
|---|
| 94 | if ($mailto == "" ) $mailto = $conf_mail['email_webmaster']; |
|---|
| 95 | } |
|---|
| 96 | if ($mailto<>"" ) $nb_destinataires +=1; |
|---|
| 97 | |
|---|
| 98 | if (!empty($args['Bcc'])) { |
|---|
| 99 | $nb_destinataires += count($args['Bcc']); |
|---|
| 100 | } |
|---|
| 101 | if (!empty($args['Cc'])) { |
|---|
| 102 | $nb_destinataires += count($args['Cc']); |
|---|
| 103 | } |
|---|
| 104 | //================= r��criture de l'ent�te =============================== |
|---|
| 105 | if ( $nb_destinataires == 1 ) |
|---|
| 106 | { |
|---|
| 107 | if ($mailto == "" ) |
|---|
| 108 | { |
|---|
| 109 | if (!empty($args['Cc']) and count($args['Cc']) > 0 ) $mailto = get_strict_email_list(implode(',', $args['Cc'])) ; |
|---|
| 110 | if (!empty($args['Bcc']) and count($args['Bcc']) > 0 ) $mailto = get_strict_email_list(implode(',', $args['Bcc'])) ; |
|---|
| 111 | |
|---|
| 112 | $headers = preg_replace('/.*Bcc(.*).\n/i', '', $headers); |
|---|
| 113 | $headers = preg_replace('/.*Cc(.*).\n/i', '', $headers); |
|---|
| 114 | |
|---|
| 115 | } |
|---|
| 116 | }else{ |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | //============================================================================= |
|---|
| 122 | if (!empty($args['Cc'])) |
|---|
| 123 | { |
|---|
| 124 | $headers= corrige_header('Cc',$headers,$args); |
|---|
| 125 | } |
|---|
| 126 | if (!empty($args['Bcc'])) |
|---|
| 127 | { |
|---|
| 128 | $headers = corrige_header('Bcc',$headers,$args); |
|---|
| 129 | } |
|---|
| 130 | //============================================================================= |
|---|
| 131 | if ($mails_options[check_header_text]=='on') { |
|---|
| 132 | |
|---|
| 133 | $texte = "This is a multi-part message in MIME format.\n"; |
|---|
| 134 | |
|---|
| 135 | $texte .= "-----=".$conf_mail['boundary_key']."\n"; |
|---|
| 136 | $texte .= "Ceci est un message est au format MIME.\n"; |
|---|
| 137 | $texte .= 'Content-Type: text/plain; charset="UTF-8"'."\n"; |
|---|
| 138 | $texte .= 'Content-Transfer-Encoding: 8bit'."\n\n"; |
|---|
| 139 | $texte .= $mails_donn�es['header_text']; // A voir texte brut... |
|---|
| 140 | |
|---|
| 141 | $texte .= "\n\n"; |
|---|
| 142 | |
|---|
| 143 | $content =$texte .$content ; |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | $ret=false; |
|---|
| 147 | |
|---|
| 148 | //======== Non mise en quarantaine ============= |
|---|
| 149 | ob_start(); |
|---|
| 150 | $ret = false; |
|---|
| 151 | if ($nb_destinataires > 0) { |
|---|
| 152 | $ret = mail($mailto, $subject, $content, $headers); |
|---|
| 153 | |
|---|
| 154 | }else{ |
|---|
| 155 | $message .= l10n('Sv_no_receiver_available'); |
|---|
| 156 | } |
|---|
| 157 | $message .= ob_get_contents(); |
|---|
| 158 | ob_end_clean(); |
|---|
| 159 | $mails_donn�es['message']=$message; |
|---|
| 160 | Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto); |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | } else { |
|---|
| 165 | |
|---|
| 166 | //================== Est en quarantaine ======================= |
|---|
| 167 | $erreur_message .= l10n('Sv_To_day_is')."<br />"; |
|---|
| 168 | if ($alerte_spam ) { |
|---|
| 169 | $type="Spams"; |
|---|
| 170 | |
|---|
| 171 | $d1=$mails_donn�es['nb_spams'] . ' \\ ' . $mails_donn�es['nb_spams_maxi']; |
|---|
| 172 | $d2=$mails_donn�es['nb_spams']; |
|---|
| 173 | $d3= $mails_donn�es['rest_spam']; |
|---|
| 174 | $d4=time()+$d3 ; |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | if ($alerte_mail) { |
|---|
| 178 | $type="Mails"; |
|---|
| 179 | |
|---|
| 180 | $d1=$mails_donn�es['nb_mails']. ' \\ ' . $mails_donn�es['nb_mails_maxi'];; |
|---|
| 181 | $d2=$mails_donn�es['date_mail']; |
|---|
| 182 | $d3= $mails_donn�es['rest_mail']; |
|---|
| 183 | $d4=time()+$d3 ; |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | } |
|---|
| 187 | if ($alerte) { |
|---|
| 188 | $type="Spams(Quarantaine)"; |
|---|
| 189 | $d1=$mails_donn�es['nb_spams'] . ' \\ ' . $mails_donn�es['nb_spams_maxi']; |
|---|
| 190 | $d2=$mails_donn�es['date_quarantaine']; |
|---|
| 191 | $d3= $mails_donn�es['reste']; |
|---|
| 192 | $d4=time()+$d3 ; |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | $d2=date(l10n('Sv_formatdate'),$d2); |
|---|
| 197 | $d3=int_to_heure($d3) ; |
|---|
| 198 | $d4=date(l10n('Sv_formatdate'),$d4); |
|---|
| 199 | |
|---|
| 200 | if ($alerte_mail) { |
|---|
| 201 | $erreur_message .='<br />'.sprintf(l10n('Sv_alerte_mail %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />'; |
|---|
| 202 | }else{ |
|---|
| 203 | $erreur_message .='<br />'.sprintf(l10n('Sv_mise_en_quarantaine %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />'; |
|---|
| 204 | |
|---|
| 205 | } |
|---|
| 206 | $infos_message = l10n('Sv_mail_not_send'); |
|---|
| 207 | |
|---|
| 208 | } |
|---|
| 209 | sauve_donn�es(); |
|---|
| 210 | return true ; |
|---|
| 211 | } |
|---|
| 212 | //=========================================================================================== |
|---|
| 213 | function Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto) |
|---|
| 214 | { |
|---|
| 215 | global $conf, $user, $conf_mail,$mails_options,$mails_donn�es , $template,$page ,$infos_message,$erreur_message,$args,$lang, $lang_info; |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | $match=array("<",">"); |
|---|
| 220 | $string=array("<",">") ; |
|---|
| 221 | |
|---|
| 222 | //Warning: mail() has been disabled for security reasons |
|---|
| 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 .= l10n('Sv_detection_de').' : Bad recipient address syntax .'; |
|---|
| 232 | $erreur_message .= l10n('Sv_verifiez_les_destinataires').' (Bcc,Cc,To)<br />'; |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | $erreur_message .= sprintf(l10n('Sv_debug_message %s %s %s %s %s'),($ret==true)? "true" : "false",$message,$mailto,$headers,$nb_destinataires); |
|---|
| 236 | //=============== La fonction mail � retourn�eune erreur ========================= |
|---|
| 237 | |
|---|
| 238 | |
|---|
| 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; |
|---|
| 245 | } |
|---|
| 246 | else |
|---|
| 247 | { |
|---|
| 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']; |
|---|
| 255 | |
|---|
| 256 | $mails_donn�es['date_quarantaine']= time() ; |
|---|
| 257 | $mails_donn�es['quarantaine']= true ; |
|---|
| 258 | $infos_message .=memo_var($mails_donn�es); |
|---|
| 259 | } |
|---|
| 260 | |
|---|
| 261 | } |
|---|
| 262 | |
|---|
| 263 | |
|---|
| 264 | |
|---|
| 265 | |
|---|
| 266 | $ret=true; |
|---|
| 267 | return $ret ; |
|---|
| 268 | |
|---|
| 269 | } |
|---|
| 270 | |
|---|
| 271 | //========================================================================================== |
|---|
| 272 | add_event_handler('get_admin_plugin_menu_links', 'admin_menu'); |
|---|
| 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 | add_event_handler('loc_after_page_header','affiche_spam' );// |
|---|
| 281 | function affiche_spam () |
|---|
| 282 | |
|---|
| 283 | { |
|---|
| 284 | include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); |
|---|
| 285 | |
|---|
| 286 | affiche_message(); |
|---|
| 287 | |
|---|
| 288 | } |
|---|
| 289 | include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); |
|---|
| 290 | $mails_options = explode("," , $conf['mail_superv']); |
|---|
| 291 | |
|---|
| 292 | //========================================================================================== |
|---|
| 293 | if ($mails_options[set_id]=='on' ) { |
|---|
| 294 | add_event_handler('register_user_check', 'Test_spam_g', EVENT_HANDLER_PRIORITY_NEUTRAL +2 , 2); |
|---|
| 295 | } |
|---|
| 296 | function Test_spam_g ($err, $user) |
|---|
| 297 | { |
|---|
| 298 | |
|---|
| 299 | if (count($err)!=0 ) return $err ; |
|---|
| 300 | if ( !isset($_POST['submit_add']) && !isset($_POST['submit']) ) return $err ; |
|---|
| 301 | //Liableelard |
|---|
| 302 | include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); |
|---|
| 303 | if ( isset($_POST['submit'])) { |
|---|
| 304 | $mail = $_POST['mail_address'] ; |
|---|
| 305 | $user_name = $_POST['login'] ; |
|---|
| 306 | }else{ |
|---|
| 307 | $mail = $user['email']; |
|---|
| 308 | $user_name = $user['username']; |
|---|
| 309 | } |
|---|
| 310 | $user_name =""; // suppression du test sur user name. |
|---|
| 311 | $ip='0'; |
|---|
| 312 | if (test_spam($ip,$user_name ,$mail )) |
|---|
| 313 | { |
|---|
| 314 | if (test_spam($ip,$user_name ,"" )) { |
|---|
| 315 | $err[] = $user_name . " ". l10n('Sv_is_a_login_spam') ; |
|---|
| 316 | }else |
|---|
| 317 | $err[] = $user_name . " : " .$mail . " ". l10n('Sv_is_a_spam') ; |
|---|
| 318 | } |
|---|
| 319 | |
|---|
| 320 | return $err ; |
|---|
| 321 | } |
|---|
| 322 | ?> |
|---|