paste.php.lv / koda glabātuve (vēl mums ir forumi un irc kanāls)

Autors: BlackHalt

Komentārs: Is TOR? PHP code snipet

Skatīt bez rindiņu numerācijas

  1. <!-- HTML -->
  2. <form id="forma" name="forma" method="post" action="">
  3. <input type="text" name="ip" />
  4. <input type="submit" name="Submit" value="Submit" />
  5. </form>
  6.  
  7. <?php
  8.  
  9. /*
  10.  
  11. BlaskHalt Is TOR? PHP code snipet
  12.  
  13. http://blackhalt.wordpress.com/2008/06/05/is-tor/
  14.  
  15. */
  16.  
  17. //error_reporting(0);
  18.  
  19. $mans_tor_fails='is_tor.txt';
  20. $svaigums='http://proxy.org/tor_blacklist.txt';
  21.  
  22. // Nocheko kaut kaadu svaigumu, viena diena:
  23.  
  24. if ((!file_exists($mans_tor_fails)) or (time() - filemtime($mans_tor_fails) > 86400)) {
  25.  
  26.  
  27. $ctx = stream_context_create(array(
  28. 'http' => array(
  29. 'timeout' => 10
  30. )
  31. )
  32. );
  33.  
  34. $atvelk=file_get_contents($svaigums,0,$ctx);
  35.  
  36.  
  37. if($atvelk==true){
  38.  
  39. // Tipa iznjemam aaraa lieko
  40. // Ar tiem njuulainiem pashi gudrojiet:
  41.  
  42. $atvelk=str_replace(
  43. array(
  44.  
  45. "RewriteEngine on \n",
  46. "\nRewriteRule ^.* - [F] ",
  47. 'RewriteCond %{REMOTE_ADDR} ^',
  48. '^',
  49. '$',
  50. '[OR]',
  51. ' ',
  52.  
  53.  
  54. ),
  55.  
  56. '',
  57.  
  58. $atvelk);
  59.  
  60. $atvelk=str_replace('\.','.',$atvelk);
  61.  
  62. // Ieraksta failaa:
  63.  
  64. $raksta=fopen($mans_tor_fails,'w+');
  65. fputs($raksta,$atvelk);
  66. fclose($raksta);
  67.  
  68. }
  69. }
  70.  
  71. // $_POST['ip'] vietā vari izmantot IP noteikshanas funkcijas.
  72.  
  73. if(isset($_POST['ip'])){
  74.  
  75. $ip=$_POST['ip'];
  76.  
  77. // Te var veel visaadus filtrus samudriit:
  78.  
  79. $ip=htmlspecialchars($ip,ENT_QUOTES);
  80.  
  81. $saraksts=array_map('trim',file($mans_tor_fails));
  82.  
  83. if(in_array($ip,$saraksts)){
  84.  
  85. echo'<h1>Ir TOR</h1>';
  86.  
  87. }
  88. else{
  89.  
  90. echo'Nav TOR';
  91.  
  92. }
  93.  
  94. }
  95.  
  96. ?>

© 2003 – 2010 PHP.lv komanda. Visas tiesības ir paturētas. Izņemot saturu, kurš ir tā autora īpašums, ja nekas nenosaka savādāk.