bug fixes

This commit is contained in:
JT Smith 2005-11-04 14:42:00 +00:00
parent e8a514b753
commit 775339a209
5 changed files with 48 additions and 51 deletions

View file

@ -12,8 +12,6 @@ my $quiet;
start();
addTimeZonesToUserPreferences();
#TODO (by somebody!):
# possibly instead of deleting old user timeZone preferences, convert them.
# MUST DO: any dates in WebGUI greater than epoch 2^32 must be reduced, because
# the new DateTime system uses Params::Validate, which will only validate integers
# up to 2^32 as SCALARs. :(
@ -25,6 +23,7 @@ sub addTimeZonesToUserPreferences {
print "\tDropping time offsets in favor of time zones.\n" unless ($quiet);
WebGUI::SQL->write("delete from userProfileData where fieldName='timeOffset'");
WebGUI::SQL->write("update userProfileField set dataValues='', fieldName='timeZone', dataType='timeZone', dataDefault=".quote("['America/Chicago']")." where fieldName='timeOffset'");
WebGUI::SQL->write("insert into userProfileData values ('1','timeZone','America/Chicago')");
}
sub removeUnneededFiles {

View file

@ -28,6 +28,8 @@ use WebGUI::SQL;
use WebGUI::Style;
use WebGUI::URL;
use WebGUI::PassiveProfiling;
use Apache2::Request;
use Apache2::Cookie;
use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::Const -compile => qw(OK DECLINED);
@ -53,7 +55,30 @@ sub contentHandler {
my $r = shift;
my $s = Apache2::ServerUtil->server;
WebGUI::Session::open($s->dir_config('WebguiRoot'),$r->dir_config('WebguiConfig'),$r);
### Add Apache Request stuff to Session
$session{wguri} = $r->uri;
### check to see if client is proxied and adjust remote_addr as necessary
if ($ENV{HTTP_X_FORWARDED_FOR} ne "") {
$session{env}{REMOTE_ADDR} = $ENV{HTTP_X_FORWARDED_FOR};
}
###----------------------------
### Apache2::Request object
$session{req} = Apache2::Request->new($r, POST_MAX => 1024 * $session{setting}{maxAttachmentSize});
###----------------------------
### form variables
#
foreach ($session{req}->param) {
$session{form}{$_} = $session{req}->param($_);
}
###----------------------------
### cookies
my %cookies = Apache2::Cookie->fetch();
foreach my $key (keys %cookies) {
my $value = $cookies{$key};
$value =~ s/$key=//; # Strange... The Apache2::Cookie value also contains the key ????
# Must be a bug in Apache2::Cookie...
$session{cookie}{$key} = $value;
}
if ($session{env}{HTTP_X_MOZ} eq "prefetch") { # browser prefetch is a bad thing
WebGUI::HTTP::setStatus("403","We don't allow prefetch, because it increases bandwidth, hurts stats, and can break web sites.");
$r->print(WebGUI::HTTP::getHeader());

View file

@ -255,7 +255,7 @@ sub getStickUrl {
}
#-------------------------------------------------------------------
id
=head2 getSubscribeUrl ( )
Formats the url to subscribe to the thread

View file

@ -62,10 +62,10 @@ sub getHeader {
return undef if ($session{http}{noHeader});
my %params;
if (isRedirect()) {
$session{modperl}->headers_out->set(Location => $session{http}{location});
$session{modperl}->status(301);
$session{req}->headers_out->set(Location => $session{http}{location});
$session{req}->status(301);
} else {
$session{modperl}->content_type($session{http}{mimetype} || "text/html");
$session{req}->content_type($session{http}{mimetype} || "text/html");
if ($session{setting}{preventProxyCache}) {
$params{"-expires"} = "-1d";
}
@ -75,8 +75,8 @@ sub getHeader {
}
$params{"-cookie"} = $session{http}{cookie};
my $status = getStatus();
# $session{modperl}->custom_response($status, '<!-- '.$session{http}{statusDescription}.' -->' );
$session{modperl}->status($status);
# $session{req}->custom_response($status, '<!-- '.$session{http}{statusDescription}.' -->' );
$session{req}->status($status);
return;
}
@ -143,13 +143,15 @@ sub setCookie {
my $name = shift;
my $value = shift;
my $ttl = shift || '+10y';
my $cookie = Apache2::Cookie->new($session{modperl},
-name=>$name,
-value=>$value,
-expires=>$ttl,
-path=>'/'
);
$cookie->bake($session{modperl});
if (exists $session{req}) {
my $cookie = Apache2::Cookie->new($session{req},
-name=>$name,
-value=>$value,
-expires=>$ttl,
-path=>'/'
);
$cookie->bake($session{req});
}
}

View file

@ -14,7 +14,6 @@ package WebGUI::Session;
=cut
use Date::Manip;
use DBI;
use Exporter;
use strict;
@ -28,8 +27,6 @@ use WebGUI::SQL;
use WebGUI::User;
use WebGUI::Utility;
use URI::Escape;
use Apache2::Request;
use Apache2::Cookie;
our @ISA = qw(Exporter);
our @EXPORT = qw(%session);
@ -78,15 +75,15 @@ sub _setupSessionVars {
tie %vars, 'Tie::CPHash';
if ($_[0] ne "") {
%vars = WebGUI::SQL->quickHash("select * from userSession where sessionId=".quote($_[0]));
if ($vars{expires} < _time() ) { #|| $vars{lastIP} ne $session{env}{REMOTE_ADDR}) { # had to remove for revolving ip proxies
if ($vars{expires} < time() ) { #|| $vars{lastIP} ne $session{env}{REMOTE_ADDR}) { # had to remove for revolving ip proxies
%vars = ();
WebGUI::Session::end($_[0]);
}
if ($vars{sessionId} ne "") {
$session{scratch} = WebGUI::SQL->buildHashRef("select name,value from userSessionScratch
where sessionId=".quote($_[0]));
WebGUI::SQL->write("update userSession set lastPageView="._time().", lastIP='$session{env}{REMOTE_ADDR}',
expires=".(_time()+$session{setting}{sessionTimeout})." where sessionId='$_[0]'");
WebGUI::SQL->write("update userSession set lastPageView=".time().", lastIP='$session{env}{REMOTE_ADDR}',
expires=".(time()+$session{setting}{sessionTimeout})." where sessionId='$_[0]'");
} else {
$vars{sessionId} = start(1,$_[0]);
}
@ -98,15 +95,10 @@ sub _setupSessionVars {
sub _setupUserInfo {
my $u = WebGUI::User->new(shift);
%{$session{user}} = (%{$u->{_profile}}, %{$u->{_user}});
# $session{modperl}->user($session{user}{username});
# $session{req}->user($session{user}{username});
$session{user}{alias} = $session{user}{username} if ($session{user}{alias} =~ /^\W+$/ || $session{user}{alias} eq "");
}
#-------------------------------------------------------------------
sub _time {
return &UnixDate(&ParseDate("now"),"%s");
}
#-------------------------------------------------------------------
# This routine returns an unique session Id.
@ -282,7 +274,6 @@ A pointer to a Fast CGI object.
sub open {
my $webguiRoot = shift;
my $configFile = shift;
$session{modperl} = shift;
my ($key);
###----------------------------
### operating system specific things
@ -312,31 +303,10 @@ sub open {
###----------------------------
### evironment variables from web server
$session{env} = \%ENV;
### check to see if client is proxied and adjust remote_addr as necessary
if ($ENV{HTTP_X_FORWARDED_FOR} ne "") {
$session{env}{REMOTE_ADDR} = $ENV{HTTP_X_FORWARDED_FOR};
}
###----------------------------
### global system settings (from settings table)
$session{setting} = WebGUI::Setting::get();
###----------------------------
### Apache2::Request object
$session{req} = Apache2::Request->new($session{modperl}, POST_MAX => 1024 * $session{setting}{maxAttachmentSize});
###----------------------------
### form variables
#
foreach ($session{req}->param) {
$session{form}{$_} = $session{req}->param($_);
}
###----------------------------
### cookies
my %cookies = Apache2::Cookie->fetch();
foreach my $key (keys %cookies) {
my $value = $cookies{$key};
$value =~ s/$key=//; # Strange... The Apache2::Cookie value also contains the key ????
# Must be a bug in Apache2::Cookie...
$session{cookie}{$key} = $value;
}
###----------------------------
### session variables
if ($session{cookie}{wgSession} eq "") {
@ -457,7 +427,8 @@ sub start {
my ($sessionId);
$sessionId = $_[1] || _uniqueSessionId();
WebGUI::SQL->write("insert into userSession values ('$sessionId', ".
(_time()+$session{setting}{sessionTimeout}).", "._time().", 0, '$ENV{REMOTE_ADDR}', ".quote($_[0]).")");
(time()+$session{setting}{sessionTimeout}).", ".time().", 0, '$ENV{REMOTE_ADDR}', ".quote($_[0]).")");
require WebGUI::HTTP;
WebGUI::HTTP::setCookie("wgSession",$sessionId);
refreshSessionVars($sessionId);
return $sessionId;