#!/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. #
# #
####################################################################
### Set Global Vars
$subscribe_file = "subscribe.html";
%Global = ("cgidir" => $0=~m#^(.*)[\\/]#?$1:(`pwd`=~/(.*)/)[0], # script directory
"cgiurl" => (split("/",$ENV{'SCRIPT_NAME'}))[-1], # script url
);
$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");
@available_fields = (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);
%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
# ----------------------------------------------------------------------------
&DB_Load(\%SetupDB, \%setup, 1); # Load Setup Options
### Files & Directories:
### Define Global Vars
$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
### Comments
if($in{'save_account'}) { &Save_Account; }
if($in{'modify_account'}) { &Modify_Account; }
if($in{'cancel_account'}) { &Cancel_Account; }
if($in{'email_account'}) { &Email_Account; }
&Control_Panel;
exit;
# ------------------------------------------------------------------------
# Function : View / Modify Account
# Usage : &Modify_Account;
# ------------------------------------------------------------------------
sub Modify_Account {
&Template("interface/modify_account.html",\%in);
if($in{'error'}) {
$Global{'show_error'} = &TemplateCell("error_html",\%in);
}
if(!$in{'username'} || !$in{'password'}) {
$in{'error'} .= "Please enter Username & Password
\n";
}
if($in{'error'} && !$in{'save_account'}) {
&Control_Panel;
}
# Search for Account using e-Mail address:
$rowcode = sub {
if($in{'username'} eq "$accounts{'username'}" && $in{'password'} eq "$accounts{'password'}") {
$account_found = $accounts{'num'};
}
};
&DB_List(\%AccountsDB, $rowcode, $sortcode, \%accounts);
if($account_found) {
if(!$in{'save_account'}) {
&DB_Load(\%AccountsDB,\%in,$account_found);
}
else {
&DB_Load(\%AccountsDB,\%defaults,$account_found);
}
print "Content-Type: text/html\n\n";
&Custom_Code;
print &Template("interface/modify_account.html",\%in);
exit;
}
else {
$in{'error'} = "Account Not Found!";
&Control_Panel;
}
}
# ------------------------------------------------------------------------
# Function : Cancel Account
# Usage : &Cancel_Account;
# ------------------------------------------------------------------------
sub Cancel_Account {
if(!$in{'username'} || !$in{'password'}) {
$in{'error'} .= "Please enter Username & Password to Cancel Account
\n";
}
if($in{'error'}) {
&Control_Panel;
}
# Search for Account using e-Mail address:
$rowcode = sub {
if($in{'username'} eq "$accounts{'username'}" && $in{'password'} eq "$accounts{'password'}") {
if(!$account_found) {
%in = %accounts;
$in{'custom_html'} = &Custom_Code;
$print = &Template("interface/modify_account.html",\%in);
### Send to Inactive:
######################################################
if($accounts{'account_length'}) {
$accounts{'account_length'} = $accounts{'account_length'} - $Global{'today'};
}
$accounts{'modified'} = &DateString("March 3rd, 1999 - HH:MM:SS",time());
$accounts{'expires_date'} = "User Canceled";
&DB_Add(\%InactivesDB, \%accounts);
&Send_Email('account_canceled',\%accounts);
}
$account_found = $accounts{'num'};
print "Content-Type: text/html\n\n";
print &Template("interface/canceled.html",\%accounts);
}
};
&DB_List(\%AccountsDB, $rowcode, $sortcode, \%accounts);
if($account_found) {
&DB_Del(\%AccountsDB,$account_found);
&Cycle_Passwords;
exit;
}
else {
$in{'error'} = "Account Not Found to Cancel!";
&Control_Panel;
}
}
# ------------------------------------------------------------------------
# Function : e-Mail Account Password
# Usage : &Email_Account;
# ------------------------------------------------------------------------
sub Email_Account {
if(!$in{'email'} || $in{'email'} !~ /.*\@.*\..*/) {
$in{'error'} .= "Please enter Your e-Mail Address or Check Syntax
\n";
}
if($in{'error'}) {
&Control_Panel;
}
# Search for Account using e-Mail address:
$rowcode = sub {
if($in{'email'} =~ /^$accounts{'email'}$/i) {
if(!$account_found) {
&Send_Email("email_password",\%accounts);
$out{'email_sent_html'} = &Template("interface/password_emailed.html",\%accounts);
}
$account_found = 1;
}
};
&DB_List(\%AccountsDB, $rowcode, $sortcode, \%accounts);
if($account_found) {
print "Content-Type: text/html\n\n";
print "$out{'email_sent_html'}\n";
exit;
}
else {
$in{'error'} = "Account Not Found!";
}
}
# ------------------------------------------------------------------------
# Function : Create Form -> Step 2
# Description : Setup Initial Form Data
#
# Usage : &Create_Form;
# Arguments : none
# ------------------------------------------------------------------------
sub Control_Panel {
&Template("interface/control_panel.html");
$in{'created'} = &DateString("March 3rd, 1999 - HH:MM:SS",time());
if($in{'error'}) {
$in{'show_error'} = &TemplateCell("error_html",\%in);
}
print "Content-type: text/html\n\n" unless ($ContentType++);
print &Template("interface/control_panel.html",\%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 {
undef($checkbox_value);
if($customs{'answers'} =~ /\|/) {
@answers = split(/\|/,$in{"FIELD$customs{'num'}"});
undef(%answer);
foreach$answer(@answers) {
$checkbox_value .= "$answer, ";
$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'}"};
if($customs{'editable'}) {
$in{'custom_fields'} .= &TemplateCell("textfield",\%customs);
}
else {
if(!$customs{'value'}) { $customs{'value'} = $defaults{"FIELD$customs{'num'}"} };
$in{'custom_fields'} .= &TemplateCell("justview",\%customs);
}
undef($customs{'value'});
}
# TextArea Field
################################################################
if($customs{'viewable'} && $customs{'type'} eq "textarea" && $customs{'question'}) {
$customs{'value'} = $in{"FIELD$customs{'num'}"};
if($customs{'editable'}) {
$in{'custom_fields'} .= &TemplateCell("textarea",\%customs);
}
else {
if(!$customs{'value'}) { $customs{'value'} = $defaults{"FIELD$customs{'num'}"} };
$customs{'value'} =~ s/\n/
/;
$in{'custom_fields'} .= &TemplateCell("justview",\%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)
}
if($customs{'editable'}) {
$in{'custom_fields'} .= &TemplateCell("radio",\%customs);
}
else {
$customs{'value'} = $in{"FIELD$customs{'num'}"};
if(!$customs{'value'}) { $customs{'value'} = $defaults{"FIELD$customs{'num'}"} };
$in{'custom_fields'} .= &TemplateCell("justview",\%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);
}
if($customs{'editable'}) {
$in{'custom_fields'} .= &TemplateCell("checkbox",\%customs);
}
else {
$customs{'value'} = "$checkbox_value";
if(!$customs{'value'}) { $customs{'value'} = $defaults{"FIELD$customs{'num'}"} };
$customs{'value'} =~ s/\|/, /g;
$in{'custom_fields'} .= &TemplateCell("justview",\%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'} .= "