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