[12394] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: Mail supervisor |
---|
| 4 | Version: auto |
---|
| 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 | |
---|
| 14 | $MAIL_SUPERV_PATH_ABS = str_replace('\\','/',dirname(__FILE__) ); |
---|
| 15 | if (!defined('MAIL_SUPERV_PATH_ABS')) define( 'MAIL_SUPERV_PATH_ABS', $MAIL_SUPERV_PATH_ABS."/"); |
---|
| 16 | |
---|
| 17 | global $conf,$mails_options,$mails_donnees ; |
---|
| 18 | |
---|
| 19 | include_once (PHPWG_ROOT_PATH.'include/functions_mail.inc.php' ); |
---|
| 20 | include_once(MAIL_SUPERV_PATH.'mail_super.inc.php'); |
---|
| 21 | $mail_supervisor = new mail_supervisor(); |
---|
| 22 | include_once(MAIL_SUPERV_PATH.'mail_send.inc.php'); |
---|
| 23 | $clj = new clj(); |
---|
| 24 | |
---|
| 25 | include_once (MAIL_SUPERV_PATH.'include/constants.php'); |
---|
| 26 | //=============================================== |
---|
| 27 | include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); |
---|
| 28 | |
---|
| 29 | mail_supervisor::Get_Options($mails_options,"mail_superv"); |
---|
| 30 | $mails_donnees=mail_supervisor::Get_Datas(); |
---|
| 31 | |
---|
| 32 | /* EVENT_HANDLER_PRIORITY_NEUTRAL */ |
---|
| 33 | add_event_handler('loc_after_page_header', array(&$mail_supervisor,'init') ); |
---|
| 34 | add_event_handler('loc_begin_page_tail', array(&$mail_supervisor,'affiche_message') ); |
---|
| 35 | add_event_handler('get_admin_plugin_menu_links', array(&$mail_supervisor,'admin_menu') ); |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | //=========================================================================================== |
---|
| 40 | add_event_handler('send_mail',array(&$clj,'send_mail'),EVENT_HANDLER_PRIORITY_NEUTRAL - 1, 6); |
---|
| 41 | add_event_handler('send_mail_to',array(&$clj,'send_mail_to') ); |
---|
| 42 | add_event_handler('send_mail_subject',array(&$clj,'send_mail_subject') ); |
---|
| 43 | add_event_handler('send_mail_content',array(&$clj,'send_mail_content') ); |
---|
| 44 | add_event_handler('send_mail_headers',array(&$clj,'send_mail_headers') ); |
---|
| 45 | |
---|
| 46 | //========================================================================================== |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | function clj_send_mail($result, $mailto, $subject, $content, $headers, $args,$nb_destinataires) { |
---|
| 50 | global $conf, $user, $lang_info; |
---|
| 51 | global $conf_mail,$mails_options,$mails_donnees ; |
---|
| 52 | global $template,$page ,$erreur_message,$infos_message, $lang; |
---|
| 53 | global $errors; |
---|
| 54 | |
---|
| 55 | include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); |
---|
| 56 | load_language('plugin.lang', MAIL_SUPERV_PATH); |
---|
| 57 | |
---|
| 58 | $arg_trigg= array($mailto, $subject, $content, $headers, $args); |
---|
| 59 | trigger_event('mail_supervisor_clj_mail',$arg_trigg); |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | $message =""; |
---|
| 63 | if (!isset($infos_message)) { $infos_message = ""; } |
---|
| 64 | if (!isset($erreur_message)) { $erreur_message = ''; } |
---|
| 65 | |
---|
| 66 | $envoie_ok=true ; |
---|
| 67 | //======== verification si envoie de mail ou blocage connexion ===================== |
---|
| 68 | if ($mails_options['no_mail_list']=='on' || $mails_options['no_connect'] == 'on' ) { |
---|
| 69 | if (kill_list()) { |
---|
| 70 | $nb_destinataires=0; ; |
---|
| 71 | $envoie_ok= false ; |
---|
| 72 | $erreur_message .= "<BR />".l10n('Sv_is_a_spam') ; |
---|
| 73 | $infos_message = l10n('Sv_mail_not_send')."<BR />"; |
---|
| 74 | if ($mails_options['no_connect'] == 'on' ){ |
---|
| 75 | if ($user['status'] == 'webmaster'){ |
---|
| 76 | //---------- continuer si web master ---------- |
---|
| 77 | }else{ |
---|
| 78 | trigger_event('mail_supervisor_send_mail', "DIE(KILL) : " . $ip . ' = ' . $user['status']); |
---|
| 79 | if (!isset($_GET['admin'])) { |
---|
| 80 | die('Blacklist : <br />' .$erreur_message. '<br /> Hacking attempt!'); |
---|
| 81 | }elseif ($_GET['admin'] != 'piwigo') |
---|
| 82 | { |
---|
| 83 | die('blacklist Hacking attempt!'); |
---|
| 84 | } |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | trigger_event('mail_supervisor_send_mail', "Kill : " . $ip . ' = ' . $user['status'] . "noconnect==off"); |
---|
| 88 | return true; |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | // lecture donnees ------------- |
---|
| 93 | $nb_mails = $mails_donnees['nb_mails'] ; |
---|
| 94 | $next_day = $mails_donnees['date_mail'] ; |
---|
| 95 | $reste = $mails_donnees['reste'] ; |
---|
| 96 | $rest_mail = $mails_donnees['rest_mail'] ; |
---|
| 97 | if ($rest_mail <=0 || $mails_donnees['nb_mails'] ==0 ){ |
---|
| 98 | $mails_donnees['nb_mails'] =0 ; |
---|
| 99 | $mails_donnees['date_mail'] = time(); |
---|
| 100 | } |
---|
| 101 | $rest_spam = $mails_donnees['rest_spam'] ; |
---|
| 102 | if ($rest_spam <=0 || $mails_donnees['nb_spams'] ==0 ){ |
---|
| 103 | $mails_donnees['nb_spams'] =0 ; |
---|
| 104 | $mails_donnees['date_spam'] = time(); |
---|
| 105 | } |
---|
| 106 | $alerte = ( $mails_donnees['reste'] >0 ) ? true : false ; |
---|
| 107 | $alerte_mail = ( $mails_donnees['nb_mails'] > $mails_donnees['nb_mails_maxi']-1 ) ? true : false ; |
---|
| 108 | $alerte_spam = ( $mails_donnees['nb_spams'] > $mails_donnees['nb_spams_maxi']-1 ) ? true : false ; |
---|
| 109 | //============================= |
---|
| 110 | // TEST envoie Message |
---|
| 111 | //============================= |
---|
| 112 | if ( ( !$alerte && !$alerte_spam && !$alerte_mail ) ) { |
---|
| 113 | $infos_message .= "nb_destinataires : $nb_destinataires Theme :" . ($args['theme'] ) ." {". $lang_info['language_name'] ."}"."<br />"; |
---|
| 114 | $infos_message .="Mailto:" .$mailto ."<br />"; |
---|
| 115 | if(isset($args['Bcc']) && count($args['Bcc'])>0) $infos_message .="Bcc: " . implode(",",$args['Bcc'])."<br />"; |
---|
| 116 | if(isset($args['Cc'])&& count($args['Cc'])>0) $infos_message .="Cc: " . implode(",",$args['Cc'])."<br />"; |
---|
| 117 | //============================================ |
---|
| 118 | // Photographie |
---|
| 119 | //============================================ |
---|
| 120 | $ret="false"; |
---|
| 121 | ob_start(); |
---|
| 122 | if ($nb_destinataires > 0) { |
---|
| 123 | if( $envoie_ok) $ret = mail($mailto, $subject,$content, $headers); |
---|
| 124 | }else{ |
---|
| 125 | echo l10n('Sv_no_receiver_available'); |
---|
| 126 | } |
---|
| 127 | $message .= ob_get_contents(); |
---|
| 128 | ob_end_clean(); |
---|
| 129 | |
---|
| 130 | $arg_trigg= array("Nb destinataires: " . $nb_destinataires,"Mail to: ".$mailto,"content: ".$content, " Reponse : " . $message); |
---|
| 131 | |
---|
| 132 | trigger_event('mail_supervisor_mail', $arg_trigg ); |
---|
| 133 | $mails_donnees['message']=$message; |
---|
| 134 | $ret= Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto, $subject,$content); |
---|
| 135 | } else { |
---|
| 136 | //================== Est en quarantaine ======================= |
---|
| 137 | |
---|
| 138 | $erreur_message .= l10n('Sv_To_day_is')."<br />"; |
---|
| 139 | if ($alerte_spam ) { |
---|
| 140 | $type="Spams"; |
---|
| 141 | $d1=$mails_donnees['nb_spams'] . ' \\ ' . $mails_donnees['nb_spams_maxi']; |
---|
| 142 | $d2=$mails_donnees['nb_spams']; |
---|
| 143 | $d3= $mails_donnees['rest_spam']; |
---|
| 144 | $d4=time()+$d3 ; |
---|
| 145 | } |
---|
| 146 | if ($alerte_mail) { |
---|
| 147 | $type="Mails"; |
---|
| 148 | $d1=$mails_donnees['nb_mails']. ' \\ ' . $mails_donnees['nb_mails_maxi'];; |
---|
| 149 | $d2=$mails_donnees['date_mail']; |
---|
| 150 | $d3= $mails_donnees['rest_mail']; |
---|
| 151 | $d4=time()+$d3 ; |
---|
| 152 | } |
---|
| 153 | if ($alerte) { |
---|
| 154 | $type="Spams(Quarantaine)"; |
---|
| 155 | $d1=$mails_donnees['nb_spams'] . ' \\ ' . $mails_donnees['nb_spams_maxi']; |
---|
| 156 | $d2=$mails_donnees['date_quarantaine']; |
---|
| 157 | $d3= $mails_donnees['reste']; |
---|
| 158 | $d4=time()+$d3 ; |
---|
| 159 | } |
---|
| 160 | $d2=date(l10n('Sv_formatdate'),$d2); |
---|
| 161 | $d3=int_to_heure($d3) ; |
---|
| 162 | $d4=date(l10n('Sv_formatdate'),$d4); |
---|
| 163 | if ($alerte_mail) { |
---|
| 164 | $erreur_message .='<br />'.sprintf(l10n('Sv_alerte_mail %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />'; |
---|
| 165 | }else{ |
---|
| 166 | $erreur_message .='<br />'.sprintf(l10n('Sv_mise_en_quarantaine %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />'; |
---|
| 167 | } |
---|
| 168 | $ret = "Error ". $type." : "; |
---|
| 169 | $ret .= l10n('Sv_mail_not_send'); |
---|
| 170 | $infos_message .= l10n('Sv_mail_not_send'); |
---|
| 171 | } |
---|
| 172 | $infos_message .= "<hr>"; |
---|
| 173 | trigger_event('mail_supervisor_message', $infos_message ); |
---|
| 174 | mail_supervisor::sauve_donnees(); |
---|
| 175 | mail_supervisor::affiche_message(); |
---|
| 176 | return $ret ;// |
---|
| 177 | } |
---|
| 178 | //=========================================================================================== |
---|
| 179 | function Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto, $subject,$content){ |
---|
| 180 | global $conf, $user, $conf_mail,$mails_options,$mails_donnees , $template,$page ,$infos_message,$erreur_message,$args,$lang, $lang_info; |
---|
| 181 | $match=array("<",">"); |
---|
| 182 | $string=array("<",">") ; |
---|
| 183 | // $headers=str_replace( $match,$string, $headers); |
---|
| 184 | // Warning: mail() has been disabled for security reasons |
---|
| 185 | $est_un_spam =!(strpos(strtolower($message), 'spam') === false); |
---|
| 186 | |
---|
| 187 | $log_message = " :".sprintf(l10n('Sv_debug_message'), |
---|
| 188 | ($ret==true)? "true" : "false", |
---|
| 189 | "\n".$message , |
---|
| 190 | "\n".$mailto , |
---|
| 191 | "\n".$subject , |
---|
| 192 | "\n".$headers , |
---|
| 193 | "\n".$content , |
---|
| 194 | "\n".$nb_destinataires) ; |
---|
| 195 | |
---|
| 196 | if ( ($ret==false) || ($est_un_spam==true) || ($nb_destinataires == 0) ) { |
---|
| 197 | //=============== La fonction mail retourne une erreur ========================= |
---|
| 198 | $ret="Error"; |
---|
| 199 | // Bad recipient address syntax |
---|
| 200 | $pos1 = strpos(strtolower($message), 'bad recipient address syntax'); |
---|
| 201 | if ( !($pos1 === false) ){ |
---|
| 202 | $erreur_message .= l10n('Sv_detection_de').' Bad recipient address syntax .'; |
---|
| 203 | $erreur_message .= l10n('Sv_verifiez_les_destinataires').' (Bcc,Cc,To)<br />'; |
---|
| 204 | } |
---|
| 205 | $erreur_message .=$ret . " :".sprintf(l10n('Sv_debug_message'), |
---|
| 206 | ($ret==true)? "true" : "false", |
---|
| 207 | htmlspecialchars($message) , |
---|
| 208 | htmlspecialchars( $mailto) , |
---|
| 209 | htmlspecialchars($subject) , |
---|
| 210 | htmlspecialchars($headers) , |
---|
| 211 | htmlspecialchars($content) , |
---|
| 212 | $nb_destinataires ); |
---|
| 213 | |
---|
| 214 | Mail_supervisor_log($mailto,$log_message) ; |
---|
| 215 | |
---|
| 216 | }else{ |
---|
| 217 | if( isset($mails_options['debug_mail']) && $mails_options['debug_mail']=="on") { |
---|
| 218 | $infos_message .="DEBUG : " .sprintf(l10n('Sv_debug_message'), |
---|
| 219 | ($ret==true)? "true" : "false", |
---|
| 220 | htmlspecialchars( $message) , |
---|
| 221 | htmlspecialchars( $mailto) , |
---|
| 222 | htmlspecialchars($subject) , |
---|
| 223 | htmlspecialchars($headers) , |
---|
| 224 | htmlspecialchars($content) , |
---|
| 225 | $nb_destinataires ); |
---|
| 226 | |
---|
| 227 | Mail_supervisor_log($mailto,"DEBUG :" . ($log_message)) ; |
---|
| 228 | } |
---|
| 229 | } |
---|
| 230 | //================================================================= |
---|
| 231 | if ($est_un_spam == false){ |
---|
| 232 | if ($mails_donnees['nb_mails']==0) { $mails_donnees['date_mail'] = time(); } |
---|
| 233 | $mails_donnees['nb_mails'] += $nb_destinataires; |
---|
| 234 | } else { |
---|
| 235 | $ret="Error spam"; |
---|
| 236 | $mails_donnees['nb_spams'] += $nb_destinataires; |
---|
| 237 | //--- Detection de spam ------------------ |
---|
| 238 | if ($mails_donnees['nb_spams']==0) {$mails_donnees['date_spam'] = time(); } |
---|
| 239 | |
---|
| 240 | $trop_de_spam =!(strpos(strtolower($message), 'trop de spam') === false); |
---|
| 241 | if ( $trop_de_spam ) { |
---|
| 242 | $mails_donnees['nb_spams_maxi']=$mails_donnees['nb_spams']; |
---|
| 243 | |
---|
| 244 | $mails_donnees['date_quarantaine']= time() ; |
---|
| 245 | $mails_donnees['quarantaine']= true ; |
---|
| 246 | $infos_message .= mail_supervisor::Memo_Var($mails_donnees); |
---|
| 247 | } |
---|
| 248 | } |
---|
| 249 | return $ret ; |
---|
| 250 | } |
---|
| 251 | //============================================================ |
---|
| 252 | global $ms_file_log,$dir,$clj_pwd; |
---|
| 253 | |
---|
| 254 | |
---|
| 255 | $clj_pwd=$conf['local_data_dir'].'/Pwd'; |
---|
| 256 | if (!is_dir($clj_pwd)){ |
---|
| 257 | $umask = umask(0); |
---|
| 258 | $mkd = @mkdir($clj_pwd, 0755, true ); |
---|
| 259 | umask($umask); |
---|
| 260 | if ($mkd==false){ |
---|
| 261 | echo "<pre>PWD:$clj_pwd"; |
---|
| 262 | fatal_error( "$clj_pwd ".l10n('no write access')); |
---|
| 263 | return false; |
---|
| 264 | } |
---|
| 265 | } |
---|
| 266 | //================================================== |
---|
| 267 | $dir=$conf['local_data_dir'].'/Mail_supervisor_log'; |
---|
| 268 | if (!is_dir($dir)){ |
---|
| 269 | $umask = umask(0); |
---|
| 270 | $mkd = @mkdir($dir, 0755, true ); |
---|
| 271 | umask($umask); |
---|
| 272 | if ($mkd==false){ |
---|
| 273 | echo "<pre>Dir:$dir"; |
---|
| 274 | fatal_error( "$dir ".l10n('no write access')); |
---|
| 275 | return false; |
---|
| 276 | } |
---|
| 277 | } |
---|
| 278 | //================================================== |
---|
| 279 | add_event_handler('loc_begin_page_header', 'set_access' ); |
---|
| 280 | function set_access(){ |
---|
| 281 | global $user; |
---|
| 282 | global $ms_file_log,$dir,$clj_pwd; |
---|
| 283 | global $user,$conf; |
---|
| 284 | $pwd=$clj_pwd; |
---|
| 285 | |
---|
| 286 | if(!file_exists( $pwd.'/.htpasswd') || !file_exists( $dir.'/.htaccess')){ |
---|
| 287 | //========================================================= |
---|
| 288 | // Création liste mot de passe |
---|
| 289 | //========================================================= |
---|
| 290 | $server=$_SERVER["SERVER_NAME"]; |
---|
| 291 | $server_ip=$_SERVER["SERVER_ADDR"]; |
---|
| 292 | $user_ip=$_SERVER["REMOTE_ADDR"]; |
---|
| 293 | |
---|
| 294 | $pattern ="/(((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]{1}[0-9]|[1-9])\.){1}((25[0-5]|2[0-4][0-9]|[1]{1}[0-9]{2}|[1-9]{1}[0-9]|[0-9])\.){2}((25[0-5]|2[0-4][0-9]|[1]{1}[0-9]{2}|[1-9]{1}[0-9]|[0-9]){1}))/" ; |
---|
| 295 | $local=preg_match($pattern,$user_ip); |
---|
| 296 | |
---|
| 297 | $file = $pwd.'/.htpasswd'; |
---|
| 298 | $htmes1 =$conf['db_user'].":".$conf['db_password']."\n"; |
---|
| 299 | $htmes2 =$conf['db_user'].":".crypt($conf['db_password'], 'rl')."\n"; |
---|
| 300 | if(preg_match("/free/i",$server)||$local) |
---|
| 301 | $htmes=$htmes1; |
---|
| 302 | else |
---|
| 303 | $htmes=$htmes2; |
---|
| 304 | //==== écriture fichier texte |
---|
| 305 | |
---|
| 306 | |
---|
| 307 | |
---|
| 308 | $fp = fopen ( $file , "w"); |
---|
| 309 | fwrite($fp , $htmes,strlen($htmes)); |
---|
| 310 | fclose ($fp); |
---|
| 311 | |
---|
| 312 | $file = $pwd.'/.htaccess'; |
---|
| 313 | @file_put_contents( $file, "deny for all" ); |
---|
| 314 | //========================================================= |
---|
| 315 | // Création fichier htaccess |
---|
| 316 | //========================================================= |
---|
| 317 | $racine=explode("/",$_SERVER["PHP_SELF"] ); |
---|
| 318 | $racine = $racine[1] ; |
---|
| 319 | if(preg_match("/free/i",$server)) { |
---|
| 320 | $AuthUserFile='PerlSetVar AuthFile '.$racine.'/_data/Pwd' .'/.htpasswd'; |
---|
| 321 | }else{ |
---|
| 322 | if($local) |
---|
| 323 | $AuthUserFile='AuthUserFile '.realpath($pwd).'\\.htpasswd'."\n".'AuthGroupFile /dev/null'; |
---|
| 324 | else |
---|
| 325 | $AuthUserFile='AuthUserFile '.realpath($pwd).'\\.htpasswd'."\n".'AuthGroupFile /dev/null'; |
---|
| 326 | } |
---|
| 327 | |
---|
| 328 | //============================================================ |
---|
| 329 | $htmes=$AuthUserFile."\n". |
---|
| 330 | 'AuthName "Mail_supervisor_log"'."\n". |
---|
| 331 | 'AuthType Basic'."\n". |
---|
| 332 | '<limit GET>'."\n". |
---|
| 333 | 'require valid-user'."\n". |
---|
| 334 | '</Limit>'; |
---|
| 335 | $file = $dir.'/.htaccess'; |
---|
| 336 | @file_put_contents( $file, $htmes ); |
---|
| 337 | //============================================================ |
---|
| 338 | |
---|
| 339 | } |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | if($ms_file_log=="") $ms_file_log = $dir."/"."pw1.html"; |
---|
| 343 | |
---|
| 344 | |
---|
| 345 | //============================================================ |
---|
| 346 | function Mail_supervisor_log($label_,$lines){ |
---|
| 347 | global $ms_file_log,$conf; |
---|
| 348 | $nb_lignes=600 ; |
---|
| 349 | $t= var_export( $lines, true ); |
---|
| 350 | $s = htmlspecialchars( $lines); |
---|
| 351 | $s = ( $lines); |
---|
| 352 | if (!file_exists($ms_file_log)) { |
---|
| 353 | $handle = fopen($ms_file_log, 'w'); |
---|
| 354 | fwrite($handle, "\n"); |
---|
| 355 | fclose($handle); |
---|
| 356 | } |
---|
| 357 | $tableau=file($ms_file_log); |
---|
| 358 | $handle = fopen($ms_file_log, 'a'); |
---|
| 359 | $nb=count ($tableau); |
---|
| 360 | if($nb>$nb_lignes) { |
---|
| 361 | $handle = fopen($ms_file_log, 'w'); |
---|
| 362 | fwrite($handle, $nb. " > " . $nb_lignes . " RAZ " ."\n"); |
---|
| 363 | } |
---|
| 364 | //rewind ($handle); // Go back to the beginning |
---|
| 365 | //fwrite ($handle, sprintf("%5d ", $nb)); // Don't forget to increment the counter |
---|
| 366 | $s="\n".date('Y m d H:m:s ')."\n".$s; |
---|
| 367 | |
---|
| 368 | |
---|
| 369 | //$s= nl2br($s); |
---|
| 370 | |
---|
| 371 | if( $s !="") fwrite($handle,$s ); |
---|
| 372 | fclose($handle); |
---|
| 373 | } |
---|
| 374 | |
---|
| 375 | |
---|
| 376 | |
---|
[4888] | 377 | ?> |
---|