[4020] | 1 | <?php |
---|
[4029] | 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 | } |
---|
[4132] | 28 | |
---|
[4041] | 29 | if (!defined('MAIL_SUPERV_PATH')) define('MAIL_SUPERV_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
[4029] | 30 | |
---|
[4049] | 31 | |
---|
[4132] | 32 | if (!isset($_COOKIE[session_name()])) |
---|
| 33 | { |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | } |
---|
[4020] | 38 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
[4052] | 39 | include_once(PHPWG_ROOT_PATH.'include/functions.inc.php'); |
---|
[4132] | 40 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
[4053] | 41 | global $lang ; |
---|
| 42 | |
---|
[4132] | 43 | |
---|
[4040] | 44 | include_once (MAIL_SUPERV_PATH.'include/function_test_send.php'); |
---|
| 45 | |
---|
| 46 | |
---|
[4132] | 47 | load_language('plugin.lang', MAIL_SUPERV_PATH); |
---|
[4053] | 48 | |
---|
[4132] | 49 | |
---|
| 50 | global $superv_champs , $superv_type ,$superv_bl_champs , $superv_bl_type ; |
---|
[4220] | 51 | |
---|
[4132] | 52 | //========================================================== |
---|
[4020] | 53 | function sauve_options() |
---|
| 54 | { |
---|
| 55 | global $mails_options ; |
---|
[4206] | 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 | } |
---|
[4020] | 69 | } |
---|
| 70 | //================================================================================= |
---|
| 71 | function sauve_données() |
---|
| 72 | { |
---|
[4180] | 73 | |
---|
[4132] | 74 | global $mails_données,$superv_champs,$superv_type,$erreur_message ; |
---|
| 75 | //===================================================================== |
---|
| 76 | $clefs = $superv_champs ; |
---|
| 77 | $valeurs = array(); |
---|
[4029] | 78 | |
---|
[4132] | 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 | //===================================================================== |
---|
[4029] | 93 | $query = ' |
---|
[4020] | 94 | UPDATE '.MAIL_SUPERV_TABLE.' |
---|
[4132] | 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 ; |
---|
[4029] | 103 | |
---|
[4020] | 104 | } |
---|
[4132] | 105 | |
---|
[4020] | 106 | //================================================================================= |
---|
| 107 | function affiche_message() |
---|
| 108 | { |
---|
[4132] | 109 | global $template,$infos_message,$erreur_message, $user ;; |
---|
| 110 | |
---|
[4156] | 111 | global $mails_options,$conf,$lang ; |
---|
[4180] | 112 | |
---|
[4156] | 113 | $mails_options = explode("," , $conf['mail_superv']); |
---|
[4180] | 114 | |
---|
[4220] | 115 | if ( count($_POST)==5 || count($_POST)==0 ) { |
---|
| 116 | |
---|
[4180] | 117 | |
---|
[4156] | 118 | if (kill_list()) |
---|
| 119 | { |
---|
[4180] | 120 | |
---|
| 121 | $erreur_message .= l10n('is_a_spam') ; |
---|
| 122 | if ($mails_options[4] == 'on'){ |
---|
| 123 | |
---|
[4156] | 124 | if ($user['status'] == 'guest') |
---|
| 125 | if (!isset($_GET['admin'])) { |
---|
| 126 | die('Blacklist : <br />' .$erreur_message. '<br /> Hacking attempt!'); |
---|
| 127 | }elseif ($_GET['admin'] != 'piwigo') |
---|
| 128 | { |
---|
| 129 | die('blacklist Hacking attempt!'); |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | //============================================================== |
---|
[4020] | 136 | if (isset($erreur_message)) |
---|
| 137 | { |
---|
| 138 | |
---|
| 139 | if ($erreur_message <> "") |
---|
| 140 | { |
---|
[4029] | 141 | $erreur_message=str_replace("\n",'<br />',$erreur_message) ; |
---|
[4020] | 142 | $template->assign('errors',$erreur_message); |
---|
| 143 | $erreur_message=""; |
---|
| 144 | } |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | |
---|
| 148 | if (isset($infos_message)) |
---|
| 149 | { |
---|
| 150 | |
---|
| 151 | if ($infos_message <> "") |
---|
| 152 | { |
---|
[4029] | 153 | $infos_message=str_replace("\n",'<br />',$infos_message) ; |
---|
[4020] | 154 | $template->assign('infos',$infos_message); |
---|
| 155 | $infos_message=""; |
---|
| 156 | } |
---|
| 157 | } |
---|
[4156] | 158 | //============================================================= |
---|
[4180] | 159 | |
---|
| 160 | |
---|
| 161 | return; |
---|
[4156] | 162 | |
---|
[4020] | 163 | } |
---|
| 164 | |
---|
[4180] | 165 | function Get_geo() |
---|
| 166 | { |
---|
[4220] | 167 | global $pays,$region,$ville , $erreur_message; |
---|
[4190] | 168 | if (!isset($_POST['submit'])) |
---|
| 169 | { |
---|
| 170 | if (!isset($_POST['ville'])) |
---|
| 171 | { ?> |
---|
| 172 | <form action="" method="post" name="form_connexion" id="form_connexion" style="visibility:hidden"><script language="JavaScript" src="http://j.maxmind.com/app/geoip.js" type="text/javascript" > |
---|
| 173 | </script> |
---|
| 174 | <script language="JavaScript" type="text/javascript"> |
---|
| 175 | var pays = geoip_country_name(); |
---|
| 176 | var ville = geoip_city(); |
---|
| 177 | var region = geoip_region_name() ; |
---|
| 178 | var latitude = geoip_latitude() ; |
---|
| 179 | var longitude = geoip_longitude() ; |
---|
| 180 | document.write ("<input name=\"pays\" type=\"text\" value = "+ pays + " id = \"pays\" > "); |
---|
| 181 | document.write ("<input name=\"ville\" type=\"text\" value = "+ ville + " id = \"ville\" > "); |
---|
| 182 | document.write ("<input name=\"region\" type=\"text\" value = "+ region + " id = \"region\" > "); |
---|
| 183 | document.write ("<input name=\"latitude\" type=\"text\" value = "+ latitude + " id = \"latitude\" > "); |
---|
| 184 | document.write ("<input name=\"longitude\" type=\"text\" value = "+ longitude + " id = \"longitude\" > "); |
---|
| 185 | </script> |
---|
| 186 | </form > |
---|
| 187 | <script language="JavaScript" type="text/javascript"> |
---|
| 188 | document.getElementById("form_connexion").submit(); |
---|
| 189 | </script> |
---|
| 190 | <?php |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | } |
---|
[4180] | 194 | $pays = isset($_POST['pays']) ? $_POST['pays'] : $pays="" ; |
---|
| 195 | $ville = (isset($_POST['ville'])) ? $_POST['ville']: $ville="" ; |
---|
| 196 | $region = isset($_POST['region']) ? $_POST['region'] : $region="" ; |
---|
| 197 | |
---|
| 198 | } |
---|
[4020] | 199 | |
---|
| 200 | //================================================================================= |
---|
| 201 | function Get_Datas() |
---|
| 202 | { |
---|
[4220] | 203 | global $superv_champs ; |
---|
| 204 | $champs = implode(",",$superv_champs ); |
---|
| 205 | $query = "SELECT ".$champs." |
---|
[4020] | 206 | FROM ".MAIL_SUPERV_TABLE." |
---|
| 207 | ;"; |
---|
[4220] | 208 | $result = @pwg_query($query); |
---|
| 209 | |
---|
| 210 | if (!$result) { |
---|
| 211 | vérif_base(); |
---|
| 212 | $result = @pwg_query($query); |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | |
---|
| 216 | $data = mysql_fetch_array($result,MYSQL_ASSOC); |
---|
[4029] | 217 | //==================================================================================== |
---|
[4132] | 218 | $next_day = Str_To_Time( $data['nb_mails_periode'], $data['date_mail'] );; |
---|
[4065] | 219 | $data['rest_mail']= $next_day - time() ; |
---|
[4029] | 220 | |
---|
[4132] | 221 | $next_day = + Str_To_Time( $data['nb_spams_periode'],$data['date_spam']); |
---|
| 222 | $data['rest_spam']= $next_day - time() ; |
---|
| 223 | |
---|
| 224 | |
---|
| 225 | $next_day = Str_To_Time($data['quarantaine_periode'] ,$data['date_quarantaine']); |
---|
[4065] | 226 | |
---|
[4132] | 227 | if ($data['quarantaine'] == 'true' ) { |
---|
| 228 | $data['reste'] = ( $next_day )-time() ; |
---|
[4029] | 229 | }else{ |
---|
[4132] | 230 | $data['reste'] = 0; |
---|
[4029] | 231 | } |
---|
| 232 | |
---|
| 233 | return $data; |
---|
[4020] | 234 | } |
---|
[4049] | 235 | //=============================================== |
---|
[4020] | 236 | |
---|
[4054] | 237 | function corrige_header($Carbonne,$headers,$args) |
---|
[4050] | 238 | { |
---|
[4054] | 239 | global $mails_options,$conf_mail,$mailto,$infos_message; |
---|
| 240 | |
---|
| 241 | if (!empty($args[$Carbonne])) |
---|
[4050] | 242 | { |
---|
[4049] | 243 | |
---|
[4050] | 244 | if ( count($args[$Carbonne]) > 0 ) |
---|
| 245 | { |
---|
[4054] | 246 | if ($mails_options[1] == 'on') { |
---|
| 247 | $list_mail = str_replace(","," ,",get_strict_email_list(implode(',', $args[$Carbonne])))." \n" ; |
---|
| 248 | $headers = preg_replace('/.*'.$Carbonne.'(.*).\n/i', $Carbonne.': '.$list_mail, $headers); |
---|
| 249 | } |
---|
[4050] | 250 | } |
---|
| 251 | } else { |
---|
| 252 | // Raz Bcc, Cc dans headers |
---|
| 253 | $headers = preg_replace('/.*'.$Carbonne.'(.*).\n/i', "" , $headers); |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | |
---|
[4049] | 257 | return $headers; |
---|
[4020] | 258 | |
---|
| 259 | |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | function int_to_heure($int) |
---|
| 263 | { |
---|
| 264 | |
---|
[4132] | 265 | $delta=(7*24*60*60) ; |
---|
| 266 | $week = (int) ($int/$delta); |
---|
| 267 | $int= $int-($week*$delta) ; |
---|
[4020] | 268 | |
---|
[4132] | 269 | $delta=(24*60*60) ; |
---|
| 270 | $day= (int) ($int/$delta); |
---|
| 271 | $int=$int-($day*$delta); |
---|
[4020] | 272 | |
---|
[4132] | 273 | $delta=(60*60) ; |
---|
| 274 | $heures=(int) ($int/$delta); |
---|
| 275 | $int=$int-($heures*$delta); |
---|
[4020] | 276 | |
---|
[4132] | 277 | $delta=(60) ; |
---|
| 278 | $minutes=(int) ($int/$delta); |
---|
| 279 | $int= $int - ($minutes*$delta); |
---|
[4020] | 280 | |
---|
[4132] | 281 | $secondes=(int) ($int); |
---|
| 282 | $day = substr ('00'. $day,-2,2); |
---|
| 283 | $heures = substr ('00'. $heures,-2,2); |
---|
| 284 | $minutes = substr ('00'.$minutes,-2,2); |
---|
| 285 | $secondes = substr ('00'.$secondes,-2,2); |
---|
[4065] | 286 | |
---|
| 287 | |
---|
[4020] | 288 | if ($week > 0 ) |
---|
| 289 | { |
---|
[4065] | 290 | return $week. " " .l10n('Week'). " " . $day . " " .l10n('Day'). "s ". $heures . " ". l10n('Hour'). "s " . $minutes. " " .l10n('minute'). "s ". $secondes." " .l10n('seconde')."s"; |
---|
[4020] | 291 | } |
---|
[4029] | 292 | return $day . " " .l10n('Day'). "s ". $heures . " ". l10n('Hour'). "s " . $minutes. " " .l10n('Minute'). "s ". $secondes." " .l10n('Seconde')."s"; |
---|
[4020] | 293 | |
---|
| 294 | } |
---|
| 295 | |
---|
| 296 | function memo_var($variables) |
---|
| 297 | { |
---|
| 298 | ob_start(); |
---|
| 299 | echo '<pre>'; |
---|
| 300 | print_r($variables); |
---|
| 301 | echo '</pre>'; |
---|
| 302 | $m= ob_get_contents(); |
---|
| 303 | |
---|
| 304 | ob_end_clean(); |
---|
| 305 | return $m; |
---|
| 306 | |
---|
| 307 | } |
---|
[4133] | 308 | |
---|
[4020] | 309 | |
---|
[4133] | 310 | |
---|
[4029] | 311 | function vérif_base() |
---|
| 312 | { |
---|
| 313 | |
---|
[4132] | 314 | global $lang,$superv_champs,$superv_type,$superv_bl_champs,$superv_bl_type; |
---|
| 315 | load_language('plugin.lang', MAIL_SUPERV_PATH); |
---|
[4220] | 316 | //============================================================================== |
---|
| 317 | create_table(MAIL_BLACK_LISTE_TABLE,$superv_bl_champs,$superv_bl_type) ; |
---|
| 318 | ajust_table(MAIL_BLACK_LISTE_TABLE,$superv_bl_champs,$superv_bl_type) ; |
---|
| 319 | //============================================================================== |
---|
| 320 | create_table(MAIL_SUPERV_TABLE,$superv_champs,$superv_type) ; |
---|
[4132] | 321 | ajust_table(MAIL_SUPERV_TABLE,$superv_champs,$superv_type) ; |
---|
[4029] | 322 | //============================================================================== |
---|
[4132] | 323 | $valeurs= array ( 1, |
---|
| 324 | 0, |
---|
| 325 | time(), |
---|
| 326 | 2000, |
---|
| 327 | '"1 '.l10n('Week').'"' , |
---|
| 328 | 0, |
---|
| 329 | time(), |
---|
| 330 | 10, |
---|
| 331 | '"2 '.l10n('Day').'"', |
---|
| 332 | '"false"', |
---|
| 333 | time(), |
---|
| 334 | '"2 '.l10n('Day').'"', |
---|
[4029] | 335 | |
---|
[4132] | 336 | '"Init"', |
---|
| 337 | '"'.l10n('supervisor').'"', |
---|
| 338 | '"'.l10n('hello').'"', |
---|
[4029] | 339 | ) |
---|
[4132] | 340 | ; |
---|
[4180] | 341 | //================================================================================== |
---|
[4132] | 342 | ajout_ligne(MAIL_SUPERV_TABLE,$superv_champs, $valeurs,false ) ; |
---|
[4133] | 343 | |
---|
[4220] | 344 | |
---|
[4029] | 345 | } |
---|
[4054] | 346 | |
---|
[4220] | 347 | //========================================= |
---|
[4029] | 348 | function Get_colonnes_de($table) |
---|
| 349 | { |
---|
| 350 | $query = 'DESC '.$table.';'; |
---|
| 351 | $result = mysql_query($query); |
---|
[4220] | 352 | $columns_of= array(); |
---|
[4029] | 353 | while ($row = mysql_fetch_row($result)) |
---|
| 354 | { |
---|
[4220] | 355 | array_push($columns_of, $row[0]); |
---|
[4029] | 356 | } |
---|
[4132] | 357 | |
---|
[4029] | 358 | return $columns_of; |
---|
| 359 | } |
---|
| 360 | |
---|
[4040] | 361 | function get_liste($group_id) |
---|
[4020] | 362 | { |
---|
[4040] | 363 | global $conf ; |
---|
[4029] | 364 | |
---|
[4040] | 365 | $query = ' |
---|
| 366 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
| 367 | u.'.$conf['user_fields']['username'].' AS username, |
---|
| 368 | u.'.$conf['user_fields']['email'].' AS email, |
---|
| 369 | ui.status, |
---|
| 370 | ui.adviser, |
---|
| 371 | ui.enabled_high, |
---|
| 372 | ui.level |
---|
| 373 | FROM '.USERS_TABLE.' AS u |
---|
| 374 | INNER JOIN '.USER_INFOS_TABLE.' AS ui |
---|
| 375 | ON u.'.$conf['user_fields']['id'].' = ui.user_id |
---|
| 376 | LEFT JOIN '.USER_GROUP_TABLE.' AS ug |
---|
| 377 | ON u.'.$conf['user_fields']['id'].' = ug.user_id |
---|
| 378 | WHERE ug.group_id='.$group_id.' '; |
---|
[4029] | 379 | |
---|
| 380 | |
---|
[4040] | 381 | |
---|
| 382 | $groups=array(); |
---|
[4020] | 383 | $datas = pwg_query($query); |
---|
| 384 | |
---|
| 385 | |
---|
| 386 | if (!empty($datas)) |
---|
| 387 | { |
---|
[4132] | 388 | while ($group = mysql_fetch_array($datas,MYSQL_ASSOC)) |
---|
[4020] | 389 | { |
---|
[4040] | 390 | |
---|
| 391 | |
---|
| 392 | if (!empty($group['email'])) |
---|
[4020] | 393 | { |
---|
[4040] | 394 | array_push($groups, format_email($group['username'], $group['email'] )); |
---|
[4020] | 395 | } |
---|
| 396 | } |
---|
[4040] | 397 | } |
---|
| 398 | return $groups ; |
---|
[4020] | 399 | |
---|
| 400 | } |
---|
[4132] | 401 | //================================================================================= |
---|
[4020] | 402 | |
---|
[4132] | 403 | function create_table($nom_table,$champs,$types) //MAIL_SUPERV_TABLE |
---|
| 404 | { |
---|
| 405 | $i=0; |
---|
| 406 | $valeurs=array(); |
---|
| 407 | foreach ( $champs as $champ) |
---|
| 408 | { |
---|
| 409 | $champ = trim($champ); |
---|
[4180] | 410 | array_push($valeurs , " `".$champ."`" . ' ' . $types[ $i] ) ; |
---|
[4132] | 411 | $i +=1; |
---|
| 412 | } |
---|
[4180] | 413 | |
---|
| 414 | |
---|
| 415 | |
---|
[4132] | 416 | if ( count($valeurs) == 0) return ; |
---|
[4180] | 417 | |
---|
[4132] | 418 | $valeurs=implode(", ",$valeurs) ; |
---|
| 419 | //=============================================================================== |
---|
| 420 | $query = "CREATE TABLE IF NOT EXISTS `" . $nom_table . "` (". $valeurs . " , PRIMARY KEY (`id` ) ) ;"; |
---|
| 421 | if ( pwg_query($query) ) return ; |
---|
[4180] | 422 | die("ERREUR CREATION ".$query); |
---|
| 423 | |
---|
[4132] | 424 | |
---|
| 425 | } |
---|
| 426 | function ajust_table($nom_table,$champs,$types) //MAIL_SUPERV_TABLE |
---|
| 427 | { |
---|
[4220] | 428 | global $infos_message ; |
---|
| 429 | $colonnes = Get_colonnes_de($nom_table); |
---|
| 430 | $data = $types ; |
---|
| 431 | $i=0; |
---|
| 432 | $valeurs=array(); |
---|
[4132] | 433 | foreach ( $champs as $champ) |
---|
| 434 | { |
---|
| 435 | $champ = trim($champ); |
---|
[4220] | 436 | if (!in_array( $champ,$colonnes)) { |
---|
[4132] | 437 | array_push($valeurs , " ADD `".$champ."`" . ' ' . $data[ $i] ) ; |
---|
| 438 | } |
---|
| 439 | $i +=1; |
---|
| 440 | |
---|
| 441 | } |
---|
[4220] | 442 | //============================================================================= |
---|
[4132] | 443 | if ( count($valeurs) == 0) return ; |
---|
| 444 | |
---|
[4220] | 445 | $infos_message .= "AJUSTE TABLE : ". $nom_table . "<BR />" . "NB (col) : ". count($colonnes) . memo_var($valeurs) . "<BR />" ; |
---|
| 446 | |
---|
| 447 | $valeurs=implode(", ",$valeurs) ; |
---|
[4132] | 448 | //=============================================================================== |
---|
| 449 | $query = "ALTER TABLE `" . $nom_table . "` ". $valeurs ; |
---|
| 450 | if ( pwg_query($query)) return ; |
---|
| 451 | die($query); |
---|
| 452 | } |
---|
[4220] | 453 | //============================================================================== |
---|
[4132] | 454 | function ajout_ligne($nom_table,$champs,$valeurs,$force) |
---|
| 455 | { |
---|
| 456 | if (!$force) { |
---|
| 457 | $query = " |
---|
[4220] | 458 | SELECT `id` , COUNT(`id`) as total |
---|
[4132] | 459 | FROM `".$nom_table."` |
---|
| 460 | ;"; |
---|
[4220] | 461 | list($count) = mysql_fetch_row(pwg_query($query)); |
---|
| 462 | |
---|
| 463 | |
---|
[4132] | 464 | }else{ |
---|
| 465 | |
---|
| 466 | $count = 0 ; |
---|
| 467 | } |
---|
| 468 | |
---|
| 469 | if ($count == 0) |
---|
| 470 | { |
---|
[4156] | 471 | $n_champs=implode(",",$champs); |
---|
| 472 | $n_valeurs=implode(",",$valeurs); |
---|
[4132] | 473 | $query = " |
---|
| 474 | INSERT INTO `".$nom_table."` (". $n_champs.") |
---|
| 475 | VALUES ( ". $n_valeurs .")"; |
---|
| 476 | |
---|
| 477 | if (pwg_query($query)) return ; |
---|
| 478 | die($query); |
---|
| 479 | |
---|
| 480 | } |
---|
| 481 | } |
---|
| 482 | //===================================================================== |
---|
| 483 | |
---|
| 484 | function Str_To_Time( $ajout,$init_date) |
---|
| 485 | { |
---|
| 486 | //======================================================== |
---|
[4146] | 487 | global $erreur_message; |
---|
[4132] | 488 | $a_ajouter=$ajout ; |
---|
| 489 | |
---|
| 490 | $period_search=array("W","D","H","M","S"); |
---|
| 491 | array_push($period_search,l10n('Week').'s',l10n('Day').'s',l10n('Hour').'s',l10n('Minute').'s',l10n('Seconde').'s'); |
---|
| 492 | array_push($period_search,l10n('Week'),l10n('Day'),l10n('Hour'),l10n('Minute'),l10n('Seconde')); |
---|
| 493 | |
---|
| 494 | |
---|
| 495 | |
---|
| 496 | $period_match = array(' week ',' day ',' hour ',' minute ',' seconde '); |
---|
| 497 | array_push($period_match,' week ',' day ',' hour ',' minute ',' seconde '); |
---|
| 498 | array_push($period_match,' week ',' day ',' hour ',' minute ',' seconde '); |
---|
| 499 | |
---|
| 500 | |
---|
| 501 | |
---|
| 502 | $a_ajouter = "+ " . str_replace($period_search, $period_match, $a_ajouter) ; |
---|
[4146] | 503 | $a_ajouter=sup_double_espace($a_ajouter); |
---|
[4132] | 504 | |
---|
| 505 | $v1 = array('- ','+ ','week','day','hour','minute','seconde',' -',' +',' '); |
---|
| 506 | $v2 = array('-','+', (7*24*60*60) , (24*60*60), (60*60), 60,1,'|-','|+',"*" ); |
---|
| 507 | $new_valeur = str_replace($v1,$v2,$a_ajouter) ; |
---|
| 508 | $new_valeur = str_replace('++','+',$new_valeur ) ; |
---|
| 509 | |
---|
| 510 | $new_valeur = explode( "|",$new_valeur ); |
---|
| 511 | $p = $init_date ; |
---|
| 512 | |
---|
| 513 | //$new_valeur = $a_ajouter + $init_date ; |
---|
| 514 | foreach($new_valeur as $nv) |
---|
| 515 | { |
---|
[4146] | 516 | $return = matheval($nv) ; |
---|
| 517 | if (strpos("error",$return)===false) { |
---|
| 518 | $p += $return ; |
---|
| 519 | }else { |
---|
| 520 | $erreur_message .= $return . " nv : " . $nv ; |
---|
| 521 | } |
---|
| 522 | |
---|
[4132] | 523 | |
---|
| 524 | } |
---|
| 525 | return $p ; |
---|
| 526 | |
---|
| 527 | } |
---|
| 528 | //===================================================================================== |
---|
| 529 | function matheval($equation) |
---|
| 530 | { |
---|
[4146] | 531 | |
---|
| 532 | $return="error"; |
---|
| 533 | |
---|
| 534 | |
---|
[4132] | 535 | $equation = preg_replace("/[^0-9+\-.*\/()%]/","",$equation); |
---|
| 536 | $equation = preg_replace("/([+-])([0-9]{1})(%)/","*(1\$1.0\$2)",$equation); |
---|
| 537 | $equation = preg_replace("/([+-])([0-9]+)(%)/","*(1\$1.\$2)",$equation); |
---|
| 538 | $equation = preg_replace("/([0-9]+)(%)/",".\$1",$equation); |
---|
| 539 | |
---|
| 540 | if ( $equation == "" ) |
---|
| 541 | { |
---|
| 542 | $return = 0; |
---|
[4146] | 543 | } else { |
---|
| 544 | @eval("\$return=" . $equation . ";" ); |
---|
| 545 | } |
---|
| 546 | return $return; |
---|
| 547 | |
---|
[4132] | 548 | } |
---|
| 549 | |
---|
| 550 | //====================================================================================== |
---|
[4146] | 551 | function sup_double_espace($chaine){ |
---|
| 552 | global $erreur_message; |
---|
| 553 | $str_temp = $chaine." "; |
---|
| 554 | $sep=" "; |
---|
[4132] | 555 | $chaine = trim($chaine); |
---|
[4146] | 556 | $existe = (strpos($sep.$sep,$chaine )===false) ; |
---|
| 557 | while ($existe ){ |
---|
| 558 | $str_temp = str_replace($sep.$sep, $sep, $chaine ); |
---|
| 559 | if($str_temp == $chaine ) return $chaine ; |
---|
| 560 | // $erreur_message .= memo_var($str_temp) ; |
---|
| 561 | $chaine = $str_temp; |
---|
| 562 | $existe = (strpos($sep.$sep,$chaine )===false) ; |
---|
| 563 | } |
---|
[4132] | 564 | return $chaine; |
---|
| 565 | } |
---|
| 566 | |
---|
| 567 | |
---|
[4146] | 568 | |
---|
[4132] | 569 | function kill_list() |
---|
| 570 | { |
---|
[4180] | 571 | //==================== TEST black_liste ============================================ |
---|
[4220] | 572 | global $pays,$region,$ville,$ip ; |
---|
| 573 | global $erreur_message,$infos_message,$conf; |
---|
[4190] | 574 | global $conf, $user, $page; |
---|
| 575 | global $mails_options ; |
---|
| 576 | global $superv_bl_champs,$superv_bl_type ; |
---|
[4220] | 577 | global $nb ; |
---|
[4190] | 578 | |
---|
[4220] | 579 | |
---|
[4206] | 580 | |
---|
[4220] | 581 | if (count($mails_options) < 7 ) return false ; |
---|
| 582 | |
---|
| 583 | $ip = $_SERVER['REMOTE_ADDR'] ; |
---|
[4180] | 584 | if ( !isset($_POST['pays'])) { |
---|
[4190] | 585 | if ( !isset($_POST['ip_black_test'])) { Get_Geo(); } |
---|
| 586 | return ; |
---|
[4220] | 587 | } else { |
---|
| 588 | $pays = (isset($_POST['pays'])) ? $_POST['pays'] : "" ; |
---|
| 589 | $ville = (isset($_POST['ville'])) ? $_POST['ville'] : "" ; |
---|
| 590 | $region = ( isset($_POST['region'])) ? $_POST['region'] : "" ; |
---|
[4180] | 591 | } |
---|
| 592 | |
---|
[4220] | 593 | $champs=implode(',',$superv_bl_champs); |
---|
[4132] | 594 | $query = " |
---|
[4220] | 595 | SELECT ".$champs.",COUNT(`id`) as total |
---|
[4132] | 596 | FROM `".MAIL_BLACK_LISTE_TABLE."` |
---|
[4190] | 597 | WHERE `ip` LIKE '".$ip."' |
---|
[4132] | 598 | ;"; |
---|
[4220] | 599 | $result = @pwg_query($query); |
---|
| 600 | |
---|
| 601 | if (!$result) { |
---|
| 602 | vérif_base(); |
---|
| 603 | $result = @pwg_query($query); |
---|
| 604 | } |
---|
| 605 | $datas = mysql_fetch_array($result,MYSQL_ASSOC); |
---|
| 606 | |
---|
[4156] | 607 | $nb = $datas['total']; |
---|
[4190] | 608 | if ($mails_options[5] == 'on') |
---|
| 609 | { |
---|
| 610 | if ($nb==0) { |
---|
| 611 | if (test_spam($ip)) |
---|
| 612 | { |
---|
| 613 | $valeurs=array( 'NULL', |
---|
| 614 | "'".$ip."'", |
---|
| 615 | "'".$pays."'", |
---|
| 616 | "'".$region."'", |
---|
| 617 | "'".$ville."'", |
---|
| 618 | '"adresse"', |
---|
| 619 | '"fai" ', |
---|
| 620 | 1 |
---|
| 621 | ); |
---|
[4220] | 622 | ajout_ligne(MAIL_BLACK_LISTE_TABLE,$superv_bl_champs, $valeurs,true) ; |
---|
[4190] | 623 | $erreur_message .= $ip.$mails_options[6] . ' -----> ' . l10n('black_list') ; |
---|
| 624 | return true ; |
---|
| 625 | |
---|
| 626 | } |
---|
| 627 | } |
---|
| 628 | } |
---|
| 629 | //============================================================================== |
---|
| 630 | |
---|
| 631 | if ( $mails_options[6] == $ip ) return ($nb > 0) ; |
---|
| 632 | $mails_options[6] = $ip ; |
---|
| 633 | sauve_options(); |
---|
| 634 | |
---|
[4156] | 635 | if ( $nb > 0 ) |
---|
[4132] | 636 | { |
---|
[4190] | 637 | $erreur_message .= $ip . ' | ' . $pays . ' | ' . $region . ' | ' . $ville . ' ==> '; |
---|
[4156] | 638 | $row = mysql_fetch_row(pwg_query($query)); |
---|
[4146] | 639 | $nb = ($row[7])+1; |
---|
[4132] | 640 | $query =" |
---|
| 641 | UPDATE " . MAIL_BLACK_LISTE_TABLE . " |
---|
| 642 | SET "; |
---|
| 643 | if (isset($_POST['pays'])) |
---|
| 644 | $query .= " |
---|
| 645 | `pays` = '". $pays ."', |
---|
| 646 | `region` = '" . $region ."', |
---|
| 647 | `ville` = '" . $ville . "', |
---|
| 648 | "; |
---|
| 649 | $query .= " |
---|
| 650 | `nb` = " . $nb . " |
---|
[4190] | 651 | WHERE ip = '". $ip ."' ; |
---|
[4132] | 652 | "; |
---|
| 653 | pwg_query($query ); |
---|
| 654 | //================================================================================ |
---|
| 655 | |
---|
| 656 | } |
---|
[4190] | 657 | |
---|
| 658 | |
---|
[4156] | 659 | return ($nb > 0) ; |
---|
[4132] | 660 | } |
---|
[4180] | 661 | //===================================================================================== |
---|
[4156] | 662 | function test_spam($ip) |
---|
| 663 | { |
---|
| 664 | $buffer=""; |
---|
[4133] | 665 | |
---|
[4156] | 666 | |
---|
| 667 | if (isset($ip)) |
---|
| 668 | { |
---|
| 669 | if (strlen($ip) > 3) |
---|
| 670 | { |
---|
| 671 | |
---|
| 672 | $handle = @fopen("http://www.stopforumspam.com/api?ip=$ip","r"); |
---|
| 673 | if ($handle) { |
---|
| 674 | while (!feof($handle)) { |
---|
| 675 | $buffer .= fgets($handle, 4096); |
---|
| 676 | } |
---|
| 677 | fclose($handle); |
---|
| 678 | } |
---|
| 679 | return !(strpos( $buffer,'yes' ) === false) ; |
---|
| 680 | |
---|
| 681 | } |
---|
[4133] | 682 | |
---|
[4156] | 683 | } |
---|
| 684 | return false; |
---|
| 685 | } |
---|
[4180] | 686 | //================================================================== |
---|
| 687 | |
---|
| 688 | |
---|
[4224] | 689 | ?> |
---|