scorpion975
IS-IT--Management
**How can i modify this to have a field when adding users, to have an expire, amount of hours?
#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
require "cookie.lib";
require "common.cgi";
&get_input;
&get_template;
&GetCookies('Custom-CGI_pass','Custom-CGI_id');
if ($Cookies{'Custom-CGI_pass'} ne "" && $Cookies{'Custom-CGI_id'} ne "") {
print "Location: main.cgi\n\n";
exit;
}
else {
print "Content-type: text/html\n\n";
if ($in{'action'} eq "") {
&signup_screen;
exit;
}
if ($in{'action'} eq "signup") {
&check_signup;
&add_user;
if ($demo ne "on") {
&mail_admin;
&mail_user;
}
&confirm_signup;
}
}
######### Signup Screen #####
sub signup_screen {
print $header;
print "<form action=\"$ENV{'SCRIPT_NAME'}\" method=\"POST\">\n";
print "<table width=\"400\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#000000\">\n";
print " <tr> \n";
print " <td>\n";
print " <table width=\"400\" border=\"0\" cellspacing=\"2\" cellpadding=\"4\">\n";
print " <tr bgcolor=\"#E2DEB8\"> \n";
print " <td colspan=\"2\"><b>Signup Information:</b> </td>\n";
print " </tr>\n";
print " <tr bgcolor=\"#E2DEB8\"> \n";
print " <td>Name: <font color=\"#CC0000\">*</font></td>\n";
print " <td><input type=text name=\"name\" value=\"\"></td>\n";
print " </tr>\n";
print " <tr bgcolor=\"#E2DEB8\"> \n";
print " <td>Address 1:</td>\n";
print " <td><input type=text name=\"address1\" value=\"\"></td>\n";
print " </tr>\n";
print " <tr bgcolor=\"#E2DEB8\"> \n";
print " <td>Address 2:</td>\n";
print " <td><input type=text name=\"address2\" value=\"\"></td>\n";
print " </tr>\n";
print " <tr bgcolor=\"#E2DEB8\"> \n";
print " <td>Country:</td>\n";
print " <td><input type=text name=\"country\" value=\"\"></td>\n";
print " </tr>\n";
print " <tr bgcolor=\"#E2DEB8\"> \n";
print " <td>Username: <font color=\"#CC0000\">*</font></td>\n";
print " <td><input type=text name=\"username\" value=\"\"></td>\n";
print " </tr>\n";
print " <tr bgcolor=\"#E2DEB8\"> \n";
print " <td>Password: <font color=\"#CC0000\">*</font></td>\n";
print " <td><input type=password name=\"password1\" value=\"\"></td>\n";
print " </tr>\n";
print " <tr bgcolor=\"#E2DEB8\"> \n";
print " <td>Password Confirm: <font color=\"#CC0000\">*</font></td>\n";
print " <td><input type=password name=\"password2\" value=\"\"></td>\n";
print " </tr>\n";
print " </tr>\n";
print " <tr bgcolor=\"#E2DEB8\"> \n";
print " <td>Email: <font color=\"#CC0000\">*</font></td>\n";
print " <td><input type=text name=\"email\" value=\"\"></td>\n";
print " </tr>\n";
print " <tr bgcolor=\"#E2DEB8\"> \n";
print " <td colspan=\"2\">\n";
print " <input type=\"hidden\" name=\"action\" value=\"signup\">\n";
print " <input type=\"submit\" value=\"Submit Information\">\n";
print " <input type=\"reset\" value=\" Reset \">\n";
print " </td>\n";
print " </tr>\n";
print " </table>\n";
print " </td>\n";
print " </tr>\n";
print "</table>\n";
print "</form>\n";
print $footer;
}
######### check signup #######
sub check_signup {
# make sure no 'bad' characters where submitted (this includes white space)
if ($in{'username'} =~ s/[^a-z0-9\_]//g || $in{'username'} eq "") {
$error = "<li> Invalid character in username, please use only a-z, 0-9 and _.\n";
}
if ($in{'password1'} =~ s/[^a-z0-9\_]//g || $in{'password2'} =~ s/[^a-z0-9\_]//g) {
$error .= "<li> Invalid character in password, please use only a-z, 0-9 and _.\n";
}
if ($in{'password1'} ne $in{'password2'}) {
$error .= "<li> Passwords not the same.\n";
}
#if ($in{'name') eq "") {
# $error .= "<li>Required filed left blank.\n";
#}
$len = length($in{'password1'});
if ($len <= 3) {
$error .= "<li> Password must be at least 4 characters long.\n";
}
$len = length($in{'username'});
if ($len <= 3) {
$error .= "<li> Username must be at least 4 characters long.\n";
}
if ($in{'name'} eq "") {
$error .= "<li> Required field left blank.\n";
}
# If the e-mail address contains: #
if ($in{'email'} =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ ||
# the e-mail address contains an invalid syntax. Or, if the #
# syntax does not match the following regular expression pattern #
# it fails basic syntax verification. #
$in{'email'} !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/) {
$error .= "<li> Please enter a correct email address.\n";
}
# if $error has a value, then they submited bad characters which could
# be a security risk if used further.
if ($error eq "") {
if (-e "$setup_base_dir/members.txt") {
open(CF, "$setup_base_dir/members.txt");
# get all th info in the file
@all = <CF>;
close(CF);
# loop for number of elements
for($i = 0; $i <= @all; $i++){
# split (explode) each line
($mem_name,$mem_password,$mem__encrypted_password,$mem_email) = split(':',$all[$i]);
# check to see if submited info matches existing info
if ($in{'username'} eq $mem_name) {
# found, the visitor identiy is verified.
$found = 1;
}
}
} else {
# if members.txt doesnt exist.
print "Error: Unable to open members file";
exit;
}
}
# this is what happens if user is not found
if ($found eq 1){
$error .= "<li> Sorry that user name is already taken please pick another.\n";
}
# this checks to see if username is on the list of banner users.
for($i = 0; $i <= $#banned_users; $i++){
if ($in{'username'} =~ s/$banned_users[$i]//gi) {
# opps, found a banned username
$found_user = 1;
}
}
if ($found_user) {
$error .= "<li> Sorry but you can't use that username, please pick another.\n";
}
# if erros ocured then tell visitor
if ($error) {
print $header;
print "<h1>Error</h1>\n";
print "Error(s) ocured while signing you up, please go back and fix there error(s),\n";
print "<p><table width=\"400\"><tr><td>$error</td></tr></table><P>\n";
print "<a href=\"javascript:history.go(-1)\"><< Back</a>\n";
print $footer;
exit;
}
}
######## add user ####
sub add_user {
# now encrypt the password
$crypted = crypt("$in{'password1'}",'£mHgF*&');
# strip of bad characters
$crypted =~ s/[^a-z0-9\_]//g;
open (SIGNUP, ">>$setup_base_dir/members.txt");
print SIGNUP ("$in{'username'}:$in{'password1'}:$crypted:$in{'email'}\n");
close (SIGNUP);
}
######## Mail Admin ####
sub mail_admin {
open (MESSAGE, "| $setup_sendmail -t -oi ");
print MESSAGE <<__END_OF_MESSAGE__;
To: $setup_email_admin
From: $setup_email_admin
Subject: New member for IMTI ACCESS ($in{"username"})
__END_OF_MESSAGE__
print MESSAGE ("A new member has signed, up here is their information.
Real name: $in{'name'}
email: $in{'email'}
address 1: $in{'address1'},
address2: $in{'address2'}
username: $in{'username'}
password: $in{'password1'}
\n");
close (MESSAGE);
}
###### Send user an email woth their username and password
sub mail_user{
# let admin know of the new member
open (MESSAGE2, "| $setup_sendmail -t -oi ");
print MESSAGE2 <<__END_OF_MESSAGE__;
To: $in{"email"}
From: $setup_email_admin
Subject: Online Access Account Info
__END_OF_MESSAGE__
print MESSAGE2 ("Thank you for taking the time to join our online community,
Here is you account information. Please keep this in a safe
place for future use.
Note: The below username and password are case sensitive. Please make sure caps lock
is off and enter in as shown below.
username: $in{'username'}
password: $in{'password1'}
To Begin write down your username and password and then go to the URL below.
For Insects- /student1
Features of website:
LIVE CHAT
MESSAGE BOARD
Practive Questions
Photos and Diagrams
Please take time and provide us with some feedback after you experience our online content, please go
to the following address:
course_eval.shtml
Regards
Support Team
===========================================================
LEGAL NOTICE
Unless expressly stated otherwise, this message is confidential and may be privileged. It
is intended for the addressee(s) only. Access to this E-mail by anyone else is unauthorized. If you
are not an addressee, any disclosure or copying of the contents of this E-mail or any action taken
(or not taken) in reliance on it is unauthorized and may be unlawful. If you are not an addressee,
please inform the sender immediately.\n");
# Please do not remove above link.
close (MESSAGE2);
}
####### Confirm Signup ####
sub confirm_signup {
print $header;
print "<body bgcolor=\"#E2DEB8\">\n";
print "<h1>Signup Successful</h1>\n";
print "Congratulations, you have successfully signuped for our site.\n";
print "Please <a href=\"login.cgi\">login here</a> to confirm your account.\n";
print $footer;
exit;
}
#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
require "cookie.lib";
require "common.cgi";
&get_input;
&get_template;
&GetCookies('Custom-CGI_pass','Custom-CGI_id');
if ($Cookies{'Custom-CGI_pass'} ne "" && $Cookies{'Custom-CGI_id'} ne "") {
print "Location: main.cgi\n\n";
exit;
}
else {
print "Content-type: text/html\n\n";
if ($in{'action'} eq "") {
&signup_screen;
exit;
}
if ($in{'action'} eq "signup") {
&check_signup;
&add_user;
if ($demo ne "on") {
&mail_admin;
&mail_user;
}
&confirm_signup;
}
}
######### Signup Screen #####
sub signup_screen {
print $header;
print "<form action=\"$ENV{'SCRIPT_NAME'}\" method=\"POST\">\n";
print "<table width=\"400\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#000000\">\n";
print " <tr> \n";
print " <td>\n";
print " <table width=\"400\" border=\"0\" cellspacing=\"2\" cellpadding=\"4\">\n";
print " <tr bgcolor=\"#E2DEB8\"> \n";
print " <td colspan=\"2\"><b>Signup Information:</b> </td>\n";
print " </tr>\n";
print " <tr bgcolor=\"#E2DEB8\"> \n";
print " <td>Name: <font color=\"#CC0000\">*</font></td>\n";
print " <td><input type=text name=\"name\" value=\"\"></td>\n";
print " </tr>\n";
print " <tr bgcolor=\"#E2DEB8\"> \n";
print " <td>Address 1:</td>\n";
print " <td><input type=text name=\"address1\" value=\"\"></td>\n";
print " </tr>\n";
print " <tr bgcolor=\"#E2DEB8\"> \n";
print " <td>Address 2:</td>\n";
print " <td><input type=text name=\"address2\" value=\"\"></td>\n";
print " </tr>\n";
print " <tr bgcolor=\"#E2DEB8\"> \n";
print " <td>Country:</td>\n";
print " <td><input type=text name=\"country\" value=\"\"></td>\n";
print " </tr>\n";
print " <tr bgcolor=\"#E2DEB8\"> \n";
print " <td>Username: <font color=\"#CC0000\">*</font></td>\n";
print " <td><input type=text name=\"username\" value=\"\"></td>\n";
print " </tr>\n";
print " <tr bgcolor=\"#E2DEB8\"> \n";
print " <td>Password: <font color=\"#CC0000\">*</font></td>\n";
print " <td><input type=password name=\"password1\" value=\"\"></td>\n";
print " </tr>\n";
print " <tr bgcolor=\"#E2DEB8\"> \n";
print " <td>Password Confirm: <font color=\"#CC0000\">*</font></td>\n";
print " <td><input type=password name=\"password2\" value=\"\"></td>\n";
print " </tr>\n";
print " </tr>\n";
print " <tr bgcolor=\"#E2DEB8\"> \n";
print " <td>Email: <font color=\"#CC0000\">*</font></td>\n";
print " <td><input type=text name=\"email\" value=\"\"></td>\n";
print " </tr>\n";
print " <tr bgcolor=\"#E2DEB8\"> \n";
print " <td colspan=\"2\">\n";
print " <input type=\"hidden\" name=\"action\" value=\"signup\">\n";
print " <input type=\"submit\" value=\"Submit Information\">\n";
print " <input type=\"reset\" value=\" Reset \">\n";
print " </td>\n";
print " </tr>\n";
print " </table>\n";
print " </td>\n";
print " </tr>\n";
print "</table>\n";
print "</form>\n";
print $footer;
}
######### check signup #######
sub check_signup {
# make sure no 'bad' characters where submitted (this includes white space)
if ($in{'username'} =~ s/[^a-z0-9\_]//g || $in{'username'} eq "") {
$error = "<li> Invalid character in username, please use only a-z, 0-9 and _.\n";
}
if ($in{'password1'} =~ s/[^a-z0-9\_]//g || $in{'password2'} =~ s/[^a-z0-9\_]//g) {
$error .= "<li> Invalid character in password, please use only a-z, 0-9 and _.\n";
}
if ($in{'password1'} ne $in{'password2'}) {
$error .= "<li> Passwords not the same.\n";
}
#if ($in{'name') eq "") {
# $error .= "<li>Required filed left blank.\n";
#}
$len = length($in{'password1'});
if ($len <= 3) {
$error .= "<li> Password must be at least 4 characters long.\n";
}
$len = length($in{'username'});
if ($len <= 3) {
$error .= "<li> Username must be at least 4 characters long.\n";
}
if ($in{'name'} eq "") {
$error .= "<li> Required field left blank.\n";
}
# If the e-mail address contains: #
if ($in{'email'} =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ ||
# the e-mail address contains an invalid syntax. Or, if the #
# syntax does not match the following regular expression pattern #
# it fails basic syntax verification. #
$in{'email'} !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/) {
$error .= "<li> Please enter a correct email address.\n";
}
# if $error has a value, then they submited bad characters which could
# be a security risk if used further.
if ($error eq "") {
if (-e "$setup_base_dir/members.txt") {
open(CF, "$setup_base_dir/members.txt");
# get all th info in the file
@all = <CF>;
close(CF);
# loop for number of elements
for($i = 0; $i <= @all; $i++){
# split (explode) each line
($mem_name,$mem_password,$mem__encrypted_password,$mem_email) = split(':',$all[$i]);
# check to see if submited info matches existing info
if ($in{'username'} eq $mem_name) {
# found, the visitor identiy is verified.
$found = 1;
}
}
} else {
# if members.txt doesnt exist.
print "Error: Unable to open members file";
exit;
}
}
# this is what happens if user is not found
if ($found eq 1){
$error .= "<li> Sorry that user name is already taken please pick another.\n";
}
# this checks to see if username is on the list of banner users.
for($i = 0; $i <= $#banned_users; $i++){
if ($in{'username'} =~ s/$banned_users[$i]//gi) {
# opps, found a banned username
$found_user = 1;
}
}
if ($found_user) {
$error .= "<li> Sorry but you can't use that username, please pick another.\n";
}
# if erros ocured then tell visitor
if ($error) {
print $header;
print "<h1>Error</h1>\n";
print "Error(s) ocured while signing you up, please go back and fix there error(s),\n";
print "<p><table width=\"400\"><tr><td>$error</td></tr></table><P>\n";
print "<a href=\"javascript:history.go(-1)\"><< Back</a>\n";
print $footer;
exit;
}
}
######## add user ####
sub add_user {
# now encrypt the password
$crypted = crypt("$in{'password1'}",'£mHgF*&');
# strip of bad characters
$crypted =~ s/[^a-z0-9\_]//g;
open (SIGNUP, ">>$setup_base_dir/members.txt");
print SIGNUP ("$in{'username'}:$in{'password1'}:$crypted:$in{'email'}\n");
close (SIGNUP);
}
######## Mail Admin ####
sub mail_admin {
open (MESSAGE, "| $setup_sendmail -t -oi ");
print MESSAGE <<__END_OF_MESSAGE__;
To: $setup_email_admin
From: $setup_email_admin
Subject: New member for IMTI ACCESS ($in{"username"})
__END_OF_MESSAGE__
print MESSAGE ("A new member has signed, up here is their information.
Real name: $in{'name'}
email: $in{'email'}
address 1: $in{'address1'},
address2: $in{'address2'}
username: $in{'username'}
password: $in{'password1'}
\n");
close (MESSAGE);
}
###### Send user an email woth their username and password
sub mail_user{
# let admin know of the new member
open (MESSAGE2, "| $setup_sendmail -t -oi ");
print MESSAGE2 <<__END_OF_MESSAGE__;
To: $in{"email"}
From: $setup_email_admin
Subject: Online Access Account Info
__END_OF_MESSAGE__
print MESSAGE2 ("Thank you for taking the time to join our online community,
Here is you account information. Please keep this in a safe
place for future use.
Note: The below username and password are case sensitive. Please make sure caps lock
is off and enter in as shown below.
username: $in{'username'}
password: $in{'password1'}
To Begin write down your username and password and then go to the URL below.
For Insects- /student1
Features of website:
LIVE CHAT
MESSAGE BOARD
Practive Questions
Photos and Diagrams
Please take time and provide us with some feedback after you experience our online content, please go
to the following address:
course_eval.shtml
Regards
Support Team
===========================================================
LEGAL NOTICE
Unless expressly stated otherwise, this message is confidential and may be privileged. It
is intended for the addressee(s) only. Access to this E-mail by anyone else is unauthorized. If you
are not an addressee, any disclosure or copying of the contents of this E-mail or any action taken
(or not taken) in reliance on it is unauthorized and may be unlawful. If you are not an addressee,
please inform the sender immediately.\n");
# Please do not remove above link.
close (MESSAGE2);
}
####### Confirm Signup ####
sub confirm_signup {
print $header;
print "<body bgcolor=\"#E2DEB8\">\n";
print "<h1>Signup Successful</h1>\n";
print "Congratulations, you have successfully signuped for our site.\n";
print "Please <a href=\"login.cgi\">login here</a> to confirm your account.\n";
print $footer;
exit;
}