Files
resatennis_tyroltenn/www/cgi-bin/Demos/DEMO_passwd.pl

289 lines
11 KiB
Perl
Executable File

#!/usr/sbin/perl
#**************************************************************************
#* *
#* Copyright (c) 1996 Silicon Graphics, Inc. *
#* All Rights Reserved *
#* *
#* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI *
#* *
#* The copyright notice above does not evidence any actual of intended *
#* publication of such source code, and is an unpublished work by Silicon *
#* Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is *
#* the property of Silicon Graphics, Inc. Any use, duplication or *
#* disclosure not specifically authorized by Silicon Graphics is strictly *
#* prohibited. *
#* *
#* RESTRICTED RIGHTS LEGEND: *
#* *
#* Use, duplication or disclosure by the Government is subject to *
#* restrictions as set forth in subdivision (c)(1)(ii) of the Rights in *
#* Technical Data and Computer Software clause at DFARS 52.227-7013, *
#* and/or in similar or successor clauses in the FAR, DOD or NASA FAR *
#* Supplement. Unpublished - rights reserved under the Copyright Laws of *
#* the United States. Contractor is SILICON GRAPHICS, INC., 2011 N. *
#* Shoreline Blvd., Mountain View, CA 94039-7311 *
#**************************************************************************
# DEMO_passwd.pl
#
# Routines to password protection
1; # Return true
sub Is_Passwd {
local($file_exists);
$file_exists = open(PASSWD, "$FILE_PASSWD");
close(PASSWD);
return($file_exists);
}
sub Passwd_Entered {
return($in{$CGI_PASSWD_ENTRY_SWITCH});
}
sub Legal_Passwd {
local($legal, $password);
$legal = 0;
if (&Is_Passwd && &Passwd_Entered) {
$password = &Decrypt_Passwd;
$legal = ("$password" eq "$in{$CGI_PASSWD_ENTRY_SWITCH}");
}
&Print_Error("$ERROR_INFO","Restricted Access Granted","$STATUS_MINOR") if ($legal);
#Global Variable
$LEGAL_PASSWD = $legal;
return($legal);
}
sub Decrypt_Passwd {
local($passwd);
open(CMD, "$CMD_CRYPT $PASSWD_KEY < $FILE_PASSWD >$FILE_PASSWD_TMP|");
close(CMD);
# Read out passwd
open(FILE, "$FILE_PASSWD_TMP");
read(FILE, $passwd, 200);
close(FILE);
# Remove tmp file
`$CMD_RM $FILE_PASSWD_TMP`;
return($passwd);
}
sub Generate_Enter_Passwd_Page {
&Print_Error("$ERROR_INFO","Restricted Access Requested","$STATUS_MINOR");
&Print_Maint_Top("Password Required", "$IMGSRC_HEADER_PASSWD", $PASSWD_OVERRIDE);
print "<font color=red size=+3>E</font><font color=red size=+1>NTER</font>\n";
print "<font color=red size=+3>P</font><font color=red size=+1>ASSWORD</font><p>\n";
print "The administration features of this interfaces have been\n";
print "password protected by the system administrator.\n";
print "Please enter the password below.\n";
&Print_Passwd_Entry_Bottom
}
sub Generate_Bad_Passwd_Page {
&Print_Error("$ERROR_INFO","Restricted Access Failed: \"$in{$CGI_PASSWD_ENTRY_SWITCH}\"","$STATUS_MINOR");
&Print_Maint_Top("Incorrect Password", "$IMGSRC_HEADER_PASSWD", $PASSWD_OVERRIDE);
print "<font color=red size=+3>E</font><font color=red size=+1>NTER</font>\n";
print "<font color=red size=+3>P</font><font color=red size=+1>ASSWORD</font><p>\n";
print "Incorrect password. Please try again\n";
&Print_Passwd_Entry_Bottom
}
sub Print_Passwd_Entry_Bottom {
print "<p>\n";
print "<form action=\"$WWW_SCRIPT\" method=GET>\n";
print "<input type=hidden name=\"$CGI_SWITCH\" value=\"$CGI_MAINT_FLAG\">\n";
print "<input type=hidden name=\"$CGI_SUB_SWITCH\" value=\"$in{$CGI_SUB_SWITCH}\">\n";
print "<input type=hidden name=\"$CGI_MAINT_OUTSIDE_SWITCH\" value=\"$CGI_MAINT_FALSE_FLAG\">\n";
print "<input type=password maxlength=30 name=\"$CGI_PASSWD_ENTRY_SWITCH\" size=35>\n";
print "<input type=submit value=\"Submit\">\n";
print "</form>\n";
&Print_Look_At_Help;
&Print_Maint_Bottom;
&Print_HTTP_Footer;
}
sub Generate_Maint_Passwd_Page {
if ($in{$CGI_MAINT_NEW_PASSWD1_SWITCH} || $in{$CGI_MAINT_NEW_PASSWD1_SWITCH} ) {
if (&Good_Passwd_Input) {
&Implement_Passwd;
&Print_Passwd_Success_Page;
} else {
&Print_Passwd_Bad_Input_Page;
}
} elsif ($in{$CGI_MAINT_PASSWD_DELETE_SWITCH}) {
&Delete_Passwd;
&Print_Passwd_Delete_Success_Page;
} else {
&Print_Passwd_Options_Page;
}
}
sub Delete_Passwd {
open(CMD, "$CMD_RM $FILE_PASSWD|");
close(CMD);
}
sub Print_Passwd_Delete_Success_Page {
&Print_Error("$ERROR_INFO","Password Deleted","$STATUS_MINOR");
&Print_Maint_Top("Delete Password <font size=2>[SUCCESS]</font>", "$IMGSRC_HEADER_PASSWD");
print "<font color=red size=+3>I</font><font color=red size=+1>NFORMATION</font><p>\n";
print "The password was successfully deleted.";
print "<p>\n<hr noshade>\n";
&Print_Add_Passwd_Form;
&Print_Maint_Bottom;
&Print_HTTP_Footer;
}
sub Good_Passwd_Input {
return(("$in{$CGI_MAINT_NEW_PASSWD1_SWITCH}" ne "" && "$in{$CGI_MAINT_NEW_PASSWD2_SWITCH}" ne "" && "$in{$CGI_MAINT_NEW_PASSWD1_SWITCH}" eq "$in{$CGI_MAINT_NEW_PASSWD2_SWITCH}"));
}
sub Implement_Passwd {
# Make tmp password file
open(FILE, ">$FILE_PASSWD_TMP");
print FILE "$in{$CGI_MAINT_NEW_PASSWD1_SWITCH}";
close(FILE);
# Encrypt this file into another file "passwd"
open(CMD, "$CMD_CRYPT $PASSWD_KEY < $FILE_PASSWD_TMP >$FILE_PASSWD|");
close(CMD);
# Remove the old tmp file
`$CMD_RM $FILE_PASSWD_TMP`;
}
sub Print_Passwd_Success_Page {
&Print_Error("$ERROR_INFO","Password Added","$STATUS_MINOR");
&Print_Maint_Top("Add Password <font size=2>[SUCCESS]</font>", "$IMGSRC_HEADER_PASSWD");
print "<font color=red size=+3>I</font><font color=red size=+1>NFORMATION</font><p>\n";
print "Password protection enabled.";
print "<p>\n";
print "<i>Should you forget your password, remove the file:<br>\n";
print "<b>$FILE_PASSWD</b></i>\n";
print "<p>\n<hr noshade>\n";
&Print_Delete_Passwd_Form;
&Print_Change_Passwd_Form;
&Print_Maint_Bottom;
&Print_HTTP_Footer;
}
sub Print_Passwd_Bad_Input_Page {
&Print_Maint_Top("Add Password <font size=2>[BAD INPUT]</font>", "$IMGSRC_HEADER_PASSWD");
print "<font color=red size=+3>E</font>";
print "<font color=red size=+1>RROR</font><p>\n";
print "<b>Your input was not valid.</b><p>Enter the same password in each field. \n";
print "Please try again.\n";
print "<br>\n";
print "<p>\n<hr noshade>\n";
&Print_Add_Passwd_Form;
&Print_Maint_Bottom;
&Print_HTTP_Footer;
}
sub Print_Add_Passwd_Page {
print "<font color=red size=+3>I</font>";
print "<font color=red size=+1>NSTRUCTIONS</font><p>\n";
print "Adding a password protects your demo information from other users. \n";
print "The password \n";
print "protects all customization utilities. \n";
print "If an unauthorized user attempts any of these functions, s/he will be \n";
print "prompted for a password.\n";
print "<br>\n";
print "<p>\n<hr noshade>\n";
&Print_Add_Passwd_Form;
}
sub Print_Add_Passwd_Form {
print "<font color=red size=+3>A</font><font color=red size=+1>DD</font> \n";
print "<font color=red size=+3>P</font><font color=red size=+1>ASSWORD</font><p>\n";
&Print_Add_Passwd_Form_Code;
}
sub Print_Add_Passwd_Form_Code {
print "<table width=0 border=0 cellpadding=5 cellspacing=0 bgcolor=$INPUT_BGCOLOR>\n<tr>\n<td bgcolor=$INPUT_BGCOLOR align=right>\n";
print "<form method=GET action=\"$WWW_SCRIPT\">\n";
print "<input type=hidden name=\"$CGI_SWITCH\" value=\"$CGI_MAINT_FLAG\">\n";
print "<input type=hidden name=\"$CGI_SUB_SWITCH\" value=\"$CGI_MAINT_PASSWD_FLAG\">\n";
print "<input type=hidden name=\"$CGI_MAINT_OUTSIDE_SWITCH\" value=\"$CGI_MAINT_FALSE_FLAG\">\n";
print "<font color=blue>\n";
print "Enter ";
print "New " if ($_[0]);
print "Password: \n";
print "</td><td>\n";
print "<input type=password maxlength=20 name=\"$CGI_MAINT_NEW_PASSWD1_SWITCH\" size=20><br>\n";
print "</font>\n";
print "</td></tr><tr><td bgcolor=$INPUT_BGCOLOR>\n";
print "<font color=blue>\n";
print "Enter ";
print "New " if ($_[0]);
print "Password Again: \n";
print "</td><td>\n";
print "<input type=password maxlength=20 name=\"$CGI_MAINT_NEW_PASSWD2_SWITCH\" size=20><br>\n"; print "<font color=blue>\n";
print "</font>\n";
print "</td></tr><tr><td colspan=2 bgcolor=$INPUT_BGCOLOR>\n";
print "<font color=blue>\n";
print "<center>\n";
print "<input type=submit value=\"Submit\">\n";
print "</center>\n";
print "</font>\n";
print "</td></tr></table>\n";
print "</form>\n";
&Print_Look_At_Help;
}
sub Print_Passwd_Options_Page {
if (&Is_Passwd) {
&Print_Maint_Top("Change/Delete Password", "$IMGSRC_HEADER_PASSWD");
&Print_Passwd_Maint_Top;
&Print_Delete_Passwd_Form;
&Print_Change_Passwd_Form;
} else {
&Print_Maint_Top("Add Password", "$IMGSRC_HEADER_PASSWD");
&Print_Add_Passwd_Page;
}
&Print_Maint_Bottom;
&Print_HTTP_Footer;
}
sub Print_Passwd_Maint_Top {
print "<font color=red size=+3>I</font>";
print "<font color=red size=+1>NSTRUCTIONS</font><p>\n";
&Print_Passwd_Info;
print "<p>\n";
print "<b>There is currently a password on this interface. <br>You may delete it or change it.</b>";
print "<br>\n";
print "<p>\n<p>\n<hr noshade>\n";
print "<p>\n";
}
sub Print_Passwd_Info {
print "With password protection, you can keep customizations safe while\n";
print "the interface is in use on the show floor. The password protects\n";
print "all customization utilities\n";
}
sub Print_Delete_Passwd_Form {
print "<font color=red size=+3>D</font><font color=red size=+1>ELETE</font> \n";
print "<font color=red size=+3>P</font><font color=red size=+1>ASSWORD</font><p>\n";
print "<p>\n";
print "<form method=GET onSubmit=\"return confirmDelete(\'password\')\" action=\"$WWW_SCRIPT\">\n";
print "<input type=hidden name=\"$CGI_SWITCH\" value=\"$CGI_MAINT_FLAG\">\n";
print "<input type=hidden name=\"$CGI_SUB_SWITCH\" value=\"$CGI_MAINT_PASSWD_FLAG\">\n";
print "<input type=hidden name=\"$CGI_MAINT_OUTSIDE_SWITCH\" value=\"$CGI_MAINT_FALSE_FLAG\">\n";
print "<input type=hidden name=\"$CGI_MAINT_PASSWD_DELETE_SWITCH\" value=\"$CGI_MAINT_TRUE_FLAG\">\n";
print "<table width=0 border=0 cellpadding=5 cellspacing=0 bgcolor=$INPUT_BGCOLOR><tr><td bgcolor=$INPUT_BGCOLOR>\n";
print "<font color=blue>\n";
print "<input type=submit value=\"Delete Password\"></font>\n";
print "</td></tr></table>\n";
print "</form>\n";
}
sub Print_Change_Passwd_Form {
print "<font color=red size=+3>C</font><font color=red size=+1>HANGE</font> \n";
print "<font color=red size=+3>P</font><font color=red size=+1>ASSWORD</font><p>\n";
print "<p>\n";
&Print_Add_Passwd_Form_Code(1);
}