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')) |
---|
25 | { |
---|
26 | die('Hacking attempt!'); |
---|
27 | } |
---|
28 | |
---|
29 | if (!defined('MAIL_SUPERV_PATH')) define('MAIL_SUPERV_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
30 | |
---|
31 | define ("check_mailto", 0); define ("check_header_carbon",1); define ("check_header_text",2); |
---|
32 | define ("no_mail_list", 3); define ("no_connect",4); define ("set_auto",5); |
---|
33 | define ("ip",6); define ("set_id",7); |
---|
34 | |
---|
35 | |
---|
36 | if (!isset($_COOKIE[session_name()])) |
---|
37 | { |
---|
38 | |
---|
39 | |
---|
40 | |
---|
41 | } |
---|
42 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
43 | include_once(PHPWG_ROOT_PATH.'include/functions.inc.php'); |
---|
44 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
45 | global $lang ; |
---|
46 | |
---|
47 | include_once (MAIL_SUPERV_PATH.'include/function_test_send.php'); |
---|
48 | load_language('plugin.lang', MAIL_SUPERV_PATH); |
---|
49 | global $superv_champs , $superv_type ,$superv_bl_champs , $superv_bl_type ; |
---|
50 | |
---|
51 | //========================================================== |
---|
52 | function sauve_options() |
---|
53 | { |
---|
54 | global $mails_options ; |
---|
55 | if ( isset($mails_options) ) |
---|
56 | { |
---|
57 | |
---|
58 | while ( count($mails_options) < 10 ) |
---|
59 | { |
---|
60 | |
---|
61 | $mails_options[]='?'; |
---|
62 | } |
---|
63 | |
---|
64 | $valeurs = implode( ',',$mails_options); |
---|
65 | $query = ' |
---|
66 | UPDATE '.CONFIG_TABLE.' |
---|
67 | SET value="'. $valeurs . '" |
---|
68 | WHERE param = "mail_superv" |
---|
69 | LIMIT 1'; |
---|
70 | pwg_query($query); |
---|
71 | |
---|
72 | } |
---|
73 | } |
---|
74 | //================================================================================= |
---|
75 | function sauve_données() |
---|
76 | { |
---|
77 | |
---|
78 | global $mails_données,$superv_champs,$superv_type,$erreur_message ; |
---|
79 | //===================================================================== |
---|
80 | $clefs = $superv_champs ; |
---|
81 | $valeurs = array(); |
---|
82 | |
---|
83 | foreach ( $clefs as $champ) |
---|
84 | { |
---|
85 | $champ = trim($champ); |
---|
86 | |
---|
87 | if ( isset($mails_données[ $champ ]) ) { |
---|
88 | $sep= (is_string($mails_données[ $champ ])) ? '"' : '' ; |
---|
89 | array_push($valeurs , "`".$champ."`" . ' = ' . $sep . $mails_données[ $champ ] . $sep) ; |
---|
90 | }else{ |
---|
91 | |
---|
92 | array_push($valeurs , "`".$champ."`" . ' = ' . "0" ) ; |
---|
93 | } |
---|
94 | } |
---|
95 | $valeurs = implode(", ",$valeurs) ; |
---|
96 | //===================================================================== |
---|
97 | $query = ' |
---|
98 | UPDATE '.MAIL_SUPERV_TABLE.' |
---|
99 | SET '. $valeurs .' |
---|
100 | WHERE `id` = 1 LIMIT 1 '; |
---|
101 | ; |
---|
102 | ob_start(); |
---|
103 | $ret= pwg_query($query) ; |
---|
104 | $m= ob_get_contents(); |
---|
105 | ob_end_clean() ; |
---|
106 | $erreur_message .= $m ; |
---|
107 | |
---|
108 | } |
---|
109 | |
---|
110 | //================================================================================= |
---|
111 | function affiche_message() |
---|
112 | { |
---|
113 | global $template,$infos_message,$erreur_message, $user ,$ip; |
---|
114 | |
---|
115 | global $mails_options,$conf,$lang ; |
---|
116 | |
---|
117 | $mails_options = explode("," , $conf['mail_superv']); |
---|
118 | if (!isset($ip)) { |
---|
119 | if (getenv("HTTP_CLIENT_IP")) |
---|
120 | { $ip=getenv("HTTP_CLIENT_IP"); } |
---|
121 | else{ $ip=getenv("REMOTE_ADDR"); } |
---|
122 | } |
---|
123 | // unset ($_SESSION['pwg_'.'action_spam']); |
---|
124 | $action_spam = pwg_get_session_var('action_spam') ; |
---|
125 | if ($action_spam == null) { $action_spam = kill_list(); } |
---|
126 | |
---|
127 | if (is_bool($action_spam)) $action_spam =($action_spam == true) ? "true" : "false" ; |
---|
128 | if ($action_spam == "true" ) |
---|
129 | { |
---|
130 | $erreur_message = $ip . " " . $action_spam ; |
---|
131 | pwg_set_session_var('action_spam', "true"); |
---|
132 | $erreur_message .= "<BR />".l10n('is_a_spam') ; |
---|
133 | if ($mails_options[no_connect] == 'on' ){ |
---|
134 | //[status] => guest |
---|
135 | //[status] => normal |
---|
136 | //[status] => webmaster |
---|
137 | if ($user['status'] != 'webmaster' ) |
---|
138 | if (!isset($_GET['admin'])) { |
---|
139 | die('Blacklist : <br />' .$erreur_message. '<br /> Hacking attempt!'); |
---|
140 | }elseif ($_GET['admin'] != 'piwigo') |
---|
141 | { |
---|
142 | die('blacklist Hacking attempt!'); |
---|
143 | } |
---|
144 | unset ($_SESSION['pwg_'.'action_spam']); |
---|
145 | } |
---|
146 | }else{ |
---|
147 | pwg_set_session_var('action_spam', "false"); |
---|
148 | } |
---|
149 | |
---|
150 | |
---|
151 | // } |
---|
152 | |
---|
153 | //============================================================== |
---|
154 | if (isset($erreur_message)) |
---|
155 | { |
---|
156 | |
---|
157 | if ($erreur_message <> "") |
---|
158 | { |
---|
159 | $erreur_message=str_replace("\n",'<br />',$erreur_message) ; |
---|
160 | $template->assign('errors',$erreur_message); |
---|
161 | $erreur_message=""; |
---|
162 | } |
---|
163 | } |
---|
164 | |
---|
165 | |
---|
166 | if (isset($infos_message)) |
---|
167 | { |
---|
168 | |
---|
169 | if ($infos_message <> "") |
---|
170 | { |
---|
171 | $infos_message=str_replace("\n",'<br />',$infos_message) ; |
---|
172 | $template->assign('infos',$infos_message); |
---|
173 | $infos_message=""; |
---|
174 | } |
---|
175 | } |
---|
176 | //============================================================= |
---|
177 | |
---|
178 | |
---|
179 | return; |
---|
180 | |
---|
181 | } |
---|
182 | |
---|
183 | function Get_geo() |
---|
184 | { |
---|
185 | global $ip,$pays,$region,$ville, $latitude ,$longitude,$mails_options; |
---|
186 | //=================================================================================== |
---|
187 | $info_geo = pwg_get_session_var('info_geo'); |
---|
188 | print_r($info_geo ); |
---|
189 | if (count($info_geo) > 0) |
---|
190 | { |
---|
191 | |
---|
192 | $pays = $info_geo[0]; |
---|
193 | $region = $info_geo[1]; |
---|
194 | $ville = $info_geo[2]; |
---|
195 | $latitude = $info_geo[3]; |
---|
196 | $longitude = $info_geo[4]; |
---|
197 | $ip = $info_geo[5]; |
---|
198 | return true; |
---|
199 | } |
---|
200 | //======================================================================= |
---|
201 | |
---|
202 | if (isset($_POST['pays'])) { |
---|
203 | $pays = isset($_POST['pays']) ? $_POST['pays'] : ""; |
---|
204 | $region = isset($_POST['region']) ? $_POST['region'] :""; |
---|
205 | $ville = (isset($_POST['ville'])) ? $_POST['ville']: ""; |
---|
206 | $latitude = isset($_POST['latitude']) ? $_POST['latitude'] : ""; |
---|
207 | $longitude = isset($_POST['longitude']) ? $_POST['longitude'] : ""; |
---|
208 | |
---|
209 | $info_geo = array( $pays ,$region , $ville ,$latitude, $longitude,$_SERVER['REMOTE_ADDR'] ); |
---|
210 | pwg_set_session_var('info_geo', $info_geo); |
---|
211 | return true; |
---|
212 | |
---|
213 | }else{ |
---|
214 | |
---|
215 | $result=""; |
---|
216 | ?> |
---|
217 | <script language="JavaScript" src="http://j.maxmind.com/app/geoip.js" type="text/javascript" > |
---|
218 | </script> |
---|
219 | <script language="JavaScript" type="text/javascript"> |
---|
220 | var pays = geoip_country_name(); |
---|
221 | var ville = geoip_city(); |
---|
222 | var region = geoip_region_name() ; |
---|
223 | var latitude = geoip_latitude() ; |
---|
224 | var longitude = geoip_longitude() ; |
---|
225 | |
---|
226 | </script> |
---|
227 | <form action="" method="post" name="form_connexion" id="form_connexion" style="visibility:hidden"> |
---|
228 | <script language="JavaScript" type="text/javascript"> |
---|
229 | document.write ("<input name=\"pays\" type=\"text\" value = "+ pays + " id = \"pays\" > "); |
---|
230 | document.write ("<input name=\"ville\" type=\"text\" value = "+ ville + " id = \"ville\" > "); |
---|
231 | document.write ("<input name=\"region\" type=\"text\" value = "+ region + " id = \"region\" > "); |
---|
232 | document.write ("<input name=\"latitude\" type=\"text\" value = "+ latitude + " id = \"latitude\" > "); |
---|
233 | document.write ("<input name=\"longitude\" type=\"text\" value = "+ longitude + " id = \"longitude\" > "); |
---|
234 | </script> |
---|
235 | |
---|
236 | </form > |
---|
237 | <script language="JavaScript" type="text/javascript"> |
---|
238 | document.getElementById("form_connexion").submit(); |
---|
239 | </script> |
---|
240 | <?php |
---|
241 | |
---|
242 | } |
---|
243 | //===================================================================================== |
---|
244 | } |
---|
245 | |
---|
246 | //================================================================================= |
---|
247 | function Get_Datas() |
---|
248 | { |
---|
249 | global $superv_champs ; |
---|
250 | $champs = implode(",",$superv_champs ); |
---|
251 | $query = "SELECT ".$champs." |
---|
252 | FROM ".MAIL_SUPERV_TABLE." |
---|
253 | ;"; |
---|
254 | $result = @pwg_query($query); |
---|
255 | |
---|
256 | if (!$result) { |
---|
257 | vérif_base(); |
---|
258 | $result = @pwg_query($query); |
---|
259 | } |
---|
260 | |
---|
261 | |
---|
262 | $data = mysql_fetch_array($result,MYSQL_ASSOC); |
---|
263 | //==================================================================================== |
---|
264 | $next_day = Str_To_Time( $data['nb_mails_periode'], $data['date_mail'] );; |
---|
265 | $data['rest_mail']= $next_day - time() ; |
---|
266 | |
---|
267 | $next_day = + Str_To_Time( $data['nb_spams_periode'],$data['date_spam']); |
---|
268 | $data['rest_spam']= $next_day - time() ; |
---|
269 | |
---|
270 | |
---|
271 | $next_day = Str_To_Time($data['quarantaine_periode'] ,$data['date_quarantaine']); |
---|
272 | |
---|
273 | if ($data['quarantaine'] == 'true' ) { |
---|
274 | $data['reste'] = ( $next_day )-time() ; |
---|
275 | }else{ |
---|
276 | $data['reste'] = 0; |
---|
277 | } |
---|
278 | |
---|
279 | return $data; |
---|
280 | } |
---|
281 | //=============================================== |
---|
282 | |
---|
283 | function corrige_header($Carbonne,$headers,$args) |
---|
284 | { |
---|
285 | global $mails_options,$conf_mail,$mailto,$infos_message; |
---|
286 | |
---|
287 | if (!empty($args[$Carbonne])) |
---|
288 | { |
---|
289 | |
---|
290 | if ( count($args[$Carbonne]) > 0 ) |
---|
291 | { |
---|
292 | if ($mails_options[check_header_carbon] == 'on') { |
---|
293 | $list_mail = str_replace(","," ,",get_strict_email_list(implode(',', $args[$Carbonne])))." \n" ; |
---|
294 | $headers = preg_replace('/.*'.$Carbonne.'(.*).\n/i', $Carbonne.': '.$list_mail, $headers); |
---|
295 | } |
---|
296 | } |
---|
297 | } else { |
---|
298 | // Raz Bcc, Cc dans headers |
---|
299 | $headers = preg_replace('/.*'.$Carbonne.'(.*).\n/i', "" , $headers); |
---|
300 | } |
---|
301 | |
---|
302 | |
---|
303 | return $headers; |
---|
304 | |
---|
305 | |
---|
306 | } |
---|
307 | |
---|
308 | function int_to_heure($int) |
---|
309 | { |
---|
310 | |
---|
311 | $delta=(7*24*60*60) ; |
---|
312 | $week = (int) ($int/$delta); |
---|
313 | $int= $int-($week*$delta) ; |
---|
314 | |
---|
315 | $delta=(24*60*60) ; |
---|
316 | $day= (int) ($int/$delta); |
---|
317 | $int=$int-($day*$delta); |
---|
318 | |
---|
319 | $delta=(60*60) ; |
---|
320 | $heures=(int) ($int/$delta); |
---|
321 | $int=$int-($heures*$delta); |
---|
322 | |
---|
323 | $delta=(60) ; |
---|
324 | $minutes=(int) ($int/$delta); |
---|
325 | $int= $int - ($minutes*$delta); |
---|
326 | |
---|
327 | $secondes=(int) ($int); |
---|
328 | $day = substr ('00'. $day,-2,2); |
---|
329 | $heures = substr ('00'. $heures,-2,2); |
---|
330 | $minutes = substr ('00'.$minutes,-2,2); |
---|
331 | $secondes = substr ('00'.$secondes,-2,2); |
---|
332 | |
---|
333 | |
---|
334 | if ($week > 0 ) |
---|
335 | { |
---|
336 | return $week. " " .l10n('Week'). " " . $day . " " .l10n('Day'). "s ". $heures . " ". l10n('Hour'). "s " . $minutes. " " .l10n('minute'). "s ". $secondes." " .l10n('seconde')."s"; |
---|
337 | } |
---|
338 | return $day . " " .l10n('Day'). "s ". $heures . " ". l10n('Hour'). "s " . $minutes. " " .l10n('Minute'). "s ". $secondes." " .l10n('Seconde')."s"; |
---|
339 | |
---|
340 | } |
---|
341 | |
---|
342 | function memo_var($variables) |
---|
343 | { |
---|
344 | ob_start(); |
---|
345 | echo '<pre>'; |
---|
346 | print_r($variables); |
---|
347 | echo '</pre>'; |
---|
348 | $m= ob_get_contents(); |
---|
349 | |
---|
350 | ob_end_clean(); |
---|
351 | return $m; |
---|
352 | |
---|
353 | } |
---|
354 | |
---|
355 | |
---|
356 | |
---|
357 | function vérif_base() |
---|
358 | { |
---|
359 | |
---|
360 | global $lang,$superv_champs,$superv_type,$superv_bl_champs,$superv_bl_type; |
---|
361 | load_language('plugin.lang', MAIL_SUPERV_PATH); |
---|
362 | //============================================================================== |
---|
363 | create_table(MAIL_BLACK_LISTE_TABLE,$superv_bl_champs,$superv_bl_type) ; |
---|
364 | ajust_table(MAIL_BLACK_LISTE_TABLE,$superv_bl_champs,$superv_bl_type) ; |
---|
365 | //============================================================================== |
---|
366 | create_table(MAIL_SUPERV_TABLE,$superv_champs,$superv_type) ; |
---|
367 | ajust_table(MAIL_SUPERV_TABLE,$superv_champs,$superv_type) ; |
---|
368 | //============================================================================== |
---|
369 | $valeurs= array ( 1, |
---|
370 | 0, |
---|
371 | time(), |
---|
372 | 2000, |
---|
373 | '"1 '.l10n('Week').'"' , |
---|
374 | 0, |
---|
375 | time(), |
---|
376 | 10, |
---|
377 | '"2 '.l10n('Day').'"', |
---|
378 | '"false"', |
---|
379 | time(), |
---|
380 | '"2 '.l10n('Day').'"', |
---|
381 | |
---|
382 | '"Init"', |
---|
383 | '"'.l10n('supervisor').'"', |
---|
384 | '"'.l10n('hello').'"', |
---|
385 | ) |
---|
386 | ; |
---|
387 | //================================================================================== |
---|
388 | ajout_ligne(MAIL_SUPERV_TABLE,$superv_champs, $valeurs,false ) ; |
---|
389 | |
---|
390 | |
---|
391 | } |
---|
392 | |
---|
393 | //========================================= |
---|
394 | function Get_colonnes_de($table) |
---|
395 | { |
---|
396 | $query = 'DESC '.$table.';'; |
---|
397 | $result = mysql_query($query); |
---|
398 | $columns_of= array(); |
---|
399 | while ($row = mysql_fetch_row($result)) |
---|
400 | { |
---|
401 | array_push($columns_of, $row[0]); |
---|
402 | } |
---|
403 | |
---|
404 | return $columns_of; |
---|
405 | } |
---|
406 | |
---|
407 | function get_liste($group_id) |
---|
408 | { |
---|
409 | global $conf ; |
---|
410 | |
---|
411 | $query = ' |
---|
412 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
413 | u.'.$conf['user_fields']['username'].' AS username, |
---|
414 | u.'.$conf['user_fields']['email'].' AS email, |
---|
415 | ui.status, |
---|
416 | ui.adviser, |
---|
417 | ui.enabled_high, |
---|
418 | ui.level |
---|
419 | FROM '.USERS_TABLE.' AS u |
---|
420 | INNER JOIN '.USER_INFOS_TABLE.' AS ui |
---|
421 | ON u.'.$conf['user_fields']['id'].' = ui.user_id |
---|
422 | LEFT JOIN '.USER_GROUP_TABLE.' AS ug |
---|
423 | ON u.'.$conf['user_fields']['id'].' = ug.user_id |
---|
424 | WHERE ug.group_id='.$group_id.' '; |
---|
425 | |
---|
426 | |
---|
427 | |
---|
428 | $groups=array(); |
---|
429 | $datas = pwg_query($query); |
---|
430 | |
---|
431 | |
---|
432 | if (!empty($datas)) |
---|
433 | { |
---|
434 | while ($group = mysql_fetch_array($datas,MYSQL_ASSOC)) |
---|
435 | { |
---|
436 | |
---|
437 | |
---|
438 | if (!empty($group['email'])) |
---|
439 | { |
---|
440 | array_push($groups, format_email($group['username'], $group['email'] )); |
---|
441 | } |
---|
442 | } |
---|
443 | } |
---|
444 | return $groups ; |
---|
445 | |
---|
446 | } |
---|
447 | //================================================================================= |
---|
448 | |
---|
449 | function create_table($nom_table,$champs,$types) //MAIL_SUPERV_TABLE |
---|
450 | { |
---|
451 | $i=0; |
---|
452 | $valeurs=array(); |
---|
453 | foreach ( $champs as $champ) |
---|
454 | { |
---|
455 | $champ = trim($champ); |
---|
456 | array_push($valeurs , " `".$champ."`" . ' ' . $types[ $i] ) ; |
---|
457 | $i +=1; |
---|
458 | } |
---|
459 | |
---|
460 | |
---|
461 | |
---|
462 | if ( count($valeurs) == 0) return ; |
---|
463 | |
---|
464 | $valeurs=implode(", ",$valeurs) ; |
---|
465 | //=============================================================================== |
---|
466 | $query = "CREATE TABLE IF NOT EXISTS `" . $nom_table . "` (". $valeurs . " , PRIMARY KEY (`id` ) ) ENGINE=MyISAM ;"; |
---|
467 | if ( pwg_query($query) ) return ; |
---|
468 | die("ERREUR CREATION ".$query); |
---|
469 | |
---|
470 | |
---|
471 | } |
---|
472 | function ajust_table($nom_table,$champs,$types) //MAIL_SUPERV_TABLE |
---|
473 | { |
---|
474 | global $infos_message ; |
---|
475 | $colonnes = Get_colonnes_de($nom_table); |
---|
476 | $data = $types ; |
---|
477 | $i=0; |
---|
478 | $valeurs=array(); |
---|
479 | foreach ( $champs as $champ) |
---|
480 | { |
---|
481 | $champ = trim($champ); |
---|
482 | if (!in_array( $champ,$colonnes)) { |
---|
483 | array_push($valeurs , " ADD `".$champ."`" . ' ' . $data[ $i] ) ; |
---|
484 | } |
---|
485 | $i +=1; |
---|
486 | |
---|
487 | } |
---|
488 | //============================================================================= |
---|
489 | if ( count($valeurs) == 0) return ; |
---|
490 | |
---|
491 | $infos_message .= "AJUSTE TABLE : ". $nom_table . "<br />" . "NB (col) : ". count($colonnes) . memo_var($valeurs) . "<br />" ; |
---|
492 | |
---|
493 | $valeurs=implode(", ",$valeurs) ; |
---|
494 | //=============================================================================== |
---|
495 | $query = "ALTER TABLE `" . $nom_table . "` ". $valeurs ; |
---|
496 | if ( pwg_query($query)) return ; |
---|
497 | die($query); |
---|
498 | } |
---|
499 | //============================================================================== |
---|
500 | function ajout_ligne($nom_table,$champs,$valeurs,$force) |
---|
501 | { |
---|
502 | if (!$force) { |
---|
503 | $query = " |
---|
504 | SELECT `id` , COUNT(`id`) as total |
---|
505 | FROM `".$nom_table."` |
---|
506 | ;"; |
---|
507 | list($count) = mysql_fetch_row(pwg_query($query)); |
---|
508 | |
---|
509 | |
---|
510 | }else{ |
---|
511 | |
---|
512 | $count = 0 ; |
---|
513 | } |
---|
514 | |
---|
515 | if ($count == 0) |
---|
516 | { |
---|
517 | $n_champs=implode(",",$champs); |
---|
518 | $n_valeurs=implode(",",$valeurs); |
---|
519 | $query = " |
---|
520 | INSERT INTO `".$nom_table."` (". $n_champs.") |
---|
521 | VALUES ( ". $n_valeurs .")"; |
---|
522 | |
---|
523 | if (pwg_query($query)) return ; |
---|
524 | die($query); |
---|
525 | |
---|
526 | } |
---|
527 | } |
---|
528 | //===================================================================== |
---|
529 | |
---|
530 | function Str_To_Time( $ajout,$init_date) |
---|
531 | { |
---|
532 | //======================================================== |
---|
533 | global $erreur_message; |
---|
534 | $a_ajouter=$ajout ; |
---|
535 | |
---|
536 | $period_search=array("W","D","H","M","S"); |
---|
537 | array_push($period_search,l10n('Week').'s',l10n('Day').'s',l10n('Hour').'s',l10n('Minute').'s',l10n('Seconde').'s'); |
---|
538 | array_push($period_search,l10n('Week'),l10n('Day'),l10n('Hour'),l10n('Minute'),l10n('Seconde')); |
---|
539 | |
---|
540 | |
---|
541 | |
---|
542 | $period_match = array(' week ',' day ',' hour ',' minute ',' seconde '); |
---|
543 | array_push($period_match,' week ',' day ',' hour ',' minute ',' seconde '); |
---|
544 | array_push($period_match,' week ',' day ',' hour ',' minute ',' seconde '); |
---|
545 | |
---|
546 | |
---|
547 | |
---|
548 | $a_ajouter = "+ " . str_replace($period_search, $period_match, $a_ajouter) ; |
---|
549 | $a_ajouter=sup_double_espace($a_ajouter); |
---|
550 | |
---|
551 | $v1 = array('- ','+ ','week','day','hour','minute','seconde',' -',' +',' '); |
---|
552 | $v2 = array('-','+', (7*24*60*60) , (24*60*60), (60*60), 60,1,'|-','|+',"*" ); |
---|
553 | $new_valeur = str_replace($v1,$v2,$a_ajouter) ; |
---|
554 | $new_valeur = str_replace('++','+',$new_valeur ) ; |
---|
555 | |
---|
556 | $new_valeur = explode( "|",$new_valeur ); |
---|
557 | $p = $init_date ; |
---|
558 | |
---|
559 | //$new_valeur = $a_ajouter + $init_date ; |
---|
560 | foreach($new_valeur as $nv) |
---|
561 | { |
---|
562 | $return = matheval($nv) ; |
---|
563 | if (strpos("error",$return)===false) { |
---|
564 | $p += $return ; |
---|
565 | }else { |
---|
566 | $erreur_message .= $return . " nv : " . $nv ; |
---|
567 | } |
---|
568 | |
---|
569 | |
---|
570 | } |
---|
571 | return $p ; |
---|
572 | |
---|
573 | } |
---|
574 | //===================================================================================== |
---|
575 | function matheval($equation) |
---|
576 | { |
---|
577 | |
---|
578 | $return="error"; |
---|
579 | |
---|
580 | |
---|
581 | $equation = preg_replace("/[^0-9+\-.*\/()%]/","",$equation); |
---|
582 | $equation = preg_replace("/([+-])([0-9]{1})(%)/","*(1\$1.0\$2)",$equation); |
---|
583 | $equation = preg_replace("/([+-])([0-9]+)(%)/","*(1\$1.\$2)",$equation); |
---|
584 | $equation = preg_replace("/([0-9]+)(%)/",".\$1",$equation); |
---|
585 | |
---|
586 | if ( $equation == "" ) |
---|
587 | { |
---|
588 | $return = 0; |
---|
589 | } else { |
---|
590 | @eval("\$return=" . $equation . ";" ); |
---|
591 | } |
---|
592 | return $return; |
---|
593 | |
---|
594 | } |
---|
595 | |
---|
596 | //====================================================================================== |
---|
597 | function sup_double_espace($chaine){ |
---|
598 | global $erreur_message; |
---|
599 | $str_temp = $chaine." "; |
---|
600 | $sep=" "; |
---|
601 | $chaine = trim($chaine); |
---|
602 | $existe = (strpos($sep.$sep,$chaine )===false) ; |
---|
603 | while ($existe ){ |
---|
604 | $str_temp = str_replace($sep.$sep, $sep, $chaine ); |
---|
605 | if($str_temp == $chaine ) return $chaine ; |
---|
606 | // $erreur_message .= memo_var($str_temp) ; |
---|
607 | $chaine = $str_temp; |
---|
608 | $existe = (strpos($sep.$sep,$chaine )===false) ; |
---|
609 | } |
---|
610 | return $chaine; |
---|
611 | } |
---|
612 | |
---|
613 | |
---|
614 | |
---|
615 | function kill_list() |
---|
616 | { |
---|
617 | //==================== TEST black_liste ============================================ |
---|
618 | global $pays,$region,$ville,$ip ; |
---|
619 | global $erreur_message,$infos_message,$conf; |
---|
620 | global $conf, $user, $page; |
---|
621 | global $mails_options ; |
---|
622 | global $superv_bl_champs,$superv_bl_type ; |
---|
623 | global $nb ; |
---|
624 | |
---|
625 | if (count($mails_options) < 7 ) return false ; |
---|
626 | |
---|
627 | $champs=implode(',',$superv_bl_champs); |
---|
628 | $query = " |
---|
629 | SELECT ".$champs.",COUNT(`ip`) as total |
---|
630 | FROM `".MAIL_BLACK_LISTE_TABLE."` |
---|
631 | WHERE '".$ip."' LIKE `ip` |
---|
632 | ;"; |
---|
633 | $result = @pwg_query($query); |
---|
634 | if (!$result) { |
---|
635 | vérif_base(); |
---|
636 | $result = @pwg_query($query); |
---|
637 | } |
---|
638 | $datas = mysql_fetch_array($result,MYSQL_ASSOC); |
---|
639 | $nb = $datas['total']; |
---|
640 | //======================================================================= |
---|
641 | |
---|
642 | if ($mails_options[set_auto] == 'on') |
---|
643 | { |
---|
644 | // $ip="94.102.63.13"; ' Spammeurs |
---|
645 | // $ip="94.102.63.15"; |
---|
646 | // $mail=matusowraber93813@gmail.com ; |
---|
647 | // $username=fretgpsolodens ; |
---|
648 | global $user_name,$mail_adresse; |
---|
649 | |
---|
650 | if (test_spam($ip,$user['username'] ,$user['email'])) |
---|
651 | { |
---|
652 | |
---|
653 | if ($nb==0) { |
---|
654 | $valeurs=array( 'NULL', |
---|
655 | "'".$ip."'", |
---|
656 | "'".$pays."'", |
---|
657 | "'".$region."'", |
---|
658 | "'".$ville."'", |
---|
659 | "'".$user['email']."'", |
---|
660 | "'".$user['username']."'", |
---|
661 | $nb+1 |
---|
662 | ); |
---|
663 | ajout_ligne(MAIL_BLACK_LISTE_TABLE,$superv_bl_champs, $valeurs,$nb==0) ; |
---|
664 | }else{ |
---|
665 | |
---|
666 | $nb +=1; |
---|
667 | |
---|
668 | $query =" |
---|
669 | UPDATE " . MAIL_BLACK_LISTE_TABLE . " |
---|
670 | SET "; |
---|
671 | if (isset($_POST['pays'])) |
---|
672 | $query .= " |
---|
673 | `pays` = '". $pays ."', |
---|
674 | `region` = '" . $region ."', |
---|
675 | `ville` = '" . $ville . "', |
---|
676 | |
---|
677 | "; |
---|
678 | |
---|
679 | $query .= " |
---|
680 | `adresse` = '".$user['email']."', |
---|
681 | `fai` = '".$user['username']."', |
---|
682 | `nb` = " . $nb . " |
---|
683 | WHERE '".$ip."' like `ip` |
---|
684 | "; |
---|
685 | |
---|
686 | pwg_query($query ); |
---|
687 | } |
---|
688 | $erreur_message .= $mails_options[ip] ." ".$user['username']." ".$user['email'] . ' -----> ' . l10n('black_list') ; |
---|
689 | // die($nb." ".$ip." ".$user['username']." ".$user['email']); |
---|
690 | return true ; |
---|
691 | |
---|
692 | } |
---|
693 | |
---|
694 | } |
---|
695 | //============================================================================== |
---|
696 | if ( $mails_options[ip] == $ip ) return ($nb > 0) ; |
---|
697 | $mails_options[ip] = $ip ; |
---|
698 | sauve_options(); |
---|
699 | |
---|
700 | if ( $nb > 0 ) |
---|
701 | { |
---|
702 | $query = " |
---|
703 | SELECT ".$champs.",COUNT(`id`) as total |
---|
704 | FROM `".MAIL_BLACK_LISTE_TABLE."` |
---|
705 | WHERE '".$ip."' = `ip` |
---|
706 | ;"; |
---|
707 | $result = @pwg_query($query); |
---|
708 | |
---|
709 | if (!$result) { |
---|
710 | vérif_base(); |
---|
711 | $result = @pwg_query($query); |
---|
712 | } |
---|
713 | $datas = mysql_fetch_array($result,MYSQL_ASSOC); |
---|
714 | $nb = $datas['total']; |
---|
715 | |
---|
716 | $row = mysql_fetch_row(pwg_query($query)); |
---|
717 | $nb = ($row[7]); |
---|
718 | $erreur_message .= $ip . ' | ' . $pays . ' | ' . $region . ' | ' . $ville . ' ' . $nb . ' ==> '; |
---|
719 | |
---|
720 | if ($nb == 0) |
---|
721 | { |
---|
722 | $valeurs=array( 'NULL', |
---|
723 | "'".$ip."'", |
---|
724 | "'".$pays."'", |
---|
725 | "'".$region."'", |
---|
726 | "'".$ville."'", |
---|
727 | "'".$user['email']."'", |
---|
728 | "'".$user['username']."'", |
---|
729 | 1 |
---|
730 | ); |
---|
731 | ajout_ligne(MAIL_BLACK_LISTE_TABLE,$superv_bl_champs, $valeurs,true) ; |
---|
732 | |
---|
733 | } else { |
---|
734 | $nb += 1; |
---|
735 | $query =" |
---|
736 | UPDATE " . MAIL_BLACK_LISTE_TABLE . " |
---|
737 | SET "; |
---|
738 | if (isset($_POST['pays'])) |
---|
739 | $query .= " |
---|
740 | `pays` = '". $pays ."', |
---|
741 | `region` = '" . $region ."', |
---|
742 | `ville` = '" . $ville . "', |
---|
743 | "; |
---|
744 | $query .= " |
---|
745 | `adresse` = '".$user['email']."', |
---|
746 | `fai` = '".$user['username']."', |
---|
747 | `nb` = " . $nb . " |
---|
748 | WHERE '".$ip."' = `ip` |
---|
749 | "; |
---|
750 | |
---|
751 | pwg_query($query ); |
---|
752 | } |
---|
753 | //================================================================================ |
---|
754 | |
---|
755 | } |
---|
756 | |
---|
757 | |
---|
758 | return ($nb > 0) ; |
---|
759 | } |
---|
760 | //===================================================================================== |
---|
761 | function test_spam($ip =0,$user_name ='', $mail_adresse = "") |
---|
762 | { |
---|
763 | $buffer=""; |
---|
764 | // fretgpsolodens |
---|
765 | $src = "http://www.stopforumspam.com/api?"; |
---|
766 | $type=array(); |
---|
767 | $result=""; |
---|
768 | if (strlen($ip)>3) { |
---|
769 | //================== Vérifie si l'IP est correct ================================ |
---|
770 | if (clj_is_ip($ip)){ |
---|
771 | |
---|
772 | } else { |
---|
773 | //================== Vérifie si l'adresse mail est correcte ================================ |
---|
774 | if( clj_is_mail($ip) ){ |
---|
775 | $mail_adresse=$ip ; |
---|
776 | $ip=""; |
---|
777 | } |
---|
778 | else |
---|
779 | { |
---|
780 | //================== Login ================ |
---|
781 | $user_name=$ip; |
---|
782 | $ip=""; |
---|
783 | } |
---|
784 | } |
---|
785 | //============================================================================= |
---|
786 | } |
---|
787 | |
---|
788 | $user_name=str_replace(" ","%20",trim($user_name)); |
---|
789 | if ($user_name==l10n('guest')) $user_name=""; |
---|
790 | $user_name=""; // ne plus tester sur le login. |
---|
791 | $mail_adresse =str_replace(" ","%20",trim($mail_adresse)); |
---|
792 | |
---|
793 | if ( strlen($user_name) > 3) $type[]="username=$user_name" ; |
---|
794 | if ( strlen($mail_adresse) > 3) $type[]="email=".$mail_adresse ; |
---|
795 | if ( strlen($ip) > 3) $type[]="ip=".$ip ; |
---|
796 | |
---|
797 | foreach ( $type as $fil ) |
---|
798 | { |
---|
799 | $resultat=""; |
---|
800 | if ( clj_fetchRemote($src.$fil , $resultat,1)) |
---|
801 | { |
---|
802 | $result .= $resultat.'<br />' ; |
---|
803 | } else { |
---|
804 | |
---|
805 | } |
---|
806 | } |
---|
807 | |
---|
808 | return !(strpos( $result ,'yes' ) === false) ; |
---|
809 | |
---|
810 | } |
---|
811 | //================================================================== |
---|
812 | function lire_fichier_distant($fichier) |
---|
813 | { |
---|
814 | $buffer=""; |
---|
815 | $handle = @fopen($fichier,"r"); |
---|
816 | if ($handle) { |
---|
817 | while (!feof($handle)) { |
---|
818 | $buffer .= fgets($handle, 4096); |
---|
819 | } |
---|
820 | fclose($handle); |
---|
821 | } |
---|
822 | |
---|
823 | return $buffer ; |
---|
824 | |
---|
825 | } |
---|
826 | //================================================ |
---|
827 | function clj_is_ip($ip) |
---|
828 | { |
---|
829 | 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 ; |
---|
830 | |
---|
831 | } |
---|
832 | |
---|
833 | function clj_is_mail($mail) |
---|
834 | { |
---|
835 | if(preg_match('/#^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,5}$#/' ,$mail)) return true ; |
---|
836 | } |
---|
837 | |
---|
838 | |
---|
839 | function clj_fetchRemote($src, &$dest, $timeout=1, $user_agent='Piwigo', $step=0) |
---|
840 | { |
---|
841 | // Try to retrieve data from local file? |
---|
842 | if (!url_is_remote($src)) |
---|
843 | { |
---|
844 | $content = @file_get_contents($src); |
---|
845 | if ($content !== false) |
---|
846 | { |
---|
847 | is_resource($dest) ? @fwrite($dest, $content) : $dest = $content; |
---|
848 | return true; |
---|
849 | } |
---|
850 | else |
---|
851 | { |
---|
852 | return false; |
---|
853 | } |
---|
854 | } |
---|
855 | |
---|
856 | // After 3 redirections, return false |
---|
857 | if ($step > 3) return false; |
---|
858 | |
---|
859 | // Initialize $dest |
---|
860 | is_resource($dest) or $dest = ''; |
---|
861 | |
---|
862 | // Try curl to read remote file |
---|
863 | if (function_exists('curl_init')) |
---|
864 | { |
---|
865 | $ch = @curl_init(); |
---|
866 | @curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
---|
867 | @curl_setopt($ch, CURLOPT_URL, $src); |
---|
868 | @curl_setopt($ch, CURLOPT_HEADER, 1); |
---|
869 | @curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); |
---|
870 | @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
---|
871 | $content = @curl_exec($ch); |
---|
872 | $header_length = @curl_getinfo($ch, CURLINFO_HEADER_SIZE); |
---|
873 | $status = @curl_getinfo($ch, CURLINFO_HTTP_CODE); |
---|
874 | @curl_close($content); |
---|
875 | if ($content !== false and $status >= 200 and $status < 400) |
---|
876 | { |
---|
877 | if (preg_match('/Location:\s+?(.+)/', substr($content, 0, $header_length), $m)) |
---|
878 | { |
---|
879 | return clj_fetchRemote($m[1], $dest,$timeout, $user_agent, $step+1); |
---|
880 | } |
---|
881 | $content = substr($content, $header_length); |
---|
882 | is_resource($dest) ? @fwrite($dest, $content) : $dest = $content; |
---|
883 | return true; |
---|
884 | } |
---|
885 | } |
---|
886 | |
---|
887 | // Try file_get_contents to read remote file |
---|
888 | if (ini_get('allow_url_fopen')) |
---|
889 | { |
---|
890 | |
---|
891 | $opts['http'] = array('timeout' => $timeout); |
---|
892 | $ctx = stream_context_create($opts); |
---|
893 | $content = @file_get_contents($src, 0, $ctx); |
---|
894 | if ($content !== false) |
---|
895 | { |
---|
896 | is_resource($dest) ? @fwrite($dest, $content) : $dest = $content; |
---|
897 | return true; |
---|
898 | } |
---|
899 | } |
---|
900 | |
---|
901 | return false; |
---|
902 | } |
---|
903 | |
---|
904 | |
---|
905 | ?> |
---|