#!/usr/local/bin/perl -w
#
# login script
#
#
use strict;
use warnings;
use CGI qw/:standard/;
use CGI::Cookie;
use URI::Escape;
##################################################################################################
# take in ID to redirect to. this function pipes in the name of the reviewed
sub redirect
{
(my $id, my $personalname) = @_;
my $urlname = uri_escape($personalname);
print "Pragma: no-cache\n\n";
print qq~
Passionate Performance Password Login
~;
print "";
print "If your browser does not support META refresh. Enter Survey";
exit;
}
##################################################################################################
sub getaccountstats
{
open(STAT, ')
{
chomp;
(my $key, my $value) = split(/=/, $_);
$accountstats{$key} = $value;
}
close(STAT);
return %accountstats;
}
##################################################################################################
#takes in account name, password
sub setcookie
{
(my $name, my $value) = @_;
my $c = new CGI::Cookie(-name => $name,
-value => $value,
-domain => '.clisurveys.com',
-secure => 0
);
print header(-cookie=>$c);
return 0;
}
##################################################################################################
# takes in accountname returns "password" as the value
sub readcookie
{
print" readcookie1";
my %cookies = fetch CGI::Cookie;
my $cookiename;
my $cookievalue;
print" readcookie2";
my $existingcookie = $cookies{$_[0]};
print" readcookie3";
if($existingcookie)
{
$cookiename = $existingcookie->name;
print" readcookie4";
$cookievalue = $existingcookie->value;
print" readcookie5";
if ($cookiename eq $_[0])
{
print" readcookie6";
return $cookievalue;
}
}
else {
print" readcookie7";
return 0;
}
}
##################################################################################################
my $localpath = $ENV{HTTP_HOST};
my %accountstats = getaccountstats();
my $validpassword = $accountstats{'password'};
my $validaccountname = substr($localpath, 0, -19);
my $querystring = $ENV{'QUERY_STRING'};
my $personalname = $accountstats{'personalname'};
if($querystring =~ /^id=/)
{
$querystring =~ s/id=//g;
redirect($querystring, $personalname);
}
my $accountname = $accountstats{'accountname'};
my $password = param('password');
if($password eq $validpassword)
{
setcookie($accountname, $password);
print qq~
Passionate Performance Login
~;
#For some reason this function doesn't find the cookie when first set... should return password.
#my $cookievalue = readcookie($accountname);
#print"cookie value (password) = ".$cookievalue;
print "";
print" Go to your profile: