[ Index ]
 

Code source de Cr@wltr@ck 2.2.1

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/include/ -> display-crawlers-info.php (source)

   1  <?php
   2  //----------------------------------------------------------------------

   3  //  CrawlTrack 2.2.1

   4  //----------------------------------------------------------------------

   5  // Crawler Tracker for website

   6  //----------------------------------------------------------------------

   7  // Author: Jean-Denis Brun

   8  //----------------------------------------------------------------------

   9  // Website: www.crawltrack.fr

  10  //----------------------------------------------------------------------

  11  // That script is distributed under GNU GPL license

  12  //----------------------------------------------------------------------

  13  // file: display-crawlers-info.php

  14  //----------------------------------------------------------------------

  15  if (!defined('IN_CRAWLT'))
  16  {
  17      echo"<h1>Hacking attempt !!!!</h1>";
  18      exit();
  19  }
  20  //initialize array

  21  $listcrawler=array();
  22  $listip=array();
  23  $usercrawler=array();
  24  $countrycode=array();
  25  $nbrcountry=array();
  26  $listcountry=array();
  27  $name=array();
  28  $nbrcountry2=array();
  29  $name2=array();
  30  $values=array();
  31  
  32  $cachename=$navig.$period.$site.$firstdayweek.$localday.$graphpos.$crawltlang;
  33  
  34  //start the caching if fopen exist

  35  if(function_exists('fopen'))
  36      {
  37      $ch = new cache($cachename);
  38      }
  39  
  40  //database connection

  41  $connexion = mysql_connect($crawlthost,$crawltuser,$crawltpassword) or die("MySQL connection to database problem");
  42  $selection = mysql_select_db($crawltdb) or die("MySQL database selection problem");
  43  
  44  //include menu 

  45  include "include/menumain.php";
  46  include "include/menusite.php";
  47  include "include/timecache.php";
  48  //mysql requete

  49  
  50  if($period>=10)
  51      {    
  52      $sqlstats = "SELECT crawler_name,  crawlt_ip_used, date, crawler_info FROM crawlt_crawler, crawlt_visits
  53      WHERE  crawlt_visits.crawlt_crawler_id_crawler=crawlt_crawler.id_crawler
  54      AND crawlt_visits.date >'".sql_quote($daterequest)."'
  55      AND  date <'".sql_quote($daterequest2)."'     
  56      AND crawlt_visits.crawlt_site_id_site='".sql_quote($site)."'";
  57      }
  58  elseif($period==5)
  59      {
  60      $sqlstats = "SELECT code, count(DISTINCT id_visit), count(DISTINCT crawler_name) FROM crawlt_crawler, crawlt_visits, crawlt_ip_used
  61      WHERE  crawlt_visits.crawlt_crawler_id_crawler=crawlt_crawler.id_crawler 
  62      AND  crawlt_visits.crawlt_ip_used = crawlt_ip_used.ip_used    
  63      AND crawlt_visits.crawlt_site_id_site='".sql_quote($site)."'
  64      GROUP BY code";    
  65      }       
  66  else
  67      {
  68      $sqlstats = "SELECT crawler_name,  crawlt_ip_used, date, crawler_info FROM crawlt_crawler, crawlt_visits
  69      WHERE  crawlt_visits.crawlt_crawler_id_crawler=crawlt_crawler.id_crawler
  70      AND crawlt_visits.date >'".sql_quote($daterequest)."' 
  71      AND crawlt_visits.crawlt_site_id_site='".sql_quote($site)."'";
  72      }
  73          
  74  $requetestats = mysql_query($sqlstats, $connexion) or die("MySQL query error");
  75      
  76  $nbrresult=mysql_num_rows($requetestats);
  77  
  78  $testip=0;
  79  if($nbrresult>=1)
  80      {    
  81      while ($ligne = mysql_fetch_row($requetestats))                                                                              
  82          {
  83          if($period !=5)
  84              {
  85              if($ligne[1]!='')
  86                  {
  87                  $testip=1;
  88                  $listcrawler[$ligne[0]]=$ligne[0];
  89                  ${'ipcrawler'.$ligne[0]}[] =$ligne[1];
  90                  $listip[$ligne[1]]=$ligne[1];
  91                  @${'nbrvisits'.$ligne[0]}[$ligne[1]]++;
  92                  ${'crawler'.$ligne[1]}[] =$ligne[0]; 
  93                  $usercrawler[$ligne[0]] = $ligne[3];                  
  94                  }
  95              }
  96          else
  97              {
  98              $testip=1;
  99              if($ligne[0]=='a2' OR $ligne[0]=='xx')
 100                  {
 101                  $nbrvisits['xx']=$ligne[1]+@$nbrvisits['xx'];
 102                  $nbrcountry['xx']=$ligne[2]+@$nbrcountry['xx'];
 103                  }
 104              else
 105                  {
 106                  $nbrvisits[$ligne[0]]=$ligne[1];
 107                  $nbrcountry[$ligne[0]]=$ligne[2];
 108                  }
 109              }
 110          }        
 111  
 112          
 113  if($testip==1)
 114      {
 115      if($period !=5)
 116          {
 117          //requete to get the country code

 118      
 119          $testexist=0;
 120          
 121          //get the existing datas in the crawlt_ip_used table

 122          $sqlexistingip = "SELECT ip_used, code FROM crawlt_ip_used";
 123          
 124          $requeteexistingip = mysql_query($sqlexistingip, $connexion) or die("MySQL query error");
 125  
 126          $nbrresultexistingip=mysql_num_rows($requeteexistingip);
 127          
 128          if($nbrresultexistingip>=1)
 129              {
 130              while ($ligneip = mysql_fetch_row($requeteexistingip))
 131                  {
 132                  $countrycode[$ligneip[0]]=$ligneip[1];                
 133                  }
 134              }        
 135          
 136               
 137             $j=0;
 138                 
 139          foreach ($listip as $ip)
 140              {
 141              //to detect same IP used by different crawler

 142              //suppression of double entries in the tables

 143              ${'crawler'.$ip}=array_unique(${'crawler'.$ip});
 144              sort(${'crawler'.$ip});                
 145                  
 146              if(!isset($countrycode[$ip]))
 147                  {
 148                  $ipexplode= explode('.',$ip);            
 149            
 150                  //maxMind GeoIp calculation formula                        

 151                  $ip2=(16777216*$ipexplode[0]) + (65536*$ipexplode[1]) + (256*$ipexplode[2]) + $ipexplode[3];
 152                  
 153                  $sqlstats = "SELECT country_code FROM crawlt_ip_data
 154                  WHERE ip_from <= '".sql_quote($ip2)."'
 155                  AND ip_to >= '".sql_quote($ip2)."'";
 156                  
 157                  $requetestats = mysql_query($sqlstats, $connexion) or die("MySQL query error");
 158          
 159                  $nbrresult1=mysql_num_rows($requetestats);
 160                  
 161                  if($nbrresult1>=1)
 162                      {    
 163                      $ligne = mysql_fetch_row($requetestats);
 164                      $countrycode[$ip]=$ligne[0];
 165                      @$nbrcountry[$ligne[0]]++;
 166                      $listcountry[]=$ligne[0];
 167                      }
 168                  else
 169                      {
 170                      $countrycode[$ip]='xx';
 171                      }  
 172                
 173                //enter the ip data in the crawlt_ip_used table

 174                
 175                
 176                  $sqlinsertip = "INSERT INTO crawlt_ip_used (ip_used, code) VALUES ('".sql_quote($ip)."','".sql_quote($countrycode[$ip])."')";
 177                  $requeteinsertip = mysql_query($sqlinsertip, $connexion) or die("MySQL query error");  
 178                        
 179                    } 
 180               else
 181                  {
 182                  $code=$countrycode[$ip];
 183                  @$nbrcountry[$code]++;
 184                  $listcountry[]=$code;                
 185                  }    
 186                $j++;       
 187              }
 188          }
 189  
 190      //treatment to prepare the datas for the graph and to display the 5 top and group the other in the 'Other' category

 191      arsort($nbrcountry);
 192  
 193      foreach ($nbrcountry as $key => $value)
 194        {
 195        $name[] = $key;
 196        }     
 197      
 198      $nbrtotcountry=count($nbrcountry);
 199      
 200      $i=0;
 201      foreach ($nbrcountry as $nbr)
 202          {
 203              if($i > 4 && $nbrtotcountry>6 )
 204              {
 205              $crawler=$name[$i];
 206              $crawler3=$language['other'];
 207              @$nbrcountry2[$crawler3]= @$nbrcountry2[$crawler3]+$nbrcountry[$crawler];
 208              }
 209          else
 210              {
 211              $crawler=$name[$i];        
 212              @$nbrcountry2[$crawler]= $nbrcountry[$crawler];
 213              }
 214          $i++;
 215          }
 216      foreach ($nbrcountry2 as $key => $value)
 217        {
 218        $name2[] = $key;
 219        } 
 220      $i=0;    
 221      foreach ($nbrcountry2 as $nbr2)
 222          {
 223  
 224          if($name2[$i]==$language['other'])
 225              {
 226              $values[$language['other']]=$nbr2;
 227              }
 228          else
 229              {
 230              $values[$country[$name2[$i]]]=$nbr2;
 231              }
 232          $i++;
 233          }         
 234  
 235      //prepare datas to be transfert to graph file

 236      $datatransferttograph=addslashes(urlencode(serialize($values)));
 237      //insert the values in the graph table 

 238      $graphname="origin-".$cachename;
 239      
 240         
 241      //check if this graph exit already in the table     

 242      $sql = "SELECT name  FROM crawlt_graph
 243                  WHERE name= '".sql_quote($graphname)."'";
 244                  
 245      
 246      $requete = mysql_query($sql, $connexion) or die("MySQL query error");
 247      $nbrresult=mysql_num_rows($requete);
 248      if($nbrresult >=1)
 249          {     
 250          $sql2 ="UPDATE crawlt_graph SET graph_values='".sql_quote($datatransferttograph)."'
 251                    WHERE name= '".sql_quote($graphname)."'";
 252          }
 253      else
 254          {
 255          $sql2 ="INSERT INTO crawlt_graph (name,graph_values) VALUES ( '".sql_quote($graphname)."','".sql_quote($datatransferttograph)."')";        
 256          }    
 257      $requete2 = mysql_query($sql2, $connexion) or die("MySQL query error");      
 258      //mysql connexion close

 259      mysql_close($connexion);        
 260          
 261      //display---------------------------------------------------------------------------------------------------------

 262      echo"<div class=\"content\">\n";
 263      echo crawltbackforward('origin',$period,$daytodaylocal,$monthtodaylocal,$yeartodaylocal,$daybeginlocal,$monthbeginlocal,$yearbeginlocal,$dayendweek,$monthendweek,$yearendweek,$crawler,$navig,$site,$graphpos);  
 264      echo"</div>\n";
 265                
 266      //graph

 267      echo"<div align='center'onmouseover=\"javascript:montre();\">\n";
 268      echo"<img src=\"./graphs/origine-graph.php?graphname=$graphname\" alt=\"graph\"  width=\"450px\" heigth=\"175px\"/>\n";
 269      echo"</div>\n";
 270      if($period != 5)
 271          {
 272          //order per crawler name

 273          asort($listcrawler);    
 274          
 275              echo"<div class='tableau' align='center'>\n";    
 276              echo"<table   cellpadding='0px' cellspacing='0' width='100%'>\n";
 277              echo"<tr><th class='tableau1'>\n";
 278              echo"".$language['crawler_name']."\n";
 279              echo"</th>\n";
 280              echo"<th class='tableau1'>\n";
 281              echo"".$language['crawler_ip_used']."\n";        
 282              echo"</th>\n";
 283              echo"<th class='tableau1'>\n";
 284              echo"".$language['nbr_visits']."\n";        
 285              echo"</th>\n";        
 286              echo"<th class='tableau2'>\n";        
 287              echo"".$language['crawler_country']."\n";
 288              echo"</th></tr>\n";
 289              
 290              //counter for alternate color lane

 291              $comptligne=2;
 292              
 293              foreach ($listcrawler as $crawl)
 294                  {
 295                  $crawldisplay=htmlentities($crawl);
 296                  //suppression of double entries in the tables

 297                  ${'ipcrawler'.$crawl}=array_unique(${'ipcrawler'.$crawl});
 298                  sort(${'ipcrawler'.$crawl});
 299              
 300              
 301                  if ($comptligne%2 ==0)
 302                      {
 303                      echo"<tr><td class='tableau3h'><a href='index.php?navig=2&amp;period=".$period."&amp;site=".$site."&amp;crawler=".$crawl."&amp;graphpos=".$graphpos."'>".$crawldisplay."</a></td>\n";
 304                      echo"<td class='tableau3g' width='20%'>\n";
 305                      foreach (${'ipcrawler'.$crawl} as $ip)
 306                          {
 307                          $nbip=count(${'crawler'.$ip});
 308                          if ($nbip > 1)
 309                              {
 310                              //test to see in case of different crawlers using the same ip if the owner is the same

 311                              for ($i=0; $i<$nbip; $i++)
 312                                  {
 313                                  ${'difuser'.$ip}[] = $usercrawler[${'crawler'.$ip}[$i]];
 314                                  }
 315                              ${'difuser'.$ip} = array_unique(${'difuser'.$ip});
 316                              
 317                              $nbuser=count(${'difuser'.$ip});
 318                              
 319                              if($nbuser > 1)
 320                                  {
 321                                  $teststrangeip = 1;
 322                                  }
 323                              else
 324                                  {
 325                                  $teststrangeip = 0;
 326                                  }
 327                              }
 328                          else
 329                              {
 330                              $teststrangeip = 0;
 331                              }
 332                          
 333                          
 334                          if ($teststrangeip == 1)
 335                              {                                
 336                              echo"&nbsp;&nbsp;&nbsp;<span class='red'>$ip&nbsp;<a href='index.php?navig=6&amp;iptosuppress=".$ip."&amp;period=".$period."&amp;site=".$site."&amp;validform=19&amp;suppressip=1&amp;graphpos=".$graphpos."'>???</a></span><br>\n";
 337                              }
 338                           else
 339                              {
 340                              echo"&nbsp;&nbsp;&nbsp;$ip<br>\n";
 341                              }                        
 342                          }
 343                      echo"</td>\n";
 344                      echo"<td class='tableau3' >\n";
 345                      foreach (${'ipcrawler'.$crawl} as $ip)
 346                          {    
 347                          
 348                                  
 349                          echo"".numbdisp(${'nbrvisits'.$crawl}[$ip])."<br>\n";
 350                          }
 351                      echo"</td>\n";                    
 352                      echo"<td class='tableau5g' width='25%'>\n";
 353                      foreach (${'ipcrawler'.$crawl} as $ip)
 354                          {
 355                          if (isset($countrycode[$ip]))
 356                              {
 357                              $code=$countrycode[$ip];
 358                              echo"&nbsp;&nbsp;&nbsp;<img src=\"./images/flags/$code.gif\" width=\"16px\" height=\"11px\"  border=\"0\" alt=\"$country[$code]\">&nbsp;&nbsp;$country[$code]<br>\n";
 359                              }
 360                          else
 361                              {
 362                              echo"&nbsp;&nbsp;&nbsp;????<br>\n";
 363                              }
 364                          }                
 365                      echo"</td></tr> \n";            
 366      
 367                      }
 368                  else
 369                      {
 370                      echo"<tr><td class='tableau30h'><a href='index.php?navig=2&amp;period=".$period."&amp;site=".$site."&amp;crawler=".$crawl."&amp;graphpos=".$graphpos."'>".$crawldisplay."</a></td>\n";
 371                      echo"<td class='tableau30g' width='20%'>\n";
 372                      foreach (${'ipcrawler'.$crawl} as $ip)
 373                          {            
 374                          $nbip=count(${'crawler'.$ip});
 375                          if ($nbip > 1)
 376                              {
 377                              //test to see in case of different crawlers using the same ip if the owner is the same

 378                              for ($i=0; $i<$nbip; $i++)
 379                                  {
 380                                  ${'difuser'.$ip}[] = $usercrawler[${'crawler'.$ip}[$i]];
 381                                  }
 382                              ${'difuser'.$ip} = array_unique(${'difuser'.$ip});
 383                             
 384                              $nbuser=count(${'difuser'.$ip});
 385                              
 386                              if($nbuser > 1)
 387                                  {
 388                                  $teststrangeip = 1;
 389                                  }
 390                              else
 391                                  {
 392                                  $teststrangeip = 0;
 393                                  }
 394                              }
 395                          else
 396                              {
 397                              $teststrangeip = 0;
 398                              }
 399                          
 400                          
 401                          if ($teststrangeip == 1)
 402                              {                                
 403                              echo"&nbsp;&nbsp;&nbsp;<span class='red'>$ip&nbsp;<a href='index.php?navig=6&amp;iptosuppress=".$ip."&amp;period=".$period."&amp;site=".$site."&amp;validform=19&amp;suppressip=1&amp;graphpos=".$graphpos."'>???</a></span><br>\n";
 404                              }
 405                           else
 406                              {
 407                              echo"&nbsp;&nbsp;&nbsp;$ip<br>\n";
 408                              } 
 409                          }
 410                      echo"</td>\n";
 411                      echo"<td class='tableau30' >\n";
 412                      foreach (${'ipcrawler'.$crawl} as $ip)
 413                          {            
 414                          echo"".numbdisp(${'nbrvisits'.$crawl}[$ip])."<br>\n";
 415                          }
 416                      echo"</td>\n";                
 417                      echo"<td class='tableau50g' width='25%'>\n";
 418                      foreach (${'ipcrawler'.$crawl} as $ip)
 419                          {            
 420                          if (isset($countrycode[$ip]))
 421                              {
 422                              $code=$countrycode[$ip];
 423                              echo"&nbsp;&nbsp;&nbsp;<img src=\"./images/flags/$code.gif\" width=\"16px\" height=\"11px\"  border=\"0\" alt=\"$country[$code]\">&nbsp;&nbsp;$country[$code]<br>\n";
 424                              }
 425                          else
 426                              {
 427                              echo"&nbsp;&nbsp;&nbsp;????<br>\n";
 428                              }
 429                          }                
 430                      echo"</td></tr> \n";                
 431                      }                
 432                  
 433                  $comptligne++;
 434                                  
 435                  }
 436          
 437              echo"</table>\n";
 438              }
 439          else
 440              {
 441              //order per country code

 442              arsort($nbrvisits); 
 443                 
 444             foreach ($nbrvisits as $key => $value)
 445                {
 446                $listcountry[] = $key;
 447                } 
 448              
 449              echo"<div class='tableau' align='center'>\n";    
 450              echo"<table   cellpadding='0px' cellspacing='0' width='100%'>\n";
 451              echo"<tr><th class='tableau1'>\n";
 452              echo"".$language['crawler_country']."\n";
 453              echo"</th>\n";
 454              echo"<th class='tableau1'>\n";
 455              echo"".$language['nbr_visits']."\n";        
 456              echo"</th>\n";        
 457              echo"<th class='tableau2'>\n";        
 458              echo"".$language['nbr_tot_crawlers']."\n";
 459              echo"</th></tr>\n";
 460              
 461              //counter for alternate color lane

 462              $comptligne=2;            
 463              foreach ($listcountry as $code)
 464                  {            
 465                  if ($comptligne%2 ==0)
 466                      {
 467                      echo"<td class='tableau3g'>&nbsp;&nbsp;&nbsp;<img src=\"./images/flags/$code.gif\" width=\"16px\" height=\"11px\"  border=\"0\" alt=\"$country[$code]\">&nbsp;&nbsp;$country[$code]</td>\n";
 468                      echo"<td class='tableau3'>".numbdisp($nbrvisits[$code])."</td>\n"; 
 469                      echo"<td class='tableau5'>".numbdisp($nbrcountry[$code])."</td></tr>\n";
 470                      }
 471                  else
 472                      {
 473                      echo"<td class='tableau30g'>&nbsp;&nbsp;&nbsp;<img src=\"./images/flags/$code.gif\" width=\"16px\" height=\"11px\"  border=\"0\" alt=\"$country[$code]\">&nbsp;&nbsp;$country[$code]</td>\n";
 474                      echo"<td class='tableau30'>".numbdisp($nbrvisits[$code])."</td>\n"; 
 475                      echo"<td class='tableau50'>".numbdisp($nbrcountry[$code])."</td></tr>\n";
 476                      }
 477                    $comptligne++;   
 478                  }
 479                echo"</table>\n";  
 480              }
 481          
 482          echo"<br>\n";
 483          echo"<p align='center'><span class='smalltext'>".$language['maxmind']." <a href='http://maxmind.com'>http://maxmind.com</a></span></p>\n";
 484          
 485          }
 486      else
 487          {
 488          //case no ip in the visit table (upgrade to 1.50)        

 489          echo"<div align='center'>\n";    
 490          echo crawltbackforward('origin',$period,$daytodaylocal,$monthtodaylocal,$yeartodaylocal,$daybeginlocal,$monthbeginlocal,$yearbeginlocal,$dayendweek,$monthendweek,$yearendweek,$crawler,$navig,$site,$graphpos);
 491          echo"<h1>".$language['no_ip']."</h1>\n";
 492          echo"<br>\n";        
 493          }
 494      }
 495  else //case no visits
 496      {
 497      echo"<div align='center'>\n";
 498      echo crawltbackforward('origin',$period,$daytodaylocal,$monthtodaylocal,$yeartodaylocal,$daybeginlocal,$monthbeginlocal,$yearbeginlocal,$dayendweek,$monthendweek,$yearendweek,$crawler,$navig,$site,$graphpos);      
 499      echo"<h1>".$language['no_visit']."</h1>\n";
 500      echo"<br>\n";
 501      }
 502  
 503      
 504  
 505  ?>


Généré le : Thu Sep 6 14:14:11 2007 par Balluche grâce à PHPXref 0.7