From 2ea58485c95fdd808d3d6a5845a06a01d17f289e Mon Sep 17 00:00:00 2001 From: JT Smith Date: Fri, 4 Aug 2006 15:16:18 +0000 Subject: [PATCH] - Added an option to override the session cookie name. --- docs/changelog/7.x.x.txt | 1 + docs/gotcha.txt | 6 ++++++ etc/WebGUI.conf.original | 4 ++++ lib/Spectre/Cron.pm | 20 +++++--------------- lib/Spectre/Workflow.pm | 14 +++++--------- lib/WebGUI.pm | 2 +- lib/WebGUI/Asset.pm | 3 ++- lib/WebGUI/Config.pm | 13 +++++++++++++ lib/WebGUI/Session.pm | 2 +- lib/WebGUI/Workflow/Cron.pm | 1 + lib/WebGUI/Workflow/Instance.pm | 2 +- 11 files changed, 40 insertions(+), 28 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index c352b411b..6e06ee51b 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -4,6 +4,7 @@ - Added some more tests to the suite. - Fixed the test skeleton - Fixed some bugs regarding Search relevance sorting (Len Kranendonk / www.ilance.nl) + - Added an option to override the session cookie name. 7.0.4 diff --git a/docs/gotcha.txt b/docs/gotcha.txt index 9216fd039..ce1935aaf 100644 --- a/docs/gotcha.txt +++ b/docs/gotcha.txt @@ -79,6 +79,12 @@ save you many hours of grief. released. It will serve as the beta, gamma, and release candidates for 7.0.0. + * The group SQL query mechanism has been changed to be more efficient, + more practical, and more consistent with the rest of WebGUI. As + such, your old query will no longer work. You used to do something + like "select 1 from table where foo='bar'", but now you need to + "select userId from table where foo='bar'". + * The "messageLog" table will be deleted during the upgrade process, and all of the messages in it. This is because the messages contained in there are no longer useful because they won't diff --git a/etc/WebGUI.conf.original b/etc/WebGUI.conf.original index e6109c41b..d28fe4446 100644 --- a/etc/WebGUI.conf.original +++ b/etc/WebGUI.conf.original @@ -8,6 +8,10 @@ "sitename" : [ "www.example.com", "example.com"], +# Rename the WebGUI Session cookie if you like. + +"cookieName" : "wgSession", + # The location where the WebGUI server will be handling # requests. This is normally just '/' or the root of the # server, but on some installations it might be /webgui or diff --git a/lib/Spectre/Cron.pm b/lib/Spectre/Cron.pm index 89ffd7582..752a0b87d 100644 --- a/lib/Spectre/Cron.pm +++ b/lib/Spectre/Cron.pm @@ -137,19 +137,8 @@ sub addJob { return 0 unless ($params->{enabled}); my $id = $params->{config}."-".$params->{taskId}; $self->debug("Adding schedule ".$params->{taskId}." to the queue."); - $self->{_jobs}{$id} = { - taskId=>$params->{taskId}, - config=>$params->{config}, - gateway=>$params->{gateway}, - sitename=>$params->{sitename}, - schedule=>join(" ", $params->{minuteOfHour}, $params->{hourOfDay}, $params->{dayOfMonth}, $params->{monthOfYear}, $params->{dayOfWeek}), - runOnce=>$params->{runOnce}, - workflowId=>$params->{workflowId}, - className=>$params->{className}, - methodName=>$params->{methodName}, - parameters=>$params->{parameters}, - priority=>$params->{priority} - }; + $params->{schedule} = join(" ", $params->{minuteOfHour}, $params->{hourOfDay}, $params->{dayOfMonth}, $params->{monthOfYear}, $params->{dayOfWeek}); + $self->{_jobs}{$id} = $params; } #------------------------------------------------------------------- @@ -400,7 +389,7 @@ sub runJob { my $url = "http://".$job->{sitename}.':'.$self->config->get("webguiPort").$job->{gateway}; my $request = POST $url, [op=>"runCronJob", taskId=>$job->{taskId}]; my $cookie = $self->{_cookies}{$job->{sitename}}; - $request->header("Cookie","wgSession=".$cookie) if (defined $cookie); + $request->header("Cookie",$job->{cookieName}."=".$cookie) if (defined $cookie); $request->header("User-Agent","Spectre"); $request->header("X-jobId",$id); $self->debug("Posting job ".$id." to $url."); @@ -431,7 +420,8 @@ sub runJobResponse { if ($response->header("Set-Cookie") ne "") { $self->debug("Storing cookie for $id for later use."); my $cookie = $response->header("Set-Cookie"); - $cookie =~ s/wgSession=([a-zA-Z0-9\_\-]{22}).*/$1/; + my $pattern = $job->{cookieName}."=([a-zA-Z0-9\_\-]{22}).*"; + $cookie =~ s/$pattern/$1/; $self->{_cookies}{$job->{sitename}} = $cookie; } my $state = $response->content; diff --git a/lib/Spectre/Workflow.pm b/lib/Spectre/Workflow.pm index c4c379716..837c8757e 100644 --- a/lib/Spectre/Workflow.pm +++ b/lib/Spectre/Workflow.pm @@ -84,13 +84,8 @@ The priority (1,2, or 3) that this instance should be run at. sub addInstance { my ($self, $params) = @_[OBJECT, ARG0]; $self->debug("Adding workflow instance ".$params->{instanceId}." from ".$params->{sitename}." to queue at priority ".$params->{priority}."."); - $self->{_instances}{$params->{instanceId}} = { - sitename=>$params->{sitename}, - instanceId=>$params->{instanceId}, - gateway => $params->{gateway}, - status=>"waiting", - priority=>$params->{priority} - }; + $params->{status} = "waiting"; + $self->{_instances}{$params->{instanceId}} = $params; push(@{$self->{"_priority".$params->{priority}}}, $params->{instanceId}); } @@ -370,7 +365,7 @@ sub runWorker { my $url = "http://".$instance->{sitename}.':'.$self->config->get("webguiPort").$instance->{gateway}; my $request = POST $url, [op=>"runWorkflow", instanceId=>$instance->{instanceId}]; my $cookie = $self->{_cookies}{$instance->{sitename}}; - $request->header("Cookie","wgSession=".$cookie) if (defined $cookie); + $request->header("Cookie",$instance->{cookieName}."=".$cookie) if (defined $cookie); $request->header("X-instanceId",$instance->{instanceId}); $request->header("User-Agent","Spectre"); $self->debug("Posting workflow instance ".$instance->{instanceId}." to $url."); @@ -418,7 +413,8 @@ sub workerResponse { if ($response->header("Set-Cookie") ne "") { $self->debug("Storing cookie for $instanceId for later use."); my $cookie = $response->header("Set-Cookie"); - $cookie =~ s/wgSession=([a-zA-Z0-9\_\-]{22}).*/$1/; + my $pattern = $self->{_instances}{$instanceId}{cookieName}."=([a-zA-Z0-9\_\-]{22}).*"; + $cookie =~ s/$pattern/$1/; $self->{_cookies}{$self->{_instances}{$instanceId}{sitename}} = $cookie; } my $state = $response->content; diff --git a/lib/WebGUI.pm b/lib/WebGUI.pm index ebce8df26..f135663a1 100644 --- a/lib/WebGUI.pm +++ b/lib/WebGUI.pm @@ -112,7 +112,7 @@ sub contentHandler { } else { $output = page($session); } - $session->http->setCookie("wgSession",$session->var->{_var}{sessionId}) unless $session->var->{_var}{sessionId} eq $session->http->getCookies->{"wgSession"}; + $session->http->setCookie($session->config->getCookieName,$session->var->{_var}{sessionId}) unless $session->var->{_var}{sessionId} eq $session->http->getCookies->{$session->config->getCookieName}; my $filename = $session->http->getStreamedFile(); if ((defined $filename) && ($session->config->get("enableStreamingUploads") eq "1")) { my $ct = guess_media_type($filename); diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 507b0d6b6..2cf9c2df4 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -196,7 +196,8 @@ sub checkView { } $self->logView(); # must find a way to do this next line better - $self->session->http->setCookie("wgSession",$self->session->var->{_var}{sessionId}) unless $self->session->var->{_var}{sessionId} eq $self->session->http->getCookies->{"wgSession"}; + my $cookieName = $self->session->config->getCookieName; + $self->session->http->setCookie($cookieName,$self->session->var->{_var}{sessionId}) unless $self->session->var->{_var}{sessionId} eq $self->session->http->getCookies->{$cookieName}; return undef; } diff --git a/lib/WebGUI/Config.pm b/lib/WebGUI/Config.pm index 87c2f0858..215acbfb6 100644 --- a/lib/WebGUI/Config.pm +++ b/lib/WebGUI/Config.pm @@ -224,6 +224,19 @@ sub get { return $self->{_config}{$param}; } +#------------------------------------------------------------------- + +=head2 getCookieName ( ) + +Returns the cookie name defined in the config file. Returns "wgSession" if one isn't defined. + +=cut + +sub getCookieName { + my $self = shift; + return $self->get("cookieName") || "wgSession"; +} + #------------------------------------------------------------------- diff --git a/lib/WebGUI/Session.pm b/lib/WebGUI/Session.pm index 50e288c19..eddc895d2 100644 --- a/lib/WebGUI/Session.pm +++ b/lib/WebGUI/Session.pm @@ -368,7 +368,7 @@ sub open { my $self = {_config=>$config, _server=>$server}; bless $self , $class; $self->{_request} = $request if (defined $request); - my $sessionId = shift || $self->http->getCookies->{"wgSession"} || $self->id->generate; + my $sessionId = shift || $self->http->getCookies->{$config->getCookieName} || $self->id->generate; $sessionId = $self->id->generate unless $self->id->valid($sessionId); my $noFuss = shift; $self->{_var} = WebGUI::Session::Var->new($self,$sessionId, $noFuss); diff --git a/lib/WebGUI/Workflow/Cron.pm b/lib/WebGUI/Workflow/Cron.pm index c3a106f28..07ae7b699 100644 --- a/lib/WebGUI/Workflow/Cron.pm +++ b/lib/WebGUI/Workflow/Cron.pm @@ -289,6 +289,7 @@ sub set { $params{config} = $self->session->config->getFilename; $params{sitename} = $self->session->config->get("sitename")->[0]; $params{gateway} = $self->session->config->get("gateway"); + $params{cookieName} = $self->session->config->getCookieName; $spectre->notify("cron/addJob", \%params); } diff --git a/lib/WebGUI/Workflow/Instance.pm b/lib/WebGUI/Workflow/Instance.pm index 30a44cba4..f478a9f50 100644 --- a/lib/WebGUI/Workflow/Instance.pm +++ b/lib/WebGUI/Workflow/Instance.pm @@ -380,7 +380,7 @@ sub set { if ($properties->{notifySpectre}) { my $spectre = WebGUI::Workflow::Spectre->new($self->session); $spectre->notify("workflow/deleteInstance",$self->getId) unless ($properties->{newlyCreated}); - $spectre->notify("workflow/addInstance", {gateway=>$self->session->config->get("gateway"), sitename=>$self->session->config->get("sitename")->[0], instanceId=>$self->getId, priority=>$self->{_data}{priority}}); + $spectre->notify("workflow/addInstance", {cookieName=>$self->session->config->getCookieName, gateway=>$self->session->config->get("gateway"), sitename=>$self->session->config->get("sitename")->[0], instanceId=>$self->getId, priority=>$self->{_data}{priority}}); } }