coverted carriage returns

This commit is contained in:
JT Smith 2004-07-29 18:13:07 +00:00
parent c136f346e7
commit 9b33ec2c7e

View file

@ -1,189 +1,189 @@
package WebGUI; package WebGUI;
our $VERSION = "6.2.0"; our $VERSION = "6.2.0";
#------------------------------------------------------------------- #-------------------------------------------------------------------
# WebGUI is Copyright 2001-2004 Plain Black LLC. # WebGUI is Copyright 2001-2004 Plain Black LLC.
#------------------------------------------------------------------- #-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license # Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using # (docs/license.txt) that came with this distribution before using
# this software. # this software.
#------------------------------------------------------------------- #-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com # http://www.plainblack.com info@plainblack.com
#------------------------------------------------------------------- #-------------------------------------------------------------------
use strict qw(vars subs); use strict qw(vars subs);
use Tie::CPHash; use Tie::CPHash;
use WebGUI::Affiliate; use WebGUI::Affiliate;
use WebGUI::Cache; use WebGUI::Cache;
use WebGUI::ErrorHandler; use WebGUI::ErrorHandler;
use WebGUI::Grouping; use WebGUI::Grouping;
use WebGUI::HTTP; use WebGUI::HTTP;
use WebGUI::International; use WebGUI::International;
use WebGUI::Macro; use WebGUI::Macro;
use WebGUI::Operation; use WebGUI::Operation;
use WebGUI::Privilege; use WebGUI::Privilege;
use WebGUI::Session; use WebGUI::Session;
use WebGUI::SQL; use WebGUI::SQL;
use WebGUI::Style; use WebGUI::Style;
use WebGUI::Page; use WebGUI::Page;
use WebGUI::URL; use WebGUI::URL;
use WebGUI::PassiveProfiling; use WebGUI::PassiveProfiling;
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub _generatePage { sub _generatePage {
my $content = shift; my $content = shift;
if ($session{form}{op} eq "" && $session{setting}{trackPageStatistics} && $session{form}{wid} ne "new") { if ($session{form}{op} eq "" && $session{setting}{trackPageStatistics} && $session{form}{wid} ne "new") {
WebGUI::SQL->write("insert into pageStatistics (dateStamp, userId, username, ipAddress, userAgent, referer, WebGUI::SQL->write("insert into pageStatistics (dateStamp, userId, username, ipAddress, userAgent, referer,
pageId, pageTitle, wobjectId, wobjectFunction) values (".time().",".$session{user}{userId} pageId, pageTitle, wobjectId, wobjectFunction) values (".time().",".$session{user}{userId}
.",".quote($session{user}{username}).", .",".quote($session{user}{username}).",
".quote($session{env}{REMOTE_ADDR}).", ".quote($session{env}{HTTP_USER_AGENT}).", ".quote($session{env}{REMOTE_ADDR}).", ".quote($session{env}{HTTP_USER_AGENT}).",
".quote($session{env}{HTTP_REFERER}).", ".$session{page}{pageId}.", ".quote($session{env}{HTTP_REFERER}).", ".$session{page}{pageId}.",
".quote($session{page}{title}).", ".quote($session{form}{wid}).", ".quote($session{form}{func}).")"); ".quote($session{page}{title}).", ".quote($session{form}{wid}).", ".quote($session{form}{func}).")");
} }
my $output = WebGUI::Macro::process(WebGUI::Style::process($content)); my $output = WebGUI::Macro::process(WebGUI::Style::process($content));
if ($session{setting}{showDebug} || ($session{form}{debug}==1 && WebGUI::Grouping::isInGroup(3))) { if ($session{setting}{showDebug} || ($session{form}{debug}==1 && WebGUI::Grouping::isInGroup(3))) {
$output .= WebGUI::ErrorHandler::showDebug(); $output .= WebGUI::ErrorHandler::showDebug();
} }
return $output; return $output;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub _processAction { sub _processAction {
my ($urlString, %form, $pair, @pairs, @param); my ($urlString, %form, $pair, @pairs, @param);
$urlString = WebGUI::URL::unescape($_[0]); $urlString = WebGUI::URL::unescape($_[0]);
@pairs = split(/\&/,$urlString); @pairs = split(/\&/,$urlString);
foreach $pair (@pairs) { foreach $pair (@pairs) {
@param = split(/\=/,$pair); @param = split(/\=/,$pair);
$form{$param[0]} = $param[1]; $form{$param[0]} = $param[1];
} }
$session{form} = \%form; $session{form} = \%form;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub _processFunctions { sub _processFunctions {
my ($wobject, $output, $proxyWobjectId, $cmd, $w); my ($wobject, $output, $proxyWobjectId, $cmd, $w);
if (exists $session{form}{func} && exists $session{form}{wid}) { if (exists $session{form}{func} && exists $session{form}{wid}) {
if ($session{form}{func} =~ /^[A-Za-z]+$/) { if ($session{form}{func} =~ /^[A-Za-z]+$/) {
if ($session{form}{wid} eq "new") { if ($session{form}{wid} eq "new") {
$wobject = {wobjectId=>"new",namespace=>$session{form}{namespace},pageId=>$session{page}{pageId}}; $wobject = {wobjectId=>"new",namespace=>$session{form}{namespace},pageId=>$session{page}{pageId}};
} else { } else {
$wobject = WebGUI::SQL->quickHashRef("select * from wobject where wobjectId=".$session{form}{wid},WebGUI::SQL->getSlave); $wobject = WebGUI::SQL->quickHashRef("select * from wobject where wobjectId=".$session{form}{wid},WebGUI::SQL->getSlave);
if (${$wobject}{namespace} eq "") { if (${$wobject}{namespace} eq "") {
WebGUI::ErrorHandler::warn("Wobject [$session{form}{wid}] appears to be missing or " WebGUI::ErrorHandler::warn("Wobject [$session{form}{wid}] appears to be missing or "
."corrupt, but was requested " ."corrupt, but was requested "
."by $session{user}{username} [$session{user}{userId}]."); ."by $session{user}{username} [$session{user}{userId}].");
$wobject = (); $wobject = ();
} }
} }
if ($wobject) { if ($wobject) {
if (${$wobject}{pageId} != $session{page}{pageId}) { if (${$wobject}{pageId} != $session{page}{pageId}) {
($proxyWobjectId) = WebGUI::SQL->quickArray("select wobject.wobjectId from ($proxyWobjectId) = WebGUI::SQL->quickArray("select wobject.wobjectId from
wobject,WobjectProxy wobject,WobjectProxy
where wobject.wobjectId=WobjectProxy.wobjectId where wobject.wobjectId=WobjectProxy.wobjectId
and wobject.pageId=".$session{page}{pageId}." and wobject.pageId=".$session{page}{pageId}."
and WobjectProxy.proxiedWobjectId=".${$wobject}{wobjectId},WebGUI::SQL->getSlave); and WobjectProxy.proxiedWobjectId=".${$wobject}{wobjectId},WebGUI::SQL->getSlave);
${$wobject}{_WobjectProxy} = $proxyWobjectId; ${$wobject}{_WobjectProxy} = $proxyWobjectId;
} }
unless (${$wobject}{pageId} == $session{page}{pageId} unless (${$wobject}{pageId} == $session{page}{pageId}
|| ${$wobject}{pageId} == 2 || ${$wobject}{pageId} == 2
|| ${$wobject}{pageId} == 3 || ${$wobject}{pageId} == 3
|| ${$wobject}{_WobjectProxy} ne "") { || ${$wobject}{_WobjectProxy} ne "") {
$output .= WebGUI::International::get(417); $output .= WebGUI::International::get(417);
WebGUI::ErrorHandler::security("access wobject [".$session{form}{wid}."] on page '" WebGUI::ErrorHandler::security("access wobject [".$session{form}{wid}."] on page '"
.$session{page}{title}."' [".$session{page}{pageId}."]."); .$session{page}{title}."' [".$session{page}{pageId}."].");
} else { } else {
if (WebGUI::Page::canView()) { if (WebGUI::Page::canView()) {
$cmd = "WebGUI::Wobject::".${$wobject}{namespace}; $cmd = "WebGUI::Wobject::".${$wobject}{namespace};
my $load = "use ".$cmd; # gotta load the wobject before you can use it my $load = "use ".$cmd; # gotta load the wobject before you can use it
eval($load); eval($load);
WebGUI::ErrorHandler::warn("Wobject failed to compile: $cmd.".$@) if($@); WebGUI::ErrorHandler::warn("Wobject failed to compile: $cmd.".$@) if($@);
$w = eval{$cmd->new($wobject)}; $w = eval{$cmd->new($wobject)};
WebGUI::ErrorHandler::fatalError("Couldn't instanciate wobject: ${$wobject}{namespace}. Root Cause: ".$@) if($@); WebGUI::ErrorHandler::fatalError("Couldn't instanciate wobject: ${$wobject}{namespace}. Root Cause: ".$@) if($@);
if ($session{form}{func} =~ /^[A-Za-z]+$/) { if ($session{form}{func} =~ /^[A-Za-z]+$/) {
$cmd = "www_".$session{form}{func}; $cmd = "www_".$session{form}{func};
$output = eval{$w->$cmd}; $output = eval{$w->$cmd};
WebGUI::ErrorHandler::fatalError("Wobject runtime error: ${$wobject}{namespace} / $session{form}{func}. Root cause: ".$@) if($@); WebGUI::ErrorHandler::fatalError("Wobject runtime error: ${$wobject}{namespace} / $session{form}{func}. Root cause: ".$@) if($@);
} else { } else {
WebGUI::ErrorHandler::security("execute an invalid function: ".$session{form}{func}); WebGUI::ErrorHandler::security("execute an invalid function: ".$session{form}{func});
} }
} else { } else {
$output = WebGUI::Privilege::noAccess(); $output = WebGUI::Privilege::noAccess();
} }
} }
} }
} else { } else {
WebGUI::ErrorHandler::security("execute an invalid function on wobject " WebGUI::ErrorHandler::security("execute an invalid function on wobject "
.$session{form}{wid}.": ".$session{form}{func}); .$session{form}{wid}.": ".$session{form}{func});
} }
} }
return $output; return $output;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub _processOperations { sub _processOperations {
my ($cmd, $output); my ($cmd, $output);
if (exists $session{form}{op}) { if (exists $session{form}{op}) {
if ($session{form}{op} =~ /^[A-Za-z]+$/) { if ($session{form}{op} =~ /^[A-Za-z]+$/) {
$cmd = "WebGUI::Operation::www_".$session{form}{op}; $cmd = "WebGUI::Operation::www_".$session{form}{op};
$output = eval($cmd); $output = eval($cmd);
WebGUI::ErrorHandler::security("call a non-existent operation: $session{form}{op}. Root cause: ".$@) if($@); WebGUI::ErrorHandler::security("call a non-existent operation: $session{form}{op}. Root cause: ".$@) if($@);
} else { } else {
WebGUI::ErrorHandler::security("execute an invalid operation: ".$session{form}{op}); WebGUI::ErrorHandler::security("execute an invalid operation: ".$session{form}{op});
} }
} }
return $output; return $output;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub page { sub page {
my $useExistingSession = $_[2]; my $useExistingSession = $_[2];
WebGUI::Session::open($_[0],$_[1]) unless ($useExistingSession); WebGUI::Session::open($_[0],$_[1]) unless ($useExistingSession);
my $useCache = ($session{form}{op} eq "" && $session{form}{wid} eq "" && $session{form}{makePrintable} eq "" my $useCache = ($session{form}{op} eq "" && $session{form}{wid} eq "" && $session{form}{makePrintable} eq ""
&& (($session{page}{cacheTimeout} > 10 && $session{user}{userId} !=1) || ($session{page}{cacheTimeoutVisitor} > 10 && $session{user}{userId} == 1)) && (($session{page}{cacheTimeout} > 10 && $session{user}{userId} !=1) || ($session{page}{cacheTimeoutVisitor} > 10 && $session{user}{userId} == 1))
&& not $session{var}{adminOn}); && not $session{var}{adminOn});
my ($output, $cache); my ($output, $cache);
if ($useCache) { if ($useCache) {
$cache = WebGUI::Cache->new("page_".$session{page}{pageId}."_".$session{user}{userId}); $cache = WebGUI::Cache->new("page_".$session{page}{pageId}."_".$session{user}{userId});
$output = $cache->get; $output = $cache->get;
} }
my $operationOutput = _processOperations(); my $operationOutput = _processOperations();
WebGUI::Affiliate::grabReferral(); WebGUI::Affiliate::grabReferral();
my $wobjectOutput = _processFunctions(); my $wobjectOutput = _processFunctions();
if ($operationOutput eq "" && $wobjectOutput eq "" && $session{form}{action2} ne "") { if ($operationOutput eq "" && $wobjectOutput eq "" && $session{form}{action2} ne "") {
_processAction($session{form}{action2}); _processAction($session{form}{action2});
$operationOutput = _processOperations(); $operationOutput = _processOperations();
$wobjectOutput = _processFunctions(); $wobjectOutput = _processFunctions();
} }
if ($output ne "") { if ($output ne "") {
# using cache # using cache
WebGUI::PassiveProfiling::addPage(); # add wobjects on page to passive profile log WebGUI::PassiveProfiling::addPage(); # add wobjects on page to passive profile log
} elsif (WebGUI::HTTP::getMimeType() ne "text/html") { } elsif (WebGUI::HTTP::getMimeType() ne "text/html") {
$output = $operationOutput.$wobjectOutput; $output = $operationOutput.$wobjectOutput;
} elsif ($operationOutput ne "") { } elsif ($operationOutput ne "") {
$output = _generatePage($operationOutput); $output = _generatePage($operationOutput);
} elsif ($wobjectOutput ne "") { } elsif ($wobjectOutput ne "") {
$output = _generatePage($wobjectOutput); $output = _generatePage($wobjectOutput);
} else { } else {
$output = _generatePage(WebGUI::Page::generate()); $output = _generatePage(WebGUI::Page::generate());
my $ttl; my $ttl;
if ($session{user}{userId} == 1) { if ($session{user}{userId} == 1) {
$ttl = $session{page}{cacheTimeoutVisitor}; $ttl = $session{page}{cacheTimeoutVisitor};
} else { } else {
$ttl = $session{page}{cacheTimeout}; $ttl = $session{page}{cacheTimeout};
} }
$cache->set($output, $ttl) if ($useCache); $cache->set($output, $ttl) if ($useCache);
} }
my $httpHeader = WebGUI::HTTP::getHeader(); my $httpHeader = WebGUI::HTTP::getHeader();
WebGUI::Session::close() unless ($useExistingSession); WebGUI::Session::close() unless ($useExistingSession);
return $httpHeader.$output; return $httpHeader.$output;
} }
1; 1;