#!/usr/local/bin/perl
$ENV{PATH} = "/usr/ucb:/bin:/usr/local/bin";

$Iadmin=<>;
$Iadminemail=<>;
$Iname=<>;
$Ihost=<>;
$Iport=<>;
$Ipath=<>;
$Iloc=<>;
$Igplus=<>;

#  make insecure fields secure
$Iadmin	 =~ m/^(.*)$/;
$admin = $1;
$Iadminemail =~ m/^(.*)$/;
$adminemail = $1;
$Iname =~ m/^(.*)$/;
$name = $1;
$Ihost =~ m/^(.*)$/;
$host = $1;
$Iport =~ m/^(.*)$/;
$port = $1;
$Ipath =~ m/^(.*)$/;
$path = $1;
$Iloc =~ m/^(.*)$/;
$loc = $1;
$Igplus =~ m/^(.*)$/;
$gplus = $1;





&GopenServer($host, $port);

if ($name =~ /^$/) {
	print "Please specify a name. e.g.\n\n  Miskatonic University\n";
	exit;
}

if ($adminemail =~ /^$/) {
	print "Please specify an administrator email.  e.g.\n\n   joe@foo.com";
	exit;
}

push(@lines, "This is what we have so far:\n\n");

push(@lines,  "Server is located in $loc\nLink info looks like:\n\n");

push(@lines,  "#Admin=$admin <$adminemail>\n");
push(@lines,  "Name=$name\n");
push(@lines,  "Host=$host\n");
push(@lines,  "Port=$port\n");
push(@lines,  "Type=1");
if ($gplus eq "yes") {
	push(@lines,  "+");
}

push(@lines,  "\n");

push(@lines,  "Path=$path\n");

push(@lines,  "\n\nThanks for using gopher+ to register, it makes our job easier.\n");
push(@lines, "A copy of this message will be mailed to the administrator\n");

	
print @lines;

open(emailit, "|mail -s \"** Gopher Registration **\" gopher@boombox.micro.umn.edu $adminemail");

print emailit @lines;
close(emailit);


sub GopenServer {
 local($server,$port) = @_;

 
 $sockaddr = 'S n a4 x8';
 (($hostname, $aliases, $type, $len, $saddr) = gethostbyname($server))
        || &Gabort("3Can't get address of: $server");
 $sin = pack($sockaddr, 2, $port, $saddr);
 socket(GSERVER, 2, 1, 0) || &Gabort("Can't create socket: $!");
 connect(GSERVER, $sin)   || &Gabort("Can't connect to server: $!");
 select(GSERVER); $| = 1; select(STDOUT); $| = 1;
}

sub GcloseServer {
	close(GSERVER);
}

sub Gabort { print "3$_[0]\r\n.\r\n"; exit; }

