home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / gopher / Unix / go4gw1.1 / go4gw < prev    next >
Encoding:
Text File  |  1993-05-03  |  2.6 KB  |  117 lines

  1. #!/usr/local/bin/perl
  2. #----------------------------------------------------------------------
  3. # variables to change
  4.  
  5. $Gconf_file = "/home/ashpool/go4gw/go4gw.conf"; # configuration file
  6. $Gport=4324;                               # port THIS daemon is running on
  7. $Ghost="mudhoney.micro.umn.EDU";            # host THIS daemon is running on
  8.  
  9.  
  10. #----------------------------------------------------------------------
  11.  
  12. #Hmm.  I'm really not sure how to catch signals...
  13. $SIG{'INT'} = 'Gabort';
  14. $SIG{'HUP'} = 'Gabort';
  15. $SIG{'QUIT'} = 'Gabort';
  16. $SIG{'PIPE'} = 'Gabort';
  17. $SIG{'ALRM'} = 'Gabort';
  18.  
  19.  
  20. &go4gw_main if (!defined($GnotServer));
  21.  
  22. sub go4gw_main {
  23.  
  24. # get command
  25. $_ = <STDIN>; s/\r//; s/\n//;
  26.  
  27. ($gw,$args) = /^(\w+)\s*(.*)$/ if (!/^$/);
  28.  
  29. open(CONF,$Gconf_file) || &Gabort("$Gconf_file: $!");
  30. while(<CONF>) { 
  31.      chop;
  32.      next if /^#/ || /^$/;
  33.      ($gateway,$user,$module,$title) = split(/:/);
  34.      if ($gw eq '' && $title) { &Greply("1$title\t$gateway\t$Ghost\t$Gport"); }
  35.      elsif ($gw eq $gateway) { &launch_gateway($user,$gateway,$module,$args); }
  36. }
  37.  
  38. if ($gw eq '') { &Greply("."); exit; }
  39. else { &Gabort("3No such gateway: $gw"); }
  40.  
  41. }
  42. sub launch_gateway {
  43.    local($user,$gateway,$module,$args) = @_;
  44.  
  45.    if ($user =~ /^\-?\d+$/) { $Guid = $user; }
  46.    elsif ($user eq '') { $Guid = -2; }
  47.    else {           
  48.        ($n,$pw,$Guid) = getpwnam($user);
  49.        if ($Guid eq '') { $Guid = "-2"; }
  50.    }
  51.  
  52.   ($<,$>) = ($Guid,$Guid) unless $>;
  53.    &Gabort("Can't load gateway: $module") if (! -e $module);
  54.    require "$module";
  55.    $main = "${gateway}_main";
  56.    $Ggw = $gateway;
  57.    &$main($args);
  58.    &Greply(".");  # shouldn't really get here, but what the hack!
  59.    exit;
  60. }
  61.  
  62. #
  63. # standard routines
  64. #
  65.  
  66. sub Greply { print "$_[0]\r\n"; }
  67.  
  68. sub Gabort { print "3$_[0]\r\n.\r\n"; exit; }
  69.  
  70. sub GopenServer {
  71.  
  72.  local($server,$port) = @_;
  73.  $sockaddr = 'S n a4 x8';
  74.  (($name, $aliases, $type, $len, $saddr) = gethostbyname($server))
  75.         || &Gabort("3Can't get address of: $server");
  76.  $sin = pack($sockaddr, 2, $port, $saddr);
  77.  socket(GSERVER, 2, 1, 0) || &Gabort("Can't create socket: $!");
  78.  connect(GSERVER, $sin)   || &Gabort("Can't connect to server: $!");
  79.  select(GSERVER); $| = 1; select(STDOUT); $| = 1;
  80. }
  81.  
  82. sub GcloseServer {
  83.   close(GSERVER);
  84. }
  85.  
  86. sub Gsend { 
  87.      print "send -> |$_[0]|\n" if (defined($Gdebug));
  88.      print GSERVER "$_[0]\r\n"; 
  89. }
  90.  
  91. sub Grecv { 
  92.    local ($_); 
  93.    $_= <GSERVER>; 
  94.    s/\n$//;
  95.    s/\r$//;
  96.    print "recv -> |$_|\n" if (defined($Gdebug));
  97.    return $_; 
  98. }
  99.  
  100. sub Gsorry {
  101.  
  102. print<<EOF;
  103.  
  104. Sorry! You have selected information that cannot be delivered off
  105. of campus due to restrictions.
  106.  
  107.    -- The Mole Hole Guardian
  108.  
  109. EOF
  110.  
  111. &Greply(".");
  112. exit;
  113.  
  114. }
  115.  
  116. 1;  # for require
  117.