#! /srvtools/http/bin/perl
#############################################################################
#  
#   File:         UserName.pl
#
#   Author:       Jungmin Kim
#
#   Created:      03/30/95
#   Modified: 
#   Version: 
#
#   Description:  Subroutines of Change.pl to modify password file
#
#############################################################################


#############################################################################
#
#  EnterUser
# 
#  INPUT:    user information (administrator)
#  OUTPUT:   HTML text
#  FUNCTION: create fill-out forms to get a new user name
#
#############################################################################

sub EnterUser{
    local($prev, $user, $subdir) = @_;

    print "Content-type\: text/html\n\n";
    print "\n";
    print "<TITLE> ADD A NEW USER </TITLE>\n";
    print "<H1> Add a New User</H1>\n";

    print "<H2>The username cannot be registered, it already exists!<P></H2>\n"
	if $prev == 1;
    print "<IMG SRC=\"$gif/pointer.xbm\" ALIGN=\"left\" ALT=\"\">";
    print "<A HREF=\"$action/$subdir\:select\:\:\:${user}\">\n";
    print "<B>RETURN to the index of forums</B>\n";
    print "</A>\n";

    print "<HR>\n";
    print "<FORM METHOD=\"POST\" ACTION=\"$change/$subdir\:retryuser\:$user\">\n";
    print "Enter the <B>USER NAME</B> to be added\: \n";
    print "<INPUT SIZE=25 NAME=\"newuser\" VALUE=\"\"><br>\n";
    print "Enter the <B>PASSWORD</B> of the USER\: \n";
    print "<INPUT TYPE=\"password\" SIZE=25 ";
    print "NAME=\"newpasswd\" VALUE=\"\"><P>\n";
    print "Press the submit button to submit\: ";
    print "<INPUT TYPE=\"submit\" VALUE=\"SUBMIT\">\n";
    print "</FORM>\n";
    print "<HR>\n";
    print "<ADDRESS>\n";
    print "<A HREF=\"$webteam\">\n";
    print "The WeBBoard development team</A>\n";
    print "</ADDRESS>\n";
    
}
1;

#############################################################################
#
#  RetryNewPasswd
# 
#  INPUT:    user information (administrator)
#  OUTPUT:   HTML text
#  FUNCTION: create fill-out forms again when the first trial is failed
#
#############################################################################

sub RetryNewPasswd{
    local($user, $subdir) = @_;

    print "Content-type\: text/html\n\n";
    print "\n";
    print "<TITLE> RETRY A NEW USER </TITLE>\n";
    print "<H1> Add a New User</H1>\n";
    print "<H2> FAILED! PLEASE TRY IT AGAIN. </H2>\n";
    print "<IMG SRC=\"$gif/pointer.xbm\" ALIGN=\"left\" ALT=\"\">";
    print "<A HREF=\"$action/$subdir:select\:$path\:\:$user\">\n";
    print "<B>RETURN to the index of forums</B>\n";
    print "</A>\n";

    print "<HR>\n";
    print "<FORM METHOD=\"POST\" ACTION=\"$change/$subdir\:retryuser\:$user\">\n";
    print "Enter the <B>USER NAME</B> to be added\: \n";
    print "<INPUT SIZE=25 NAME=\"newuser\" VALUE=\"$username\"><br>\n";
    print "Enter the <B>PASSWORD</B> of the USER\: \n";
    print "<INPUT TYPE=\"password\" SIZE=25 ";
    print "NAME=\"newpasswd\" VALUE=\"\"><P>\n";
    print "Press the submit button to submit\: ";
    print "<INPUT TYPE=\"submit\" VALUE=\"SUBMIT\">\n";
    print "</FORM>\n";
    print "<HR>\n";
    print "<ADDRESS>\n";
    print "<A HREF=\"$webteam\">\n";
    print "The WeBBoard development team</A>\n";
    print "</ADDRESS>\n";
}
1;

#############################################################################
#
#  RetryUser
# 
#  INPUT:    user name (new), password (new), user information (administrator)
#  OUTPUT:   HTML text
#  FUNCTION: create fill-out forms again to confirm the user name
#
#############################################################################

sub RetryUser{
    local($username, $passwd, $user, $subdir) = @_;


    print "Content-type: text/html\n\n";
    print "\n";
    print "<TITLE> ADD A NEW USER </TITLE>\n";
    print "<H1> Add a New User</H1>\n";
    print "<H2> Please enter the password again. </H2>\n";
    print "<IMG SRC=\"$gif/pointer.xbm\" ALIGN=\"left\" ALT=\"\">";
    print "<A HREF=\"$action/$subdir\:select\:\:\:$user\">\n";
    print "<B>RETURN to the index of forums</B>\n";
    print "</A>\n";

    $username =~ s/&/&amp;/g;
    $username =~ s/>/&gt;/g;
    $username =~ s/</&lt;/g;
    $username =~ s/\"/&quot;/g;
    $passwd =~ s/&/&amp;/g;
    $passwd =~ s/>/&gt;/g;
    $passwd =~ s/</&lt;/g;
    $passwd =~ s/\"/&quot;/g;

    print "<HR>\n";
    print "<FORM METHOD=\"POST\" ACTION=\"$change/$subdir\:equal\:$user\">\n";
    print "Enter the <B>USER NAME</B> to be added\: \n";
    print "<INPUT SIZE=25 NAME=\"newuser2\" VALUE=\"$username\"><br>\n";
    print "Enter the <B>PASSWORD</B> of the USER\: \n";
    print "<INPUT TYPE=\"password\" SIZE=25 ";
    print "NAME=\"newpasswd2\" VALUE=\"\"><P>\n";
    print "Press the submit button to submit\: ";
    print "<INPUT TYPE=\"submit\" VALUE=\"SUBMIT\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"newuser\" VALUE=\"${username}\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"newpasswd\" VALUE=\"${passwd}\">\n";
    print "</FORM>\n";
    print "<HR>\n";
    print "<ADDRESS>\n";
    print "<A HREF=\"$webteam\">\n";
    print "The WeBBoard development team</A>\n";
    print "</ADDRESS>\n";
}
1;

#############################################################################
#
#  NameEmail
# 
#  INPUT:    user name (new), password (new), user information (administrator)
#  OUTPUT:   HTML text
#  FUNCTION: fill-out forms for real name and e-mail address
#
#############################################################################

sub NameEmail{
    local($username, $passwd, $user, $subdir) = @_;

    print "Content-type\: text/html\n\n";
    print "\n";

    print "<TITLE> ADD A NEW USER </TITLE>\n";
    print "<H1> Add a New User</H1>\n";
    print "<H2> Please enter new user's name and e-mail address. </H2>\n";
    print "<IMG SRC=\"$gif/pointer.xbm\" ALIGN=\"left\" ALT=\"\">";
    print "<A HREF=\"$action/$subdir\:select\:$path\:\:$user\">\n";
    print "<B>RETURN to the index of forums</B>\n";
    print "</A>\n";

    $username =~ s/&/&amp;/g;
    $username =~ s/>/&gt;/g;
    $username =~ s/</&lt;/g;
    $username =~ s/\"/&quot;/g;
    $passwd =~ s/&/&amp;/g;
    $passwd =~ s/>/&gt;/g;
    $passwd =~ s/</&lt;/g;
    $passwd =~ s/\"/&quot;/g;

    print "<HR>\n";
    print "<FORM METHOD=\"POST\" ACTION=\"$change/$subdir\:saveuser\:$user\">\n";
    print "Enter your name\: \n";
    print "<INPUT SIZE=30 NAME=\"name\" VALUE=\"\"><br>\n";
    print "E-mail Address\: \n";
    print "<INPUT SIZE=30 NAME=\"email\" VALUE=\"\"><P>\n";
    print "Press the submit button to submit\: ";
    print "<INPUT TYPE=\"submit\" VALUE=\"SUBMIT\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"newuser\" VALUE=\"${username}\">\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"newpasswd\" VALUE=\"${passwd}\">\n";
    print "</FORM>\n";
    print "<HR>\n";
    print "<ADDRESS>\n";
    print "<A HREF=\"$webteam\">\n";
    print "The WeBBoard development team</A>\n";
    print "</ADDRESS>\n";
}
1;



#############################################################################
#
#  SaveName
# 
#  INPUT:    user name, password, real name, email address, (new user)
#  OUTPUT:   HTML text
#  FUNCTION: save the new user into password file
#
#############################################################################

sub SaveName{
    local($uid, $passwd, $name, $email) = @_;
    local($user);

    $user = &CheckName($uid);
    if ($user ne "0") {return 1;}

    system("cp $fcheckfile $fcheckfile.bak");
    open(OUTFILE, ">>$fcheckfile") ||
	print "Content-type\: text/html\n\n\n Cannot open $fcheckfile\: $!";
    print OUTFILE "$uid\:$passwd\:$name\:$email\n";
    close(OUTFILE);
    # chmod 400, $fcheckfile;
    0;
}
1;

#############################################################################
#
#  DeleteUser
# 
#  INPUT:    user information (administrator)
#  OUTPUT:   HTML text
#  FUNCTION: create fill-out forms to delete a user name
#
#############################################################################

sub DeleteUser{
    local($user, $subdir) = @_;


    print "Content-type\: text/html\n\n";
    print "\n";
    print "<TITLE> DELETE A  USER </TITLE>\n";
    print "<H1> Delete a User</H1>\n";
    print "<IMG SRC=\"$gif/pointer.xbm\" ALIGN=\"left\" ALT=\"\">";
    print "<A HREF=\"$action/$subdir\:select\:\:\:${user}\">\n";
    print "<B>RETURN to the index of forums</B>\n";
    print "</A>\n";

    print "<HR>\n";
    print "<FORM METHOD=\"POST\" ACTION=\"$change/$subdir\:removeuser\:$user\">\n";
    print "Enter the <B>USER NAME</B> to be deleted\: \n";
    print "<INPUT SIZE=25 NAME=\"deluser\" VALUE=\"\"><P>\n";
    print "Press the submit button to submit\: ";
    print "<INPUT TYPE=\"submit\" VALUE=\"SUBMIT\">\n";
    print "</FORM>\n";
    print "<HR>\n";
    print "<ADDRESS>\n";
    print "<A HREF=\"$webteam\">\n";
    print "The WeBBoard development team</A>\n";
    print "</ADDRESS>\n";
    
}
1;

#############################################################################
#
#  RemoveName
# 
#  INPUT:    user name
#  OUTPUT:   HTML text
#  FUNCTION: remove the new user from password file
#
#############################################################################

sub RemoveName{
    local($uid) = @_;
    local(@names, $i);
    @names = ();

    system("cp $fcheckfile $fcheckfile.bak");
    open(INFILE, "< $fcheckfile") ||
	print "Content-type\: text/html\n\n\n Cannot open $fcheckfile\: $!";
    while(<INFILE>) {
	if(/^$uid/) { next; }
	push(@names, $_);
    }

    open(OUTFILE, "> $fcheckfile") ||
	print "Content-type\: text/html\n\n\n Cannot open $fcheckfile\: $!";
    foreach $i (0 .. $#names) {
	print OUTFILE $names[$i];
    }
    close(OUTFILE);
    # chmod 400, $fcheckfile;
}
1;

