home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / gopher / Unix / go4gw1.1 / g2archie < prev    next >
Encoding:
Text File  |  1993-04-30  |  2.9 KB  |  115 lines

  1. #!/usr/local/bin/perl
  2.  
  3. #----------------------------------------------------------------------
  4. # variables you should change, note that archie server is set dynamically below:
  5.  
  6. $archie_server = "archie.sura.net";
  7. $archie_prog   = "/usr/local/bin/archie";
  8. $ftp_gateway   = "joeboy.micro.umn.edu";
  9. $ftp_port      = 70;
  10.  
  11. @sound_types   = (".snd$",  ".au$");
  12. @image_types   = (".gif$", ".tiff$", ".pcx$", ".jpg$");
  13. @binary_types  = (".exe$", ".tar.Z$", ".zip$", ".zoo$", ".arj$", ".arc$",
  14.           ".lzh$", ".hyp", ".pak$", ".exe$", ".com$");
  15. @hqx_types     = (".hqx$");
  16.  
  17.  
  18.  
  19. #----------------------------------------------------------------------
  20.  
  21. # gateway from gopher to archie
  22. # this is the "brute force" kind of approach; a tidier solution
  23. # would speak the prospero protocols directly.
  24.  
  25. $archie = "archie.sura.net";
  26. $type = "exact";
  27.  
  28.  
  29. sub archie_main {
  30.     
  31.     local($_) = @_;
  32.     
  33.     if (/^$/) {
  34.     &Greply("7Exact search of archive sites on the internet\t$Ggw exact\t$Ghost\t$Gport");
  35.     &Greply("7Substring search of archive sites on the internet\t$Ggw substr\t$Ghost\t$Gport");
  36.     &Greply(".");
  37.     exit;
  38.     }
  39.     
  40.     ($type, $query, $gplus) = split('\t');
  41.  
  42.     $query =~ s/([^A-Za-z0-9])/\\$1/g;
  43.  
  44.     @DaytoMon  = ("", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
  45.     
  46.     
  47.     if ($gplus eq '!') {
  48.     print ".\r\n";
  49.     exit;
  50.     }
  51.     
  52.     if ($type eq "exact") {
  53.     $arg = " -e ";
  54.     } else {
  55.     $arg = " -s ";
  56.     }
  57.  
  58.     exit if (length($query) <1);
  59.  
  60.     &Greply("0Starting Archie Search, patience.....\t\tbogusip.micro.umn.edu\t70");
  61.  
  62.     #
  63.     # This code does load balancing, it's worth it, beleive me..
  64.     #
  65.     @archies = ("archie.unl.edu", "archie.sura.net", "archie.ans.net", "archie.rutgers.edu");
  66.     $archiemap{"unl"} = "archie.unl.edu";
  67.     $archiemap{"sura"} = "archie.sura.net";
  68.     $archiemap{"ans"} = "archie.ans.net";
  69.     $archiemap{"rutge"} = "archie.rutgers.edu";
  70.  
  71.     open(moo, "/usr/ucb/rup @archies|");
  72.     $load = 10000.0;
  73.     $litehost = "sura";
  74.     while (<moo>) {
  75.         m/^archie\.([^\. ]*)[\. ^u].*load average: ([0-9\.^ ]*)/;
  76.         if ($2 < $load) {
  77.                 $load = $2;
  78.                 $litehost = $1;
  79.         }
  80.     }
  81.  
  82.     close(moo);
  83.     $archie_server =  $archiemap{$litehost} ;
  84.  
  85.     &Greply("OSearching Archie server at $archie_server\t\tbogusip.micro.umn.edu\t70");
  86.     
  87.     $archcmd = "$archie_prog -l -t $arg -h $archie_server $query";
  88.     @result = `$archcmd`;
  89.     foreach (@result) {
  90.     ($time, $size, $host, $file) = split;
  91.     $type = 0;  # assume text.
  92.     $type = "1" if ($file =~ m./$.) ;
  93.         foreach $i (@binary_types) {
  94.         $type = "9" if ($file =~ /$i/i);
  95.     }
  96.         foreach $i (@image_types) {
  97.         $type = "I" if ($file =~ /$i/i);
  98.     }
  99.         foreach $i (@sound_types) {
  100.         $type = "s" if ($file =~ /$i/i);
  101.     }
  102.         foreach $i (@hqx_types) {
  103.         $type = "4" if ($file =~ /$i/i);
  104.     }
  105.     
  106.     &Greply("$type$host:$file\tftp:$host@$file\t$ftp_gateway\t$ftp_port");
  107.     }
  108.     
  109.     print ".\r\n";
  110.     exit;
  111.     
  112. }
  113.  
  114. 1; # for reqiure
  115.