Changeset 22118 for extensions/Mail_supervisor
- Timestamp:
- Apr 10, 2013, 10:58:35 AM (11 years ago)
- Location:
- extensions/Mail_supervisor
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/Mail_supervisor/admin/mail_superv_admin.php
r19010 r22118 265 265 WHERE id = '.$group_id.' 266 266 ;'; 267 list($group_name) = mysql _fetch_row(pwg_query($query));267 list($group_name) = mysqli_fetch_row(pwg_query($query)); 268 268 } else { 269 269 $group_name=""; … … 338 338 WHERE id = '.$_POST['group'].' 339 339 ;'; 340 list($group_name) = mysql _fetch_row(pwg_query($query));340 list($group_name) = mysqli_fetch_row(pwg_query($query)); 341 341 342 342 array_push( … … 358 358 $result = pwg_query($query); 359 359 //---------------------------------------------------------------- 360 while ($row = mysql _fetch_array($result,MYSQL_ASSOC)) {360 while ($row = mysqli_fetch_array($result,MYSQL_ASSOC)) { 361 361 $groups[$row['id']] = $row['name']; } 362 362 //--------------------------------------------------------------- -
extensions/Mail_supervisor/include/Scripts.js
r11807 r22118 1 var image_w = jQuery(window).width(); 2 var image_h = jQuery(window).height(); 1 3 function blockToggleDisplay(headerId, contentId) { 2 4 var revHeader = document.getElementById(headerId); -
extensions/Mail_supervisor/include/fonctions.php
r13572 r22118 32 32 global $template ; 33 33 34 //=============================================== 34 //================================================ 35 35 function corrige_header($Carbonne,$headers,$args,$cl_list_mail,$mailto="") { 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 36 global $mails_options,$conf_mail,$infos_message; 37 if (!empty($args[$Carbonne]) && count($args[$Carbonne]) > 0 ){ 38 $cl_list_mail = str_replace(","," , ",get_strict_email_list(implode(',', $args[$Carbonne])))." \n" ; 39 $cl_liste_dest = implode(', ', $args[$Carbonne])." \n"; 40 if ($mails_options['check_header_carbon'] == 'on') { 41 $headers = preg_replace('/.*'.$Carbonne.':(.*).\n/i', $Carbonne.': '. $cl_list_mail, $headers); 42 } 43 $ret->list_mail = $cl_list_mail ; 44 } else { 45 // Raz Bcc, Cc dans headers 46 $headers = preg_replace('/.*'.$Carbonne.'(.*).\n/i', "" , $headers); 47 $ret->list_mail = "" ; 48 } 49 $ret->headers = $headers ; 50 return $ret; 51 51 } 52 52 53 53 function int_to_heure($int){ 54 global $lang,$mails_donnees ; 55 $v0=Date_to_numeric(l10n('Day') ); 56 57 58 59 $delta=(7*24*60*60) ; 60 $week = (int) ($int/$delta); 61 $int= $int-($week*$delta) ; 62 63 $delta=(24*60*60) ; 64 $day= (int) ($int/$delta); 65 $int=$int-($day*$delta); 66 67 $delta=(60*60) ; 68 $heures=(int) ($int/$delta); 69 $int=$int-($heures*$delta); 70 71 $delta=(60) ; 72 $minutes=(int) ($int/$delta); 73 $int= $int - ($minutes*$delta); 74 75 $secondes=(int) ($int); 76 $day = substr ('00'. $day,-2,2); 77 $heures = substr ('00'. $heures,-2,2); 78 $minutes = substr ('00'.$minutes,-2,2); 79 $secondes = substr ('00'.$secondes,-2,2); 80 81 $retour=""; 82 $Week=explode(" ",l10n('Week %d')); 83 $Week= ($Week[0]); 84 85 if ($week > 0 ) $retour .= "+" . $week ." " . $Week ; 86 if ($day > 0) $retour .= "+" . $day ." " .l10n('Day'); 87 if ($heures > 0) $retour .= "+" . $heures." " .l10n('Hour'); 88 if ($minutes > 0) $retour .= "+" . $minutes." " .l10n('Minute'); 89 if ($secondes > 0) $retour .= "+" . $secondes." " .l10n('Second'); 90 $retour=str_replace("+0","+",$retour); 91 //================================================================================================ 92 return $retour; 54 global $lang,$mails_donnees ; 55 $v0=Date_to_numeric(l10n('Day') ); 56 57 $delta=(7*24*60*60) ; 58 $week = (int) ($int/$delta); 59 $int= $int-($week*$delta) ; 60 61 $delta=(24*60*60) ; 62 $day= (int) ($int/$delta); 63 $int=$int-($day*$delta); 64 65 $delta=(60*60) ; 66 $heures=(int) ($int/$delta); 67 $int=$int-($heures*$delta); 68 69 $delta=(60) ; 70 $minutes=(int) ($int/$delta); 71 $int= $int - ($minutes*$delta); 72 73 $secondes=(int) ($int); 74 $day = substr ('00'. $day,-2,2); 75 $heures = substr ('00'. $heures,-2,2); 76 $minutes = substr ('00'.$minutes,-2,2); 77 $secondes = substr ('00'.$secondes,-2,2); 78 79 $retour=""; 80 $Week=explode(" ",l10n('Week %d')); 81 $Week= ($Week[0]); 82 83 if ($week > 0 ) $retour .= "+" . $week ." " . $Week ; 84 if ($day > 0) $retour .= "+" . $day ." " .l10n('Day'); 85 if ($heures > 0) $retour .= "+" . $heures." " .l10n('Hour'); 86 if ($minutes > 0) $retour .= "+" . $minutes." " .l10n('Minute'); 87 if ($secondes > 0) $retour .= "+" . $secondes." " .l10n('Second'); 88 $retour=str_replace("+0","+",$retour); 89 //================================================================================================ 90 return $retour; 93 91 } 94 92 95 93 96 94 function verif_base(){ 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 '"Information"' 123 124 95 global $lang,$superv_champs,$superv_type,$superv_bl_champs,$superv_bl_type; 96 load_language('plugin.lang', MAIL_SUPERV_PATH); 97 //============================================================================== 98 create_table(MAIL_BLACK_LISTE_TABLE,$superv_bl_champs,$superv_bl_type) ; 99 ajust_table(MAIL_BLACK_LISTE_TABLE,$superv_bl_champs,$superv_bl_type) ; 100 //============================================================================== 101 create_table(mail_superv_TABLE,$superv_champs,$superv_type) ; 102 ajust_table(mail_superv_TABLE,$superv_champs,$superv_type) ; 103 //============================================================================== 104 $valeurs= array ( 1, 105 0, 106 time(), 107 2000, 108 '"604800"' , 109 0, 110 time(), 111 10, 112 '"172800"', 113 '"false"', 114 time(), 115 '"172800"', 116 '"Init"', 117 '"'.l10n('Sv_supervisor').'"', 118 '"'.l10n('hello').'"', 119 '"Test Mail_supervisor"', 120 '"Information"' 121 ); 122 ajout_ligne(mail_superv_TABLE,$superv_champs, $valeurs,false ) ; 125 123 } 126 124 //========================================= 127 function Get_colonnes_de($table) 128 { 129 $query = 'DESC '.$table.';'; 130 $result = mysql_query($query); 131 $columns_of= array(); 132 while ($row = mysql_fetch_row($result)) 133 { 134 array_push($columns_of, $row[0]); 135 } 136 137 return $columns_of; 125 function Get_colonnes_de($table){ 126 $query = 'DESC '.$table.';'; 127 $result = pwg_query('desc '.$table); 128 $columns_of= array(); 129 while ($row = pwg_db_fetch_assoc($result)) 130 { 131 array_push($columns_of, $row['Field']); 132 } 133 pwg_db_free_result($result); 134 return $columns_of; 138 135 } 139 136 //========================================= 140 137 function get_liste($group_id){ 141 global $conf ;142 143 SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 while ($group = mysql_fetch_array($datas,MYSQL_ASSOC)){160 161 162 163 164 165 166 167 168 169 170 171 138 global $conf ; 139 $query = ' 140 SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, 141 u.'.$conf['user_fields']['username'].' AS username, 142 u.'.$conf['user_fields']['email'].' AS email, 143 ui.status, 144 ui.enabled_high, 145 ui.level 146 FROM '.USERS_TABLE.' AS u 147 INNER JOIN '.USER_INFOS_TABLE.' AS ui 148 ON u.'.$conf['user_fields']['id'].' = ui.user_id 149 LEFT JOIN '.USER_GROUP_TABLE.' AS ug 150 ON u.'.$conf['user_fields']['id'].' = ug.user_id 151 WHERE ug.group_id='.$group_id.' '; 152 $groups=array(); 153 $datas = pwg_query($query); 154 155 if (!empty($datas)) { 156 while ($group = mysqli_fetch_array($datas,MYSQL_ASSOC)){ 157 if (!empty($group['email'])){ 158 //array_push($groups, format_email($group['username'], $group['email'] )); 159 array_push($groups, 160 array( 'username' => $group['username'], 161 'email' => $group['email'], 162 'format_email' => format_email($group['username'], $group['email'] ) 163 ) 164 ); 165 } 166 } 167 } 168 return $groups ; 172 169 173 170 } … … 176 173 function create_table($nom_table,$champs,$types) //mail_superv_TABLE 177 174 { 178 $i=0; 179 $valeurs=array(); 180 foreach ( $champs as $champ) { 181 $champ = trim($champ); 182 array_push($valeurs , " `".$champ."`" . ' ' . $types[ $i] ) ; 183 $i +=1; 184 } 185 186 187 188 if ( count($valeurs) == 0) return ; 189 190 $valeurs=implode(", ",$valeurs) ; 191 //=============================================================================== 192 $query = "CREATE TABLE IF NOT EXISTS `" . $nom_table . "` (". $valeurs . " , PRIMARY KEY (`id` ) ) ENGINE=MyISAM ;"; 193 if ( pwg_query($query) ) return ; 194 die("ERREUR CREATION ".$query); 175 $i=0; 176 $valeurs=array(); 177 foreach ( $champs as $champ) { 178 $champ = trim($champ); 179 array_push($valeurs , " `".$champ."`" . ' ' . $types[ $i] ) ; 180 $i +=1; 181 } 182 if ( count($valeurs) == 0) return ; 183 $valeurs=implode(", ",$valeurs) ; 184 //=============================================================================== 185 $query = "CREATE TABLE IF NOT EXISTS `" . $nom_table . "` (". $valeurs . " , PRIMARY KEY (`id` ) ) ENGINE=MyISAM ;"; 186 if ( pwg_query($query) ) return ; 187 die("ERREUR CREATION ".$query); 195 188 196 189 … … 198 191 //=========================================================== 199 192 function ajust_table($nom_table,$champs,$types){ //mail_superv_TABLE 200 global $infos_message ;201 $colonnes = Get_colonnes_de($nom_table);202 203 204 205 206 207 208 209 210 211 212 213 //=============================================================================214 215 216 217 218 219 193 global $infos_message ; 194 $colonnes = Get_colonnes_de($nom_table); 195 $data = $types ; 196 $i=0; 197 $valeurs=array(); 198 foreach ( $champs as $champ) { 199 $champ = trim($champ); 200 if (!in_array( $champ,$colonnes)) { 201 array_push($valeurs , " ADD `".$champ."`" . ' ' . $data[ $i] ) ; 202 } 203 $i +=1; 204 205 } 206 //============================================================================= 207 if ( count($valeurs) == 0) return ; 208 $valeurs=implode(", ",$valeurs) ; 209 //=============================================================================== 210 $query = "ALTER TABLE `" . $nom_table . "` ". $valeurs ; 211 if ( pwg_query($query)) return ; 212 die($query); 220 213 } 221 214 //============================================================================== 222 function ajout_ligne($nom_table,$champs,$valeurs,$force) 223 {224 if (!$force) { 225 $query = " 226 SELECT `id` , COUNT(`id`) as total 227 FROM `".$nom_table."` GROUP by `id` 228 ;";229 list($count) = mysql_fetch_row(pwg_query($query)); 230 231 232 }else{ 233 234 235 }236 $data=array(); 237 238 $query = " SELECT * FROM `".$nom_table."` ;"; 239 240 241 while ($row = mysql_fetch_array($datas,MYSQL_ASSOC)){242 array_push($data,$row); 243 244 245 $count= count($data); 246 if ($count == 0) { 247 $n_champs=implode(",",$champs); 248 $n_valeurs=implode(",",$valeurs);249 $query = " 250 INSERT INTO `".$nom_table."` (". $n_champs.") 251 VALUES ( ". $n_valeurs .")"; 252 253 if (pwg_query($query)) return ; 254 die("fonction.php 256".$query);255 256 257 215 function ajout_ligne($nom_table,$champs,$valeurs,$force){ 216 if (!$force) { 217 $query = " 218 SELECT `id` , COUNT(`id`) as total 219 FROM `".$nom_table."` GROUP by `id` 220 ;"; 221 $datas=pwg_query($query) ; 222 if (!empty($datas)) { 223 list($count) = mysqli_fetch_row($datas); 224 } 225 226 }else{ 227 $count = 0 ; 228 } 229 230 $data=array(); 231 $query = " SELECT * FROM `".$nom_table."` ;"; 232 $datas = pwg_query($query); 233 if (!empty($datas)) { 234 while ($row = mysqli_fetch_array($datas,MYSQL_ASSOC)){ 235 array_push($data,$row); 236 } 237 } 238 239 $count= count($data); 240 if ($count == 0) { 241 $n_champs=implode(",",$champs); 242 $n_valeurs=implode(",",$valeurs); 243 $query = " 244 INSERT INTO `".$nom_table."` (". $n_champs.") 245 VALUES ( ". $n_valeurs .")"; 246 247 if (pwg_query($query)) return ; 248 die("fonction.php 256".$query); 249 } 250 258 251 } 259 252 //===================================================================== 260 253 function verif_mails_donnees(){ 261 262 263 if (!is_numeric($mails_donnees['nb_mails_periode'])){264 265 266 267 if (!is_numeric($mails_donnees['nb_spams_periode'])){268 269 270 271 if (!is_numeric($mails_donnees['quarantaine_periode'])){272 273 274 275 276 277 278 279 280 281 282 254 global $mails_donnees,$infos_message,$erreur_message,$page; 255 256 if (!is_numeric($mails_donnees['nb_mails_periode'])){ 257 $periode = Str_To_Time( $mails_donnees['nb_mails_periode'],0); 258 $mails_donnees['nb_mails_periode']= ($periode > 0) ? $periode : '604800' ; 259 } 260 if (!is_numeric($mails_donnees['nb_spams_periode'])){ 261 $periode=Str_To_Time( $mails_donnees['nb_spams_periode'],0); 262 $mails_donnees['nb_spams_periode']= ($periode > 0) ? $periode : '172800' ; ; 263 } 264 if (!is_numeric($mails_donnees['quarantaine_periode'])){ 265 $periode=Str_To_Time( $mails_donnees['quarantaine_periode'],0); 266 $mails_donnees['quarantaine_periode']= ($periode > 0) ? $periode : '172800' ; 267 } 268 if ($infos_message != "") { 269 array_push($page['infos'], $infos_message); 270 $infos_message=""; 271 } 272 if ($erreur_message != "") { 273 array_push($page['errors'], $erreur_message); 274 $erreur_message =""; 275 } 283 276 284 277 } 285 278 //======================================================================= 286 279 function Date_to_numeric( $Valeurs ){ 287 global $lang,$erreur_message,$infos_message;288 289 $a_ajouter = $Valeurs ;290 291 292 if (!isset($lang['Sv_second'])) {293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 }309 //--- traduction --> anglais ---310 311 312 $new_valeur =( preg_replace("/[0-9+\-.*\/()%]/"," ",$a_ajouter));313 $nv = trim( sup_double_espace($new_valeur)) ;314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 280 global $lang,$erreur_message,$infos_message; 281 282 $a_ajouter = $Valeurs ; 283 284 285 if (!isset($lang['Sv_second'])) { 286 $Week=explode(" ",l10n('Week %d')); 287 $Week= ($Week[0]); 288 289 $lang['Sv_week'] = $Week; 290 $lang['Sv_day'] = l10n('Day') ; 291 $lang['Sv_hour'] = l10n('Hour') ; 292 $lang['Sv_minute'] = l10n('Minute') ; 293 $lang['Sv_second'] = l10n('Second'); 294 295 $lang['Sv_'. $lang['Sv_week']] = 'week'; 296 $lang['Sv_'. $lang['Sv_day']] = 'day'; 297 $lang['Sv_'. $lang['Sv_hour']] = 'hour'; 298 $lang['Sv_'. $lang['Sv_minute']] = 'minute'; 299 $lang['Sv_'. $lang['Sv_second']] = 'second'; 300 301 } 302 //--- traduction --> anglais --- 303 304 //========= suppression numeric et symbole ========== 305 $new_valeur =( preg_replace("/[0-9+\-.*\/()%]/"," ",$a_ajouter)); 306 $nv = trim( sup_double_espace($new_valeur)) ; 307 308 309 310 $conv['week']= (7*24*60*60); 311 $conv['day']= (24*60*60); 312 $conv['hour']= (60*60) ; 313 $conv['minute']= 60 ; 314 $conv['second']= 1; 315 316 $nv = explode(" ", $nv ); 317 318 foreach($nv as $nv1){ 319 if (!isset($lang['Sv_'. $nv1]) ) { 320 //==== au cas pluriel === 321 $nv0 = substr($nv1, 0,-1) ; 322 $a_ajouter= str_replace( $nv1,$nv0, $a_ajouter); 323 $nv1 = $nv0 ; 324 } 325 if (!isset($lang['Sv_'. $nv1]) ) { 326 $erreur_message .= $nv1. " ".l10n('not_found')."<br />"; 327 // die($erreur_message); 328 }else { 329 ob_start(); 330 $match = $conv[strtolower($lang['Sv_'. $nv1])] ; 331 $a_ajouter = str_replace($nv1," ". $match ." ",$a_ajouter) ; 332 $erreur_message .= ob_get_contents(); 333 ob_end_clean(); 334 } 335 } 336 337 $a_ajouter = "+ " . $a_ajouter ; 338 $a_ajouter=sup_double_espace($a_ajouter); 339 $v1 = array('- ','+ ',' -', ' +', ' '); 340 $v2 = array('-' ,'+' ,'|-', '|+', "*"); 341 342 $new_valeur = str_replace($v1,$v2,$a_ajouter) ; 343 $new_valeur = str_replace('++','+',$new_valeur ) ; 344 345 return $new_valeur; 353 346 } 354 347 //===================================================================== 355 348 function Str_To_Time( $ajout,$init_date) 356 349 { 357 //========================================================358 359 360 361 362 363 364 if (is_numeric($ajout))365 366 else367 {368 369 370 371 372 $new_valeur = explode( "|", $valeur );373 374 $p = $init_date ;375 $n0=0;376 $erreur = false;377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 return intval($p) ;350 //======================================================== 351 global $erreur_message,$infos_message,$user; 352 global $lang; 353 354 $ajout=ucwords ($ajout); 355 356 357 if (is_numeric($ajout)) 358 $valeur= $ajout ; 359 else 360 { 361 $valeur= Date_to_numeric( $ajout) ; 362 363 } 364 365 $new_valeur = explode( "|", $valeur ); 366 367 $p = $init_date ; 368 $n0=0; 369 $erreur = false; 370 371 //$new_valeur = $a_ajouter + $init_date ; 372 foreach($new_valeur as $nv) 373 { 374 $return = matheval($nv) ; 375 if (strpos("error",$return)===false) { 376 $p += $return ; 377 }else { 378 $erreur_message .= "[" . $ajout . "] --> " . l10n('Sv_syntax_error') . " : " . $nv ."<br />"; 379 $erreur = true; 380 } 381 382 383 } 384 if ($erreur) $p = -1000 ; 385 return intval($p) ; 393 386 394 387 } 395 388 //===================================================================================== 396 389 function matheval($equation) 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 390 { 391 392 $return="error"; 393 394 395 $equation = preg_replace("/[^0-9+\-.*\/()%]/","",$equation); 396 $equation = preg_replace("/([+-])([0-9]{1})(%)/","*(1\$1.0\$2)",$equation); 397 $equation = preg_replace("/([+-])([0-9]+)(%)/","*(1\$1.\$2)",$equation); 398 $equation = preg_replace("/([0-9]+)(%)/",".\$1",$equation); 399 400 if ( $equation == "" ) 401 { 402 $return = 0; 403 } else { 404 @eval("\$return=" . $equation . ";" ); 405 } 406 return $return; 407 408 } 416 409 417 410 //====================================================================================== 418 411 function sup_double_espace($chaine){ 419 global $erreur_message;420 421 422 423 424 425 426 427 428 // $erreur_message .= $mail_supervisor->Memo_Var($str_temp) ;429 430 431 432 412 global $erreur_message; 413 $str_temp = $chaine." "; 414 $sep=" "; 415 $chaine = trim($chaine); 416 if ($chaine=="") return ; 417 $existe = (strpos($sep.$sep,$chaine )===false) ; 418 while ($existe ){ 419 $str_temp = str_replace($sep.$sep, $sep, $chaine ); 420 if($str_temp == $chaine ) return $chaine ; 421 // $erreur_message .= $mail_supervisor->Memo_Var($str_temp) ; 422 $chaine = $str_temp; 423 $existe = (strpos($sep.$sep,$chaine )===false) ; 424 } 425 return $chaine; 433 426 } 434 427 //==================== TEST black_liste ============================================ 435 428 function kill_list() { 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 $datas = mysql_fetch_array($result,MYSQL_ASSOC);461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 $datas = mysql_fetch_array($result,MYSQL_ASSOC);525 526 527 $row = mysql_fetch_row(pwg_query($query));528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 429 global $pays,$region,$ville,$ip ; 430 global $erreur_message,$infos_message,$conf; 431 global $conf, $user, $page; 432 global $mails_options ; 433 global $superv_bl_champs,$superv_bl_type ; 434 global $nb ; 435 if (!isset($ip)) { 436 if (getenv("HTTP_CLIENT_IP")) { 437 $ip=getenv("HTTP_CLIENT_IP"); 438 }else{ 439 $ip=getenv("REMOTE_ADDR"); 440 } 441 } 442 $champs=implode(',',$superv_bl_champs); 443 $query = "SELECT ".$champs.",COUNT(`ip`) as total 444 FROM `".MAIL_BLACK_LISTE_TABLE."` 445 WHERE '".$ip."' LIKE `ip` 446 GROUP by `ip` 447 ;"; 448 $result = @pwg_query($query); 449 if (!$result) { 450 verif_base(); 451 $result = @pwg_query($query); 452 } 453 $datas = mysqli_fetch_array($result,MYSQL_ASSOC); 454 $nb = $datas['total']|0; 455 //======================================================================= 456 if ($mails_options['set_auto'] == 'on') { 457 global $user_name,$mail_adresse; 458 459 if (isset($nb) && $nb>0) { 460 //if (test_spam($ip,$user['username'] ,$user['email'])) // ne plus tester automatiquement . 461 if ($nb==0) { 462 $valeurs=array( 'NULL', 463 "'".$ip."'", 464 "'".$pays."'", 465 "'".$region."'", 466 "'".$ville."'", 467 "'".$user['email']."'", 468 "'".$user['username']."'", 469 $nb+1 470 ); 471 ajout_ligne(MAIL_BLACK_LISTE_TABLE,$superv_bl_champs, $valeurs,$nb==0) ; 472 }else{ 473 $mail_supervisor->Get_geo(); 474 $nb +=1; 475 $query ="UPDATE " . MAIL_BLACK_LISTE_TABLE . " SET "; 476 if (isset($_POST['pays'])) 477 $query .= "`pays` = '". $pays ."', 478 `region` = '" . $region ."', 479 `ville` = '" . $ville . "', 480 "; 481 $query .= "`adresse` = '".$user['email']."', 482 `fai` = '".$user['username']."', 483 `nb` = " . $nb . " 484 WHERE '".$ip."' like `ip` "; 485 pwg_query($query ); 486 } 487 $erreur_message .= $pays . $ip ." <br />User Name :".$user['username']."<br />User Mail :".$user['email'] . ' -----> ' . l10n('Sv_set_black_liste') ; 488 // die($nb." ".$ip." ".$user['username']." ".$user['email']); 489 490 return true ; 491 } 492 } 493 //============================================================================== 494 if (empty($mail_supervisor)) { 495 $mail_supervisor = new mail_supervisor(); 496 } 497 498 if ( $mails_options['ip'] == $ip ) return ($nb > 0) ; 499 $ip0= $mails_options['ip'] ; 500 $mails_options['ip'] = $ip ; 501 502 $mail_supervisor->sauve_options(); 503 if ( $nb > 0 ) 504 { 505 $query = " 506 SELECT ".$champs.",COUNT(`id`) as total 507 FROM `".MAIL_BLACK_LISTE_TABLE."` 508 WHERE '".$ip."' = `ip` 509 GROUP by `ip` 510 ;"; 511 $result = @pwg_query($query); 512 513 if (!$result) { 514 verif_base(); 515 $result = @pwg_query($query); 516 } 517 $datas = mysqli_fetch_array($result,MYSQL_ASSOC); 518 $nb = $datas['total']; 519 520 $row = mysqli_fetch_row(pwg_query($query)); 521 $nb = ($row[7]); 522 $erreur_message .= $ip0 . ' | ' .$ip . ' | ' . $pays . ' | ' . $region . ' | ' . $ville . ' ' . $nb . ' ==> '; 523 524 if ($nb == 0) 525 { 526 $valeurs=array( 'NULL', 527 "'".$ip."'", 528 "'".$pays."'", 529 "'".$region."'", 530 "'".$ville."'", 531 "'".$user['email']."'", 532 "'".$user['username']."'", 533 1 534 ); 535 ajout_ligne(MAIL_BLACK_LISTE_TABLE,$superv_bl_champs, $valeurs,true) ; 536 537 } else { 538 $nb += 1; 539 $query =" 540 UPDATE " . MAIL_BLACK_LISTE_TABLE . " 541 SET "; 542 if (isset($_POST['pays'])) 543 $query .= " 544 `pays` = '". $pays ."', 545 `region` = '" . $region ."', 546 `ville` = '" . $ville . "', 547 "; 548 $query .= " 549 `adresse` = '".$user['email']."', 550 `fai` = '".$user['username']."', 551 `nb` = " . $nb . " 552 WHERE '".$ip."' = `ip` 553 "; 554 555 pwg_query($query ); 556 } 557 } 558 return ($nb > 0) ; 566 559 } 567 560 //===================================================================================== 568 561 function test_spam($ip =0,$user_name ='', $mail_adresse = ""){ 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 562 $buffer=""; 563 global $page,$infos_message; 564 $src = "http://www.stopforumspam.com/api?"; 565 $type=array(); 566 $result=""; 567 $ip= sup_double_espace($ip); 568 if (strlen($ip)>3) { 569 //================== Verifie si l'IP est correct ================================ 570 if (clj_is_ip($ip)){ 571 572 } else { 573 //================== Verifie si l'adresse mail est correcte ================================ 574 if( clj_is_mail($ip) ){ 575 $mail_adresse=$ip ; 576 $ip=""; 577 } 578 else 579 { 580 //================== Login ================ 581 $user_name=$ip; 582 $ip=""; 583 } 584 } 585 //============================================================================= 586 } 587 588 $user_name=str_replace(" ","%20",trim($user_name)); 589 if ($user_name==l10n('Sv_guest')) $user_name=""; 590 $user_name=""; // ne plus tester sur le login. 591 $mail_adresse =str_replace(" ","%20",trim($mail_adresse)); 592 if ( strlen($user_name) > 3) $type[]="username=$user_name" ; 593 if ( strlen($mail_adresse) > 3) $type[]="email=".$mail_adresse ; 594 if ( strlen($ip) > 3) $type[]="ip=".$ip ; 595 foreach ( $type as $fil ) { 596 $resultat=""; 597 if ( clj_fetchRemote($src.$fil , $resultat,1)) 598 $result .= $resultat.'<br />' ; 599 } 600 601 return !(strpos( $result ,'yes' ) === false) ; 609 602 610 603 } 611 604 //================================================================== 612 605 function lire_fichier_distant($fichier){ 613 614 615 616 617 618 619 620 621 622 606 $buffer=""; 607 $handle = @fopen($fichier,"r"); 608 if ($handle) { 609 while (!feof($handle)) { 610 $buffer .= fgets($handle, 4096); 611 } 612 fclose($handle); 613 } 614 615 return $buffer ; 623 616 624 617 } 625 618 //================================================ 626 619 function clj_is_ip($ip){ 627 if (preg_match("/^(((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}))$/",$ip)) return true ;620 if (preg_match("/^(((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}))$/",$ip)) return true ; 628 621 629 622 } … … 632 625 { 633 626 634 635 627 if(preg_match('/^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,5}$/' ,$mail)) return true ; 628 if(preg_match('/#^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,5}$#/' ,$mail)) return true ; 636 629 } 637 630 … … 639 632 function clj_fetchRemote($src, &$dest, $timeout=1, $user_agent='Piwigo', $step=0) 640 633 { 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 634 // Try to retrieve data from local file? 635 // http://www.stopforumspam.com/api?ip=95.211.1.39 636 637 if ($src=="") return ; 638 639 if (!url_is_remote($src)) 640 { 641 642 $content = @file_get_contents($src); 643 if ($content !== false) 644 { 645 is_resource($dest) ? @fwrite($dest, $content) : $dest = $content; 646 return true; 647 } 648 else 649 { 650 return false; 651 } 652 } 653 654 // After 3 redirections, return false 655 if ($step > 3) return false; 656 657 // Initialize $dest 658 is_resource($dest) or $dest = ''; 659 660 // Try curl to read remote file 661 if (function_exists('curl_init')) 662 { 663 $ch = @curl_init(); 664 @curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); 665 @curl_setopt($ch, CURLOPT_URL, $src); 666 @curl_setopt($ch, CURLOPT_HEADER, 1); 667 @curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); 668 @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 669 $content = @curl_exec($ch); 670 $header_length = @curl_getinfo($ch, CURLINFO_HEADER_SIZE); 671 $status = @curl_getinfo($ch, CURLINFO_HTTP_CODE); 672 @curl_close($content); 673 if ($content !== false and $status >= 200 and $status < 400) 674 { 675 if (preg_match('/Location:\s+?(.+)/', substr($content, 0, $header_length), $m)) 676 { 677 return clj_fetchRemote($m[1], $dest,$timeout, $user_agent, $step+1); 678 } 679 $content = substr($content, $header_length); 680 is_resource($dest) ? @fwrite($dest, $content) : $dest = $content; 681 return true; 682 } 683 } 684 685 // Try file_get_contents to read remote file 686 if (ini_get('allow_url_fopen')) 687 { 688 689 $opts['http'] = array('timeout' => $timeout); 690 $ctx = stream_context_create($opts); 691 $content = @file_get_contents($src, 0, $ctx); 692 if ($content !== false) 693 { 694 is_resource($dest) ? @fwrite($dest, $content) : $dest = $content; 695 return true; 696 } 697 } 698 699 return false; 707 700 } 708 701 -
extensions/Mail_supervisor/include/save_info.php
r13572 r22118 13 13 ;"; 14 14 //============================================================================== 15 list($count) = mysql _fetch_row(pwg_query($query));15 list($count) = mysqli_fetch_row(pwg_query($query)); 16 16 //============================================================================== 17 17 $valeurs=array( 'NULL', … … 49 49 $liste_bl = array(); 50 50 $result = pwg_query($query); 51 while ($row = mysql _fetch_array($result,MYSQL_ASSOC)) {51 while ($row = mysqli_fetch_array($result,MYSQL_ASSOC)) { 52 52 array_push($liste_bl,$row); 53 53 } 54 54 //================ Liste IP ============== 55 $req = mysql_query('SELECT count(distinct(`IP`)) FROM '.HISTORY_TABLE.' ');56 $op=mysql _fetch_row($req);55 $req = pwg_query('SELECT count(distinct(`IP`)) FROM '.HISTORY_TABLE.' '); 56 $op=mysqli_fetch_row($req); 57 57 $nbip = array_pop($op) ; 58 58 … … 78 78 $result = pwg_query($query); 79 79 $liste_ip=array(); 80 while ($row = mysql _fetch_array($result,MYSQL_ASSOC)) {80 while ($row = mysqli_fetch_array($result,MYSQL_ASSOC)) { 81 81 82 82 array_push($liste_ip, $row); -
extensions/Mail_supervisor/mail_super.inc.php
r13572 r22118 22 22 23 23 class mail_supervisor { 24 //============================================================ 25 /* 26 * admin_menu 27 */ 28 static public function admin_menu($menu) { 29 array_push($menu, 30 array( 'NAME' => 'Mail supervisor', 31 'URL' => get_admin_plugin_menu_link(MAIL_SUPERV_PATH . 'admin/mail_superv_admin.php') 32 ) 33 ); 34 return $menu; 35 } 36 //============================================================ 37 /* 38 * init 39 */ 40 static public function init() { 41 global $template,$version,$icon_path,$page; 42 $action_spam = pwg_get_session_var('action_spam') ; 43 $theme="default"; 44 $themeconf=$template->get_template_vars('themeconf'); 45 $theme=$themeconf['id']; 46 if (file_exists ( 'admin/themes/clear/icon/help.png')) $icon_path = 'admin/themes/clear/icon/help.png'; 47 else $icon_path = "admin/template/goto/theme/clear/icon/help.png"; 48 if (PHPWG_VERSION < 2.2 ) { 49 $file =MAIL_SUPERV_PATH_ABS.'admin/header_2_1.tpl' ; 50 51 } else { 52 $file = MAIL_SUPERV_PATH_ABS.'admin/header_2_2.tpl' ; 53 54 } 55 if(isset($_GET['action_spam']) and $_GET['action_spam']=="no"){ 56 pwg_set_session_var('action_spam', "false"); 57 unset ($_SESSION['pwg_'.'action_spam']); 58 } 59 $action_spam=pwg_get_session_var('action_spam'); 60 $template->set_filenames(array('mail_superv_init'=> $file )); 61 $MAIL_SUPERV_PATH=str_replace(PHPWG_ROOT_PATH,"",MAIL_SUPERV_PATH) ; 62 $profile=array('theme' => $theme, 63 'PHPWG_VERSION' => PHPWG_VERSION , 64 'MAIL_SUPERV_PATH' => $MAIL_SUPERV_PATH , 65 'MAIL_SUPERV_PATH_ABS' => MAIL_SUPERV_PATH_ABS 66 ); 67 68 $template->assign( $profile ); 69 $template->append('footer_elements', '<input id="action_spam" name="action_spam" type="hidden" value="'.$action_spam.'" />'); 70 $template->parse( 'mail_superv_init', false); 71 return ;// 72 }// function init 73 //============================================================ 74 /* 75 * affiche_message 76 */ 77 //============================================================ 78 static public function affiche_message(){ 79 global $template,$infos_message,$erreur_message, $user ,$ip; 80 global $mails_options,$conf,$lang,$page ; 81 global $action_spam ; 82 if (!isset($ip)) { 83 if (getenv("HTTP_CLIENT_IP")) { 84 $ip=getenv("HTTP_CLIENT_IP"); 85 }else{ 86 $ip=getenv("REMOTE_ADDR"); 87 } 88 } 89 // unset ($_SESSION['pwg_'.'action_spam']); 90 $action_spam = pwg_get_session_var('action_spam') ; 91 92 if ($action_spam == null or $action_spam == 'false') { 93 $action_spam = kill_list(); 94 } 95 96 if (is_bool($action_spam)) $action_spam =($action_spam == true) ? "true" : "false" ; 97 if ($action_spam == "true" ) { 98 $erreur_message .= $ip . " " . $action_spam ; 99 pwg_set_session_var('action_spam', "true"); 100 $erreur_message .= "<br />".l10n('Sv_is_a_spam') ; 101 if ($mails_options['no_connect'] == 'on1' ){ 102 //[status] => guest 103 //[status] => normal 104 //[status] => webmaster 105 if ($user['status'] != 'webmaster' ) 106 if (!isset($_GET['admin'])) { 107 die('Blacklist : <br />' .$erreur_message. '<br /> Hacking attempt!'); 108 }elseif ($_GET['admin'] != 'piwigo'){ 109 die('blacklist Hacking attempt!'); 110 } 111 unset ($_SESSION['pwg_'.'action_spam']); 112 } 113 }else{ 114 pwg_set_session_var('action_spam', "false"); 115 } 116 117 if (isset($infos_message)) 118 if ($infos_message != "") { 119 $infos_message = str_replace("\n",'<br />',$infos_message) ; 120 if (!isset($page['infos'])) $page['infos']=Array($infos_message); 121 else if(is_array($page['infos'])) array_push($page['infos'], $infos_message); 122 else $page['infos']=Array($infos_message); 123 $infos_message=""; 124 } 125 if (isset($erreur_message)) 126 if ($erreur_message != "") { 127 $erreur_message = str_replace("\n",'<br />',$erreur_message) ; 128 if (!isset($page['errors'])) $page['errors']=Array($erreur_message); 129 else if(is_array($page['errors'])) array_push($page['errors'], $erreur_message); 130 else $page['errors']=Array($erreur_message); 131 $erreur_message =""; 132 } 133 return $action_spam; 134 } //fin Affiche_message 135 136 //============================================================ 137 /* 138 * Get_geo 139 */ 140 static public function Get_geo() { 141 global $info_geo,$ip,$pays,$region,$ville, $latitude ,$longitude,$mails_options; 142 //=================================================================================== 143 $info_geo = pwg_get_session_var('info_geo'); 144 if (count($info_geo) > 0){ 145 $pays = $info_geo[0]; 146 $region = $info_geo[1]; 147 $ville = $info_geo[2]; 148 $latitude = $info_geo[3]; 149 $longitude = $info_geo[4]; 150 $ip = $info_geo[5]; 151 return true; 152 } 153 //======================================================================= 154 if (isset($_POST['pays'])) { 155 $pays = isset($_POST['pays']) ? $_POST['pays'] : ""; 156 $region = isset($_POST['region']) ? $_POST['region'] :""; 157 $ville = (isset($_POST['ville'])) ? $_POST['ville']: ""; 158 $latitude = isset($_POST['latitude']) ? $_POST['latitude'] : ""; 159 $longitude = isset($_POST['longitude']) ? $_POST['longitude'] : ""; 160 $info_geo = array( $pays ,$region , $ville ,$latitude, $longitude,$_SERVER['REMOTE_ADDR'] ); 161 pwg_set_session_var('info_geo', $info_geo); 162 return true; 163 }else{ 164 165 $result=""; 166 echo '<script type="text/javascript">get_script_geo();</script>'; 167 return true; 168 } 169 } // fin get_geo 170 //===================================================================================== 171 /* 172 * Memo_Var 173 */ 174 static public function Memo_Var($variables) { 175 ob_start(); 176 echo '<pre>'; 177 if(count($variables)>1){ 178 foreach($variables as $key => $line){ 179 echo $key . " => " . $line ; 180 echo "<br />"; 181 } 182 }else{ 183 echo "<i>".$variables."</i><br />"; 184 } 185 186 $m= ob_get_contents(); 187 ob_end_clean(); 188 return $m; 189 } 190 //====================================================================================== 191 static public function Get_Version_plugins($dir){ 192 $path = $dir; 193 $plg_data = implode( '', file($path.'main.inc.php') ); 194 if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) ) 195 { 196 $plugin['name'] = trim( $val[1] ); 197 } 198 if (preg_match("|Version: (.*)|", $plg_data, $val)) 199 { 200 $plugin['version'] = trim($val[1]); 201 } 202 if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) ) 203 { 204 $plugin['uri'] = trim($val[1]); 205 } 206 if ($desc = load_language('description.txt', $path.'/', array('return' => true))) 207 { 208 $plugin['description'] = trim($desc); 209 } 210 elseif ( preg_match("|Description: (.*)|", $plg_data, $val) ) 211 { 212 $plugin['description'] = trim($val[1]); 213 } 214 if ( preg_match("|Author: (.*)|", $plg_data, $val) ) 215 { 216 $plugin['author'] = trim($val[1]); 217 } 218 if ( preg_match("|Author URI: (.*)|", $plg_data, $val) ) 219 { 220 $plugin['author uri'] = trim($val[1]); 221 } 222 if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid=')) 223 { 224 list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']); 225 if (is_numeric($extension)) $plugin['extension'] = $extension; 226 } 227 // IMPORTANT SECURITY ! 228 $plugin = array_map('htmlspecialchars', $plugin); 229 return $plugin ; 230 } 231 //========================================================== 232 function Get_Options(&$parametres,$str_index){ 233 global $conf ; 234 $mails_options= $conf[$str_index]; 235 if(isset($mails_options)) 236 if ( preg_match("|s:(.*)|", $mails_options, $val) ) 237 $parametres = unserialize($conf['mail_superv']); 238 else{ 239 $parametres=explode(",",$mails_options); 240 } 241 //====== par defaut ======================= 242 $new_val=false; 243 244 if (empty($def_para)) 245 $def_para = (object) ''; 246 247 $def_para->check_mailto="on"; 248 $def_para->check_header_carbon="on"; 249 $def_para->check_send_webmaster="off"; 250 $def_para->no_ipaddress="off"; // interdiction adresse ip 251 252 $def_para->no_mail_list="on"; 253 $def_para->no_connect="on"; // empeche l'ip de se connecter au site. 254 $def_para->set_auto="on"; // Test a l'ouverture et enregistrement 255 $def_para->ip="127.0.0.1"; // derniere adresse IP 256 $def_para->set_id="on"; // enregistrment nouvel 257 $def_para->debug_mail="off"; // debogage 258 259 foreach ($def_para as $key => $value) { 260 if(isset($parametres[$key])){ 261 $value=$parametres[$key]; 262 } else { 263 $new_val=true; 264 } 265 $new_val= isset($_POST[$key]) && $new_val ; 266 unset( $parametres[$key]) ; 267 $parametres[$key]= (isset($_POST[$key]))? "on" : $value ; 268 } 269 270 if($new_val){ 271 sauve_options(); 272 } 273 return $parametres ; 274 } 275 //========================================================== 276 function Set_Options($parametres,$str_index){ 277 global $infos_message,$conf; 278 foreach ($parametres as $key => $value) { 279 $parametres[$key]=(isset($_POST[$key]))? "on" : $value ; 280 } 281 $parametres['no_connect']= 'off' ; 282 return $parametres ; 283 } 284 //========================================================== 285 286 function sauve_options(){ 287 global $options,$infos_message,$conf,$mails_options ; 288 $infos_message .=l10n("save_config")."<br>"; 289 if (empty($mail_supervisor)) { 290 $mail_supervisor = new mail_supervisor(); 291 } 292 $mails_parametres= $mail_supervisor->Set_Options($mails_options,"mail_superv"); 293 294 if ( isset($mails_parametres) ) 295 { $query = ' 296 UPDATE '.CONFIG_TABLE.' 297 SET value="'.addslashes(serialize($mails_parametres)).'" 298 WHERE param = "mail_superv" 299 LIMIT 1'; 300 pwg_query($query); 301 } 302 303 } 304 305 /**************************************** 306 * sauve_donnees() 307 ****************************************/ 308 function sauve_donnees(){ 309 global $mails_donnees,$superv_champs,$superv_type,$erreur_message ; 310 //===================================================================== 311 $clefs = $superv_champs ; 312 $valeurs = array(); 313 foreach ( $clefs as $champ){ 314 $champ = trim($champ); 315 if($champ !="id") 316 if ( isset($mails_donnees[ $champ ]) ) { 317 $sep= (is_string($mails_donnees[ $champ ])) ? '"' : '' ; 318 array_push($valeurs , "`".$champ."`" . ' = ' . $sep . $mails_donnees[ $champ ] . $sep) ; 319 }else{ 320 array_push($valeurs , "`".$champ."`" . ' = ' . "0" ) ; 321 } 322 } 323 324 $valeurs = implode(", ",$valeurs) ; 325 //===================================================================== 326 $query = ' 327 UPDATE '.mail_superv_TABLE.' 328 SET '. $valeurs .' 329 WHERE `id` = 1 LIMIT 1 '; 330 ; 331 ob_start(); 332 $ret= pwg_query($query) ; 333 $m= ob_get_contents(); 334 if($m!="") $m="Mail_super.inc.php sauve_donnees() l:323<br />".$m; 335 ob_end_clean() ; 336 $erreur_message .= $m ; 337 } 338 //================================================================================= 339 function Get_Datas(){ 340 global $superv_champs ; 341 verif_base(); 342 $champs = implode(",",$superv_champs ); 343 $query = "SELECT ".$champs." 344 FROM ".mail_superv_TABLE." 345 ;"; 346 $result = @pwg_query($query); 347 348 if (!$result) { 349 verif_base(); 350 $result = @pwg_query($query); 351 } 352 $data = mysql_fetch_array($result,MYSQL_ASSOC); 353 //==================================================================================== 354 $next_day = Str_To_Time( $data['nb_mails_periode'], $data['date_mail'] ); 355 $next_day = ($next_day >0) ? $next_day : (604800 + time()) ; 356 $data['rest_mail'] = $next_day - time() ; 357 $next_day = Str_To_Time( $data['nb_spams_periode'],$data['date_spam']); 358 $next_day = ($next_day >0) ? $next_day : (172800 + time()) ; 359 $data['rest_spam'] = $next_day - time() ; 360 $next_day = Str_To_Time($data['quarantaine_periode'] ,$data['date_quarantaine']); 361 $next_day = ($next_day >0) ? $next_day : (172800 + time()) ; 362 //==================================================================================== 363 if ($data['quarantaine'] == 'true' ) { 364 $data['reste'] = ( $next_day )-time() ; 365 }else{ 366 $data['reste'] = 0; 367 } 368 369 return $data; 370 } 371 } 24 //============================================================ 25 /* 26 * admin_menu 27 */ 28 static public function admin_menu($menu) { 29 array_push($menu, 30 array( 'NAME' => 'Mail supervisor', 31 'URL' => get_admin_plugin_menu_link(MAIL_SUPERV_PATH . 'admin/mail_superv_admin.php') 32 ) 33 ); 34 return $menu; 35 } 36 //============================================================ 37 /* 38 * init 39 */ 40 static public function init() { 41 global $template,$version,$icon_path,$page; 42 $action_spam = pwg_get_session_var('action_spam') ; 43 $theme="default"; 44 $themeconf=$template->get_template_vars('themeconf'); 45 $theme=$themeconf['id']; 46 if (file_exists ( 'admin/themes/clear/icon/help.png')) $icon_path = 'admin/themes/clear/icon/help.png'; 47 else $icon_path = "admin/template/goto/theme/clear/icon/help.png"; 48 if (PHPWG_VERSION < 2.2 ) { 49 $file =MAIL_SUPERV_PATH_ABS.'admin/header_2_1.tpl' ; 50 51 } else { 52 $file = MAIL_SUPERV_PATH_ABS.'admin/header_2_2.tpl' ; 53 54 } 55 if(isset($_GET['action_spam']) and $_GET['action_spam']=="no"){ 56 pwg_set_session_var('action_spam', "false"); 57 unset ($_SESSION['pwg_'.'action_spam']); 58 } 59 $action_spam=pwg_get_session_var('action_spam'); 60 $template->set_filenames(array('mail_superv_init'=> $file )); 61 $MAIL_SUPERV_PATH=str_replace(PHPWG_ROOT_PATH,"",MAIL_SUPERV_PATH) ; 62 $profile=array('theme' => $theme, 63 'PHPWG_VERSION' => PHPWG_VERSION , 64 'MAIL_SUPERV_PATH' => $MAIL_SUPERV_PATH , 65 'MAIL_SUPERV_PATH_ABS' => MAIL_SUPERV_PATH_ABS 66 ); 67 68 $template->assign( $profile ); 69 $template->append('footer_elements', '<input id="action_spam" name="action_spam" type="hidden" value="'.$action_spam.'" />'); 70 $template->parse( 'mail_superv_init', false); 71 return ;// 72 }// function init 73 //============================================================ 74 /* 75 * affiche_message 76 */ 77 //============================================================ 78 static public function affiche_message(){ 79 global $template,$infos_message,$erreur_message, $user ,$ip; 80 global $mails_options,$conf,$lang,$page ; 81 global $action_spam ; 82 if (!isset($ip)) { 83 if (getenv("HTTP_CLIENT_IP")) { 84 $ip=getenv("HTTP_CLIENT_IP"); 85 }else{ 86 $ip=getenv("REMOTE_ADDR"); 87 } 88 } 89 // unset ($_SESSION['pwg_'.'action_spam']); 90 $action_spam = pwg_get_session_var('action_spam') ; 91 92 if ($action_spam == null or $action_spam == 'false') { 93 $action_spam = kill_list(); 94 } 95 96 if (is_bool($action_spam)) $action_spam =($action_spam == true) ? "true" : "false" ; 97 if ($action_spam == "true" ) { 98 $erreur_message .= $ip . " " . $action_spam ; 99 pwg_set_session_var('action_spam', "true"); 100 $erreur_message .= "<br />".l10n('Sv_is_a_spam') ; 101 if ($mails_options['no_connect'] == 'on1' ){ 102 //[status] => guest 103 //[status] => normal 104 //[status] => webmaster 105 if ($user['status'] != 'webmaster' ) 106 if (!isset($_GET['admin'])) { 107 die('Blacklist : <br />' .$erreur_message. '<br /> Hacking attempt!'); 108 }elseif ($_GET['admin'] != 'piwigo'){ 109 die('blacklist Hacking attempt!'); 110 } 111 unset ($_SESSION['pwg_'.'action_spam']); 112 } 113 }else{ 114 pwg_set_session_var('action_spam', "false"); 115 } 116 117 if (isset($infos_message)) 118 if ($infos_message != "") { 119 $infos_message = str_replace("\n",'<br />',$infos_message) ; 120 if (!isset($page['infos'])) $page['infos']=Array($infos_message); 121 else if(is_array($page['infos'])) array_push($page['infos'], $infos_message); 122 else $page['infos']=Array($infos_message); 123 $infos_message=""; 124 } 125 if (isset($erreur_message)) 126 if ($erreur_message != "") { 127 $erreur_message = str_replace("\n",'<br />',$erreur_message) ; 128 if (!isset($page['errors'])) $page['errors']=Array($erreur_message); 129 else if(is_array($page['errors'])) array_push($page['errors'], $erreur_message); 130 else $page['errors']=Array($erreur_message); 131 $erreur_message =""; 132 } 133 return $action_spam; 134 } //fin Affiche_message 135 136 //============================================================ 137 /* 138 * Get_geo 139 */ 140 static public function Get_geo() { 141 global $info_geo,$ip,$pays,$region,$ville, $latitude ,$longitude,$mails_options; 142 //=================================================================================== 143 $info_geo = pwg_get_session_var('info_geo'); 144 if (count($info_geo) > 0){ 145 $pays = $info_geo[0]; 146 $region = $info_geo[1]; 147 $ville = $info_geo[2]; 148 $latitude = $info_geo[3]; 149 $longitude = $info_geo[4]; 150 $ip = $info_geo[5]; 151 return true; 152 } 153 //======================================================================= 154 if (isset($_POST['pays'])) { 155 $pays = isset($_POST['pays']) ? $_POST['pays'] : ""; 156 $region = isset($_POST['region']) ? $_POST['region'] :""; 157 $ville = (isset($_POST['ville'])) ? $_POST['ville']: ""; 158 $latitude = isset($_POST['latitude']) ? $_POST['latitude'] : ""; 159 $longitude = isset($_POST['longitude']) ? $_POST['longitude'] : ""; 160 $info_geo = array( $pays ,$region , $ville ,$latitude, $longitude,$_SERVER['REMOTE_ADDR'] ); 161 pwg_set_session_var('info_geo', $info_geo); 162 return true; 163 }else{ 164 165 $result=""; 166 echo '<script type="text/javascript">get_script_geo();</script>'; 167 return true; 168 } 169 } // fin get_geo 170 //===================================================================================== 171 /* 172 * Memo_Var 173 */ 174 static public function Memo_Var($variables) { 175 ob_start(); 176 echo '<pre>'; 177 if(count($variables)>1){ 178 foreach($variables as $key => $line){ 179 echo $key . " => " . $line ; 180 echo "<br />"; 181 } 182 }else{ 183 echo "<i>".$variables."</i><br />"; 184 } 185 186 $m= ob_get_contents(); 187 ob_end_clean(); 188 return $m; 189 } 190 //====================================================================================== 191 static public function Get_Version_plugins($dir){ 192 $path = $dir; 193 $plg_data = implode( '', file($path.'main.inc.php') ); 194 if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) ) 195 { 196 $plugin['name'] = trim( $val[1] ); 197 } 198 if (preg_match("|Version: (.*)|", $plg_data, $val)) 199 { 200 $plugin['version'] = trim($val[1]); 201 } 202 if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) ) 203 { 204 $plugin['uri'] = trim($val[1]); 205 } 206 if ($desc = load_language('description.txt', $path.'/', array('return' => true))) 207 { 208 $plugin['description'] = trim($desc); 209 } 210 elseif ( preg_match("|Description: (.*)|", $plg_data, $val) ) 211 { 212 $plugin['description'] = trim($val[1]); 213 } 214 if ( preg_match("|Author: (.*)|", $plg_data, $val) ) 215 { 216 $plugin['author'] = trim($val[1]); 217 } 218 if ( preg_match("|Author URI: (.*)|", $plg_data, $val) ) 219 { 220 $plugin['author uri'] = trim($val[1]); 221 } 222 if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid=')) 223 { 224 list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']); 225 if (is_numeric($extension)) $plugin['extension'] = $extension; 226 } 227 // IMPORTANT SECURITY ! 228 $plugin = array_map('htmlspecialchars', $plugin); 229 return $plugin ; 230 } 231 //========================================================== 232 function Get_Options(&$parametres,$str_index){ 233 global $conf ; 234 $mails_options= $conf[$str_index]; 235 if(isset($mails_options)) 236 if ( preg_match("|s:(.*)|", $mails_options, $val) ) 237 $parametres = unserialize($conf['mail_superv']); 238 else{ 239 $parametres=explode(",",$mails_options); 240 } 241 //====== par defaut ======================= 242 $new_val=false; 243 244 if (empty($def_para)) 245 $def_para = (object) ''; 246 247 $def_para->check_mailto="on"; 248 $def_para->check_header_carbon="on"; 249 $def_para->check_send_webmaster="off"; 250 $def_para->no_ipaddress="off"; // interdiction adresse ip 251 252 $def_para->no_mail_list="on"; 253 $def_para->no_connect="on"; // empeche l'ip de se connecter au site. 254 $def_para->set_auto="on"; // Test a l'ouverture et enregistrement 255 $def_para->ip="127.0.0.1"; // derniere adresse IP 256 $def_para->set_id="on"; // enregistrment nouvel 257 $def_para->debug_mail="off"; // debogage 258 259 foreach ($def_para as $key => $value) { 260 if(isset($parametres[$key])){ 261 $value=$parametres[$key]; 262 } else { 263 $new_val=true; 264 } 265 $new_val= isset($_POST[$key]) && $new_val ; 266 unset( $parametres[$key]) ; 267 $parametres[$key]= (isset($_POST[$key]))? "on" : $value ; 268 } 269 270 if($new_val){ 271 sauve_options(); 272 } 273 return $parametres ; 274 } 275 //========================================================== 276 function Set_Options($parametres,$str_index){ 277 global $infos_message,$conf; 278 foreach ($parametres as $key => $value) { 279 $parametres[$key]=(isset($_POST[$key]))? "on" : $value ; 280 } 281 $parametres['no_connect']= 'off' ; 282 return $parametres ; 283 } 284 //========================================================== 285 286 function sauve_options(){ 287 global $options,$infos_message,$conf,$mails_options ; 288 $infos_message .=l10n("save_config")."<br>"; 289 if (empty($mail_supervisor)) { 290 $mail_supervisor = new mail_supervisor(); 291 } 292 $mails_parametres= $mail_supervisor->Set_Options($mails_options,"mail_superv"); 293 294 if ( isset($mails_parametres) ) 295 { 296 $query = ' 297 UPDATE '.CONFIG_TABLE.' 298 SET value="'.addslashes(serialize($mails_parametres)).'" 299 WHERE param = "mail_superv" 300 LIMIT 1'; 301 pwg_query($query); 302 } 303 304 } 305 306 /**************************************** 307 * sauve_donnees() 308 ****************************************/ 309 function sauve_donnees(){ 310 global $mails_donnees,$superv_champs,$superv_type,$erreur_message ; 311 //===================================================================== 312 $clefs = $superv_champs ; 313 $valeurs = array(); 314 foreach ( $clefs as $champ){ 315 $champ = trim($champ); 316 if($champ !="id") 317 if ( isset($mails_donnees[ $champ ]) ) { 318 $sep= (is_string($mails_donnees[ $champ ])) ? '"' : '' ; 319 array_push($valeurs , "`".$champ."`" . ' = ' . $sep . $mails_donnees[ $champ ] . $sep) ; 320 }else{ 321 array_push($valeurs , "`".$champ."`" . ' = ' . "0" ) ; 322 } 323 } 324 325 $valeurs = implode(", ",$valeurs) ; 326 //===================================================================== 327 $query = ' 328 UPDATE '.mail_superv_TABLE.' 329 SET '. $valeurs .' 330 WHERE `id` = 1 LIMIT 1 '; 331 ; 332 ob_start(); 333 $ret= pwg_query($query) ; 334 $m= ob_get_contents(); 335 if($m!="") $m="Mail_super.inc.php sauve_donnees() l:323<br />".$m; 336 ob_end_clean() ; 337 $erreur_message .= $m ; 338 } 339 //================================================================================ 340 function Get_Datas(){ 341 global $superv_champs ; 342 verif_base(); 343 $champs = implode(",",$superv_champs ); 344 $query = "SELECT ".$champs." 345 FROM ".mail_superv_TABLE." 346 ;"; 347 $result = pwg_query($query); 348 349 if (!$result) { 350 verif_base(); 351 $result = pwg_query($query); 352 } 353 if ($result) { 354 $data = mysqli_fetch_array($result,MYSQL_ASSOC); 355 } 356 //==================================================================================== 357 $next_day = Str_To_Time( $data['nb_mails_periode'], $data['date_mail'] ); 358 $next_day = ($next_day >0) ? $next_day : (604800 + time()) ; 359 $data['rest_mail'] = $next_day - time() ; 360 $next_day = Str_To_Time( $data['nb_spams_periode'],$data['date_spam']); 361 $next_day = ($next_day >0) ? $next_day : (172800 + time()) ; 362 $data['rest_spam'] = $next_day - time() ; 363 $next_day = Str_To_Time($data['quarantaine_periode'] ,$data['date_quarantaine']); 364 $next_day = ($next_day >0) ? $next_day : (172800 + time()) ; 365 //==================================================================================== 366 if ($data['quarantaine'] == 'true' ) { 367 $data['reste'] = ( $next_day )-time() ; 368 }else{ 369 $data['reste'] = 0; 370 } 371 372 return $data; 373 } 374 } 372 375 ?> -
extensions/Mail_supervisor/main.inc.php
r19018 r22118 1 1 <?php 2 2 /* 3 Plugin Name: Mail supervisor4 Version: 1. 5.93 Plugin Name: Mail supervisor 4 Version: 1.6.0 5 5 Description: Mail supervisor surveille l'envoie des mails. 6 6 Plugin URI: http://piwigo.org/ext/extension_view.php?eid=315 … … 8 8 Author URI:http://cljosse.free.fr 9 9 */ 10 11 /************************************** 12 * (local) httpconf 13 * [mail function] 14 ; For Win32 only. 15 ; http://php.net/smtp 16 SMTP = smtp.xxxx.fr 17 ; http://php.net/smtp-port 18 smtp_port = 25 19 20 ; For Win32 only. 21 ; http://php.net/sendmail-from 22 sendmail_from = toto@xxxx.fr 23 **************************************/ 24 10 25 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 11 26 if (!defined('mail_superv_DIR')) define('mail_superv_DIR' , basename(dirname(__FILE__))); … … 22 37 23 38 $mail_supervisor = new mail_supervisor(); 24 39 25 40 include_once(MAIL_SUPERV_PATH.'mail_send.inc.php'); 26 41 $clj = new clj(); … … 31 46 include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); 32 47 33 34 48 $mail_supervisor->Get_Options($mails_options,"mail_superv"); 49 $mails_donnees=$mail_supervisor->Get_Datas(); 35 50 36 51 /* EVENT_HANDLER_PRIORITY_NEUTRAL */ … … 52 67 53 68 function clj_send_mail($result, $mailto, $subject, $content, $headers, $args,$nb_destinataires) { 54 global $conf, $user, $lang_info; 55 global $conf_mail,$mails_options,$mails_donnees ; 56 global $template,$page ,$erreur_message,$infos_message, $lang; 57 global $errors; 58 59 include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); 60 load_language('plugin.lang', MAIL_SUPERV_PATH); 61 62 $arg_trigg= array($mailto, $subject, $content, $headers, $args); 63 trigger_event('mail_supervisor_clj_mail',$arg_trigg); 64 if (empty($mail_supervisor)) 65 $mail_supervisor = new mail_supervisor(); 66 67 $message =""; 68 if (!isset($infos_message)) { $infos_message = ""; } 69 if (!isset($erreur_message)) { $erreur_message = ''; } 70 71 $envoie_ok=true ; 72 //======== verification si envoie de mail ou blocage connexion ===================== 73 if ($mails_options['no_mail_list']=='on' || $mails_options['no_connect'] == 'on' ) { 74 if (kill_list()) { 75 $nb_destinataires=0; ; 76 $envoie_ok= false ; 77 $erreur_message .= "<BR />".l10n('Sv_is_a_spam') ; 78 $infos_message = l10n('Sv_mail_not_send')."<BR />"; 79 if ($mails_options['no_connect'] == 'on' ){ 80 if ($user['status'] == 'webmaster'){ 81 //---------- continuer si web master ---------- 82 }else{ 83 trigger_event('mail_supervisor_send_mail', "DIE(KILL) : " . $ip . ' = ' . $user['status']); 84 if (!isset($_GET['admin'])) { 85 die('Blacklist : <br />' .$erreur_message. '<br /> Hacking attempt!'); 86 }elseif ($_GET['admin'] != 'piwigo') 87 { 88 die('blacklist Hacking attempt!'); 89 } 90 } 91 } 92 trigger_event('mail_supervisor_send_mail', "Kill : " . $ip . ' = ' . $user['status'] . "noconnect==off"); 93 return true; 94 } 95 } 96 97 // lecture donnees ------------- 98 $nb_mails = $mails_donnees['nb_mails'] ; 99 $next_day = $mails_donnees['date_mail'] ; 100 $reste = $mails_donnees['reste'] ; 101 $rest_mail = $mails_donnees['rest_mail'] ; 102 if ($rest_mail <=0 || $mails_donnees['nb_mails'] ==0 ){ 103 $mails_donnees['nb_mails'] =0 ; 104 $mails_donnees['date_mail'] = time(); 105 } 106 $rest_spam = $mails_donnees['rest_spam'] ; 107 if ($rest_spam <=0 || $mails_donnees['nb_spams'] ==0 ){ 108 $mails_donnees['nb_spams'] =0 ; 109 $mails_donnees['date_spam'] = time(); 110 } 111 $alerte = ( $mails_donnees['reste'] >0 ) ? true : false ; 112 $alerte_mail = ( $mails_donnees['nb_mails'] > $mails_donnees['nb_mails_maxi']-1 ) ? true : false ; 113 $alerte_spam = ( $mails_donnees['nb_spams'] > $mails_donnees['nb_spams_maxi']-1 ) ? true : false ; 114 //============================= 115 // TEST envoie Message 116 //============================= 117 if ( ( !$alerte && !$alerte_spam && !$alerte_mail ) ) { 118 $infos_message .= "nb_destinataires : $nb_destinataires Theme :" . ($args['theme'] ) ." {". $lang_info['language_name'] ."}"."<br />"; 119 $infos_message .="Mailto:" .$mailto ."<br />"; 120 if(isset($args['Bcc']) && count($args['Bcc'])>0) $infos_message .="Bcc: " . implode(",",$args['Bcc'])."<br />"; 121 if(isset($args['Cc'])&& count($args['Cc'])>0) $infos_message .="Cc: " . implode(",",$args['Cc'])."<br />"; 122 //============================================ 123 // Photographie 124 //============================================ 125 $ret="false"; 126 ob_start(); 127 if ($nb_destinataires > 0) { 128 if( $envoie_ok) $ret = mail($mailto, $subject,$content, $headers); 129 }else{ 130 echo l10n('Sv_no_receiver_available'); 131 } 132 $message .= ob_get_contents(); 133 ob_end_clean(); 134 135 $arg_trigg= array("Nb destinataires: " . $nb_destinataires,"Mail to: ".$mailto,"content: ".$content, " Reponse : " . $message); 136 137 trigger_event('mail_supervisor_mail', $arg_trigg ); 138 $mails_donnees['message']=$message; 139 $ret= Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto, $subject,$content); 140 } else { 141 //================== Est en quarantaine ======================= 142 143 $erreur_message .= l10n('Sv_To_day_is')."<br />"; 144 if ($alerte_spam ) { 145 $type="Spams"; 146 $d1=$mails_donnees['nb_spams'] . ' \\ ' . $mails_donnees['nb_spams_maxi']; 147 $d2=$mails_donnees['nb_spams']; 148 $d3= $mails_donnees['rest_spam']; 149 $d4=time()+$d3 ; 150 } 151 if ($alerte_mail) { 152 $type="Mails"; 153 $d1=$mails_donnees['nb_mails']. ' \\ ' . $mails_donnees['nb_mails_maxi'];; 154 $d2=$mails_donnees['date_mail']; 155 $d3= $mails_donnees['rest_mail']; 156 $d4=time()+$d3 ; 157 } 158 if ($alerte) { 159 $type="Spams(Quarantaine)"; 160 $d1=$mails_donnees['nb_spams'] . ' \\ ' . $mails_donnees['nb_spams_maxi']; 161 $d2=$mails_donnees['date_quarantaine']; 162 $d3= $mails_donnees['reste']; 163 $d4=time()+$d3 ; 164 } 165 $d2=date(l10n('Sv_formatdate'),$d2); 166 $d3=int_to_heure($d3) ; 167 $d4=date(l10n('Sv_formatdate'),$d4); 168 if ($alerte_mail) { 169 $erreur_message .='<br />'.sprintf(l10n('Sv_alerte_mail %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />'; 170 }else{ 171 $erreur_message .='<br />'.sprintf(l10n('Sv_mise_en_quarantaine %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />'; 172 } 173 $ret = "Error ". $type." : "; 174 $ret .= l10n('Sv_mail_not_send'); 175 $infos_message .= l10n('Sv_mail_not_send'); 176 } 177 $infos_message .= "<hr>"; 178 179 trigger_event('mail_supervisor_message', $infos_message ); 180 $mail_supervisor->sauve_donnees(); 181 $mail_supervisor->affiche_message(); 182 return $ret ;// 69 global $conf, $user, $lang_info; 70 global $conf_mail,$mails_options,$mails_donnees ; 71 global $template,$page ,$erreur_message,$infos_message, $lang; 72 global $errors; 73 74 include_once (MAIL_SUPERV_PATH.'include/fonctions.php'); 75 load_language('plugin.lang', MAIL_SUPERV_PATH); 76 77 $arg_trigg= array($mailto, $subject, $content, $headers, $args); 78 trigger_event('mail_supervisor_clj_mail',$arg_trigg); 79 if (empty($mail_supervisor)) 80 $mail_supervisor = new mail_supervisor(); 81 82 $message =""; 83 if (!isset($infos_message)) { 84 $infos_message = ""; 85 } 86 if (!isset($erreur_message)) { 87 $erreur_message = ''; 88 } 89 90 $envoie_ok=true ; 91 //======== verification si envoie de mail ou blocage connexion ===================== 92 if ($mails_options['no_mail_list']=='on' || $mails_options['no_connect'] == 'on' ) { 93 if (kill_list()) { 94 $nb_destinataires=0; ; 95 $envoie_ok= false ; 96 $erreur_message .= "<BR />".l10n('Sv_is_a_spam') ; 97 $infos_message = l10n('Sv_mail_not_send')."<BR />"; 98 if ($mails_options['no_connect'] == 'on' ){ 99 if ($user['status'] == 'webmaster'){ 100 //---------- continuer si web master ---------- 101 }else{ 102 trigger_event('mail_supervisor_send_mail', "DIE(KILL) : " . $ip . ' = ' . $user['status']); 103 if (!isset($_GET['admin'])) { 104 die('Blacklist : <br />' .$erreur_message. '<br /> Hacking attempt!'); 105 }elseif ($_GET['admin'] != 'piwigo') 106 { 107 die('blacklist Hacking attempt!'); 108 } 109 } 110 } 111 trigger_event('mail_supervisor_send_mail', "Kill : " . $ip . ' = ' . $user['status'] . "noconnect==off"); 112 return true; 113 } 114 } 115 116 // lecture donnees ------------- 117 $nb_mails = $mails_donnees['nb_mails'] ; 118 $next_day = $mails_donnees['date_mail'] ; 119 $reste = $mails_donnees['reste'] ; 120 $rest_mail = $mails_donnees['rest_mail'] ; 121 if ($rest_mail <=0 || $mails_donnees['nb_mails'] ==0 ){ 122 $mails_donnees['nb_mails'] =0 ; 123 $mails_donnees['date_mail'] = time(); 124 } 125 $rest_spam = $mails_donnees['rest_spam'] ; 126 if ($rest_spam <=0 || $mails_donnees['nb_spams'] ==0 ){ 127 $mails_donnees['nb_spams'] =0 ; 128 $mails_donnees['date_spam'] = time(); 129 } 130 $alerte = ( $mails_donnees['reste'] >0 ) ? true : false ; 131 $alerte_mail = ( $mails_donnees['nb_mails'] > $mails_donnees['nb_mails_maxi']-1 ) ? true : false ; 132 $alerte_spam = ( $mails_donnees['nb_spams'] > $mails_donnees['nb_spams_maxi']-1 ) ? true : false ; 133 //============================= 134 // TEST envoie Message 135 //============================= 136 if ( ( !$alerte && !$alerte_spam && !$alerte_mail ) ) { 137 $infos_message .= "nb_destinataires : $nb_destinataires Theme :" . ($args['theme'] ) ." {". $lang_info['language_name'] ."}"."<br />"; 138 $infos_message .="Mailto:" .$mailto ."<br />"; 139 if(isset($args['Bcc']) && count($args['Bcc'])>0) $infos_message .="Bcc: " . implode(",",$args['Bcc'])."<br />"; 140 if(isset($args['Cc'])&& count($args['Cc'])>0) $infos_message .="Cc: " . implode(",",$args['Cc'])."<br />"; 141 //============================================ 142 // Photographie 143 //============================================ 144 $ret="false"; 145 ob_start(); 146 if ($nb_destinataires > 0) { 147 if( $envoie_ok) $ret = mail($mailto, $subject,$content, $headers); 148 }else{ 149 echo l10n('Sv_no_receiver_available'); 150 } 151 $message .= ob_get_contents(); 152 ob_end_clean(); 153 154 $arg_trigg= array("Nb destinataires: " . $nb_destinataires,"Mail to: ".$mailto,"content: ".$content, " Reponse : " . $message); 155 156 trigger_event('mail_supervisor_mail', $arg_trigg ); 157 $mails_donnees['message']=$message; 158 $ret= Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto, $subject,$content); 159 } else { 160 //================== Est en quarantaine ======================= 161 162 $erreur_message .= l10n('Sv_To_day_is')."<br />"; 163 if ($alerte_spam ) { 164 $type="Spams"; 165 $d1=$mails_donnees['nb_spams'] . ' \\ ' . $mails_donnees['nb_spams_maxi']; 166 $d2=$mails_donnees['nb_spams']; 167 $d3= $mails_donnees['rest_spam']; 168 $d4=time()+$d3 ; 169 } 170 if ($alerte_mail) { 171 $type="Mails"; 172 $d1=$mails_donnees['nb_mails']. ' \\ ' . $mails_donnees['nb_mails_maxi'];; 173 $d2=$mails_donnees['date_mail']; 174 $d3= $mails_donnees['rest_mail']; 175 $d4=time()+$d3 ; 176 } 177 if ($alerte) { 178 $type="Spams(Quarantaine)"; 179 $d1=$mails_donnees['nb_spams'] . ' \\ ' . $mails_donnees['nb_spams_maxi']; 180 $d2=$mails_donnees['date_quarantaine']; 181 $d3= $mails_donnees['reste']; 182 $d4=time()+$d3 ; 183 } 184 $d2=date(l10n('Sv_formatdate'),$d2); 185 $d3=int_to_heure($d3) ; 186 $d4=date(l10n('Sv_formatdate'),$d4); 187 if ($alerte_mail) { 188 $erreur_message .='<br />'.sprintf(l10n('Sv_alerte_mail %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />'; 189 }else{ 190 $erreur_message .='<br />'.sprintf(l10n('Sv_mise_en_quarantaine %s %s %s %s %s'),$type,$d1,$d2,$d3,$d4).'<br />'; 191 } 192 $ret = "Error ". $type." : "; 193 $ret .= l10n('Sv_mail_not_send'); 194 $infos_message .= l10n('Sv_mail_not_send'); 195 } 196 $infos_message .= "<hr>"; 197 198 trigger_event('mail_supervisor_message', $infos_message ); 199 $mail_supervisor->sauve_donnees(); 200 $mail_supervisor->affiche_message(); 201 return $ret ;// 183 202 } 184 203 //=========================================================================================== 185 204 function Gestion_erreurs($message,$ret,$nb_destinataires,$headers,$mailto, $subject,$content){ 186 global $conf, $user, $conf_mail,$mails_options,$mails_donnees , $template,$page ,$infos_message,$erreur_message,$args,$lang, $lang_info; 187 $match=array("<",">"); 188 $string=array("<",">") ; 189 // $headers=str_replace( $match,$string, $headers); 190 // Warning: mail() has been disabled for security reasons 191 $est_un_spam =!(strpos(strtolower($message), 'spam') === false); 192 193 $log_message = " :".sprintf(l10n('Sv_debug_message'), 194 ($ret==true)? "true" : "false", 195 "\n".$message , 196 "\n".$mailto , 197 "\n".$subject , 198 "\n".$headers , 199 "\n".$content , 200 "\n".$nb_destinataires) ; 201 202 if ( ($ret==false) || ($est_un_spam==true) || ($nb_destinataires == 0) ) { 203 //=============== La fonction mail retourne une erreur ========================= 204 $ret="Error"; 205 // Bad recipient address syntax 206 $pos1 = strpos(strtolower($message), 'bad recipient address syntax'); 207 if ( !($pos1 === false) ){ 208 $erreur_message .= l10n('Sv_detection_de').' Bad recipient address syntax .'; 209 $erreur_message .= l10n('Sv_verifiez_les_destinataires').' (Bcc,Cc,To)<br />'; 210 } 211 $erreur_message .=$ret . " :".sprintf(l10n('Sv_debug_message'), 212 ($ret==true)? "true" : "false", 213 htmlspecialchars($message) , 214 htmlspecialchars( $mailto) , 215 htmlspecialchars($subject) , 216 htmlspecialchars($headers) , 217 htmlspecialchars($content) , 218 $nb_destinataires ); 219 220 Mail_supervisor_log($mailto,$log_message) ; 221 222 }else{ 223 if( isset($mails_options['debug_mail']) && $mails_options['debug_mail']=="on") { 224 $infos_message .="DEBUG : " .sprintf(l10n('Sv_debug_message'), 225 ($ret==true)? "true" : "false", 226 htmlspecialchars( $message) , 227 htmlspecialchars( $mailto) , 228 htmlspecialchars($subject) , 229 htmlspecialchars($headers) , 230 htmlspecialchars($content) , 231 $nb_destinataires ); 232 233 Mail_supervisor_log($mailto,"DEBUG :" . ($log_message)) ; 234 } 235 } 236 //================================================================= 237 if ($est_un_spam == false){ 238 if ($mails_donnees['nb_mails']==0) { $mails_donnees['date_mail'] = time(); } 239 $mails_donnees['nb_mails'] += $nb_destinataires; 240 } else { 241 $ret="Error spam"; 242 $mails_donnees['nb_spams'] += $nb_destinataires; 243 //--- Detection de spam ------------------ 244 if ($mails_donnees['nb_spams']==0) {$mails_donnees['date_spam'] = time(); } 245 246 $trop_de_spam =!(strpos(strtolower($message), 'trop de spam') === false); 247 if ( $trop_de_spam ) { 248 $mails_donnees['nb_spams_maxi']=$mails_donnees['nb_spams']; 249 250 $mails_donnees['date_quarantaine']= time() ; 251 $mails_donnees['quarantaine']= true ; 252 $infos_message .= $mail_supervisor->Memo_Var($mails_donnees); 253 } 254 } 255 return $ret ; 205 global $conf, $user, $conf_mail,$mails_options,$mails_donnees , $template,$page ,$infos_message,$erreur_message,$args,$lang, $lang_info; 206 $match=array("<",">"); 207 $string=array("<",">") ; 208 // $headers=str_replace( $match,$string, $headers); 209 // Warning: mail() has been disabled for security reasons 210 $est_un_spam =!(strpos(strtolower($message), 'spam') === false); 211 212 $log_message = " :".sprintf(l10n('Sv_debug_message'), 213 ($ret==true)? "true" : "false", 214 "\n".$message , 215 "\n".$mailto , 216 "\n".$subject , 217 "\n".$headers , 218 "\n".$content , 219 "\n".$nb_destinataires) ; 220 221 if ( ($ret==false) || ($est_un_spam==true) || ($nb_destinataires == 0) ) { 222 //=============== La fonction mail retourne une erreur ========================= 223 $ret="Error"; 224 // Bad recipient address syntax 225 $pos1 = strpos(strtolower($message), 'bad recipient address syntax'); 226 if ( !($pos1 === false) ){ 227 $erreur_message .= l10n('Sv_detection_de').' Bad recipient address syntax .'; 228 $erreur_message .= l10n('Sv_verifiez_les_destinataires').' (Bcc,Cc,To)<br />'; 229 } 230 $erreur_message .=$ret . " :".sprintf(l10n('Sv_debug_message'), 231 ($ret==true)? "true" : "false", 232 htmlspecialchars($message) , 233 htmlspecialchars( $mailto) , 234 htmlspecialchars($subject) , 235 htmlspecialchars($headers) , 236 htmlspecialchars($content) , 237 $nb_destinataires ); 238 239 Mail_supervisor_log($mailto,$log_message) ; 240 241 }else{ 242 if( isset($mails_options['debug_mail']) && $mails_options['debug_mail']=="on") { 243 $infos_message .="DEBUG : " .sprintf(l10n('Sv_debug_message'), 244 ($ret==true)? "true" : "false", 245 htmlspecialchars( $message) , 246 htmlspecialchars( $mailto) , 247 htmlspecialchars($subject) , 248 htmlspecialchars($headers) , 249 htmlspecialchars($content) , 250 $nb_destinataires ); 251 252 Mail_supervisor_log($mailto,"DEBUG :" . ($log_message)) ; 253 } 254 } 255 //================================================================= 256 if ($est_un_spam == false){ 257 if ($mails_donnees['nb_mails']==0) { 258 $mails_donnees['date_mail'] = time(); 259 } 260 $mails_donnees['nb_mails'] += $nb_destinataires; 261 } else { 262 $ret="Error spam"; 263 $mails_donnees['nb_spams'] += $nb_destinataires; 264 //--- Detection de spam ------------------ 265 if ($mails_donnees['nb_spams']==0) { 266 $mails_donnees['date_spam'] = time(); 267 } 268 269 $trop_de_spam =!(strpos(strtolower($message), 'trop de spam') === false); 270 if ( $trop_de_spam ) { 271 $mails_donnees['nb_spams_maxi']=$mails_donnees['nb_spams']; 272 273 $mails_donnees['date_quarantaine']= time() ; 274 $mails_donnees['quarantaine']= true ; 275 $infos_message .= $mail_supervisor->Memo_Var($mails_donnees); 276 } 277 } 278 return $ret ; 256 279 } 257 280 //============================================================ 258 281 global $ms_file_log,$dir,$clj_pwd; 259 260 261 $clj_pwd=$conf['local_data_dir'].'/Pwd'; 262 if (!is_dir($clj_pwd)){ 263 $umask = umask(0); 264 $mkd = @mkdir($clj_pwd, 0755, true ); 265 umask($umask); 266 if ($mkd==false){ 267 echo "<pre>PWD:$clj_pwd"; 268 fatal_error( "$clj_pwd ".l10n('no write access')); 269 return false; 270 } 271 } 282 $clj_pwd= $conf['data_location'].'/Pwd'; 283 if (!is_dir($clj_pwd)){ 284 $umask = umask(0); 285 $mkd = @mkdir($clj_pwd, 0755, true ); 286 umask($umask); 287 if ($mkd==false){ 288 echo "<pre>PWD:$clj_pwd"; 289 fatal_error( "$clj_pwd ".l10n('no write access')); 290 return false; 291 } 292 } 272 293 //================================================== 273 $dir=$conf[' local_data_dir'].'/Mail_supervisor_log';274 if (!is_dir($dir)){ 275 276 277 278 279 280 281 282 283 294 $dir=$conf['data_location'].'/Mail_supervisor_log'; 295 if (!is_dir($dir)){ 296 $umask = umask(0); 297 $mkd = @mkdir($dir, 0755, true ); 298 umask($umask); 299 if ($mkd==false){ 300 echo "<pre>Dir:$dir"; 301 fatal_error( "$dir ".l10n('no write access')); 302 return false; 303 } 304 } 284 305 //================================================== 285 306 //add_event_handler('loc_begin_page_header', 'set_access' ); 286 307 function set_access(){ 287 global $user;288 289 global $user,$conf; 290 291 292 if(!file_exists( $pwd.'/.htpasswd') || !file_exists( $dir.'/.htaccess')){293 //=========================================================294 295 //=========================================================296 $server=$_SERVER["SERVER_NAME"];297 $server_ip=$_SERVER["SERVER_ADDR"];298 $user_ip=$_SERVER["REMOTE_ADDR"];299 $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}))/" ; 300 301 302 $file = $pwd.'/.htpasswd'; 303 $htmes1 =$conf['db_user'].":".$conf['db_password']."\n"; 304 $htmes2 =$conf['db_user'].":".crypt($conf['db_password'], 'rl')."\n"; 305 if(preg_match("/free/i",$server)||$local) 306 307 308 309 //==== Ecriture fichier texte 310 311 $fp = fopen ( $file , "w"); 312 fwrite($fp , $htmes,strlen($htmes)); 313 fclose ($fp); 314 315 316 317 //=========================================================318 319 //=========================================================320 $racine=explode("/",$_SERVER["PHP_SELF"] );321 $racine = $racine[1] ;322 if(preg_match("/free/i",$server)) {323 324 }else{325 326 327 328 $AuthUserFile='AuthUserFile '.realpath($pwd).'\\.htpasswd'."\n".'AuthGroupFile /dev/null';329 }330 331 //============================================================332 $htmes=$AuthUserFile."\n".333 334 'AuthType Basic'."\n".335 '<limit GET>'."\n".336 'require valid-user'."\n".337 '</Limit>';338 339 340 //============================================================341 342 343 344 308 global $user; 309 global $ms_file_log,$dir,$clj_pwd; 310 global $user,$conf; 311 $pwd=$clj_pwd; 312 313 if(!file_exists( $pwd.'/.htpasswd') || !file_exists( $dir.'/.htaccess')){ 314 //========================================================= 315 // Creation liste mot de passe 316 //========================================================= 317 $server=$_SERVER["SERVER_NAME"]; 318 $server_ip=$_SERVER["SERVER_ADDR"]; 319 $user_ip=$_SERVER["REMOTE_ADDR"]; 320 $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}))/" ; 321 $local=preg_match($pattern,$user_ip); 322 323 $file = $pwd.'/.htpasswd'; 324 $htmes1 =$conf['db_user'].":".$conf['db_password']."\n"; 325 $htmes2 =$conf['db_user'].":".crypt($conf['db_password'], 'rl')."\n"; 326 if(preg_match("/free/i",$server)||$local) 327 $htmes=$htmes1; 328 else 329 $htmes=$htmes2; 330 //==== Ecriture fichier texte 331 332 $fp = fopen ( $file , "w"); 333 fwrite($fp , $htmes,strlen($htmes)); 334 fclose ($fp); 335 336 $file = $pwd.'/.htaccess'; 337 @file_put_contents( $file, "deny for all" ); 338 //========================================================= 339 // Creation fichier htaccess 340 //========================================================= 341 $racine=explode("/",$_SERVER["PHP_SELF"] ); 342 $racine = $racine[1] ; 343 if(preg_match("/free/i",$server)) { 344 $AuthUserFile='PerlSetVar AuthFile '.$racine.'/_data/Pwd' .'/.htpasswd'; 345 }else{ 346 if($local) 347 $AuthUserFile='AuthUserFile '.realpath($pwd).'\\.htpasswd'."\n".'AuthGroupFile /dev/null'; 348 else 349 $AuthUserFile='AuthUserFile '.realpath($pwd).'\\.htpasswd'."\n".'AuthGroupFile /dev/null'; 350 } 351 352 //============================================================ 353 $htmes=$AuthUserFile."\n". 354 'AuthName "Mail_supervisor_log"'."\n". 355 'AuthType Basic'."\n". 356 '<limit GET>'."\n". 357 'require valid-user'."\n". 358 '</Limit>'; 359 $file = $dir.'/.htaccess'; 360 @file_put_contents( $file, $htmes ); 361 //============================================================ 362 363 } 364 365 } 345 366 346 367 if($ms_file_log=="") $ms_file_log = $dir."/"."pw1.html"; … … 349 370 //============================================================ 350 371 function Mail_supervisor_log($label_,$lines){ 351 global $ms_file_log,$conf; 352 353 $t= var_export( $lines, true );354 $s = htmlspecialchars( $lines);355 356 if (!file_exists($ms_file_log)) { 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 //$s= nl2br($s);374 375 376 372 global $ms_file_log,$conf; 373 $nb_lignes=600 ; 374 $t= var_export( $lines, true ); 375 $s = htmlspecialchars( $lines); 376 $s = ( $lines); 377 if (!file_exists($ms_file_log)) { 378 $handle = fopen($ms_file_log, 'w'); 379 fwrite($handle, "\n"); 380 fclose($handle); 381 } 382 $tableau=file($ms_file_log); 383 $handle = fopen($ms_file_log, 'a'); 384 $nb=count ($tableau); 385 if($nb>$nb_lignes) { 386 $handle = fopen($ms_file_log, 'w'); 387 fwrite($handle, $nb. " > " . $nb_lignes . " RAZ " ."\n"); 388 } 389 //rewind ($handle); // Go back to the beginning 390 //fwrite ($handle, sprintf("%5d ", $nb)); // Don't forget to increment the counter 391 $s="\n".date('Y m d H:m:s ')."\n".$s; 392 393 394 //$s= nl2br($s); 395 396 if( $s !="") fwrite($handle,$s ); 397 fclose($handle); 377 398 } 378 399
Note: See TracChangeset
for help on using the changeset viewer.