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

  1. #!/usr/local/bin/perl
  2.  
  3. #----------------------------------------------------------------------
  4. # variables you can change:
  5.  
  6. #$webster_server  = "webster.lcs.mit.edu";
  7. #$webster_port    = 103;
  8.  
  9. $webster_server = "nakamichi.micro.umn.edu";
  10. $webster_port   = 2627;
  11.  
  12. @webster_acl=(
  13. #     ipaddress  access + = allow, - = deny    
  14.      '^134.84\.      +',
  15.      '^128.101\.     +',
  16.      '.*         -'
  17.   );
  18.  
  19. #----------------------------------------------------------------------
  20.  
  21. sub webster_main {
  22.  local($_ )= @_;
  23.  
  24.  &Gsorry if /^sorry$/;
  25.  
  26.   if (&check_access() eq '-') {
  27.       &Greply("0Sorry! No access off of campus!\t$Ggw sorry\t$Ghost\t$Gport");
  28.       &Greply("."); 
  29.       exit; 
  30.   }
  31.  
  32.  if (/^$/) {
  33.   &Greply("7Lookup word in dictionary\t$Ggw default SPELL\t$Ghost\t$Gport");
  34.   &Greply("7Lookup word in dictionary (phonetic match)\t$Ggw default PSPELL\t$Ghost\t$Gport");
  35.   &Greply("7Search text of entire dictionary\t$Ggw dictionary-full SPELL\t$Ghost\t$Gport");
  36.   &Greply("7Show words that start with\t$Ggw default ENDINGS\t$Ghost\t$Gport");
  37.   &Greply("7Thesaurus\t$Ggw thesaurus SPELL\t$Ghost\t$Gport");
  38.   &Greply(".");
  39.   exit(0);
  40.  }
  41.  
  42.  ($index,$cmd,$query) = /^(\S+)\s+(\S+)\s+(.+)$/;
  43.  
  44.   &GopenServer($webster_server,$webster_port);
  45.  
  46.   &Gsend("INDEX $index") if ($index ne 'default');
  47.  
  48.   if ($cmd eq "PSPELL") {                     # phonetic lookup
  49.        &Gsend("SPELL $query ?");
  50.   } else {
  51.        &Gsend("$cmd $query");
  52.   }
  53.  
  54. $_ = &Grecv;
  55.  
  56.   if (/^SPELLING 0/ || /^WILD 0/) {
  57.         &Greply(".");
  58.    } elsif (/^SPELLING 1/) {
  59.       &Greply("0$query\t$Ggw $index DEFINE $query\t$Ghost\t$Gport"); 
  60.       &Greply(".");
  61.    } elsif (/^SPELLING$/ || /^MATCHS$/ || /^WILD/) {
  62.         $/ = "\200";
  63.         $buf = <GSERVER>;
  64.         $buf =~ s/[\r\200]//g;
  65.         foreach (split(/\n/,$buf)) { /\d+\s+(\S+)/; $words{$1}=""; }
  66.         foreach (sort keys %words) { 
  67.                &Greply("0$_\t$Ggw $index DEFINE $_\t$Ghost\t$Gport"); 
  68.         }
  69.         &Greply(".");
  70.    } elsif (/^DEFINITION/) {
  71.         $/ = "\200";
  72.         $buf = <GSERVER>;
  73.         $buf =~ s/[\r\200]//g;
  74.         print $buf;
  75.    } else {
  76.         &Greply(".");
  77.    }
  78.   &Gsend("QUIT");
  79.   &GcloseServer;
  80.   exit;
  81. }
  82.  
  83. sub check_access {
  84.  
  85.    return 1 if (-t STDIN);
  86.    $sockaddr = 'S n a4 x8';
  87.    $mysockaddr = getpeername(STDIN);
  88.    ($ramily,$rport,$raddr) = unpack($sockaddr,$mysockaddr);
  89.    ($a,$b,$c,$d) = unpack('C4',$raddr);
  90.    $ipaddress = "$a.$b.$c.$d";
  91.  
  92.    foreach (@webster_acl) {
  93.       ($ipacl,$access)=split;
  94.       return $access if  ($ipaddress =~ /$ipacl/);
  95.    }
  96.    return '-'; #default is to restrict access
  97. }
  98.  
  99. 1; # for require
  100.