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