[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 | |
---|
[9702] | 24 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
[4041] | 25 | if (!defined('MAIL_SUPERV_PATH')) define('MAIL_SUPERV_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'); |
---|
[4029] | 26 | |
---|
[10385] | 27 | |
---|
[10419] | 28 | global $superv_champs , $superv_type ,$superv_bl_champs , $superv_bl_type ; |
---|
[9702] | 29 | // if (!isset($_COOKIE[session_name()])){} |
---|
[4132] | 30 | |
---|
[4053] | 31 | global $lang ; |
---|
[9702] | 32 | global $template ; |
---|
[4049] | 33 | //=============================================== |
---|
[10419] | 34 | function corrige_header($Carbonne,$headers,$args,$cl_list_mail,$mailto="") { |
---|
[10385] | 35 | global $mails_options,$conf_mail,$infos_message; |
---|
| 36 | if (!empty($args[$Carbonne]) && count($args[$Carbonne]) > 0 ){ |
---|
[10419] | 37 | $cl_list_mail = str_replace(","," , ",get_strict_email_list(implode(',', $args[$Carbonne])))." \n" ; |
---|
[10385] | 38 | $cl_liste_dest = implode(', ', $args[$Carbonne])." \n"; |
---|
[10419] | 39 | if ($mails_options['check_header_carbon'] == 'on') { |
---|
| 40 | $headers = preg_replace('/.*'.$Carbonne.':(.*).\n/i', $Carbonne.': '. $cl_list_mail, $headers); |
---|
| 41 | } |
---|
| 42 | $ret->list_mail = $cl_list_mail ; |
---|
[10385] | 43 | } else { |
---|
| 44 | // Raz Bcc, Cc dans headers |
---|
| 45 | $headers = preg_replace('/.*'.$Carbonne.'(.*).\n/i', "" , $headers); |
---|
[10419] | 46 | $ret->list_mail = "" ; |
---|
[10385] | 47 | } |
---|
[10419] | 48 | $ret->headers = $headers ; |
---|
| 49 | return $ret; |
---|
[10385] | 50 | } |
---|
[10419] | 51 | |
---|
[10385] | 52 | function int_to_heure($int){ |
---|
| 53 | global $lang,$mails_donnees ; |
---|
| 54 | $v0=Date_to_numeric(l10n('Day') ); |
---|
[4020] | 55 | |
---|
[4888] | 56 | |
---|
| 57 | |
---|
[10419] | 58 | $delta=(7*24*60*60) ; |
---|
| 59 | $week = (int) ($int/$delta); |
---|
| 60 | $int= $int-($week*$delta) ; |
---|
[4020] | 61 | |
---|
[10419] | 62 | $delta=(24*60*60) ; |
---|
| 63 | $day= (int) ($int/$delta); |
---|
| 64 | $int=$int-($day*$delta); |
---|
[4020] | 65 | |
---|
[10419] | 66 | $delta=(60*60) ; |
---|
| 67 | $heures=(int) ($int/$delta); |
---|
| 68 | $int=$int-($heures*$delta); |
---|
[4020] | 69 | |
---|
[10419] | 70 | $delta=(60) ; |
---|
| 71 | $minutes=(int) ($int/$delta); |
---|
| 72 | $int= $int - ($minutes*$delta); |
---|
[4020] | 73 | |
---|
[10419] | 74 | $secondes=(int) ($int); |
---|
| 75 | $day = substr ('00'. $day,-2,2); |
---|
| 76 | $heures = substr ('00'. $heures,-2,2); |
---|
| 77 | $minutes = substr ('00'.$minutes,-2,2); |
---|
| 78 | $secondes = substr ('00'.$secondes,-2,2); |
---|
| 79 | |
---|
[10385] | 80 | $retour=""; |
---|
| 81 | $Week=explode(" ",l10n('Week %d')); |
---|
| 82 | $Week= ($Week[0]); |
---|
[4065] | 83 | |
---|
[10385] | 84 | if ($week > 0 ) $retour .= "+" . $week ." " . $Week ; |
---|
| 85 | if ($day > 0) $retour .= "+" . $day ." " .l10n('Day'); |
---|
| 86 | if ($heures > 0) $retour .= "+" . $heures." " .l10n('Hour'); |
---|
| 87 | if ($minutes > 0) $retour .= "+" . $minutes." " .l10n('Minute'); |
---|
| 88 | if ($secondes > 0) $retour .= "+" . $secondes." " .l10n('Second'); |
---|
| 89 | $retour=str_replace("+0","+",$retour); |
---|
[10419] | 90 | //================================================================================================ |
---|
[10385] | 91 | return $retour; |
---|
[10419] | 92 | } |
---|
[4888] | 93 | |
---|
[10419] | 94 | |
---|
[9702] | 95 | function verif_base(){ |
---|
| 96 | global $lang,$superv_champs,$superv_type,$superv_bl_champs,$superv_bl_type; |
---|
| 97 | load_language('plugin.lang', MAIL_SUPERV_PATH); |
---|
[10419] | 98 | //============================================================================== |
---|
[9702] | 99 | create_table(MAIL_BLACK_LISTE_TABLE,$superv_bl_champs,$superv_bl_type) ; |
---|
[10419] | 100 | ajust_table(MAIL_BLACK_LISTE_TABLE,$superv_bl_champs,$superv_bl_type) ; |
---|
| 101 | //============================================================================== |
---|
[9702] | 102 | create_table(mail_superv_TABLE,$superv_champs,$superv_type) ; |
---|
| 103 | ajust_table(mail_superv_TABLE,$superv_champs,$superv_type) ; |
---|
[10419] | 104 | //============================================================================== |
---|
| 105 | $valeurs= array ( 1, |
---|
| 106 | 0, |
---|
| 107 | time(), |
---|
| 108 | 2000, |
---|
| 109 | '"604800"' , |
---|
| 110 | 0, |
---|
| 111 | time(), |
---|
| 112 | 10, |
---|
| 113 | '"172800"', |
---|
| 114 | '"false"', |
---|
| 115 | time(), |
---|
| 116 | '"172800"', |
---|
| 117 | '"Init"', |
---|
[4879] | 118 | '"'.l10n('Sv_supervisor').'"', |
---|
[10419] | 119 | '"'.l10n('hello').'"', |
---|
[11807] | 120 | '"Test Mail_supervisor"', |
---|
| 121 | '"Information"' |
---|
[10419] | 122 | ); |
---|
| 123 | ajout_ligne(mail_superv_TABLE,$superv_champs, $valeurs,false ) ; |
---|
[4029] | 124 | } |
---|
[4220] | 125 | //========================================= |
---|
[4029] | 126 | function Get_colonnes_de($table) |
---|
| 127 | { |
---|
| 128 | $query = 'DESC '.$table.';'; |
---|
| 129 | $result = mysql_query($query); |
---|
[4220] | 130 | $columns_of= array(); |
---|
[4029] | 131 | while ($row = mysql_fetch_row($result)) |
---|
| 132 | { |
---|
[4220] | 133 | array_push($columns_of, $row[0]); |
---|
[4029] | 134 | } |
---|
[10419] | 135 | |
---|
[4029] | 136 | return $columns_of; |
---|
| 137 | } |
---|
[11807] | 138 | //========================================= |
---|
[10385] | 139 | function get_liste($group_id){ |
---|
[4040] | 140 | global $conf ; |
---|
| 141 | $query = ' |
---|
| 142 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
| 143 | u.'.$conf['user_fields']['username'].' AS username, |
---|
| 144 | u.'.$conf['user_fields']['email'].' AS email, |
---|
| 145 | ui.status, |
---|
| 146 | ui.enabled_high, |
---|
| 147 | ui.level |
---|
| 148 | FROM '.USERS_TABLE.' AS u |
---|
| 149 | INNER JOIN '.USER_INFOS_TABLE.' AS ui |
---|
| 150 | ON u.'.$conf['user_fields']['id'].' = ui.user_id |
---|
| 151 | LEFT JOIN '.USER_GROUP_TABLE.' AS ug |
---|
| 152 | ON u.'.$conf['user_fields']['id'].' = ug.user_id |
---|
[10419] | 153 | WHERE ug.group_id='.$group_id.' '; |
---|
[4040] | 154 | $groups=array(); |
---|
[10419] | 155 | $datas = pwg_query($query); |
---|
| 156 | |
---|
[9702] | 157 | if (!empty($datas)) { |
---|
[10419] | 158 | while ($group = mysql_fetch_array($datas,MYSQL_ASSOC)){ |
---|
| 159 | if (!empty($group['email'])){ |
---|
[10816] | 160 | //array_push($groups, format_email($group['username'], $group['email'] )); |
---|
| 161 | array_push($groups, |
---|
| 162 | array( 'username' => $group['username'], |
---|
| 163 | 'email' => $group['email'], |
---|
| 164 | 'format_email' => format_email($group['username'], $group['email'] ) |
---|
| 165 | ) |
---|
| 166 | ); |
---|
[4020] | 167 | } |
---|
| 168 | } |
---|
[10419] | 169 | } |
---|
[4040] | 170 | return $groups ; |
---|
[10419] | 171 | |
---|
[4020] | 172 | } |
---|
[4132] | 173 | //================================================================================= |
---|
[4020] | 174 | |
---|
[9702] | 175 | function create_table($nom_table,$champs,$types) //mail_superv_TABLE |
---|
[4132] | 176 | { |
---|
[10419] | 177 | $i=0; |
---|
| 178 | $valeurs=array(); |
---|
[9702] | 179 | foreach ( $champs as $champ) { |
---|
| 180 | $champ = trim($champ); |
---|
| 181 | array_push($valeurs , " `".$champ."`" . ' ' . $types[ $i] ) ; |
---|
| 182 | $i +=1; |
---|
[4132] | 183 | } |
---|
[4180] | 184 | |
---|
| 185 | |
---|
| 186 | |
---|
[10419] | 187 | if ( count($valeurs) == 0) return ; |
---|
| 188 | |
---|
[4132] | 189 | $valeurs=implode(", ",$valeurs) ; |
---|
[10419] | 190 | //=============================================================================== |
---|
| 191 | $query = "CREATE TABLE IF NOT EXISTS `" . $nom_table . "` (". $valeurs . " , PRIMARY KEY (`id` ) ) ENGINE=MyISAM ;"; |
---|
| 192 | if ( pwg_query($query) ) return ; |
---|
| 193 | die("ERREUR CREATION ".$query); |
---|
| 194 | |
---|
| 195 | |
---|
[4132] | 196 | } |
---|
[11807] | 197 | //=========================================================== |
---|
| 198 | function ajust_table($nom_table,$champs,$types){ //mail_superv_TABLE |
---|
[4220] | 199 | global $infos_message ; |
---|
| 200 | $colonnes = Get_colonnes_de($nom_table); |
---|
[10419] | 201 | $data = $types ; |
---|
| 202 | $i=0; |
---|
| 203 | $valeurs=array(); |
---|
[11807] | 204 | foreach ( $champs as $champ) { |
---|
[4132] | 205 | $champ = trim($champ); |
---|
[10419] | 206 | if (!in_array( $champ,$colonnes)) { |
---|
[4132] | 207 | array_push($valeurs , " ADD `".$champ."`" . ' ' . $data[ $i] ) ; |
---|
[10419] | 208 | } |
---|
| 209 | $i +=1; |
---|
| 210 | |
---|
[4132] | 211 | } |
---|
[10419] | 212 | //============================================================================= |
---|
| 213 | if ( count($valeurs) == 0) return ; |
---|
[4220] | 214 | $valeurs=implode(", ",$valeurs) ; |
---|
[10419] | 215 | //=============================================================================== |
---|
| 216 | $query = "ALTER TABLE `" . $nom_table . "` ". $valeurs ; |
---|
| 217 | if ( pwg_query($query)) return ; |
---|
| 218 | die($query); |
---|
[4132] | 219 | } |
---|
[10419] | 220 | //============================================================================== |
---|
[4132] | 221 | function ajout_ligne($nom_table,$champs,$valeurs,$force) |
---|
| 222 | { |
---|
| 223 | if (!$force) { |
---|
| 224 | $query = " |
---|
[10419] | 225 | SELECT `id` , COUNT(`id`) as total |
---|
| 226 | FROM `".$nom_table."` GROUP by `id` |
---|
| 227 | ;"; |
---|
| 228 | list($count) = mysql_fetch_row(pwg_query($query)); |
---|
[4220] | 229 | |
---|
[10419] | 230 | |
---|
[4132] | 231 | }else{ |
---|
| 232 | |
---|
[10419] | 233 | $count = 0 ; |
---|
[4132] | 234 | } |
---|
[11807] | 235 | $data=array(); |
---|
[10419] | 236 | |
---|
[11807] | 237 | $query = " SELECT * FROM `".$nom_table."` ;"; |
---|
| 238 | $datas = pwg_query($query); |
---|
| 239 | if (!empty($datas)) { |
---|
| 240 | while ($row = mysql_fetch_array($datas,MYSQL_ASSOC)){ |
---|
| 241 | array_push($data,$row); |
---|
| 242 | } |
---|
| 243 | } |
---|
| 244 | $count= count($data); |
---|
| 245 | if ($count == 0) { |
---|
[4156] | 246 | $n_champs=implode(",",$champs); |
---|
| 247 | $n_valeurs=implode(",",$valeurs); |
---|
[10419] | 248 | $query = " |
---|
| 249 | INSERT INTO `".$nom_table."` (". $n_champs.") |
---|
| 250 | VALUES ( ". $n_valeurs .")"; |
---|
| 251 | |
---|
| 252 | if (pwg_query($query)) return ; |
---|
[11807] | 253 | die("fonction.php 256".$query); |
---|
[10419] | 254 | |
---|
[4132] | 255 | } |
---|
[11807] | 256 | |
---|
[4132] | 257 | } |
---|
| 258 | //===================================================================== |
---|
[10385] | 259 | function verif_mails_donnees(){ |
---|
| 260 | global $mails_donnees,$infos_message,$erreur_message,$page; |
---|
[4132] | 261 | |
---|
[9702] | 262 | if (!is_numeric($mails_donnees['nb_mails_periode'])){ |
---|
| 263 | $periode = Str_To_Time( $mails_donnees['nb_mails_periode'],0); |
---|
| 264 | $mails_donnees['nb_mails_periode']= ($periode > 0) ? $periode : '604800' ; |
---|
[4888] | 265 | } |
---|
[9702] | 266 | if (!is_numeric($mails_donnees['nb_spams_periode'])){ |
---|
| 267 | $periode=Str_To_Time( $mails_donnees['nb_spams_periode'],0); |
---|
| 268 | $mails_donnees['nb_spams_periode']= ($periode > 0) ? $periode : '172800' ; ; |
---|
[4888] | 269 | } |
---|
[9702] | 270 | if (!is_numeric($mails_donnees['quarantaine_periode'])){ |
---|
| 271 | $periode=Str_To_Time( $mails_donnees['quarantaine_periode'],0); |
---|
[10419] | 272 | $mails_donnees['quarantaine_periode']= ($periode > 0) ? $periode : '172800' ; |
---|
[4888] | 273 | } |
---|
[9702] | 274 | if ($infos_message != "") { |
---|
| 275 | array_push($page['infos'], $infos_message); |
---|
| 276 | $infos_message=""; |
---|
[10419] | 277 | } |
---|
[9702] | 278 | if ($erreur_message != "") { |
---|
| 279 | array_push($page['errors'], $erreur_message); |
---|
| 280 | $erreur_message =""; |
---|
[10419] | 281 | } |
---|
| 282 | |
---|
[4888] | 283 | } |
---|
| 284 | //======================================================================= |
---|
[10385] | 285 | function Date_to_numeric( $Valeurs ){ |
---|
[4888] | 286 | global $lang,$erreur_message,$infos_message; |
---|
[4132] | 287 | |
---|
[4888] | 288 | $a_ajouter = $Valeurs ; |
---|
[4879] | 289 | |
---|
| 290 | |
---|
[4888] | 291 | if (!isset($lang['Sv_second'])) { |
---|
[10385] | 292 | $Week=explode(" ",l10n('Week %d')); |
---|
| 293 | $Week= ($Week[0]); |
---|
[4888] | 294 | |
---|
[10385] | 295 | $lang['Sv_week'] = $Week; |
---|
| 296 | $lang['Sv_day'] = l10n('Day') ; |
---|
| 297 | $lang['Sv_hour'] = l10n('Hour') ; |
---|
| 298 | $lang['Sv_minute'] = l10n('Minute') ; |
---|
| 299 | $lang['Sv_second'] = l10n('Second'); |
---|
[4888] | 300 | |
---|
[10385] | 301 | $lang['Sv_'. $lang['Sv_week']] = 'week'; |
---|
| 302 | $lang['Sv_'. $lang['Sv_day']] = 'day'; |
---|
| 303 | $lang['Sv_'. $lang['Sv_hour']] = 'hour'; |
---|
| 304 | $lang['Sv_'. $lang['Sv_minute']] = 'minute'; |
---|
| 305 | $lang['Sv_'. $lang['Sv_second']] = 'second'; |
---|
[4888] | 306 | |
---|
[10419] | 307 | } |
---|
| 308 | //--- traduction --> anglais --- |
---|
[4888] | 309 | |
---|
[7050] | 310 | //========= suppression numeric et symbole ========== |
---|
[10419] | 311 | $new_valeur =( preg_replace("/[0-9+\-.*\/()%]/"," ",$a_ajouter)); |
---|
[4888] | 312 | $nv = trim( sup_double_espace($new_valeur)) ; |
---|
| 313 | |
---|
[10419] | 314 | |
---|
| 315 | |
---|
| 316 | $conv['week']= (7*24*60*60); |
---|
| 317 | $conv['day']= (24*60*60); |
---|
| 318 | $conv['hour']= (60*60) ; |
---|
| 319 | $conv['minute']= 60 ; |
---|
| 320 | $conv['second']= 1; |
---|
| 321 | |
---|
[4888] | 322 | $nv = explode(" ", $nv ); |
---|
[10419] | 323 | |
---|
[10385] | 324 | foreach($nv as $nv1){ |
---|
| 325 | if (!isset($lang['Sv_'. $nv1]) ) { |
---|
[10419] | 326 | //==== au cas pluriel === |
---|
| 327 | $nv0 = substr($nv1, 0,-1) ; |
---|
[10385] | 328 | $a_ajouter= str_replace( $nv1,$nv0, $a_ajouter); |
---|
[10419] | 329 | $nv1 = $nv0 ; |
---|
| 330 | } |
---|
[10385] | 331 | if (!isset($lang['Sv_'. $nv1]) ) { |
---|
[10419] | 332 | $erreur_message .= $nv1. " ".l10n('not_found')."<br />"; |
---|
| 333 | // die($erreur_message); |
---|
[10385] | 334 | }else { |
---|
[10419] | 335 | ob_start(); |
---|
[10385] | 336 | $match = $conv[strtolower($lang['Sv_'. $nv1])] ; |
---|
| 337 | $a_ajouter = str_replace($nv1," ". $match ." ",$a_ajouter) ; |
---|
| 338 | $erreur_message .= ob_get_contents(); |
---|
| 339 | ob_end_clean(); |
---|
[10419] | 340 | } |
---|
[4888] | 341 | } |
---|
| 342 | |
---|
[10385] | 343 | $a_ajouter = "+ " . $a_ajouter ; |
---|
| 344 | $a_ajouter=sup_double_espace($a_ajouter); |
---|
| 345 | $v1 = array('- ','+ ',' -', ' +', ' '); |
---|
| 346 | $v2 = array('-' ,'+' ,'|-', '|+', "*"); |
---|
[4888] | 347 | |
---|
[10385] | 348 | $new_valeur = str_replace($v1,$v2,$a_ajouter) ; |
---|
| 349 | $new_valeur = str_replace('++','+',$new_valeur ) ; |
---|
[10419] | 350 | |
---|
[10385] | 351 | return $new_valeur; |
---|
[4888] | 352 | } |
---|
| 353 | //===================================================================== |
---|
| 354 | function Str_To_Time( $ajout,$init_date) |
---|
| 355 | { |
---|
| 356 | //======================================================== |
---|
| 357 | global $erreur_message,$infos_message,$user; |
---|
| 358 | global $lang; |
---|
[10419] | 359 | |
---|
[4888] | 360 | $ajout=ucwords ($ajout); |
---|
[10419] | 361 | |
---|
| 362 | |
---|
[4888] | 363 | if (is_numeric($ajout)) |
---|
| 364 | $valeur= $ajout ; |
---|
| 365 | else |
---|
| 366 | { |
---|
| 367 | $valeur= Date_to_numeric( $ajout) ; |
---|
[10419] | 368 | |
---|
[4888] | 369 | } |
---|
[10419] | 370 | |
---|
[4888] | 371 | $new_valeur = explode( "|", $valeur ); |
---|
[4132] | 372 | |
---|
| 373 | $p = $init_date ; |
---|
[4879] | 374 | $n0=0; |
---|
[4888] | 375 | $erreur = false; |
---|
| 376 | |
---|
[10419] | 377 | //$new_valeur = $a_ajouter + $init_date ; |
---|
| 378 | foreach($new_valeur as $nv) |
---|
| 379 | { |
---|
| 380 | $return = matheval($nv) ; |
---|
| 381 | if (strpos("error",$return)===false) { |
---|
| 382 | $p += $return ; |
---|
| 383 | }else { |
---|
| 384 | $erreur_message .= "[" . $ajout . "] --> " . l10n('Sv_syntax_error') . " : " . $nv ."<br />"; |
---|
| 385 | $erreur = true; |
---|
| 386 | } |
---|
| 387 | |
---|
| 388 | |
---|
| 389 | } |
---|
| 390 | if ($erreur) $p = -1000 ; |
---|
[4888] | 391 | return intval($p) ; |
---|
[10419] | 392 | |
---|
[4132] | 393 | } |
---|
| 394 | //===================================================================================== |
---|
[10419] | 395 | function matheval($equation) |
---|
| 396 | { |
---|
[4146] | 397 | |
---|
| 398 | $return="error"; |
---|
| 399 | |
---|
[10419] | 400 | |
---|
| 401 | $equation = preg_replace("/[^0-9+\-.*\/()%]/","",$equation); |
---|
| 402 | $equation = preg_replace("/([+-])([0-9]{1})(%)/","*(1\$1.0\$2)",$equation); |
---|
| 403 | $equation = preg_replace("/([+-])([0-9]+)(%)/","*(1\$1.\$2)",$equation); |
---|
| 404 | $equation = preg_replace("/([0-9]+)(%)/",".\$1",$equation); |
---|
| 405 | |
---|
| 406 | if ( $equation == "" ) |
---|
| 407 | { |
---|
| 408 | $return = 0; |
---|
| 409 | } else { |
---|
| 410 | @eval("\$return=" . $equation . ";" ); |
---|
[4146] | 411 | } |
---|
[10419] | 412 | return $return; |
---|
[4132] | 413 | |
---|
[10419] | 414 | } |
---|
| 415 | |
---|
[4132] | 416 | //====================================================================================== |
---|
[4146] | 417 | function sup_double_espace($chaine){ |
---|
| 418 | global $erreur_message; |
---|
[10419] | 419 | $str_temp = $chaine." "; |
---|
| 420 | $sep=" "; |
---|
| 421 | $chaine = trim($chaine); |
---|
[9702] | 422 | if ($chaine=="") return ; |
---|
[10419] | 423 | $existe = (strpos($sep.$sep,$chaine )===false) ; |
---|
| 424 | while ($existe ){ |
---|
| 425 | $str_temp = str_replace($sep.$sep, $sep, $chaine ); |
---|
| 426 | if($str_temp == $chaine ) return $chaine ; |
---|
| 427 | // $erreur_message .= mail_supervisor::Memo_Var($str_temp) ; |
---|
| 428 | $chaine = $str_temp; |
---|
| 429 | $existe = (strpos($sep.$sep,$chaine )===false) ; |
---|
| 430 | } |
---|
| 431 | return $chaine; |
---|
[4132] | 432 | } |
---|
[10419] | 433 | //==================== TEST black_liste ============================================ |
---|
[9702] | 434 | function kill_list() { |
---|
| 435 | global $pays,$region,$ville,$ip ; |
---|
[10419] | 436 | global $erreur_message,$infos_message,$conf; |
---|
[9702] | 437 | global $conf, $user, $page; |
---|
| 438 | global $mails_options ; |
---|
[10419] | 439 | global $superv_bl_champs,$superv_bl_type ; |
---|
| 440 | global $nb ; |
---|
[9702] | 441 | if (!isset($ip)) { |
---|
| 442 | if (getenv("HTTP_CLIENT_IP")) { |
---|
| 443 | $ip=getenv("HTTP_CLIENT_IP"); |
---|
| 444 | }else{ |
---|
| 445 | $ip=getenv("REMOTE_ADDR"); |
---|
| 446 | } |
---|
| 447 | } |
---|
| 448 | $champs=implode(',',$superv_bl_champs); |
---|
[10419] | 449 | $query = "SELECT ".$champs.",COUNT(`ip`) as total |
---|
| 450 | FROM `".MAIL_BLACK_LISTE_TABLE."` |
---|
| 451 | WHERE '".$ip."' LIKE `ip` |
---|
| 452 | GROUP by `ip` |
---|
| 453 | ;"; |
---|
| 454 | $result = @pwg_query($query); |
---|
| 455 | if (!$result) { |
---|
| 456 | verif_base(); |
---|
| 457 | $result = @pwg_query($query); |
---|
| 458 | } |
---|
| 459 | $datas = mysql_fetch_array($result,MYSQL_ASSOC); |
---|
| 460 | $nb = $datas['total']|0; |
---|
| 461 | //======================================================================= |
---|
| 462 | if ($mails_options['set_auto'] == 'on') { |
---|
[9702] | 463 | global $user_name,$mail_adresse; |
---|
[4132] | 464 | |
---|
[9702] | 465 | if (isset($nb) && $nb>0) { |
---|
[10419] | 466 | //if (test_spam($ip,$user['username'] ,$user['email'])) // ne plus tester automatiquement . |
---|
[9702] | 467 | if ($nb==0) { |
---|
[10419] | 468 | $valeurs=array( 'NULL', |
---|
| 469 | "'".$ip."'", |
---|
| 470 | "'".$pays."'", |
---|
| 471 | "'".$region."'", |
---|
| 472 | "'".$ville."'", |
---|
| 473 | "'".$user['email']."'", |
---|
| 474 | "'".$user['username']."'", |
---|
| 475 | $nb+1 |
---|
| 476 | ); |
---|
| 477 | ajout_ligne(MAIL_BLACK_LISTE_TABLE,$superv_bl_champs, $valeurs,$nb==0) ; |
---|
| 478 | }else{ |
---|
| 479 | mail_supervisor::Get_geo(); |
---|
| 480 | $nb +=1; |
---|
| 481 | $query ="UPDATE " . MAIL_BLACK_LISTE_TABLE . " SET "; |
---|
| 482 | if (isset($_POST['pays'])) |
---|
| 483 | $query .= "`pays` = '". $pays ."', |
---|
| 484 | `region` = '" . $region ."', |
---|
| 485 | `ville` = '" . $ville . "', |
---|
| 486 | "; |
---|
| 487 | $query .= "`adresse` = '".$user['email']."', |
---|
| 488 | `fai` = '".$user['username']."', |
---|
| 489 | `nb` = " . $nb . " |
---|
| 490 | WHERE '".$ip."' like `ip` "; |
---|
| 491 | pwg_query($query ); |
---|
| 492 | } |
---|
[11807] | 493 | $erreur_message .= $pays . $ip ." <br />User Name :".$user['username']."<br />User Mail :".$user['email'] . ' -----> ' . l10n('Sv_set_black_liste') ; |
---|
[10419] | 494 | // die($nb." ".$ip." ".$user['username']." ".$user['email']); |
---|
| 495 | |
---|
| 496 | return true ; |
---|
| 497 | } |
---|
[4190] | 498 | } |
---|
| 499 | //============================================================================== |
---|
[9702] | 500 | |
---|
[10419] | 501 | if ( $mails_options['ip'] == $ip ) return ($nb > 0) ; |
---|
[9702] | 502 | $ip0= $mails_options['ip'] ; |
---|
[10419] | 503 | $mails_options['ip'] = $ip ; |
---|
| 504 | mail_supervisor::sauve_options(); |
---|
| 505 | if ( $nb > 0 ) |
---|
| 506 | { |
---|
| 507 | $query = " |
---|
| 508 | SELECT ".$champs.",COUNT(`id`) as total |
---|
| 509 | FROM `".MAIL_BLACK_LISTE_TABLE."` |
---|
| 510 | WHERE '".$ip."' = `ip` |
---|
| 511 | GROUP by `ip` |
---|
| 512 | ;"; |
---|
| 513 | $result = @pwg_query($query); |
---|
| 514 | |
---|
| 515 | if (!$result) { |
---|
| 516 | verif_base(); |
---|
| 517 | $result = @pwg_query($query); |
---|
| 518 | } |
---|
| 519 | $datas = mysql_fetch_array($result,MYSQL_ASSOC); |
---|
| 520 | $nb = $datas['total']; |
---|
| 521 | |
---|
| 522 | $row = mysql_fetch_row(pwg_query($query)); |
---|
| 523 | $nb = ($row[7]); |
---|
| 524 | $erreur_message .= $ip0 . ' | ' .$ip . ' | ' . $pays . ' | ' . $region . ' | ' . $ville . ' ' . $nb . ' ==> '; |
---|
| 525 | |
---|
| 526 | if ($nb == 0) |
---|
| 527 | { |
---|
| 528 | $valeurs=array( 'NULL', |
---|
| 529 | "'".$ip."'", |
---|
| 530 | "'".$pays."'", |
---|
| 531 | "'".$region."'", |
---|
| 532 | "'".$ville."'", |
---|
| 533 | "'".$user['email']."'", |
---|
| 534 | "'".$user['username']."'", |
---|
| 535 | 1 |
---|
| 536 | ); |
---|
| 537 | ajout_ligne(MAIL_BLACK_LISTE_TABLE,$superv_bl_champs, $valeurs,true) ; |
---|
| 538 | |
---|
| 539 | } else { |
---|
| 540 | $nb += 1; |
---|
| 541 | $query =" |
---|
| 542 | UPDATE " . MAIL_BLACK_LISTE_TABLE . " |
---|
| 543 | SET "; |
---|
| 544 | if (isset($_POST['pays'])) |
---|
| 545 | $query .= " |
---|
| 546 | `pays` = '". $pays ."', |
---|
| 547 | `region` = '" . $region ."', |
---|
| 548 | `ville` = '" . $ville . "', |
---|
| 549 | "; |
---|
| 550 | $query .= " |
---|
| 551 | `adresse` = '".$user['email']."', |
---|
| 552 | `fai` = '".$user['username']."', |
---|
| 553 | `nb` = " . $nb . " |
---|
| 554 | WHERE '".$ip."' = `ip` |
---|
| 555 | "; |
---|
| 556 | |
---|
| 557 | pwg_query($query ); |
---|
| 558 | } |
---|
| 559 | } |
---|
[9702] | 560 | return ($nb > 0) ; |
---|
[4132] | 561 | } |
---|
[4180] | 562 | //===================================================================================== |
---|
[10385] | 563 | function test_spam($ip =0,$user_name ='', $mail_adresse = ""){ |
---|
[9702] | 564 | $buffer=""; |
---|
| 565 | global $page,$infos_message; |
---|
| 566 | $src = "http://www.stopforumspam.com/api?"; |
---|
| 567 | $type=array(); |
---|
| 568 | $result=""; |
---|
| 569 | $ip= sup_double_espace($ip); |
---|
[10419] | 570 | if (strlen($ip)>3) { |
---|
[9702] | 571 | //================== Verifie si l'IP est correct ================================ |
---|
[10419] | 572 | if (clj_is_ip($ip)){ |
---|
| 573 | |
---|
| 574 | } else { |
---|
| 575 | //================== Verifie si l'adresse mail est correcte ================================ |
---|
| 576 | if( clj_is_mail($ip) ){ |
---|
| 577 | $mail_adresse=$ip ; |
---|
| 578 | $ip=""; |
---|
| 579 | } |
---|
| 580 | else |
---|
| 581 | { |
---|
| 582 | //================== Login ================ |
---|
| 583 | $user_name=$ip; |
---|
| 584 | $ip=""; |
---|
| 585 | } |
---|
| 586 | } |
---|
[9702] | 587 | //============================================================================= |
---|
| 588 | } |
---|
[4861] | 589 | |
---|
[9702] | 590 | $user_name=str_replace(" ","%20",trim($user_name)); |
---|
| 591 | if ($user_name==l10n('Sv_guest')) $user_name=""; |
---|
| 592 | $user_name=""; // ne plus tester sur le login. |
---|
| 593 | $mail_adresse =str_replace(" ","%20",trim($mail_adresse)); |
---|
[10419] | 594 | if ( strlen($user_name) > 3) $type[]="username=$user_name" ; |
---|
[9702] | 595 | if ( strlen($mail_adresse) > 3) $type[]="email=".$mail_adresse ; |
---|
[10419] | 596 | if ( strlen($ip) > 3) $type[]="ip=".$ip ; |
---|
| 597 | foreach ( $type as $fil ) { |
---|
[9702] | 598 | $resultat=""; |
---|
| 599 | if ( clj_fetchRemote($src.$fil , $resultat,1)) |
---|
[10419] | 600 | $result .= $resultat.'<br />' ; |
---|
[9702] | 601 | } |
---|
[4361] | 602 | |
---|
[9702] | 603 | return !(strpos( $result ,'yes' ) === false) ; |
---|
[10419] | 604 | |
---|
[4323] | 605 | } |
---|
| 606 | //================================================================== |
---|
[10385] | 607 | function lire_fichier_distant($fichier){ |
---|
| 608 | $buffer=""; |
---|
[10419] | 609 | $handle = @fopen($fichier,"r"); |
---|
[10385] | 610 | if ($handle) { |
---|
[10419] | 611 | while (!feof($handle)) { |
---|
[10385] | 612 | $buffer .= fgets($handle, 4096); |
---|
[10419] | 613 | } |
---|
| 614 | fclose($handle); |
---|
| 615 | } |
---|
| 616 | |
---|
[10385] | 617 | return $buffer ; |
---|
[4156] | 618 | |
---|
| 619 | } |
---|
[4337] | 620 | //================================================ |
---|
[10385] | 621 | function clj_is_ip($ip){ |
---|
[4451] | 622 | 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 ; |
---|
[10419] | 623 | |
---|
[4337] | 624 | } |
---|
| 625 | |
---|
| 626 | function clj_is_mail($mail) |
---|
[10419] | 627 | { |
---|
[8917] | 628 | |
---|
[10419] | 629 | if(preg_match('/^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,5}$/' ,$mail)) return true ; |
---|
| 630 | if(preg_match('/#^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,5}$#/' ,$mail)) return true ; |
---|
| 631 | } |
---|
[4361] | 632 | |
---|
[10419] | 633 | |
---|
[4361] | 634 | function clj_fetchRemote($src, &$dest, $timeout=1, $user_agent='Piwigo', $step=0) |
---|
| 635 | { |
---|
| 636 | // Try to retrieve data from local file? |
---|
[8917] | 637 | // http://www.stopforumspam.com/api?ip=95.211.1.39 |
---|
| 638 | |
---|
| 639 | if ($src=="") return ; |
---|
[10419] | 640 | |
---|
[4361] | 641 | if (!url_is_remote($src)) |
---|
| 642 | { |
---|
[10419] | 643 | |
---|
[4361] | 644 | $content = @file_get_contents($src); |
---|
| 645 | if ($content !== false) |
---|
| 646 | { |
---|
| 647 | is_resource($dest) ? @fwrite($dest, $content) : $dest = $content; |
---|
| 648 | return true; |
---|
| 649 | } |
---|
| 650 | else |
---|
| 651 | { |
---|
| 652 | return false; |
---|
| 653 | } |
---|
| 654 | } |
---|
[10419] | 655 | |
---|
[4361] | 656 | // After 3 redirections, return false |
---|
| 657 | if ($step > 3) return false; |
---|
| 658 | |
---|
| 659 | // Initialize $dest |
---|
| 660 | is_resource($dest) or $dest = ''; |
---|
| 661 | |
---|
| 662 | // Try curl to read remote file |
---|
| 663 | if (function_exists('curl_init')) |
---|
| 664 | { |
---|
| 665 | $ch = @curl_init(); |
---|
| 666 | @curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
---|
| 667 | @curl_setopt($ch, CURLOPT_URL, $src); |
---|
| 668 | @curl_setopt($ch, CURLOPT_HEADER, 1); |
---|
| 669 | @curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); |
---|
| 670 | @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
---|
| 671 | $content = @curl_exec($ch); |
---|
| 672 | $header_length = @curl_getinfo($ch, CURLINFO_HEADER_SIZE); |
---|
| 673 | $status = @curl_getinfo($ch, CURLINFO_HTTP_CODE); |
---|
| 674 | @curl_close($content); |
---|
| 675 | if ($content !== false and $status >= 200 and $status < 400) |
---|
| 676 | { |
---|
| 677 | if (preg_match('/Location:\s+?(.+)/', substr($content, 0, $header_length), $m)) |
---|
| 678 | { |
---|
[4366] | 679 | return clj_fetchRemote($m[1], $dest,$timeout, $user_agent, $step+1); |
---|
[4361] | 680 | } |
---|
| 681 | $content = substr($content, $header_length); |
---|
| 682 | is_resource($dest) ? @fwrite($dest, $content) : $dest = $content; |
---|
| 683 | return true; |
---|
| 684 | } |
---|
| 685 | } |
---|
| 686 | |
---|
| 687 | // Try file_get_contents to read remote file |
---|
| 688 | if (ini_get('allow_url_fopen')) |
---|
| 689 | { |
---|
| 690 | |
---|
| 691 | $opts['http'] = array('timeout' => $timeout); |
---|
| 692 | $ctx = stream_context_create($opts); |
---|
| 693 | $content = @file_get_contents($src, 0, $ctx); |
---|
| 694 | if ($content !== false) |
---|
| 695 | { |
---|
| 696 | is_resource($dest) ? @fwrite($dest, $content) : $dest = $content; |
---|
| 697 | return true; |
---|
| 698 | } |
---|
| 699 | } |
---|
| 700 | |
---|
| 701 | return false; |
---|
| 702 | } |
---|
| 703 | |
---|
[4888] | 704 | |
---|
[4224] | 705 | ?> |
---|