#!/usr/bin/perl
####################################################################
# Script: | Password Manager #
# Version: | 2.2 #
# By: | i2 Services, Inc. / CGI World #
# Web Site: | http://www.cgi-world.com #
# Copyright: | CGI World of i2-Services, Inc. #
# Released: | September 29th 2004 #
# Updated: | October 18th, 2005 #
####################################################################
# By using this software, you have agreed to the license #
# agreement packaged with this program. i2-Services, Inc #
# (CGI-World.Com) reserves the right to track this license. #
# #
####################################################################
$subscribe_file = "subscribe.html";
# Subscribe / Create account Template file name.
####################################################################
# DO NOT EDIT BELOW THIS LINE
####################################################################
%Global = ("cgidir" => $0=~m#^(.*)[\\/]#?$1:(`pwd`=~/(.*)/)[0], # script directory
"cgiurl" => (split("/",$ENV{'SCRIPT_NAME'}))[-1], # script url
"sendmail" => "/usr/sbin/sendmail", # sendmail
);
$cgidir = "$Global{'cgidir'}";
$custom_count = 20;
$SIG{__DIE__} = $SIG{__WARN__} = \&HTML_Error; # show error msg on die/warn
srand(time^($$+($$<<15))); # Set Random Number Seed
$|++; # Unbuffer output
### Display Image
if($ENV{'QUERY_STRING'} =~ /.gif|.jpg^/gi) {$image = "$ENV{'QUERY_STRING'}"; &Display_Image; exit };
### Database Definitions
%SetupDB = ("datafile" => "prog_files/setup.dat",
"filelock" => "prog_files/setup.lock",
"fields" => [qw(num login_timeout login_id login_pw mailprog mailprog_location admin_email mail_server cp_url last_update company update_time action default_length default_renew exp_warning default_groups default_no_exp admin_url dup_email wait_time send_number)],
"backup" => "disabled",
"cgiext" => ".cgi");
%AccountsDB = ("datafile" => "prog_files/accounts.dat",
"filelock" => "prog_files/accounts.lock",
"fields" => [qw(num full_name email username password created modified account_length renew_length no_expiration sub_groups expires_date extra extra extra extra extra extra extra extra extra extra FIELD1 FIELD2 FIELD3 FIELD4 FIELD5 FIELD6 FIELD7 FIELD8 FIELD9 FIELD10 FIELD11 FIELD12 FIELD13 FIELD14 FIELD15 FIELD16 FIELD17 FIELD18 FIELD19 FIELD20)],
"backup" => "monthly",
"cgiext" => ".cgi");
%ApprovalsDB = ("datafile" => "prog_files/approvals.dat",
"filelock" => "prog_files/approvals.lock",
"fields" => [qw(num full_name email username password created modified account_length renew_length no_expiration sub_groups expires_date extra extra extra extra extra extra extra extra extra extra FIELD1 FIELD2 FIELD3 FIELD4 FIELD5 FIELD6 FIELD7 FIELD8 FIELD9 FIELD10 FIELD11 FIELD12 FIELD13 FIELD14 FIELD15 FIELD16 FIELD17 FIELD18 FIELD19 FIELD20)],
"backup" => "monthly",
"cgiext" => ".cgi");
%InactivesDB = ("datafile" => "prog_files/inactives.dat",
"filelock" => "prog_files/inactives.lock",
"fields" => [qw(num full_name email username password created modified account_length renew_length no_expiration sub_groups expires_date extra extra extra extra extra extra extra extra extra extra FIELD1 FIELD2 FIELD3 FIELD4 FIELD5 FIELD6 FIELD7 FIELD8 FIELD9 FIELD10 FIELD11 FIELD12 FIELD13 FIELD14 FIELD15 FIELD16 FIELD17 FIELD18 FIELD19 FIELD20)],
"backup" => "monthly",
"cgiext" => ".cgi");
%CustomsDB = ("datafile" => "prog_files/customs.dat",
"filelock" => "prog_files/customs.lock",
"fields" => [qw(num sort type question answers required viewable editable searchable)],
"backup" => "monthly",
"cgiext" => ".cgi");
@mon = qw(Null Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
@month = qw(Null January February March April May June July August September October November December);
# ----------------------------------------------------------------------------
# Main : Test conditions and give commands
# ----------------------------------------------------------------------------
### Files & Directories:
&DB_Load(\%SetupDB, \%setup, 1); # Load Setup Options
$Global{'today'} = int(time / 86400);
$todays_date = &DateString("March 3rd, 1999",time());
if($setup{'last_update'} ne "$todays_date") {
&Cycle_Data;
}
%in = &ReadForm; # Read CGI Form input
%ck = &ReadCookie; # Load Browser Cookies
### Define Global Vars
### Create
if($in{'save_form'}) { &Save_Form; }
if($in{'add_user'}) { &Create_Account; }
&Create_Account;
exit;
# ------------------------------------------------------------------------
# Function : Save Form
# Description : Same / Update Form
#
# Usage : &Save_Form;
# Arguments : none
# ------------------------------------------------------------------------
sub Save_Form {
# Check for General Errors
if(!$in{'full_name'}) { $in{'error'} .= "
Required: Your Name
"; }
if(!$in{'username'} || $in{'username'} =~ s/[^A-Za-z0-9\.\-\_\@]//igs) {
$in{'error'} .= " Username Not Correct Format
";
}
if(!$in{'password'}) { $in{'error'} .= " Required: Password
"; }
if(!$in{'email'} || $in{'email'} !~ /.*\@.*\..*/) {
$in{'error'} .= " e-Mail Address Not Correct Format
";
}
if($in{'no_expiration'}) { $in{'no_exp_checked'} = " checked" };
$rowcode = sub {
if($customs{'viewable'} && $customs{'required'} && $customs{'question'} && !$in{"FIELD$customs{'num'}"}) {
$in{'error'} .= " Required: $customs{'question'}
";
}
};
### Database Sort Order
$sortcode = sub {
$value_a = (split(/\¡/,$a))[1];
$value_b = (split(/\¡/,$b))[1];
lc($value_b) <=> lc($value_a);
};
&DB_List(\%CustomsDB, $rowcode, $sortcode, \%customs);
##########################
### Check if e-Mail or Username is in Active Use
############################################################
$rowcode = sub {
if($in{'username'} =~ /^$accounts{'username'}$/i && $accounts{'username'} !~ /^$in{'user'}$/i) {
$in{'error'} .= " Username is Already in Use
";
$in{'username'} = $in{'user'};
}
if($setup{'dup_email'} && $in{'email'} =~ /^$accounts{'email'}$/i && !$email_found) {
$in{'error'} .= " e-Mail Address Already on File
";
$email_found = 1;
}
};
&DB_List(\%AccountsDB, $rowcode, $sortcode, \%accounts);
### Check if e-Mail or Username is in Approval Database
############################################################
$rowcode = sub {
if($in{'username'} =~ /^$accounts{'username'}$/i && $accounts{'username'} !~ /^$in{'user'}$/i) {
$in{'error'} .= " Username is Already in Use
";
$in{'username'} = $in{'user'};
}
if($setup{'dup_email'} && $in{'email'} =~ /^$accounts{'email'}$/i && !$email_found) {
$in{'error'} .= " e-Mail Address Already on File
";
$email_found = 1;
}
};
&DB_List(\%ApprovalsDB, $rowcode, $sortcode, \%accounts);
### Check if e-Mail or Username is in Inactive Database
############################################################
$rowcode = sub {
if($in{'username'} =~ /^$accounts{'username'}$/i && $accounts{'username'} !~ /^$in{'user'}$/i) {
$in{'error'} .= " Username is Already in Use
";
$in{'username'} = $in{'user'};
}
if($setup{'dup_email'} && $in{'email'} =~ /^$accounts{'email'}$/i && !$email_found) {
$in{'error'} .= " e-Mail Address Already on File
";
$email_found = 1;
}
};
&DB_List(\%InactivesDB, $rowcode, $sortcode, \%accounts);
##########################
# If Erorrs, Go Back to Setup New Form
if($in{'error'}) {
if($in{'edit'}) {
$in{'num'} = $in{'edit'};
&Modify_Account;
}
else {
&Create_Account;
}
}
# ADD NEW ACCOUNT
################################################################
for(1.. $custom_count) {
if($two{"FIELD$_"}) {
$in{"FIELD$_"} = $multiples{"FIELD$_"};
}
}
# Auto Activate New Account:
###########################################################
if($setup{'action'} eq "activate") {
$in{'modified'} = &DateString("March 3rd, 1999 - HH:MM:SS",time());
$in{'created'} = &DateString("March 3rd, 1999 - HH:MM:SS",time());
$in{'account_length'} = $in{'account_length'} || $setup{'default_length'};
$in{'renew_length'} = $in{'renew_length'} || $setup{'default_renew'};
$in{'sub_groups'} = $in{'sub_groups'} || $setup{'default_groups'};
$today = int(time / 86400);
$exp_date = time + 86400 * $in{'account_length'};
($sec,$min,$hour,$mday2,$month,$year2) = localtime($exp_date);
$month++;
$year2 += 1900;
if($mday2 < 10) { $mday2 = "0$mday2" };
$in{'expires_date'} = "$month[$month] $mday2, $year2";
if($setup{'default_no_exp'} || $in{'no_exp'}) {
$in{'expires_date'} = "No Expiration";
$in{'no_expiration'} = "No Expiration";
}
if($in{'account_length'} && int($in{'account_length'})) {
$in{'account_length'} += $today;
}
$in{'num'} = &DB_Add(\%AccountsDB, \%in);
&Send_Email('account_created');
print "Content-Type:text/html\n\n";
print &Template("interface/thanks.html",\%in);
&Cycle_Passwords;
exit;
}
# Account Needs to be Approved:
###########################################################
else {
$in{'modified'} = &DateString("March 3rd, 1999 - HH:MM:SS",time());
$in{'created'} = &DateString("March 3rd, 1999 - HH:MM:SS",time());
$in{'account_length'} = $in{'account_length'} || $setup{'default_length'};
$in{'renew_length'} = $in{'renew_length'} || $setup{'default_renew'};
$in{'sub_groups'} = $in{'sub_groups'} || $setup{'default_groups'};
$today = int(time / 86400);
$exp_date = time + 86400 * $in{'account_length'};
($sec,$min,$hour,$mday2,$month,$year2) = localtime($exp_date);
$month++;
$year2 += 1900;
if($mday2 < 10) { $mday2 = "0$mday2" };
$in{'expires_date'} = "$month[$month] $mday2, $year2";
if($setup{'default_no_exp'} || $in{'no_exp'}) {
$in{'expires_date'} = "No Expiration";
$in{'no_expiration'} = "No Expiration";
}
$in{'num'} = &DB_Add(\%ApprovalsDB, \%in);
$in{'admin_url'} = $setup{'admin_url'};
&Send_Email('new_approval');
print "Content-Type:text/html\n\n";
print &Template("interface/approve_thanks.html",\%in);
exit;
}
}
# ------------------------------------------------------------------------
# Function : Create Form -> Step 2
# Description : Setup Initial Form Data
#
# Usage : &Create_Form;
# Arguments : none
# ------------------------------------------------------------------------
sub Create_Account {
&Template("interface/$subscribe_file");
$in{'created'} = &DateString("March 3rd, 1999 - HH:MM:SS",time());
if($in{'error'}) {
$in{'show_error'} = &TemplateCell("error_html",\%in);
}
&Custom_Code;
print "Content-type: text/html\n\n" unless ($ContentType++);
print &Template("interface/$subscribe_file",\%in);
exit;
}
# ------------------------------------------------------------------------
# Function : Custom Field Code
# Usage : &Custom_Code;
# ------------------------------------------------------------------------
sub Custom_Code {
# Create Custom Field HTML
###########################################################
&Template("interface/fields_html.html");
### Check if record matches keyword query
$rowcode = sub {
if($customs{'answers'} =~ /\|/) {
@answers = split(/\|/,$in{"FIELD$customs{'num'}"});
undef(%answer);
foreach$answer(@answers) {
$answer{"$answer"} = 1;
}
}
if($customs{'question'} && $customs{'required'}) {
$customs{'question'} = "$customs{'question'}";
}
# Text Field
################################################################
if($customs{'viewable'} && $customs{'type'} eq "textfield" && $customs{'question'}) {
$customs{'value'} = $in{"FIELD$customs{'num'}"};
$in{'custom_fields'} .= &TemplateCell("textfield",\%customs);
undef($customs{'value'});
}
# TextArea Field
################################################################
if($customs{'viewable'} && $customs{'type'} eq "textarea" && $customs{'question'}) {
$customs{'value'} = $in{"FIELD$customs{'num'}"};
$in{'custom_fields'} .= &TemplateCell("textarea",\%customs);
undef($customs{'value'});
}
# Radio Options
################################################################
if($customs{'viewable'} && $customs{'type'} eq "radio" && $customs{'question'}) {
@options = split(/\|/,$customs{'answers'});
foreach$option(@options) {
if($in{"FIELD$customs{'num'}"} =~ /^$option$/i) { $checked = " checked" };
$customs{'radio_options'} .= " $option
\n";
undef($checked)
}
$in{'custom_fields'} .= &TemplateCell("radio",\%customs);
undef($customs{'radio_options'});
}
# Check Box Options
################################################################
if($customs{'viewable'} && $customs{'type'} eq "checkbox" && $customs{'question'}) {
@options = split(/\|/,$customs{'answers'});
foreach$option(@options) {
$hash = "FIELD$customs{'num'}";
if($$hash{"$option"} || $answer{"$option"}) { $checked = " checked" };
$customs{'checkbox_options'} .= " $option
\n";
undef($checked);
}
$in{'custom_fields'} .= &TemplateCell("checkbox",\%customs);
undef($customs{'checkbox_options'});
}
# Drop Down Options
################################################################
if($customs{'viewable'} && $customs{'type'} eq "dropdown" && $customs{'question'}) {
@options = split(/\|/,$customs{'answers'});
foreach$option(@options) {
if($in{"FIELD$customs{'num'}"} =~ /^$option$/i) { $selected = " selected" };
$customs{'dropdown_options'} .= "