home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / UNIX / GOPHER / GO4GW1.2B / G2GO4 < prev    next >
Encoding:
Text File  |  1993-07-13  |  2.8 KB  |  107 lines

  1. #To: gopher@boombox.micro.umn.edu
  2. #Subject: Gopher on a Firewall
  3. #Organisation: BNR Europe, HARLOW, Essex CM17 9NA, GB
  4. #Phone: +44 279 402423
  5. #Return-Receipt-To: A.Macpherson@bnr.co.uk
  6. #Date: Mon, 17 May 93 19:38:24 +0100
  7. #From: Andrew Macpherson (Postmaster) <A.Macpherson@bnr.co.uk>
  8. #Status: OR
  9.  
  10. #You may think this trivial, but it is offered with my complements
  11.  
  12. #The use is to allow access to the gopher-world from a Network behind a
  13. #firewall.
  14.  
  15.  
  16.  
  17. #----------------------------------------------------------------------
  18. # Firewall gopher-hole, A.Macpherson@bnr.co.uk
  19.  
  20. @g2go4_acl=(
  21. #     ipaddress  access + = allow, - = deny    
  22. #     '^47\.      +',
  23. #     '^128.199\.     +',
  24.      '.*         +'
  25.   );
  26.  
  27. $SafeTypes = "^(0|1|3|4|5|6|7|9)" ;  # Gopher tags we will pass
  28. #----------------------------------------------------------------------
  29.  
  30. sub g2go4_main {
  31.  local($_ )= @_;
  32.  
  33.  &Gsorry if /^sorry$/;
  34.  
  35.   if (&check_access() eq '-') {
  36.       &Greply("0Sorry! No access from Non-local hosts\t$Ggw sorry\t$Ghost\t$Gport");
  37.       &Greply("."); 
  38.       exit; 
  39.   }
  40.  
  41.  if (/^$/) {
  42.   &Greply("1Imperial College Archive\t$Ggw 70\007src.doc.ic.ac.uk\007\t$Ghost\t$Gport");
  43.   &Greply(".");
  44.   exit(0);
  45.  }
  46.  ( $port, $host, $query ) = split('\007') ;
  47.  &GopenServer($host, $port);
  48.  &Gsend($query) ;
  49.  
  50.  # We may be doing a file transfer here, or it may be another menu
  51.  # all we can do is intuit.
  52.  
  53.  $First = <GSERVER> ;
  54.  $Second = <GSERVER> ;
  55.  if ( $First =~ /^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*$/ &&
  56.     ($Second eq ".\r\n" ||
  57.      $Second =~ /^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*$/ )) { # close enough
  58.     $First =~ s/[\r\n]//g ;
  59.   ( $disp, $sel, $host, $port ) = split('\t', $First) ;
  60.     print "${disp}\t$Ggw ${port}\7${host}\7${sel}\t$Ghost\t$Gport\r\n" 
  61.     if $disp =~ m/${SafeTypes}/ ;
  62.     if ($Second eq ".\r\n" ) {
  63.       print $Second ;
  64.       exit 0;
  65.     }
  66.     $Second =~ s/[\r\n]//g ;
  67.   ( $disp, $sel, $host, $port ) = split('\t', $Second) ;
  68.     print "${disp}\t$Ggw ${port}\7${host}\7${sel}\t$Ghost\t$Gport\r\n" 
  69.     if $disp =~ m/${SafeTypes}/ ;
  70.     while(<GSERVER>) {
  71.       s/[\r\n]//g ;
  72.       if ( $_ eq "." ) {
  73.     print ".\r\n" ;
  74.     exit 0;
  75.       }
  76.     ( $disp, $sel, $host, $port ) = split('\t') ;
  77.       print "${disp}\t$Ggw ${port}\7${host}\7${sel}\t$Ghost\t$Gport\r\n" 
  78.     if $disp =~ m/${SafeTypes}/ ;
  79.     }
  80.  } else {
  81.    while(<GSERVER>) {
  82.      print ;
  83.    }
  84.  }
  85. }
  86.  
  87.  
  88.  
  89. sub check_access {
  90.  
  91.    return 1 if (-t STDIN);
  92.    $sockaddr = 'S n a4 x8';
  93.    $mysockaddr = getpeername(STDIN);
  94.    ($ramily,$rport,$raddr) = unpack($sockaddr,$mysockaddr);
  95.    ($a,$b,$c,$d) = unpack('C4',$raddr);
  96.    $ipaddress = "$a.$b.$c.$d";
  97.  
  98.    foreach (@g2go4_acl) {
  99.       ($ipacl,$access)=split;
  100.       return $access if  ($ipaddress =~ /$ipacl/);
  101.    }
  102.    return '-'; #default is to restrict access
  103. }
  104.  
  105. 1; # for require
  106.  
  107.