diff --git a/etc/dev.localhost.localdomain.psgi b/etc/dev.localhost.localdomain.psgi index 4591416da..febb7bdbd 100644 --- a/etc/dev.localhost.localdomain.psgi +++ b/etc/dev.localhost.localdomain.psgi @@ -1,8 +1,9 @@ BEGIN { + # This is just a temporary hack - our $WEBGUI_ROOT = '/data/WebGUI'; + our $WEBGUI_ROOT = '/data/WebGUI'; our $WEBGUI_DOMAINS = '/data/domains'; - our $WEBGUI_CONFIG = 'dev.localhost.localdomain'; + our $WEBGUI_CONFIG = 'dev.localhost.localdomain'; } use local::lib $WEBGUI_ROOT; use WebGUI; @@ -11,26 +12,30 @@ use Plack::Builder; my $app = sub { my $env = shift; - $env->{'wg.WEBGUI_ROOT'} = $WEBGUI_ROOT; - $env->{'wg.WEBGUI_CONFIG'} = "$WEBGUI_CONFIG.conf"; - $env->{'wg.DIR_CONFIG.WebguiRoot'} = $env->{'wg.WEBGUI_ROOT'}; + $env->{'wg.WEBGUI_ROOT'} = $WEBGUI_ROOT; + $env->{'wg.WEBGUI_CONFIG'} = "$WEBGUI_CONFIG.conf"; + $env->{'wg.DIR_CONFIG.WebguiRoot'} = $env->{'wg.WEBGUI_ROOT'}; $env->{'wg.DIR_CONFIG.WebguiConfig'} = $env->{'wg.WEBGUI_CONFIG'}; WebGUI::handle_psgi($env); }; # Apply some Middleware builder { + # /extras - enable Plack::Middleware::Static - path => qr{^/extras/}, root => "$WEBGUI_ROOT/www/"; - + enable Plack::Middleware::Static + path => qr{^/extras/}, + root => "$WEBGUI_ROOT/www/"; + # /uploads (ignore .wgaccess for now..) - enable Plack::Middleware::Static - path => qr{^/uploads/}, root => "$WEBGUI_DOMAINS/dev.localhost.localdomain/public/"; - + enable Plack::Middleware::Static + path => qr{^/uploads/}, + root => "$WEBGUI_DOMAINS/dev.localhost.localdomain/public/"; + enable Plack::Middleware::XFramework framework => 'WebGUI'; - - enable Plack::Middleware::AccessLog format => "combined"; - + + # Already enabled by plackup script + # enable Plack::Middleware::AccessLog format => "combined"; + $app; -} \ No newline at end of file +} diff --git a/lib/WebGUI.pm b/lib/WebGUI.pm index b39615f43..f60f377de 100644 --- a/lib/WebGUI.pm +++ b/lib/WebGUI.pm @@ -78,8 +78,13 @@ A reference to a WebGUI::Config object. One will be created if it isn't specifie sub authen { my ($request, $username, $password, $config) = @_; - $request = Apache2::Request->new($request); - my $server = Apache2::ServerUtil->server; + my $server; + if ($request->isa('WebGUI::Session::Plack')) { + $server = $request->server; + } else { + $request = Apache2::Request->new($request); + $server = Apache2::ServerUtil->server; #instantiate the server api + } my $status = Apache2::Const::OK; # set username and password if it's an auth handler @@ -173,15 +178,15 @@ sub handler { my $gotMatch = 0; # handle basic auth -# my $auth = $request->headers_in->{'Authorization'}; -# if ($auth =~ m/^Basic/) { # machine oriented -# # Get username and password from Apache and hand over to authen -# $auth =~ s/Basic //; -# authen($request, split(":", MIME::Base64::decode_base64($auth), 2), $config); -# } -# else { # realm oriented -# $request->push_handlers(PerlAuthenHandler => sub { return WebGUI::authen($request, undef, undef, $config)}); -# } + my $auth = $request->headers_in->{'Authorization'}; + if ($auth =~ m/^Basic/) { # machine oriented + # Get username and password from Apache and hand over to authen + $auth =~ s/Basic //; + authen($request, split(":", MIME::Base64::decode_base64($auth), 2), $config); + } + else { # realm oriented + $request->push_handlers(PerlAuthenHandler => sub { return WebGUI::authen($request, undef, undef, $config)}); + } # url handlers @@ -212,6 +217,8 @@ sub handler { return Apache2::Const::DECLINED; } + + sub handle_psgi { my $env = shift; require WebGUI::Session::Plack; diff --git a/lib/WebGUI/Session/Plack.pm b/lib/WebGUI/Session/Plack.pm index 2cd5906fc..0ef9a90c5 100644 --- a/lib/WebGUI/Session/Plack.pm +++ b/lib/WebGUI/Session/Plack.pm @@ -19,7 +19,7 @@ sub new { require Plack::Response; my $request = Plack::Request->new( $p{env} ); - my $response = $request->new_response; + my $response = $request->new_response(200); my $self = bless { %p, @@ -59,10 +59,17 @@ sub protocol { shift->request->protocol(@_) } sub status { shift->response->status(@_) } sub status_line {} +sub auth_type { + # should we support this? +} + # TODO: I suppose this should do some sort of IO::Handle thing my @body; sub print { shift; push @body, @_ } +my $sendfile; +sub sendfile { shift; $sendfile = shift; } + sub dir_config { my $self = shift; my $c = shift; @@ -100,7 +107,11 @@ sub push_handlers { sub finalize { my $self = shift; - $self->response->body(\@body); + if ($sendfile && open my $fh, '<', $sendfile) { + $self->response->body( $fh ); + } else { + $self->response->body( $sendfile || \@body); + } return $self->response->finalize; }