Added pluggable URL and content handlers.

This commit is contained in:
JT Smith 2007-12-14 22:08:09 +00:00
parent fb33859cc6
commit 1fc11fbda8
19 changed files with 1101 additions and 411 deletions

View file

@ -564,9 +564,6 @@ sub fixUrl {
$self->session->config->get("extrasURL"),
$self->session->config->get("uploadsURL"),
);
if (defined $self->session->config->get('passthruUrls')) {
push @badUrls, @{ $self->session->config->get('passthruUrls') };
}
foreach my $badUrl (@badUrls) {
$badUrl =~ s{ / $ }{}x; # Remove trailing slashes from the end of the URL
if ($badUrl =~ /^http/) {
@ -1083,25 +1080,7 @@ A reference to the current session.
sub getNotFound {
my $class = shift;
my $session = shift;
if ($session->url->getRequestedUrl eq "*give-credit-where-credit-is-due*") {
my $content = "";
open(my $FILE,"<",$session->config->getWebguiRoot."/docs/credits.txt");
while (<$FILE>) {
$content .= $_;
}
close($FILE);
return WebGUI::Asset->newByPropertyHashRef($session,{
className=>"WebGUI::Asset::Snippet",
snippet=> '<pre>'.$content.'</pre>'
});
} elsif ($session->url->getRequestedUrl eq "abcdefghijklmnopqrstuvwxyz") {
return WebGUI::Asset->newByPropertyHashRef($session,{
className=>"WebGUI::Asset::Snippet",
snippet=>q|<div style="width: 600px; padding: 200px;">&#87;&#104;&#121;&#32;&#119;&#111;&#117;&#108;&#100;&#32;&#121;&#111;&#117;&#32;&#116;&#121;&#112;&#101;&#32;&#105;&#110;&#32;&#116;&#104;&#105;&#115;&#32;&#85;&#82;&#76;&#63;&#32;&#82;&#101;&#97;&#108;&#108;&#121;&#46;&#32;&#87;&#104;&#97;&#116;&#32;&#119;&#101;&#114;&#101;&#32;&#121;&#111;&#117;&#32;&#101;&#120;&#112;&#101;&#99;&#116;&#105;&#110;&#103;&#32;&#116;&#111;&#32;&#115;&#101;&#101;&#32;&#104;&#101;&#114;&#101;&#63;&#32;&#89;&#111;&#117;&#32;&#114;&#101;&#97;&#108;&#108;&#121;&#32;&#110;&#101;&#101;&#100;&#32;&#116;&#111;&#32;&#103;&#101;&#116;&#32;&#97;&#32;&#108;&#105;&#102;&#101;&#46;&#32;&#65;&#114;&#101;&#32;&#121;&#111;&#117;&#32;&#115;&#116;&#105;&#108;&#108;&#32;&#104;&#101;&#114;&#101;&#63;&#32;&#83;&#101;&#114;&#105;&#111;&#117;&#115;&#108;&#121;&#44;&#32;&#121;&#111;&#117;&#32;&#110;&#101;&#101;&#100;&#32;&#116;&#111;&#32;&#103;&#111;&#32;&#100;&#111;&#32;&#115;&#111;&#109;&#101;&#116;&#104;&#105;&#110;&#103;&#32;&#101;&#108;&#115;&#101;&#46;&#32;&#73;&#32;&#116;&#104;&#105;&#110;&#107;&#32;&#121;&#111;&#117;&#114;&#32;&#98;&#111;&#115;&#115;&#32;&#105;&#115;&#32;&#99;&#97;&#108;&#108;&#105;&#110;&#103;&#46;</div>|
});
} else {
return WebGUI::Asset->newByDynamicClass($session, $session->setting->get("notFoundPage"));
}
return WebGUI::Asset->newByDynamicClass($session, $session->setting->get("notFoundPage"));
}

235
lib/WebGUI/Content/Asset.pm Normal file
View file

@ -0,0 +1,235 @@
package WebGUI::Content::Asset;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2007 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
use LWP::MediaTypes qw(guess_media_type);
use Time::HiRes;
use WebGUI::Asset;
=head1 NAME
Package WebGUI::Content::MyHandler
=head1 DESCRIPTION
A content handler that serves up assets.
=head1 SYNOPSIS
use WebGUI::Content::Asset;
my $output = WebGUI::Content::Asset::handler($session);
=head1 SUBROUTINES
These subroutines are available from this package:
=cut
#-------------------------------------------------------------------
=head2 getAsset ( session [, assetUrl ] )
Returns an asset based upon the requested asset URL, or optionally pass one in.
=cut
sub getAsset {
my $session = shift;
my $assetUrl = shift;
my $asset = eval{WebGUI::Asset->newByUrl($session,$assetUrl,$session->form->process("revision"))};
if ($@) {
$session->errorHandler->warn("Couldn't instantiate asset for url: ".$assetUrl." Root cause: ".$@);
}
return $asset;
}
#-------------------------------------------------------------------
=head2 getRequestedAssetUrl ( session [, assetUrl ] )
Returns an asset based upon the requested asset URL, or optionally pass one in.
=cut
sub getRequestedAssetUrl {
my $session = shift;
my $assetUrl = shift || $session->url->getRequestedUrl;
return $assetUrl;
}
#-------------------------------------------------------------------
=head2 handler ( session )
The content handler for this package.
=cut
sub handler {
my ($session) = @_;
my ($errorHandler, $http, $var, $asset, $request, $config) = $session->quick(qw(errorHandler http var asset request config));
my $output = "";
if ($errorHandler->canShowPerformanceIndicators) { #show performance indicators if required
my $t = [Time::HiRes::gettimeofday()];
$output = page($session);
$t = Time::HiRes::tv_interval($t) ;
if ($output =~ /<\/title>/) {
$output =~ s/<\/title>/ : ${t} seconds<\/title>/i;
}
else {
# Kludge.
my $mimeType = $http->getMimeType();
if ($mimeType eq 'text/css') {
$session->output->print("\n/* Page generated in $t seconds. */\n");
}
elsif ($mimeType eq 'text/html') {
$session->output->print("\nPage generated in $t seconds.\n");
}
else {
# Don't apply to content when we don't know how
# to modify it semi-safely.
}
}
}
else {
my $asset = getAsset($session, getRequestedAssetUrl($session));
# display from cache if page hasn't been modified.
if ($var->get("userId") eq "1" && defined $asset && !$http->ifModifiedSince($asset->getContentLastModified)) {
$http->setStatus("304","Content Not Modified");
$http->sendHeader;
$session->close;
return Apache2::Const::OK;
}
# return the page.
else {
$output = page($session, undef, $asset);
}
}
my $filename = $http->getStreamedFile();
if ((defined $filename) && ($config->get("enableStreamingUploads") eq "1")) {
my $ct = guess_media_type($filename);
my $oldContentType = $request->content_type($ct);
if ($request->sendfile($filename) ) {
$session->close;
return Apache2::Const::OK;
} else {
$request->content_type($oldContentType);
}
}
$http->sendHeader(); #http object will only send the header once per request, so if the above sent a header as part of it's operation, this will do nothing.
unless ($http->isRedirect()) {
$session->output->print($output);
if ($errorHandler->canShowDebug()) {
$session->output->print($errorHandler->showDebug(),1);
}
}
# ...
return $output;
}
#-------------------------------------------------------------------
=head2 page ( session , [ assetUrl ] )
Processes operations (if any), then tries the requested method on the asset corresponding to the requested URL. If that asset fails to be created, it tries the default page.
=head3 session
The current WebGUI::Session object.
=head3 assetUrl
Optionally pass in a URL to be loaded.
=cut
sub page {
my $session = shift;
my $assetUrl = getRequestedAssetUrl($session, shift);
my $asset = shift || getAsset($session, $assetUrl);
my $output = undef;
if (defined $asset) {
my $method = "view";
if ($session->form->param("func")) {
$method = $session->form->param("func");
unless ($method =~ /^[A-Za-z0-9]+$/) {
$session->errorHandler->security("to call a non-existent method $method on $assetUrl");
$method = "view";
}
}
$output = tryAssetMethod($session,$asset,$method);
$output = tryAssetMethod($session,$asset,"view") unless ($output || ($method eq "view"));
}
if ($output eq "") {
if ($session->var->isAdminOn) { # they're expecting it to be there, so let's help them add it
my $asset = WebGUI::Asset->newByUrl($session, $session->url->getRefererUrl) || WebGUI::Asset->getDefault($session);
$output = $asset->addMissing($assetUrl);
} else { # not in admin mode, so can't create it, so display not found
$session->http->setStatus("404","Page Not Found");
my $notFound = WebGUI::Asset->getNotFound($session);
if (defined $notFound) {
$output = tryAssetMethod($session,$notFound,'view');
} else {
$session->errorHandler->error("The notFound page could not be instanciated!");
$output = "An error was encountered while processing your request.";
}
$output = "An error was encountered while processing your request." if $output eq '';
}
}
if ($output eq "chunked") {
$output = undef;
}
return $output;
}
#-------------------------------------------------------------------
=head2 tryAssetMethod ( session )
Tries an asset method on the requested asset. Tries the "view" method if that method fails.
=head3 session
The current WebGUI::Session object.
=cut
sub tryAssetMethod {
my $session = shift;
my $asset = shift;
my $method = shift;
my $state = $asset->get("state");
return if ($state ne "published" && $state ne "archived" && !$session->var->isAdminOn); # can't interact with an asset if it's not published
$session->asset($asset);
my $methodToTry = "www_".$method;
my $output = eval{$asset->$methodToTry()};
if ($@) {
$session->errorHandler->warn("Couldn't call method ".$method." on asset for url: ".$session->url->getRequestedUrl." Root cause: ".$@);
if ($method ne "view") {
$output = tryAssetMethod($session,$asset,'view');
} else {
# fatals return chunked
$output = 'chunked';
}
}
return $output;
}
1;

View file

@ -0,0 +1,64 @@
package WebGUI::Content::Maintenance;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2007 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
=head1 NAME
Package WebGUI::Content::Maintenance;
=head1 DESCRIPTION
A content handler that does whatever I tell it to do.
=head1 SYNOPSIS
use WebGUI::Content::Maintenance;
my $output = WebGUI::Content::Maintenance::handler($session);
=head1 SUBROUTINES
These subroutines are available from this package:
=cut
#-------------------------------------------------------------------
=head2 handler ( session )
The content handler for this package.
=cut
sub handler {
my $session = shift;
if ($session->setting->get("specialState") eq "upgrading") {
$session->http->sendHeader;
my $output = "";
open(my $FILE,"<",$session->config->getWebguiRoot."/docs/maintenance.html");
while (<$FILE>) {
$output .= $_;
}
close($FILE);
return $output;
}
return;
}
1;

View file

@ -0,0 +1,58 @@
package WebGUI::Content::Operation;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2007 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
use WebGUI::Operation;
=head1 NAME
Package WebGUI::Content::Operation
=head1 DESCRIPTION
A content handler that handles operations.
=head1 SYNOPSIS
use WebGUI::Content::Operation;
my $output = WebGUI::Content::Operation::handler($session);
=head1 SUBROUTINES
These subroutines are available from this package:
=cut
#-------------------------------------------------------------------
=head2 handler ( session )
The content handler for this package.
=cut
sub handler {
my ($session) = @_;
my $output = "";
my $op = $session->form->process("op");
if ($op) {
$output = WebGUI::Operation::execute($session,$op);
}
return $output;
}
1;

View file

@ -0,0 +1,59 @@
package WebGUI::Content::Prefetch;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2007 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
=head1 NAME
Package WebGUI::Content::Prefetch
=head1 DESCRIPTION
A content handler that prevents prefetching browsers.
=head1 SYNOPSIS
use WebGUI::Content::Prefetch;
my $output = WebGUI::Content::Prefetch::handler($session);
=head1 SUBROUTINES
These subroutines are available from this package:
=cut
#-------------------------------------------------------------------
=head2 handler ( session )
The content handler for this package.
=cut
sub handler {
my ($session) = @_;
if ($session->env->get("HTTP_X_MOZ") eq "prefetch") { # browser prefetch is a bad thing
my $http = $session->http;
$http->setStatus("403","We don't allow prefetch, because it increases bandwidth, hurts stats, and can break web sites.");
$http->sendHeader;
return "none";
}
return;
}
1;

View file

@ -1,4 +1,4 @@
package WebGUI::Setup;
package WebGUI::Content::Setup;
=head1 LEGAL
@ -34,7 +34,7 @@ Initializes a new WebGUI install.
=head1 SYNOPSIS
use WebGUI::Setup;
WebGUI::Setup::setup();
WebGUI::Content::Setup::handler();
=head1 SUBROUTINES
@ -99,9 +99,9 @@ sub addPage {
#-------------------------------------------------------------------
=head2 setup ( session )
=head2 handler ( session )
Handles a specialState: "setup"
Handles a specialState: "init"
=head3 session
@ -109,8 +109,11 @@ The current WebGUI::Session object.
=cut
sub setup {
sub handler {
my $session = shift;
unless ($session->setting->get("specialState") eq "init") {
return;
}
$session->http->setCacheControl("none");
my $i18n = WebGUI::International->new($session, "WebGUI");
my ($output,$legend) = "";
@ -227,7 +230,7 @@ a:visited { color: '.$form->get("visitedLinkColor").'; }
#mainBodyContentContainer { padding: 5px; margin-left: 200px; font-family: serif, times new roman; font-size: 12pt; }
#pageFooterContainer { text-align: center; background-color: '.$form->get("footerBackgroundColor").'; color: '.$form->get("footerTextColor").'; }
#copyrightContainer { font-size: 8pt; }
#pageWidthContainer { width: 80%; margin-left: auto; margin-right: auto; font-family: sans-serif, helvetica, arial; border: 3px solid black; }
#pageWidthContainer { margin-left: 10%; margin-right: 10%; font-family: sans-serif, helvetica, arial; border: 3px solid black; }
';
my $css = addAsset($importNode, {
title => "my-style.css",
@ -557,6 +560,7 @@ return props[propName];
<img src="'.$session->url->extras('background.jpg').'" style="border-style:none;position: absolute; top: 0; left: 0; width: 100%; height: 1000px; z-index: 1;" />
</body> </html>';
$session->http->setMimeType("text/html");
$session->http->sendHeader;
return $page;
}

View file

@ -0,0 +1,63 @@
package WebGUI::Content::Upgrading;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2007 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
=head1 NAME
Package WebGUI::Content::Upgrading
=head1 DESCRIPTION
A content handler that displays a maintenance page when in a special upgrade state.
=head1 SYNOPSIS
use WebGUI::Content::Upgrading;
my $output = WebGUI::Content::Upgrading::handler($session);
=head1 SUBROUTINES
These subroutines are available from this package:
=cut
#-------------------------------------------------------------------
=head2 handler ( session )
The content handler for this package.
=cut
sub handler {
my ($session) = @_;
if ($session->setting->get("specialState") eq "upgrading") {
my $output = "";
$session->http->sendHeader;
open(my $FILE,"<",$session->config->getWebguiRoot."/docs/maintenance.html");
while (<$FILE>) {
$session->output->print($_);
}
close($FILE);
return "none";
}
return;
}
1;

View file

@ -0,0 +1,55 @@
package WebGUI::Content::MyHandler;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2007 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
=head1 NAME
Package WebGUI::Content::MyHandler
=head1 DESCRIPTION
A content handler that does whatever I tell it to do.
=head1 SYNOPSIS
use WebGUI::Content::MyHandler;
my $output = WebGUI::Content::MyHandler::handler($session);
=head1 SUBROUTINES
These subroutines are available from this package:
=cut
#-------------------------------------------------------------------
=head2 handler ( session )
The content handler for this package.
=cut
sub handler {
my ($session) = @_;
my $output = "";
# ...
return $output;
}
1;

82
lib/WebGUI/URL/Content.pm Normal file
View file

@ -0,0 +1,82 @@
package WebGUI::URL::Content;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2007 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
use Apache2::Const -compile => qw(OK DECLINED);
use WebGUI::Affiliate;
use WebGUI::Session;
=head1 NAME
Package WebGUI::URL::Content
=head1 DESCRIPTION
A URL handler that does whatever I tell it to do.
=head1 SYNOPSIS
use WebGUI::URL::Content;
my $status = WebGUI::URL::Content::handler($r, $s, $config);
=head1 SUBROUTINES
These subroutines are available from this package:
=cut
#-------------------------------------------------------------------
=head2 handler ( request, server, config )
The Apache request handler for this package.
=cut
sub handler {
my ($request, $server, $config) = @_;
$request->push_handlers(PerlResponseHandler => sub {
my $session = WebGUI::Session->open($server->dir_config('WebguiRoot'), $config->getFilename, $request, $server);
foreach my $handler (@{$config->get("contentHandlers")}) {
my $handlerPath = $handler.".pm";
$handlerPath =~ s{::}{/}g;
eval { require $handlerPath };
if ( $@ ) {
$session->errorHandler->error("Couldn't load content handler $handler.");
}
else {
my $command = $handler."::handler";
no strict qw(refs);
my $output = &$command($session);
use strict;
if ($output) {
unless ($output eq "none" || $output eq "redirect") {
$session->output->print($output);
}
last;
}
}
}
WebGUI::Affiliate::grabReferral($session); # process affiliate tracking request
$session->close;
return Apache2::Const::OK;
});
$request->push_handlers(PerlTransHandler => sub { return Apache2::Const::OK });
return Apache2::Const::DECLINED;
}
1;

66
lib/WebGUI/URL/Credits.pm Normal file
View file

@ -0,0 +1,66 @@
package WebGUI::URL::Credits;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2007 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
use Apache2::Const -compile => qw(OK DECLINED);
use WebGUI::Session;
=head1 NAME
Package WebGUI::URL::Credits
=head1 DESCRIPTION
A URL handler that displays the credits file.
=head1 SYNOPSIS
use WebGUI::URL::Credits;
my $status = WebGUI::URL::Credits::handler($r, $s, $config);
=head1 SUBROUTINES
These subroutines are available from this package:
=cut
#-------------------------------------------------------------------
=head2 handler ( request, server, config )
The Apache request handler for this package.
=cut
sub handler {
my ($request, $server, $config) = @_;
$request->push_handlers(PerlResponseHandler => sub {
my $content = "";
open(my $FILE, "<", $config->getWebguiRoot."/docs/credits.txt");
while (my $line = <$FILE>) {
$content .= $line;
}
close($FILE);
print $content;
return Apache2::Const::OK;
} );
$request->push_handlers(PerlTransHandler => sub { return Apache2::Const::OK });
return Apache2::Const::DECLINED;
}
1;

View file

@ -0,0 +1,59 @@
package WebGUI::URL::PassThru;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2007 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
use Apache2::Const -compile => qw(OK DECLINED DIR_MAGIC_TYPE);
=head1 NAME
Package WebGUI::URL::PassThru
=head1 DESCRIPTION
A URL handler that just passes the URLs back to Apache.
=head1 SYNOPSIS
use WebGUI::URL::PassThru;
my $status = WebGUI::URL::PassThru::handler($r, $s, $config);
=head1 SUBROUTINES
These subroutines are available from this package:
=cut
#-------------------------------------------------------------------
=head2 handler ( request, server, config )
=cut
sub handler {
my ($request, $server, $config) = @_;
if ($request->handler eq 'perl-script' && # Handler is Perl
-d $request->filename && # Filename requested is a directory
$request->is_initial_req) # and this is the initial request
{
$request->handler(Apache2::Const::DIR_MAGIC_TYPE); # Hand off to mod_dir
return Apache2::Const::OK;
}
return Apache2::Const::DECLINED;
}
1;

61
lib/WebGUI/URL/Snoop.pm Normal file
View file

@ -0,0 +1,61 @@
package WebGUI::URL::Snoop;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2007 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
use Apache2::Const -compile => qw(OK DECLINED);
use WebGUI::Session;
=head1 NAME
Package WebGUI::URL::Snoop
=head1 DESCRIPTION
A URL handler that should never be called.
=head1 SYNOPSIS
use WebGUI::URL::Snoop;
my $status = WebGUI::URL::Snoop::handler($r, $configFile);
=head1 SUBROUTINES
These subroutines are available from this package:
=cut
#-------------------------------------------------------------------
=head2 handler ( request, configFile )
The Apache request handler for this package.
=cut
sub handler {
my ($request, $server, $config) = @_;
$request->content_type("text/html");
$request->push_handlers(PerlResponseHandler => sub {
print q|<html><head><title>Snoopy</title></head><body><div style="width: 600px; padding: 200px;">&#87;&#104;&#121;&#32;&#119;&#111;&#117;&#108;&#100;&#32;&#121;&#111;&#117;&#32;&#116;&#121;&#112;&#101;&#32;&#105;&#110;&#32;&#116;&#104;&#105;&#115;&#32;&#85;&#82;&#76;&#63;&#32;&#82;&#101;&#97;&#108;&#108;&#121;&#46;&#32;&#87;&#104;&#97;&#116;&#32;&#119;&#101;&#114;&#101;&#32;&#121;&#111;&#117;&#32;&#101;&#120;&#112;&#101;&#99;&#116;&#105;&#110;&#103;&#32;&#116;&#111;&#32;&#115;&#101;&#101;&#32;&#104;&#101;&#114;&#101;&#63;&#32;&#89;&#111;&#117;&#32;&#114;&#101;&#97;&#108;&#108;&#121;&#32;&#110;&#101;&#101;&#100;&#32;&#116;&#111;&#32;&#103;&#101;&#116;&#32;&#97;&#32;&#108;&#105;&#102;&#101;&#46;&#32;&#65;&#114;&#101;&#32;&#121;&#111;&#117;&#32;&#115;&#116;&#105;&#108;&#108;&#32;&#104;&#101;&#114;&#101;&#63;&#32;&#83;&#101;&#114;&#105;&#111;&#117;&#115;&#108;&#121;&#44;&#32;&#121;&#111;&#117;&#32;&#110;&#101;&#101;&#100;&#32;&#116;&#111;&#32;&#103;&#111;&#32;&#100;&#111;&#32;&#115;&#111;&#109;&#101;&#116;&#104;&#105;&#110;&#103;&#32;&#101;&#108;&#115;&#101;&#46;&#32;&#73;&#32;&#116;&#104;&#105;&#110;&#107;&#32;&#121;&#111;&#117;&#114;&#32;&#98;&#111;&#115;&#115;&#32;&#105;&#115;&#32;&#99;&#97;&#108;&#108;&#105;&#110;&#103;&#46;</div></body></html>|;
return Apache2::Const::OK;
} );
$request->push_handlers(PerlTransHandler => sub { return Apache2::Const::OK });
return Apache2::Const::DECLINED;
}
1;

View file

@ -0,0 +1,54 @@
package WebGUI::URL::Unauthorized;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2007 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
use Apache2::Const -compile => qw(AUTH_REQUIRED);
=head1 NAME
Package WebGUI::URL::Unauthorized
=head1 DESCRIPTION
A URL handler that deals with requests where the user cannot access what they requested.
=head1 SYNOPSIS
use WebGUI::URL::Unauthorized;
my $status = WebGUI::URL::Unauthorized::handler($r, $s, $config);
=head1 SUBROUTINES
These subroutines are available from this package:
=cut
#-------------------------------------------------------------------
=head2 handler ( request, server, config )
The Apache request handler for this package.
=cut
sub handler {
my ($request, $server, $config) = @_;
return Apache2::Const::AUTH_REQUIRED;
}
1;

85
lib/WebGUI/URL/Uploads.pm Normal file
View file

@ -0,0 +1,85 @@
package WebGUI::URL::Uploads;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2007 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
use Apache2::Const -compile => qw(OK DECLINED NOT_FOUND AUTH_REQUIRED);
use WebGUI::Session;
=head1 NAME
Package WebGUI::URL::Uploads;
=head1 DESCRIPTION
A URL handler that handles privileges for uploaded files.
=head1 SYNOPSIS
use WebGUI::URL::Uploads;
my $status = WebGUI::URL::Uploads::handler($r, $s, $config);
=head1 SUBROUTINES
These subroutines are available from this package:
=cut
#-------------------------------------------------------------------
=head2 handler ( request, server, config )
The Apache request handler for this package.
=cut
sub handler {
my ($request, $server, $config) = @_;
$request->push_handlers(PerlAccessHandler => sub {
if (-e $request->filename) {
my $path = $request->filename;
$path =~ s/^(\/.*\/).*$/$1/;
if (-e $path.".wgaccess") {
my $fileContents;
open(my $FILE, "<" ,$path.".wgaccess");
while (my $line = <$FILE>) {
$fileContents .= $line;
}
close($FILE);
my @privs = split("\n", $fileContents);
unless ($privs[1] eq "7" || $privs[1] eq "1") {
my $session = WebGUI::Session->open($server->dir_config('WebguiRoot'), $config->getFilename, $request, $server);
my $hasPrivs = ($session->var->get("userId") eq $privs[0] || $session->user->isInGroup($privs[1]) || $session->user->isInGroup($privs[2]));
$session->close();
if ($hasPrivs) {
return Apache2::Const::OK;
}
else {
return Apache2::Const::AUTH_REQUIRED;
}
}
}
return Apache2::Const::OK;
}
else {
return Apache2::Const::NOT_FOUND;
}
} );
return Apache2::Const::DECLINED;
}
1;

View file

@ -0,0 +1,55 @@
package WebGUI::URL::MyHandler;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2007 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
use Apache2::Const -compile => qw(OK DECLINED NOT_FOUND DIR_MAGIC_TYPE);
=head1 NAME
Package WebGUI::URL::MyHandler
=head1 DESCRIPTION
A URL handler that does whatever I tell it to do.
=head1 SYNOPSIS
use WebGUI::URL::MyHandler;
my $status = WebGUI::URL::MyHandler::handler($r, $configFile);
=head1 SUBROUTINES
These subroutines are available from this package:
=cut
#-------------------------------------------------------------------
=head2 handler ( request, server, config )
The Apache request handler for this package.
=cut
sub handler {
my ($request, $server, $config) = @_;
# ...
return Apache2::Const::DECLINED;
}
1;