1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org | |
---|
6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | This program is free software; you can redistribute it and/or modify | |
---|
10 | // | it under the terms of the GNU General Public License as published by | |
---|
11 | // | the Free Software Foundation | |
---|
12 | // | | |
---|
13 | // | This program is distributed in the hope that it will be useful, but | |
---|
14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
16 | // | General Public License for more details. | |
---|
17 | // | | |
---|
18 | // | You should have received a copy of the GNU General Public License | |
---|
19 | // | along with this program; if not, write to the Free Software | |
---|
20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
21 | // | USA. | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
25 | if (!defined('MAIL_SUPERV_PATH')) define('MAIL_SUPERV_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
26 | |
---|
27 | |
---|
28 | global $superv_champs , $superv_type ,$superv_bl_champs , $superv_bl_type ; |
---|
29 | // if (!isset($_COOKIE[session_name()])){} |
---|
30 | |
---|
31 | global $lang ; |
---|
32 | global $template ; |
---|
33 | |
---|
34 | //=============================================== |
---|
35 | function corrige_header($Carbonne,$headers,$args,$cl_list_mail,$mailto="") { |
---|
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 | } |
---|
52 | |
---|
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; |
---|
93 | } |
---|
94 | |
---|
95 | |
---|
96 | function verif_base(){ |
---|
97 | global $lang,$superv_champs,$superv_type,$superv_bl_champs,$superv_bl_type; |
---|
98 | load_language('plugin.lang', MAIL_SUPERV_PATH); |
---|
99 | //============================================================================== |
---|
100 | create_table(MAIL_BLACK_LISTE_TABLE,$superv_bl_champs,$superv_bl_type) ; |
---|
101 | ajust_table(MAIL_BLACK_LISTE_TABLE,$superv_bl_champs,$superv_bl_type) ; |
---|
102 | //============================================================================== |
---|
103 | create_table(mail_superv_TABLE,$superv_champs,$superv_type) ; |
---|
104 | ajust_table(mail_superv_TABLE,$superv_champs,$superv_type) ; |
---|
105 | //============================================================================== |
---|
106 | $valeurs= array ( 1, |
---|
107 | 0, |
---|
108 | time(), |
---|
109 | 2000, |
---|
110 | '"604800"' , |
---|
111 | 0, |
---|
112 | time(), |
---|
113 | 10, |
---|
114 | '"172800"', |
---|
115 | '"false"', |
---|
116 | time(), |
---|
117 | '"172800"', |
---|
118 | '"Init"', |
---|
119 | '"'.l10n('Sv_supervisor').'"', |
---|
120 | '"'.l10n('hello').'"', |
---|
121 | '"Test Mail_supervisor"', |
---|
122 | '"Information"' |
---|
123 | ); |
---|
124 | ajout_ligne(mail_superv_TABLE,$superv_champs, $valeurs,false ) ; |
---|
125 | } |
---|
126 | //========================================= |
---|
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; |
---|
138 | } |
---|
139 | //========================================= |
---|
140 | function get_liste($group_id){ |
---|
141 | global $conf ; |
---|
142 | $query = ' |
---|
143 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
144 | u.'.$conf['user_fields']['username'].' AS username, |
---|
145 | u.'.$conf['user_fields']['email'].' AS email, |
---|
146 | ui.status, |
---|
147 | ui.enabled_high, |
---|
148 | ui.level |
---|
149 | FROM '.USERS_TABLE.' AS u |
---|
150 | INNER JOIN '.USER_INFOS_TABLE.' AS ui |
---|
151 | ON u.'.$conf['user_fields']['id'].' = ui.user_id |
---|
152 | LEFT JOIN '.USER_GROUP_TABLE.' AS ug |
---|
153 | ON u.'.$conf['user_fields']['id'].' = ug.user_id |
---|
154 | WHERE ug.group_id='.$group_id.' '; |
---|
155 | $groups=array(); |
---|
156 | $datas = pwg_query($query); |
---|
157 | |
---|
158 | if (!empty($datas)) { |
---|
159 | while ($group = mysql_fetch_array($datas,MYSQL_ASSOC)){ |
---|
160 | if (!empty($group['email'])){ |
---|
161 | //array_push($groups, format_email($group['username'], $group['email'] )); |
---|
162 | array_push($groups, |
---|
163 | array( 'username' => $group['username'], |
---|
164 | 'email' => $group['email'], |
---|
165 | 'format_email' => format_email($group['username'], $group['email'] ) |
---|
166 | ) |
---|
167 | ); |
---|
168 | } |
---|
169 | } |
---|
170 | } |
---|
171 | return $groups ; |
---|
172 | |
---|
173 | } |
---|
174 | //================================================================================= |
---|
175 | |
---|
176 | function create_table($nom_table,$champs,$types) //mail_superv_TABLE |
---|
177 | { |
---|
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); |
---|
195 | |
---|
196 | |
---|
197 | } |
---|
198 | //=========================================================== |
---|
199 | function ajust_table($nom_table,$champs,$types){ //mail_superv_TABLE |
---|
200 | global $infos_message ; |
---|
201 | $colonnes = Get_colonnes_de($nom_table); |
---|
202 | $data = $types ; |
---|
203 | $i=0; |
---|
204 | $valeurs=array(); |
---|
205 | foreach ( $champs as $champ) { |
---|
206 | $champ = trim($champ); |
---|
207 | if (!in_array( $champ,$colonnes)) { |
---|
208 | array_push($valeurs , " ADD `".$champ."`" . ' ' . $data[ $i] ) ; |
---|
209 | } |
---|
210 | $i +=1; |
---|
211 | |
---|
212 | } |
---|
213 | //============================================================================= |
---|
214 | if ( count($valeurs) == 0) return ; |
---|
215 | $valeurs=implode(", ",$valeurs) ; |
---|
216 | //=============================================================================== |
---|
217 | $query = "ALTER TABLE `" . $nom_table . "` ". $valeurs ; |
---|
218 | if ( pwg_query($query)) return ; |
---|
219 | die($query); |
---|
220 | } |
---|
221 | //============================================================================== |
---|
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 | $count = 0 ; |
---|
235 | } |
---|
236 | $data=array(); |
---|
237 | |
---|
238 | $query = " SELECT * FROM `".$nom_table."` ;"; |
---|
239 | $datas = pwg_query($query); |
---|
240 | if (!empty($datas)) { |
---|
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 | |
---|
258 | } |
---|
259 | //===================================================================== |
---|
260 | function verif_mails_donnees(){ |
---|
261 | global $mails_donnees,$infos_message,$erreur_message,$page; |
---|
262 | |
---|
263 | if (!is_numeric($mails_donnees['nb_mails_periode'])){ |
---|
264 | $periode = Str_To_Time( $mails_donnees['nb_mails_periode'],0); |
---|
265 | $mails_donnees['nb_mails_periode']= ($periode > 0) ? $periode : '604800' ; |
---|
266 | } |
---|
267 | if (!is_numeric($mails_donnees['nb_spams_periode'])){ |
---|
268 | $periode=Str_To_Time( $mails_donnees['nb_spams_periode'],0); |
---|
269 | $mails_donnees['nb_spams_periode']= ($periode > 0) ? $periode : '172800' ; ; |
---|
270 | } |
---|
271 | if (!is_numeric($mails_donnees['quarantaine_periode'])){ |
---|
272 | $periode=Str_To_Time( $mails_donnees['quarantaine_periode'],0); |
---|
273 | $mails_donnees['quarantaine_periode']= ($periode > 0) ? $periode : '172800' ; |
---|
274 | } |
---|
275 | if ($infos_message != "") { |
---|
276 | array_push($page['infos'], $infos_message); |
---|
277 | $infos_message=""; |
---|
278 | } |
---|
279 | if ($erreur_message != "") { |
---|
280 | array_push($page['errors'], $erreur_message); |
---|
281 | $erreur_message =""; |
---|
282 | } |
---|
283 | |
---|
284 | } |
---|
285 | //======================================================================= |
---|
286 | 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 | $Week=explode(" ",l10n('Week %d')); |
---|
294 | $Week= ($Week[0]); |
---|
295 | |
---|
296 | $lang['Sv_week'] = $Week; |
---|
297 | $lang['Sv_day'] = l10n('Day') ; |
---|
298 | $lang['Sv_hour'] = l10n('Hour') ; |
---|
299 | $lang['Sv_minute'] = l10n('Minute') ; |
---|
300 | $lang['Sv_second'] = l10n('Second'); |
---|
301 | |
---|
302 | $lang['Sv_'. $lang['Sv_week']] = 'week'; |
---|
303 | $lang['Sv_'. $lang['Sv_day']] = 'day'; |
---|
304 | $lang['Sv_'. $lang['Sv_hour']] = 'hour'; |
---|
305 | $lang['Sv_'. $lang['Sv_minute']] = 'minute'; |
---|
306 | $lang['Sv_'. $lang['Sv_second']] = 'second'; |
---|
307 | |
---|
308 | } |
---|
309 | //--- traduction --> anglais --- |
---|
310 | |
---|
311 | //========= suppression numeric et symbole ========== |
---|
312 | $new_valeur =( preg_replace("/[0-9+\-.*\/()%]/"," ",$a_ajouter)); |
---|
313 | $nv = trim( sup_double_espace($new_valeur)) ; |
---|
314 | |
---|
315 | |
---|
316 | |
---|
317 | $conv['week']= (7*24*60*60); |
---|
318 | $conv['day']= (24*60*60); |
---|
319 | $conv['hour']= (60*60) ; |
---|
320 | $conv['minute']= 60 ; |
---|
321 | $conv['second']= 1; |
---|
322 | |
---|
323 | $nv = explode(" ", $nv ); |
---|
324 | |
---|
325 | foreach($nv as $nv1){ |
---|
326 | if (!isset($lang['Sv_'. $nv1]) ) { |
---|
327 | //==== au cas pluriel === |
---|
328 | $nv0 = substr($nv1, 0,-1) ; |
---|
329 | $a_ajouter= str_replace( $nv1,$nv0, $a_ajouter); |
---|
330 | $nv1 = $nv0 ; |
---|
331 | } |
---|
332 | if (!isset($lang['Sv_'. $nv1]) ) { |
---|
333 | $erreur_message .= $nv1. " ".l10n('not_found')."<br />"; |
---|
334 | // die($erreur_message); |
---|
335 | }else { |
---|
336 | ob_start(); |
---|
337 | $match = $conv[strtolower($lang['Sv_'. $nv1])] ; |
---|
338 | $a_ajouter = str_replace($nv1," ". $match ." ",$a_ajouter) ; |
---|
339 | $erreur_message .= ob_get_contents(); |
---|
340 | ob_end_clean(); |
---|
341 | } |
---|
342 | } |
---|
343 | |
---|
344 | $a_ajouter = "+ " . $a_ajouter ; |
---|
345 | $a_ajouter=sup_double_espace($a_ajouter); |
---|
346 | $v1 = array('- ','+ ',' -', ' +', ' '); |
---|
347 | $v2 = array('-' ,'+' ,'|-', '|+', "*"); |
---|
348 | |
---|
349 | $new_valeur = str_replace($v1,$v2,$a_ajouter) ; |
---|
350 | $new_valeur = str_replace('++','+',$new_valeur ) ; |
---|
351 | |
---|
352 | return $new_valeur; |
---|
353 | } |
---|
354 | //===================================================================== |
---|
355 | function Str_To_Time( $ajout,$init_date) |
---|
356 | { |
---|
357 | //======================================================== |
---|
358 | global $erreur_message,$infos_message,$user; |
---|
359 | global $lang; |
---|
360 | |
---|
361 | $ajout=ucwords ($ajout); |
---|
362 | |
---|
363 | |
---|
364 | if (is_numeric($ajout)) |
---|
365 | $valeur= $ajout ; |
---|
366 | else |
---|
367 | { |
---|
368 | $valeur= Date_to_numeric( $ajout) ; |
---|
369 | |
---|
370 | } |
---|
371 | |
---|
372 | $new_valeur = explode( "|", $valeur ); |
---|
373 | |
---|
374 | $p = $init_date ; |
---|
375 | $n0=0; |
---|
376 | $erreur = false; |
---|
377 | |
---|
378 | //$new_valeur = $a_ajouter + $init_date ; |
---|
379 | foreach($new_valeur as $nv) |
---|
380 | { |
---|
381 | $return = matheval($nv) ; |
---|
382 | if (strpos("error",$return)===false) { |
---|
383 | $p += $return ; |
---|
384 | }else { |
---|
385 | $erreur_message .= "[" . $ajout . "] --> " . l10n('Sv_syntax_error') . " : " . $nv ."<br />"; |
---|
386 | $erreur = true; |
---|
387 | } |
---|
388 | |
---|
389 | |
---|
390 | } |
---|
391 | if ($erreur) $p = -1000 ; |
---|
392 | return intval($p) ; |
---|
393 | |
---|
394 | } |
---|
395 | //===================================================================================== |
---|
396 | function matheval($equation) |
---|
397 | { |
---|
398 | |
---|
399 | $return="error"; |
---|
400 | |
---|
401 | |
---|
402 | $equation = preg_replace("/[^0-9+\-.*\/()%]/","",$equation); |
---|
403 | $equation = preg_replace("/([+-])([0-9]{1})(%)/","*(1\$1.0\$2)",$equation); |
---|
404 | $equation = preg_replace("/([+-])([0-9]+)(%)/","*(1\$1.\$2)",$equation); |
---|
405 | $equation = preg_replace("/([0-9]+)(%)/",".\$1",$equation); |
---|
406 | |
---|
407 | if ( $equation == "" ) |
---|
408 | { |
---|
409 | $return = 0; |
---|
410 | } else { |
---|
411 | @eval("\$return=" . $equation . ";" ); |
---|
412 | } |
---|
413 | return $return; |
---|
414 | |
---|
415 | } |
---|
416 | |
---|
417 | //====================================================================================== |
---|
418 | function sup_double_espace($chaine){ |
---|
419 | global $erreur_message; |
---|
420 | $str_temp = $chaine." "; |
---|
421 | $sep=" "; |
---|
422 | $chaine = trim($chaine); |
---|
423 | if ($chaine=="") return ; |
---|
424 | $existe = (strpos($sep.$sep,$chaine )===false) ; |
---|
425 | while ($existe ){ |
---|
426 | $str_temp = str_replace($sep.$sep, $sep, $chaine ); |
---|
427 | if($str_temp == $chaine ) return $chaine ; |
---|
428 | // $erreur_message .= mail_supervisor::Memo_Var($str_temp) ; |
---|
429 | $chaine = $str_temp; |
---|
430 | $existe = (strpos($sep.$sep,$chaine )===false) ; |
---|
431 | } |
---|
432 | return $chaine; |
---|
433 | } |
---|
434 | //==================== TEST black_liste ============================================ |
---|
435 | function kill_list() { |
---|
436 | global $pays,$region,$ville,$ip ; |
---|
437 | global $erreur_message,$infos_message,$conf; |
---|
438 | global $conf, $user, $page; |
---|
439 | global $mails_options ; |
---|
440 | global $superv_bl_champs,$superv_bl_type ; |
---|
441 | global $nb ; |
---|
442 | if (!isset($ip)) { |
---|
443 | if (getenv("HTTP_CLIENT_IP")) { |
---|
444 | $ip=getenv("HTTP_CLIENT_IP"); |
---|
445 | }else{ |
---|
446 | $ip=getenv("REMOTE_ADDR"); |
---|
447 | } |
---|
448 | } |
---|
449 | $champs=implode(',',$superv_bl_champs); |
---|
450 | $query = "SELECT ".$champs.",COUNT(`ip`) as total |
---|
451 | FROM `".MAIL_BLACK_LISTE_TABLE."` |
---|
452 | WHERE '".$ip."' LIKE `ip` |
---|
453 | GROUP by `ip` |
---|
454 | ;"; |
---|
455 | $result = @pwg_query($query); |
---|
456 | if (!$result) { |
---|
457 | verif_base(); |
---|
458 | $result = @pwg_query($query); |
---|
459 | } |
---|
460 | $datas = mysql_fetch_array($result,MYSQL_ASSOC); |
---|
461 | $nb = $datas['total']|0; |
---|
462 | //======================================================================= |
---|
463 | if ($mails_options['set_auto'] == 'on') { |
---|
464 | global $user_name,$mail_adresse; |
---|
465 | |
---|
466 | if (isset($nb) && $nb>0) { |
---|
467 | //if (test_spam($ip,$user['username'] ,$user['email'])) // ne plus tester automatiquement . |
---|
468 | if ($nb==0) { |
---|
469 | $valeurs=array( 'NULL', |
---|
470 | "'".$ip."'", |
---|
471 | "'".$pays."'", |
---|
472 | "'".$region."'", |
---|
473 | "'".$ville."'", |
---|
474 | "'".$user['email']."'", |
---|
475 | "'".$user['username']."'", |
---|
476 | $nb+1 |
---|
477 | ); |
---|
478 | ajout_ligne(MAIL_BLACK_LISTE_TABLE,$superv_bl_champs, $valeurs,$nb==0) ; |
---|
479 | }else{ |
---|
480 | mail_supervisor::Get_geo(); |
---|
481 | $nb +=1; |
---|
482 | $query ="UPDATE " . MAIL_BLACK_LISTE_TABLE . " SET "; |
---|
483 | if (isset($_POST['pays'])) |
---|
484 | $query .= "`pays` = '". $pays ."', |
---|
485 | `region` = '" . $region ."', |
---|
486 | `ville` = '" . $ville . "', |
---|
487 | "; |
---|
488 | $query .= "`adresse` = '".$user['email']."', |
---|
489 | `fai` = '".$user['username']."', |
---|
490 | `nb` = " . $nb . " |
---|
491 | WHERE '".$ip."' like `ip` "; |
---|
492 | pwg_query($query ); |
---|
493 | } |
---|
494 | $erreur_message .= $pays . $ip ." <br />User Name :".$user['username']."<br />User Mail :".$user['email'] . ' -----> ' . l10n('Sv_set_black_liste') ; |
---|
495 | // die($nb." ".$ip." ".$user['username']." ".$user['email']); |
---|
496 | |
---|
497 | return true ; |
---|
498 | } |
---|
499 | } |
---|
500 | //============================================================================== |
---|
501 | |
---|
502 | if ( $mails_options['ip'] == $ip ) return ($nb > 0) ; |
---|
503 | $ip0= $mails_options['ip'] ; |
---|
504 | $mails_options['ip'] = $ip ; |
---|
505 | mail_supervisor::sauve_options(); |
---|
506 | if ( $nb > 0 ) |
---|
507 | { |
---|
508 | $query = " |
---|
509 | SELECT ".$champs.",COUNT(`id`) as total |
---|
510 | FROM `".MAIL_BLACK_LISTE_TABLE."` |
---|
511 | WHERE '".$ip."' = `ip` |
---|
512 | GROUP by `ip` |
---|
513 | ;"; |
---|
514 | $result = @pwg_query($query); |
---|
515 | |
---|
516 | if (!$result) { |
---|
517 | verif_base(); |
---|
518 | $result = @pwg_query($query); |
---|
519 | } |
---|
520 | $datas = mysql_fetch_array($result,MYSQL_ASSOC); |
---|
521 | $nb = $datas['total']; |
---|
522 | |
---|
523 | $row = mysql_fetch_row(pwg_query($query)); |
---|
524 | $nb = ($row[7]); |
---|
525 | $erreur_message .= $ip0 . ' | ' .$ip . ' | ' . $pays . ' | ' . $region . ' | ' . $ville . ' ' . $nb . ' ==> '; |
---|
526 | |
---|
527 | if ($nb == 0) |
---|
528 | { |
---|
529 | $valeurs=array( 'NULL', |
---|
530 | "'".$ip."'", |
---|
531 | "'".$pays."'", |
---|
532 | "'".$region."'", |
---|
533 | "'".$ville."'", |
---|
534 | "'".$user['email']."'", |
---|
535 | "'".$user['username']."'", |
---|
536 | 1 |
---|
537 | ); |
---|
538 | ajout_ligne(MAIL_BLACK_LISTE_TABLE,$superv_bl_champs, $valeurs,true) ; |
---|
539 | |
---|
540 | } else { |
---|
541 | $nb += 1; |
---|
542 | $query =" |
---|
543 | UPDATE " . MAIL_BLACK_LISTE_TABLE . " |
---|
544 | SET "; |
---|
545 | if (isset($_POST['pays'])) |
---|
546 | $query .= " |
---|
547 | `pays` = '". $pays ."', |
---|
548 | `region` = '" . $region ."', |
---|
549 | `ville` = '" . $ville . "', |
---|
550 | "; |
---|
551 | $query .= " |
---|
552 | `adresse` = '".$user['email']."', |
---|
553 | `fai` = '".$user['username']."', |
---|
554 | `nb` = " . $nb . " |
---|
555 | WHERE '".$ip."' = `ip` |
---|
556 | "; |
---|
557 | |
---|
558 | pwg_query($query ); |
---|
559 | } |
---|
560 | } |
---|
561 | return ($nb > 0) ; |
---|
562 | } |
---|
563 | //===================================================================================== |
---|
564 | function test_spam($ip =0,$user_name ='', $mail_adresse = ""){ |
---|
565 | $buffer=""; |
---|
566 | global $page,$infos_message; |
---|
567 | $src = "http://www.stopforumspam.com/api?"; |
---|
568 | $type=array(); |
---|
569 | $result=""; |
---|
570 | $ip= sup_double_espace($ip); |
---|
571 | if (strlen($ip)>3) { |
---|
572 | //================== Verifie si l'IP est correct ================================ |
---|
573 | if (clj_is_ip($ip)){ |
---|
574 | |
---|
575 | } else { |
---|
576 | //================== Verifie si l'adresse mail est correcte ================================ |
---|
577 | if( clj_is_mail($ip) ){ |
---|
578 | $mail_adresse=$ip ; |
---|
579 | $ip=""; |
---|
580 | } |
---|
581 | else |
---|
582 | { |
---|
583 | //================== Login ================ |
---|
584 | $user_name=$ip; |
---|
585 | $ip=""; |
---|
586 | } |
---|
587 | } |
---|
588 | //============================================================================= |
---|
589 | } |
---|
590 | |
---|
591 | $user_name=str_replace(" ","%20",trim($user_name)); |
---|
592 | if ($user_name==l10n('Sv_guest')) $user_name=""; |
---|
593 | $user_name=""; // ne plus tester sur le login. |
---|
594 | $mail_adresse =str_replace(" ","%20",trim($mail_adresse)); |
---|
595 | if ( strlen($user_name) > 3) $type[]="username=$user_name" ; |
---|
596 | if ( strlen($mail_adresse) > 3) $type[]="email=".$mail_adresse ; |
---|
597 | if ( strlen($ip) > 3) $type[]="ip=".$ip ; |
---|
598 | foreach ( $type as $fil ) { |
---|
599 | $resultat=""; |
---|
600 | if ( clj_fetchRemote($src.$fil , $resultat,1)) |
---|
601 | $result .= $resultat.'<br />' ; |
---|
602 | } |
---|
603 | |
---|
604 | return !(strpos( $result ,'yes' ) === false) ; |
---|
605 | |
---|
606 | } |
---|
607 | //================================================================== |
---|
608 | function lire_fichier_distant($fichier){ |
---|
609 | $buffer=""; |
---|
610 | $handle = @fopen($fichier,"r"); |
---|
611 | if ($handle) { |
---|
612 | while (!feof($handle)) { |
---|
613 | $buffer .= fgets($handle, 4096); |
---|
614 | } |
---|
615 | fclose($handle); |
---|
616 | } |
---|
617 | |
---|
618 | return $buffer ; |
---|
619 | |
---|
620 | } |
---|
621 | //================================================ |
---|
622 | function clj_is_ip($ip){ |
---|
623 | 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 ; |
---|
624 | |
---|
625 | } |
---|
626 | |
---|
627 | function clj_is_mail($mail) |
---|
628 | { |
---|
629 | |
---|
630 | if(preg_match('/^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,5}$/' ,$mail)) return true ; |
---|
631 | if(preg_match('/#^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,5}$#/' ,$mail)) return true ; |
---|
632 | } |
---|
633 | |
---|
634 | |
---|
635 | function clj_fetchRemote($src, &$dest, $timeout=1, $user_agent='Piwigo', $step=0) |
---|
636 | { |
---|
637 | // Try to retrieve data from local file? |
---|
638 | // http://www.stopforumspam.com/api?ip=95.211.1.39 |
---|
639 | |
---|
640 | if ($src=="") return ; |
---|
641 | |
---|
642 | if (!url_is_remote($src)) |
---|
643 | { |
---|
644 | |
---|
645 | $content = @file_get_contents($src); |
---|
646 | if ($content !== false) |
---|
647 | { |
---|
648 | is_resource($dest) ? @fwrite($dest, $content) : $dest = $content; |
---|
649 | return true; |
---|
650 | } |
---|
651 | else |
---|
652 | { |
---|
653 | return false; |
---|
654 | } |
---|
655 | } |
---|
656 | |
---|
657 | // After 3 redirections, return false |
---|
658 | if ($step > 3) return false; |
---|
659 | |
---|
660 | // Initialize $dest |
---|
661 | is_resource($dest) or $dest = ''; |
---|
662 | |
---|
663 | // Try curl to read remote file |
---|
664 | if (function_exists('curl_init')) |
---|
665 | { |
---|
666 | $ch = @curl_init(); |
---|
667 | @curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
---|
668 | @curl_setopt($ch, CURLOPT_URL, $src); |
---|
669 | @curl_setopt($ch, CURLOPT_HEADER, 1); |
---|
670 | @curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); |
---|
671 | @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
---|
672 | $content = @curl_exec($ch); |
---|
673 | $header_length = @curl_getinfo($ch, CURLINFO_HEADER_SIZE); |
---|
674 | $status = @curl_getinfo($ch, CURLINFO_HTTP_CODE); |
---|
675 | @curl_close($content); |
---|
676 | if ($content !== false and $status >= 200 and $status < 400) |
---|
677 | { |
---|
678 | if (preg_match('/Location:\s+?(.+)/', substr($content, 0, $header_length), $m)) |
---|
679 | { |
---|
680 | return clj_fetchRemote($m[1], $dest,$timeout, $user_agent, $step+1); |
---|
681 | } |
---|
682 | $content = substr($content, $header_length); |
---|
683 | is_resource($dest) ? @fwrite($dest, $content) : $dest = $content; |
---|
684 | return true; |
---|
685 | } |
---|
686 | } |
---|
687 | |
---|
688 | // Try file_get_contents to read remote file |
---|
689 | if (ini_get('allow_url_fopen')) |
---|
690 | { |
---|
691 | |
---|
692 | $opts['http'] = array('timeout' => $timeout); |
---|
693 | $ctx = stream_context_create($opts); |
---|
694 | $content = @file_get_contents($src, 0, $ctx); |
---|
695 | if ($content !== false) |
---|
696 | { |
---|
697 | is_resource($dest) ? @fwrite($dest, $content) : $dest = $content; |
---|
698 | return true; |
---|
699 | } |
---|
700 | } |
---|
701 | |
---|
702 | return false; |
---|
703 | } |
---|
704 | |
---|
705 | |
---|
706 | ?> |
---|