#!/usr/bin/perl
;# newuser (c) 1995, 1996 Chris Church / aD! Data Systems
;# psylark@ad.org

require 'bbs-lib.pl';
require '/usr/local/etc/adbbs.cf';

sub show_intro {

 $wfile = "/usr/local/etc/new.user";
 &rsp($wfile);
 print "Do You Agree With These Terms ? [Y/N](Y) -> ";
 $ent = <>;
 chop($ent);
 if ($ent eq 'n' || $ent eq 'N') {
	print "Goodbye Then!!\n";
	exit;
	} else { return; }
}
 	
sub uname {

 system("/bin/stty", "iuclc");
 print "All Letters Will Be Translated To Lower Case!\n";
 print "Enter The Username You Would Like \(Letters \& Numbers Only!\)\n";
 print "-> ";
 $uname = <>;
 chop($uname);
 if ($uname =~ /[^a-zA-Z0-9]/) { 
	print "Username Is Invalid!!!\(Must Consist Of Letters And/Or Numbers\n";
	&uname;
	}
 print "o. Running Length Check On Username $uname\n";
 $ch =~ /(.{1,8}).*/;
 print "o. Checking for the existance of $uname \(final after length check\)\n";
 $passwdf = "/etc/passwd";
 open(passwdf) || die "Could Not Open Password File! : $!\n";
 while(<passwdf>) {
	if (/^${uname}.*/) {
		print "User Name Is Already In Use! Try Again\n";
		&uname;
		}
	}
 print "o. Username passed existance check\n";
 system("/bin/stty", "-iuclc");
}

sub do_file {
 $fdir = "/tmp/acctf";
 local($curfile) = "$fdir/acct.$$"; 
 open(wfile, "> $curfile") || die "Could Not Open Storage File : $!\n";
 print wfile "login	$uname\n";
 print wfile "passwd	$pass\n";
 print wfile "gcos	$gcos\n";
 close(wfile);
}


&show_intro;
&uname;
print "Enter The Password You Wish To Use \(It Will Not Be Echoed!\)\n";
print "-> ";
system("/bin/stty", "-echo");
$pass = <>;
chop($pass);
system("/bin/stty", "echo");
print "\nEnter The Information You Would Like Displayed When Fingered\n";
print "-> ";
$gcos = <>;
chop($gcos);
print "Would You Like To See The Information For Your Account As It Stands?\n";
print "Y/N (Y) -> ";
$ent = <>;
chop($ent);
if ($ent eq 'n' || $ent eq 'N') {
	&do_file;
	} else { 
	print "Username : $uname\nPassword: $pass\nGCOS: $gcos\n";
	&do_file;
}
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
	localtime(time);
print "All accounts are created at 59 minutes past the hour\n";
print "The system time is $hour:$min:$sec\n";
if ($min == 59) { print "Your Account Will Be Created In One Hour\n";}
	else { 
		$curt = $min; $blah = (59 - $curt);
		print "Your Account will Be Created In $blah Minutes\n";
}


