From c3acc50381e38b3babcad1b0ea8098e0173289a1 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Thu, 1 Dec 2005 06:08:08 +0000 Subject: [PATCH] added gateway code so sites can exist at /somepath and not just at / --- docs/upgrades/upgrade_6.7.8-6.8.0.pl | 2 ++ etc/WebGUI.conf.original | 12 ++++++++++ lib/WebGUI.pm | 8 +++++-- lib/WebGUI/Asset.pm | 6 ++--- lib/WebGUI/Asset/Post/Thread.pm | 3 +-- lib/WebGUI/Auth.pm | 2 +- lib/WebGUI/Icon.pm | 32 ++++++++++++------------- lib/WebGUI/Macro/PageUrl.pm | 2 +- lib/WebGUI/Macro/Slash_gatewayUrl.pm | 4 +++- lib/WebGUI/Macro/r_printable.pm | 2 +- lib/WebGUI/URL.pm | 36 ++++++++++++++-------------- 11 files changed, 64 insertions(+), 45 deletions(-) diff --git a/docs/upgrades/upgrade_6.7.8-6.8.0.pl b/docs/upgrades/upgrade_6.7.8-6.8.0.pl index d8f04bab9..0a3de0bfe 100644 --- a/docs/upgrades/upgrade_6.7.8-6.8.0.pl +++ b/docs/upgrades/upgrade_6.7.8-6.8.0.pl @@ -759,9 +759,11 @@ sub updateConfigFile { push(@{$newConfig{assets}}, "WebGUI::Asset::Wobject::Matrix") unless isIn("WebGUI::Asset::Wobject::Matrix",@{$newConfig{assets}}); push(@{$newConfig{assets}}, "WebGUI::Asset::Wobject::InOutBoard") unless isIn("WebGUI::Asset::Wobject::InOutBoard",@{$newConfig{assets}}); push(@{$newConfig{assets}}, "WebGUI::Asset::File::ZipArchive") unless isIn("WebGUI::Asset::File::ZipArchive",@{$newConfig{assets}}); + push(@{$newConfig{assets}}, "WebGUI::Asset::Wobject::Dashboard") unless isIn("WebGUI::Asset::Wobject::Dashboard",@{$newConfig{assets}}); push(@{$newConfig{assets}}, "WebGUI::Asset::Wobject::StockData") unless isIn("WebGUI::Asset::Wobject::StockData",@{$newConfig{assets}}); push(@{$newConfig{assets}}, "WebGUI::Asset::Wobject::WeatherData") unless isIn("WebGUI::Asset::Wobject::WeatherData",@{$newConfig{assets}}); push(@{$newConfig{assets}}, "WebGUI::Asset::Wobject::MultiSearch") unless isIn("WebGUI::Asset::Wobject::MultiSearch",@{$newConfig{assets}}); + $newConfig{location} = "/"; $conf->purge; $conf->set(%newConfig); $conf->write; diff --git a/etc/WebGUI.conf.original b/etc/WebGUI.conf.original index 50270086c..d528205f7 100644 --- a/etc/WebGUI.conf.original +++ b/etc/WebGUI.conf.original @@ -1,7 +1,19 @@ # Add a comma separated list of the names this site can use. +# The first site in the list will be used as the default +# sitename for generating offline URLs and other functions. sitename = www.example.com, example.com +# 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 +# /site1, /site2, etc. If this is set to anything other than +# '/' then a matching block should +# contain the WebGUI handler instead in the Apache +# VirtualHost configuration. + +gateway = / + # The relative or fully qualified URL to the extras folder # that comes with WebGUI. diff --git a/lib/WebGUI.pm b/lib/WebGUI.pm index ba48e4c08..8ee545ce3 100644 --- a/lib/WebGUI.pm +++ b/lib/WebGUI.pm @@ -38,6 +38,7 @@ use Apache2::RequestIO (); use Apache2::Const -compile => qw(OK DECLINED NOT_FOUND); use Apache2::ServerUtil (); + #------------------------------------------------------------------- sub handler { my $r = shift; @@ -54,6 +55,9 @@ sub handler { $r->handler('perl-script'); $r->set_handlers(PerlAccessHandler => \&uploadsHandler); } else { + $session{requestedUrl} = $session{wguri}; + my $gateway = $session{config}{gateway}; + $session{requestedUrl} =~ s/^$gateway(.*)$/$1/; $r->handler('perl-script'); $r->set_handlers(PerlResponseHandler => \&contentHandler); $r->set_handlers(PerlTransHandler => sub { return Apache2::Const::OK }); @@ -137,7 +141,7 @@ sub page { if ($output eq "") { my $asset = eval{WebGUI::Asset->newByUrl($assetUrl,$session{form}{revision})}; if ($@) { - WebGUI::ErrorHandler::warn("Couldn't instantiate asset for url: ".$session{wguri}." Root cause: ".$@); + WebGUI::ErrorHandler::warn("Couldn't instantiate asset for url: ".$session{requestedUrl}." Root cause: ".$@); } if (defined $asset) { my $method = "view"; @@ -205,7 +209,7 @@ sub tryAssetMethod { my $methodToTry = "www_".$method; my $output = eval{$asset->$methodToTry()}; if ($@) { - WebGUI::ErrorHandler::warn("Couldn't call method ".$method." on asset for url: ".$session{wguri}." Root cause: ".$@); + WebGUI::ErrorHandler::warn("Couldn't call method ".$method." on asset for url: ".$session{requestedUrl}." Root cause: ".$@); $output = tryAssetMethod($asset,'view') if ($method ne "view"); } return $output; diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index c83a27ffb..1a37b7842 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -784,7 +784,7 @@ Returns the not found object. The not found object is set in the settings. =cut sub getNotFound { - if ($session{wguri} eq "/*give-credit-where-credit-is-due*") { + if ($session{requestedUrl} eq "*give-credit-where-credit-is-due*") { my $content = ""; open(FILE,"<".$session{config}{webguiRoot}."/docs/credits.txt"); while () { @@ -795,7 +795,7 @@ sub getNotFound { className=>"WebGUI::Asset::Snippet", snippet=> '
'.$content.'
' }); - } elsif ($session{wguri} eq "/abcdefghijklmnopqrstuvwxyz") { + } elsif ($session{requestedUrl} eq "abcdefghijklmnopqrstuvwxyz") { return WebGUI::Asset->newByPropertyHashRef({ className=>"WebGUI::Asset::Snippet", snippet=>q|
Why would you type in this URL? Really. What were you expecting to see here? You really need to get a life. Are you still here? Seriously, you need to go do something else. I think your boss is calling.
| @@ -1101,7 +1101,7 @@ A specific revision to instanciate. By default we instanciate the newest publish sub newByUrl { my $class = shift; - my $url = shift || $session{wguri}; + my $url = shift || $session{requestedUrl}; my $revisionDate = shift; $url = lc($url); $url =~ s/\/$//; diff --git a/lib/WebGUI/Asset/Post/Thread.pm b/lib/WebGUI/Asset/Post/Thread.pm index bb332fd38..8f2090def 100644 --- a/lib/WebGUI/Asset/Post/Thread.pm +++ b/lib/WebGUI/Asset/Post/Thread.pm @@ -666,8 +666,7 @@ sub view { } else { $sql .= "asset.lineage"; } - my $currentPageUrl = $session{wguri}; - $currentPageUrl =~ s/^\///; + my $currentPageUrl = $session{requestedUrl}; $p->setDataByQuery($sql, undef, undef, undef, "url", $currentPageUrl); foreach my $dataSet (@{$p->getPageData()}) { next unless ($dataSet->{className} eq "WebGUI::Asset::Post" || $dataSet->{className} eq "WebGUI::Asset::Post::Thread"); #handle non posts! diff --git a/lib/WebGUI/Auth.pm b/lib/WebGUI/Auth.pm index e15c0b2a5..82c8129f6 100644 --- a/lib/WebGUI/Auth.pm +++ b/lib/WebGUI/Auth.pm @@ -383,7 +383,7 @@ sub displayLogin { my $method = $_[0] || "login"; my $vars = $_[1]; unless ($session{form}{op} eq "auth") { - WebGUI::Session::setScratch("redirectAfterLogin",WebGUI::URL::gateway($session{wguri},$session{env}{QUERY_STRING})); + WebGUI::Session::setScratch("redirectAfterLogin",WebGUI::URL::page($session{env}{QUERY_STRING})); } $vars->{title} = WebGUI::International::get(66); my $action; diff --git a/lib/WebGUI/Icon.pm b/lib/WebGUI/Icon.pm index c3830ccec..28355b0c0 100644 --- a/lib/WebGUI/Icon.pm +++ b/lib/WebGUI/Icon.pm @@ -101,7 +101,7 @@ The URL to any page. Defaults to the current page. sub copyIcon { my ($output, $pageURL); - $pageURL = $_[1] || $session{wguri}; + $pageURL = $_[1] || $session{requestedUrl}; $output = ''; $output .= ''.WebGUI::International::get('Copy','Icon').''; return $output; @@ -125,7 +125,7 @@ The URL to any page. Defaults to the current page. sub cutIcon { my ($output, $pageURL); - $pageURL = $_[1] || $session{wguri}; + $pageURL = $_[1] || $session{requestedUrl}; $output = ''; $output .= ''.WebGUI::International::get('Cut','Icon').''; return $output; @@ -158,7 +158,7 @@ sub deleteIcon { $confirmText = qq| onclick="return confirm('$confirmText')" |; } - $pageURL = $_[1] || $session{wguri}; + $pageURL = $_[1] || $session{requestedUrl}; $output = ''; $output .= ''.WebGUI::International::get('Delete','Icon').''; @@ -195,7 +195,7 @@ The URL to any page. Defaults to the current page. sub editIcon { my ($output, $pageURL); - $pageURL = $_[1] || $session{wguri}; + $pageURL = $_[1] || $session{requestedUrl}; $output = ''; $output .= ''.WebGUI::International::get('Edit','Icon').''; return $output; @@ -219,7 +219,7 @@ The URL to any page. Defaults to the current page. sub exportIcon { my ($output, $pageURL); - $pageURL = $_[1] || $session{wguri}; + $pageURL = $_[1] || $session{requestedUrl}; $output = ''; # TODO Change icon to Jeffs export icon $output .= ''.WebGUI::International::get('Export','Icon').''; @@ -292,7 +292,7 @@ The URL to any page. Defaults to the current page. sub lockedIcon { my ($output, $pageURL); - $pageURL = $_[1] || $session{wguri}; + $pageURL = $_[1] || $session{requestedUrl}; $output = ''; $output .= ''.WebGUI::International::get('locked','Icon').''; return $output; @@ -316,7 +316,7 @@ The URL to any page. Defaults to the current page. sub manageIcon { my ($output, $pageURL); - $pageURL = $_[1] || $session{wguri}; + $pageURL = $_[1] || $session{requestedUrl}; $output = ''; $output .= ''.WebGUI::International::get('Manage','Icon').''; return $output; @@ -340,7 +340,7 @@ The URL to any page. Defaults to the current page. sub moveBottomIcon { my ($output, $pageURL); - $pageURL = $_[1] || $session{wguri}; + $pageURL = $_[1] || $session{requestedUrl}; $output = ''; $output .= ''.WebGUI::International::get('Move To Bottom','Icon').''; return $output; @@ -364,7 +364,7 @@ The URL to any page. Defaults to the current page. sub moveDownIcon { my ($output, $pageURL); - $pageURL = $_[1] || $session{wguri}; + $pageURL = $_[1] || $session{requestedUrl}; $output = ''; $output .= ''.WebGUI::International::get('Move Down','Icon').''; return $output; @@ -388,7 +388,7 @@ The URL to any page. Defaults to the current page. sub moveLeftIcon { my ($output, $pageURL); - $pageURL = $_[1] || $session{wguri}; + $pageURL = $_[1] || $session{requestedUrl}; $output = ''; $output .= ''.WebGUI::International::get('Move Left','Icon').''; return $output; @@ -412,7 +412,7 @@ The URL to any page. Defaults to the current page. sub moveRightIcon { my ($output, $pageURL); - $pageURL = $_[1] || $session{wguri}; + $pageURL = $_[1] || $session{requestedUrl}; $output = ''; $output .= ''.WebGUI::International::get('Move Right','Icon').''; return $output; @@ -436,7 +436,7 @@ The URL to any page. Defaults to the current page. sub moveTopIcon { my ($output, $pageURL); - $pageURL = $_[1] || $session{wguri}; + $pageURL = $_[1] || $session{requestedUrl}; $output = ''; $output .= ''.WebGUI::International::get('Move To Top','Icon').''; return $output; @@ -460,7 +460,7 @@ The URL to any page. Defaults to the current page. sub moveUpIcon { my ($output, $pageURL); - $pageURL = $_[1] || $session{wguri}; + $pageURL = $_[1] || $session{requestedUrl}; $output = ''; $output .= ''.WebGUI::International::get('Move Up','Icon').''; return $output; @@ -496,7 +496,7 @@ The URL to any page. Defaults to the current page. sub pasteIcon { my ($output, $pageURL); - $pageURL = $_[1] || $session{wguri}; + $pageURL = $_[1] || $session{requestedUrl}; $output = ''; $output .= ''.WebGUI::International::get('Paste','Icon').''; return $output; @@ -520,7 +520,7 @@ The URL to any page. Defaults to the current page. sub shortcutIcon { my ($output, $pageURL); - $pageURL = $_[1] || $session{wguri}; + $pageURL = $_[1] || $session{requestedUrl}; $output = ''; $output .= ''.WebGUI::International::get('Create Shortcut','Icon').''; return $output; @@ -544,7 +544,7 @@ The URL to any page. Defaults to the current page. sub viewIcon { my ($output, $pageURL); - $pageURL = $_[1] || $session{wguri}; + $pageURL = $_[1] || $session{requestedUrl}; $output = ''; $output .= ''.WebGUI::International::get('View','Icon').''; return $output; diff --git a/lib/WebGUI/Macro/PageUrl.pm b/lib/WebGUI/Macro/PageUrl.pm index 777e73211..47265ad7a 100644 --- a/lib/WebGUI/Macro/PageUrl.pm +++ b/lib/WebGUI/Macro/PageUrl.pm @@ -16,7 +16,7 @@ use WebGUI::URL; #------------------------------------------------------------------- sub process { - return $session{wguri}; + return WebGUI::URL::page(); } diff --git a/lib/WebGUI/Macro/Slash_gatewayUrl.pm b/lib/WebGUI/Macro/Slash_gatewayUrl.pm index 79ccce1d7..92639353a 100644 --- a/lib/WebGUI/Macro/Slash_gatewayUrl.pm +++ b/lib/WebGUI/Macro/Slash_gatewayUrl.pm @@ -11,10 +11,12 @@ package WebGUI::Macro::Slash_gatewayUrl; #------------------------------------------------------------------- use strict; +use WebGUI::Session; +use WebGUI::URL; #------------------------------------------------------------------- sub process { - return "/"; + return WebGUI::URL::gateway(); } diff --git a/lib/WebGUI/Macro/r_printable.pm b/lib/WebGUI/Macro/r_printable.pm index 04c67f1fe..300ad587e 100644 --- a/lib/WebGUI/Macro/r_printable.pm +++ b/lib/WebGUI/Macro/r_printable.pm @@ -25,7 +25,7 @@ sub process { if ($session{env}{REQUEST_URI} =~ /op\=/) { $append = 'op2='.WebGUI::URL::escape($append); } - $temp = WebGUI::URL::gateway($session{wguri},$append); + $temp = WebGUI::URL::page($append); $temp =~ s/\/\//\//; $temp = WebGUI::URL::append($temp,$session{env}{QUERY_STRING}); if ($param[1] ne "") { diff --git a/lib/WebGUI/URL.pm b/lib/WebGUI/URL.pm index d962e0e6a..86d39e330 100644 --- a/lib/WebGUI/URL.pm +++ b/lib/WebGUI/URL.pm @@ -97,7 +97,7 @@ The string to escape. =cut sub escape { - return uri_escape($_[0]); + return uri_escape(shift); } @@ -105,11 +105,11 @@ sub escape { =head2 gateway ( pageURL [ , pairs ] ) -Generate a URL based on WebGUI's gateway script. +Generate a URL based on WebGUI's location directive. =head3 pageURL -The urlized title of a page that you wish to create a URL for. +The url of an asset that you wish to create a fully qualified URL for. =head3 pairs @@ -120,13 +120,17 @@ Name value pairs to add to the URL in the form of: =cut sub gateway { - $_[0] =~ s/^\///; - my $url = '/'.$_[0]; + my $pageUrl = shift; + my $pairs = shift; + $pageUrl =~ s/^\///; + my $url = $session{config}{gateway}; + $url .= '/' unless ($url =~ m/\/$/); + $url .= $pageUrl; if ($session{setting}{preventProxyCache} == 1) { $url = append($url,"noCache=".randint(0,1000).';'.time()); } - if ($_[1]) { - $url = append($url,$_[1]); + if ($pairs) { + $url = append($url,$pairs); } return $url; } @@ -169,8 +173,7 @@ sub setSiteURL { =head2 getSiteURL ( ) -Returns a constructed site url. The returned -value can be overridden using the setSiteURL function. +Returns a constructed site url. The returned value can be overridden using the setSiteURL function. =cut @@ -222,7 +225,7 @@ Returns the URL of the current page. =head3 pairs Name value pairs to add to the URL in the form of: - +gateway() name1=value1;name2=value2;name3=value3 =head3 useSiteUrl @@ -243,15 +246,12 @@ sub page { if ($useFullUrl) { $url = getSiteURL(); } - $url .= '/'; - my $pathinfo; + $url .= gateway(); if ($session{asset}) { - $pathinfo = $session{asset}->get("url"); + $url .= $session{asset}->get("url"); } else { - $pathinfo = $session{wguri}; - $pathinfo =~ s/^\/(.*)/$1/; + $url .= $session{requestedUrl}; } - $url .= $pathinfo; if ($session{setting}{preventProxyCache} == 1 && !$skipPreventProxyCache) { $url = append($url,"noCache=".randint(0,1000).';'.time()); } @@ -276,7 +276,7 @@ The string to unescape. =cut sub unescape { - return uri_unescape($_[0]); + return uri_unescape(shift); } #------------------------------------------------------------------- @@ -293,7 +293,7 @@ Returns a url that is safe for WebGUI pages. sub urlize { my ($value); - $value = lc($_[0]); #lower cases whole string + $value = lc(shift); #lower cases whole string $value = makeCompliant($value); $value =~ s/\/$//; return $value;