hostlist.php 908 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. // Requires PHP >= 4.3.0
  3. // Author: "Krasko Oleksandr" <0m3r.mail@gmail.com>
  4. // Minor improvements by Christian Grothoff <christian@grothoff.org>
  5. header("Content-Type: application/octet-stream\r\n\r\n");
  6. $extmas = array();
  7. $pv=$_GET['p'];
  8. if (isset($pv))
  9. {
  10. for ($ii=0;$ii<64;$ii++)
  11. if (0 != ($pv & (1 << $ii)))
  12. $extmas[] = $ii;
  13. }
  14. else
  15. {
  16. $extmas = array('2','3','4','5','6','8','12','17','23','25');
  17. }
  18. $path = '/var/lib/gnunet/data/hosts/'; // adjust as necessary
  19. $dir = opendir($path);
  20. if (! $dir)
  21. die("Cannot open directory $path.\n");
  22. $mas = array();
  23. while ($fname = readdir($dir)) {
  24. $fn = $path . '/' . $fname;
  25. if (is_file($fn)) {
  26. $dpo = strpos($fname, '.') + 1;
  27. $len = strlen($fname);
  28. if (in_array(substr($fname, $dpo - $len), $extmas))
  29. $mas[] = $fn;
  30. }
  31. }
  32. shuffle($mas); // randomize order
  33. foreach ($mas as $val)
  34. echo file_get_contents($val);
  35. ?>