URL handlers are now completely replaced by Middleware
This commit is contained in:
parent
9b4e67b828
commit
30a2c09a36
11 changed files with 53 additions and 414 deletions
|
|
@ -45,6 +45,7 @@ sub call {
|
|||
} catch {
|
||||
# We don't have a logger object, so for now just warn() the error
|
||||
warn "Unable to instantiate WebGUI::Session - $_";
|
||||
return; # make sure $session assignment is undef
|
||||
};
|
||||
|
||||
if ( !$session ) {
|
||||
|
|
@ -85,7 +86,11 @@ sub call {
|
|||
|
||||
# Close the Session
|
||||
$env->{'webgui.session'}->close();
|
||||
#memory_cycle_ok( $env->{'webgui.session'} );
|
||||
delete $env->{'webgui.session'};
|
||||
|
||||
#use Test::Memory::Cycle;
|
||||
#memory_cycle_ok( $env );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
34
lib/WebGUI/Middleware/Snoop.pm
Normal file
34
lib/WebGUI/Middleware/Snoop.pm
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package WebGUI::Middleware::Snoop;
|
||||
use strict;
|
||||
use parent qw(Plack::Middleware);
|
||||
|
||||
=head1 NAME
|
||||
|
||||
WebGUI::Middleware::Snoop - sample middleware port of WebGUI::URL::Snoop
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This is PSGI middleware for WebGUI.
|
||||
|
||||
It was ported from L<WebGUI::URL::Snoop>, back when we still had URL handlers.
|
||||
|
||||
L<WebGUI::URL::Snoop> described itself as "A URL handler that should never be called."
|
||||
|
||||
You might find this middleware useful as a template for creating other simple classes.
|
||||
|
||||
=cut
|
||||
|
||||
sub call {
|
||||
my $self = shift;
|
||||
my $env = shift;
|
||||
|
||||
my $path = $env->{PATH_INFO};
|
||||
if ($path =~ qr{^/abcdefghijklmnopqrstuvwxyz$}) {
|
||||
my $snoop = q|<html><head><title>Snoopy</title></head><body><div style="width: 600px; padding: 200px;">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.</div></body></html>|;
|
||||
return [ 200, [ 'Content-Type' => 'text/html' ], [ $snoop ] ];
|
||||
} else {
|
||||
return $self->app->($env);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
package WebGUI::URL::Credits;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2009 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 APR::Finfo ();
|
||||
use APR::Const -compile => qw(FINFO_NORM);
|
||||
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) = @_;
|
||||
my $filename = $config->getWebguiRoot."/docs/credits.txt";
|
||||
$request->push_handlers(PerlResponseHandler => sub {
|
||||
$request->content_type('text/plain');
|
||||
$request->sendfile($filename);
|
||||
return Apache2::Const::OK;
|
||||
});
|
||||
$request->push_handlers(PerlTransHandler => sub { return Apache2::Const::OK });
|
||||
$request->push_handlers(PerlMapToStorageHandler => sub { return Apache2::Const::OK });
|
||||
return Apache2::Const::OK;
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
package WebGUI::URL::PassThru;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2009 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::OK;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
package WebGUI::URL::Snoop;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2009 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 {
|
||||
$request->print(q|<html><head><title>Snoopy</title></head><body><div style="width: 600px; padding: 200px;">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.</div></body></html>|);
|
||||
return Apache2::Const::OK;
|
||||
} );
|
||||
$request->push_handlers(PerlTransHandler => sub { return Apache2::Const::OK });
|
||||
return Apache2::Const::OK;
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
package WebGUI::URL::Unauthorized;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2009 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;
|
||||
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
package WebGUI::URL::Uploads;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2009 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 = $request->pnotes('wgSession');
|
||||
unless (defined $session) {
|
||||
# $session = WebGUI::Session->open($server->dir_config('WebguiRoot'), $config->getFilename, $request);
|
||||
}
|
||||
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::OK;
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
package WebGUI::URL::MyHandler;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2009 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);
|
||||
|
||||
|
||||
=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::OK;
|
||||
}
|
||||
|
||||
1;
|
||||
#vim:ft=perl
|
||||
Loading…
Add table
Add a link
Reference in a new issue