Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'plebgui' into plebgui-7.10
Conflicts: lib/WebGUI.pm
- Loading branch information
Showing
12 changed files
with
468 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<VirtualHost *:80> | ||
PerlOptions +Parent | ||
PerlSwitches -I/data/WebGUI/lib | ||
|
||
# CGI | ||
#AddHandler cgi-script cgi | ||
#ScriptAlias / /data/WebGUI/etc/dev.localhost.localdomain.cgi/ | ||
#<Directory /data/WebGUI/etc> | ||
# Options +ExecCGI | ||
#</Directory> | ||
|
||
# Apache2 | ||
#SetHandler perl-script | ||
#PerlHandler Plack::Server::Apache2 | ||
#PerlSetVar psgi_app /data/WebGUI/etc/dev.localhost.localdomain.psgi | ||
|
||
# FastCGI | ||
FastCgiServer /data/WebGUI/etc/dev.localhost.localdomain.fcgi | ||
ScriptAlias / /data/WebGUI/etc/dev.localhost.localdomain.fcgi/ | ||
|
||
# mod_psgi | ||
#<Location /> | ||
# SetHandler psgi | ||
# PSGIApp /data/WebGUI/etc/dev.localhost.localdomain.psgi | ||
#</Location> | ||
|
||
</VirtualHost> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/perl | ||
use Plack::Server::CGI; | ||
|
||
my $app = Plack::Util::load_psgi("/data/WebGUI/etc/dev.localhost.localdomain.psgi"); | ||
Plack::Server::CGI->new->run($app); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/perl | ||
use Plack::Server::FCGI; | ||
|
||
my $app = Plack::Util::load_psgi("/data/WebGUI/etc/dev.localhost.localdomain.psgi"); | ||
Plack::Server::FCGI->new->run($app); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
LOAD PSGI | ||
CREATE SERVICE psgi | ||
SET role = web_server | ||
SET listen = 127.0.0.1:80 | ||
SET plugins = psgi | ||
PSGI_APP = dev.localhost.localdomain.psgi | ||
ENABLE psgi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use Plack::Builder; | ||
use lib '/data/WebGUI/lib'; | ||
use WebGUI; | ||
WebGUI->init( root => '/data/WebGUI', config => 'dev.localhost.localdomain.conf' ); | ||
|
||
builder { | ||
|
||
# Handle /extras via Plack::Middleware::Static | ||
# (or Plack::Middleware::WebGUI could do this for us by looking up extrasPath and extrasURL in site.conf) | ||
enable 'Plack::Middleware::Static', | ||
path => qr{^/extras/}, | ||
root => '/data/WebGUI/www'; | ||
|
||
# Handle /uploads via Plack::Middleware::WGAccess (including .wgaccess) | ||
# (or Plack::Middleware::WebGUI could do this for us by looking up uploadsPath and uploadsURL in site.conf) | ||
#enable 'Plack::Middleware::WGAccess', | ||
# path => qr{^/uploads/}, | ||
# root => '/data/domains/dev.localhost.localdomain/public'; | ||
|
||
enable 'Plack::Middleware::Static', | ||
path => qr{^/uploads/}, | ||
root => '/data/domains/dev.localhost.localdomain/public'; | ||
|
||
sub { WebGUI::handle_psgi(shift) }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package Plack::Middleware::WGAccess; | ||
use strict; | ||
use warnings; | ||
use base qw/Plack::Middleware::Static/; | ||
use Path::Class 'dir'; | ||
|
||
=head1 NAME | ||
Plack::Middleware::WGAccess | ||
=head1 DESCRIPTION | ||
Plack Middleware that delivers static files with .wgaccess awareness | ||
=cut | ||
|
||
sub _handle_static { | ||
my($self, $env) = @_; | ||
|
||
####################################### | ||
# Copied from Plack::Middleware::Static::_handle_static | ||
|
||
my $path_match = $self->path or return; | ||
|
||
if ($env->{PATH_INFO} =~ m!\.\.[/\\]!) { | ||
return $self->return_403; | ||
} | ||
|
||
my $path = do { | ||
my $matched; | ||
local $_ = $env->{PATH_INFO}; | ||
if (ref $path_match eq 'CODE') { | ||
$matched = $path_match->($_); | ||
} else { | ||
$matched = $_ =~ $path_match; | ||
} | ||
return unless $matched; | ||
$_; | ||
} or return; | ||
|
||
my $docroot = dir($self->root || "."); | ||
my $file = $docroot->file(File::Spec::Unix->splitpath($path)); | ||
my $realpath = Cwd::realpath($file->absolute->stringify); | ||
|
||
# Is the requested path within the root? | ||
if ($realpath && !$docroot->subsumes($realpath)) { | ||
return $self->return_403; | ||
} | ||
|
||
# Does the file actually exist? | ||
if (!$realpath || !-f $file) { | ||
return $self->return_404; | ||
} | ||
|
||
# If the requested file present but lacking the permission to read it? | ||
if (!-r $file) { | ||
return $self->return_403; | ||
} | ||
|
||
############################### | ||
# Copied from WebGUI::URL::Uploads | ||
my $wgaccess = File::Spec::Unix->catfile($file->dir, '.wgaccess'); | ||
if (-e $wgaccess) { | ||
my $fileContents; | ||
open(my $FILE, "<", $wgaccess); | ||
while (my $line = <$FILE>) { | ||
$fileContents .= $line; | ||
} | ||
close($FILE); | ||
my @privs = split("\n", $fileContents); | ||
unless ($privs[1] eq "7" || $privs[1] eq "1") { | ||
|
||
# Construct request,server,config in the usual way | ||
require WebGUI::Session::Plack; | ||
my $request = WebGUI::Session::Plack->new( env => $env ); | ||
my $server = $request->server; | ||
|
||
my $session = $request->pnotes('wgSession'); | ||
unless (defined $session) { | ||
$session = WebGUI::Session->open($server->dir_config('WebguiRoot'), $request->dir_config('WebguiConfig'), $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 $self->SUPER::_handle_static($env); # serve statically | ||
} | ||
else { | ||
return $self->return_403; | ||
} | ||
} | ||
} else { | ||
return $self->SUPER::_handle_static($env); # serve statically | ||
} | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package Plack::Middleware::WebGUI; | ||
use strict; | ||
use warnings; | ||
use base qw/Plack::Middleware/; | ||
|
||
__PACKAGE__->mk_accessors('root', 'config'); | ||
|
||
=head1 NAME | ||
Plack::Middleware::WebGUI | ||
=head1 DESCRIPTION | ||
Plack Middleware that populates $env | ||
=cut | ||
|
||
sub call { | ||
my $self = shift; | ||
my $env = shift; | ||
|
||
$env->{'wg.WEBGUI_ROOT'} = $self->root; | ||
$env->{'wg.WEBGUI_CONFIG'} = $self->config; | ||
|
||
$self->app->($env); | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.