Bio-Das-ProServer

 view release on metacpan or  search on metacpan

Build.PL  view on Meta::CPAN

					       'File::Spec'                   => '3.25',
					       'POSIX'                        => '1.08',
					       'CGI'                          => '3.29',
					       'Socket'                       => '1.77',
					       'POE'                          => '0.9999',
					       'POE::Filter::HTTPD'           => '1.2188',
					       'POE::Wheel::ReadWrite'        => '1.2199',
					       'POE::Wheel::SocketFactory'    => '1.2194',
					       'Getopt::Long'                 => '2.34',
					       'Sys::Hostname'                => '1.11',
					       'HTTP::Request'                => '1.40',
					       'HTTP::Response'               => '1.53',
					       'HTTP::Date'                   => '1.47',
					       'Compress::Zlib'               => '2.005',
					       'HTML::Entities'               => '1.27',
					       'Readonly'                     => '1.03',
					       'Config::IniFiles'             => '2.32',
					      },
				  recommends => {
						 'DBI'                            => '1.52',      # for database-backed SourceAdaptors
						 'LWP::UserAgent'                 => '2.033',     # Optional, for Transport::wgetz, Transport::martservice,

META.yml  view on Meta::CPAN

  Net::IP: 1.25
  XML::Writer: 0.612
requires:
  CGI: 3.29
  Compress::Zlib: 2.005
  Config::IniFiles: 2.32
  File::Spec: 3.25
  Getopt::Long: 2.34
  HTML::Entities: 1.27
  HTTP::Date: 1.47
  HTTP::Request: 1.40
  HTTP::Response: 1.53
  POE: 0.9999
  POE::Filter::HTTPD: 1.2188
  POE::Wheel::ReadWrite: 1.2199
  POE::Wheel::SocketFactory: 1.2194
  POSIX: 1.08
  Readonly: 1.03
  Socket: 1.77
  Sys::Hostname: 1.11
resources:

README  view on Meta::CPAN


Any missing dependencies will be reported during the build process. All are
available from CPAN (http://www.cpan.org).

CGI
Compress::Zlib
Config::IniFiles
File::Spec
Getopt::Long
HTML::Entities
HTTP::Request
HTTP::Response
HTTP::Date
POE
POE::Filter::HTTPD
POE::Wheel::ReadWrite
POE::Wheel::SocketFactory
POSIX
Socket
Sys::Hostname

eg/proserver.cgi  view on Meta::CPAN


  my ($cfgfile) = $ENV{'PROSERVER_CFG'} =~ m|([/_a-z\d\.\-]+)|mix;
  $cfgfile    ||= q();

  if($cfgfile ne $ENV{'PROSERVER_CFG'}) {
    croak "PROSERVER_CFG failed to detaint ($cfgfile)\n";
  }

  my $config   = Bio::Das::ProServer::Config->new({'inifile' => $cfgfile,});
  my $heap     = {'method' => 'cgi','self' => {'config' => $config,'logformat'=>$config->logformat()},};
  my $request  = HTTP::Request->new( 'GET', $ENV{'REQUEST_URI'}||q() );
  my $response = Bio::Das::ProServer::build_das_response($heap, $request);

  print $response->headers->as_string, "\n", $response->content();
  return;
}

lib/Bio/Das/ProServer.pm  view on Meta::CPAN

#
## no critic (ValuesAndExpressions::ProhibitMagicNumbers)
## no critic (Variables::RequireLocalizedPunctuationVars)
## no critic (ControlStructures::ProhibitCascadingIfElse)
#
package Bio::Das::ProServer;
use warnings;
use strict;
use Bio::Das::ProServer::Config;
use CGI qw(:cgi);
use HTTP::Request;
use HTTP::Response;
use Compress::Zlib;
use Getopt::Long;
use POE;                         # Base features.
use POE::Filter::HTTPD;          # For serving HTTP content.
use POE::Wheel::ReadWrite;       # For socket I/O.
use POE::Wheel::SocketFactory;   # For serving socket connections.
use POSIX qw(setsid strftime);
use File::Spec;
use Sys::Hostname;

lib/Bio/Das/ProServer.pm  view on Meta::CPAN

=head2 make_pidfile

=head2 remove_pidfile

=head2 log

=head1 DEPENDENCIES

Bio::Das::ProServer::Config
CGI :cgi
HTTP::Request
HTTP::Response
Compress::Zlib
Getopt::Long
POE
POE::Filter::HTTPD
POE::Wheel::ReadWrite
POE::Wheel::SocketFactory
POSIX setsid strftime
File::Spec
Sys::Hostname

lib/Bio/Das/ProServer/Authenticator.pm  view on Meta::CPAN

  my $auth = Bio::Das::ProServer::Authenticator::<impl>->new({
    'dsn'    => $, # source name
    'config' => $, # source config
    'debug'  => $, # debug flag
  });
  
  my $allow = $auth->authenticate({
    'socket'    => $, # handle
    'peer_addr' => $, # packed
    'peer_port' => $, # number
    'request'   => $, # HTTP::Request object
    'cgi'       => $, # CGI object
    'call'      => $, # DAS command
  });

=head1 DESCRIPTION

This is a stub class intended to be extended.

=head1 CONFIGURATION AND ENVIRONMENT

lib/Bio/Das/ProServer/Authenticator.pm  view on Meta::CPAN

    'config' => $, # source config
    'debug'  => $, # debug flag
  });

=head2 authenticate : Applies authentication to a request.

  my $allow = $oAuth->authenticate({
    'socket'    => $, # handle
    'peer_addr' => $, # packed
    'peer_port' => $, # number
    'request'   => $, # HTTP::Request object
    'cgi'       => $, # CGI object
    'call'      => $, # DAS command
  });
  
Authenticates a request by making use of various request data. If requests are
to be denied, the authentication operation should return an appropriate
HTTP::Response object. Otherwise nothing (undef) is returned.

This stub method denies all requests with a standard 403 (Forbidden) response.

lib/Bio/Das/ProServer/Authenticator/http.pm  view on Meta::CPAN

To authenticate a request:

  my $auth = Bio::Das::ProServer::Authenticator::http->new({
    'config' => {
                 'authurl'     => 'http://my.example.com/is_root?query=%token',
                },
  });
  
  my $allow = $auth->authenticate({
    'peer_addr' => $, # packed
    'request'   => $, # HTTP::Request object
    'cgi'       => $, # CGI object
    ...
  });
  
=head1 DESCRIPTION

Authenticates DAS requests by connecting to a remote authentication HTTP server.
An authentication token is parsed from the DAS request. By default this should
be in an 'Authorization' header, but the authenticator can be configured to look
in a cookie, CGI parameter or a header with a different name.

lib/Bio/Das/ProServer/Authenticator/http.pm  view on Meta::CPAN


=head1 SUBROUTINES/METHODS

=head2 authenticate : Applies authentication to a request.

  Requires: a hash reference containing details of the DAS request
  Returns:  either nothing (allow) or a HTTP::Response (deny)

  my $allow = $oAuth->authenticate({
    'peer_addr' => $, # packed
    'request'   => $, # HTTP::Request object
    'cgi'       => $, # CGI object
    ...
  });

  The method follows this procedure:
  1. Parse an authentication token from the DAS request (parse_token method).
  2. Check for cached results for this token.
  3. If not found, query the remote server.
  4. Store the response in the cache, unless it is a server error (500)
  4. If the response code is 200 allow the request, otherwise deny.

=head2 parse_token : Parses the DAS request to extract an authentication token

  Requires: a hash reference containing details of the DAS request
  Returns:  a string authentication token

  my $token = $oAuth->parse_token({
    'peer_addr' => $, # packed
    'request'   => $, # HTTP::Request object
    'cgi'       => $, # CGI object
    ...
  });

  Depending on configuration, the authentication token is extracted from:
  1. a named cookie
  2. a named CGI parameter
  3. a named request header
  4. the 'Authorization' request header (default)

lib/Bio/Das/ProServer/Authenticator/ip.pm  view on Meta::CPAN

To authenticate a request:

  my $auth = Bio::Das::ProServer::Authenticator::ip->new({
    'config' => {
                 'authallow' => $, # IP whitelist
                },
  });
  
  my $allow = $auth->authenticate({
    'peer_addr' => $, # packed
    'request'   => $, # HTTP::Request object
    ...
  });

Once authenticated the IP address is stored:

  if ($allow) {
    my $ip    = $auth->ip();
  }

To simply perform IP address authentication but not deny requests, configure the

lib/Bio/Das/ProServer/Authenticator/ip.pm  view on Meta::CPAN


=head1 SUBROUTINES/METHODS

=head2 authenticate : Applies authentication to a request.

  Requires: a hash reference containing details of the DAS request
  Returns:  either nothing (allow) or a HTTP::Response (deny)

  my $allow = $oAuth->authenticate({
    'peer_addr' => $, # packed (socket IP address)
    'request'   => $, # HTTP::Request object (for X-Forwarded-For header)
    ...
  });

=head2 ip : Gets the authenticated IP address

  my $sIp = $oAuth->ip();

=head2 init : Initialises the IP whitelist

=head1 DIAGNOSTICS

lib/Bio/Das/ProServer/SourceAdaptor/proxy.pm  view on Meta::CPAN

# Author:        dj3
# Maintainer:    $Author: zerojinx $
# Created:       2005-10-21
# Last Modified: $Date: 2010-11-02 11:37:11 +0000 (Tue, 02 Nov 2010) $
# Id:            $Id: proxy.pm 687 2010-11-02 11:37:11Z zerojinx $
# Source:        $Source: /nfs/team117/rmp/tmp/Bio-Das-ProServer/Bio-Das-ProServer/lib/Bio/Das/ProServer/SourceAdaptor/proxy.pm,v $
#
package Bio::Das::ProServer::SourceAdaptor::proxy;
use strict;
use warnings;
use HTTP::Request;
use LWP::UserAgent;
use Bio::Das::Lite;
use base qw(Bio::Das::ProServer::SourceAdaptor);

our $VERSION = do { my ($v) = (q$Revision: 687 $ =~ /\d+/mxsg); $v; };

sub capabilities {
  return {
	  features   => '1.0',
	  stylesheet => '1.0',
	 };
}

sub das_stylesheet {
  my $self = shift;
  return LWP::UserAgent->new->request(HTTP::Request->new('GET', $self->config->{sourcedsn}.'/stylesheet'))->content;
}

sub build_features {
  my ($self, $opts) = @_;
  my $seg   = $opts->{segment};
  my $start = $opts->{start};
  my $end   = $opts->{end};
  my $das   = Bio::Das::Lite->new($self->config->{sourcedsn});
  my @results;
  $das->features((exists $opts->{start})?"$seg:$start,$end":$seg,

lib/Bio/Das/ProServer/SourceAdaptor/proxy.pm  view on Meta::CPAN

=head2 das_stylesheet

=head2 build_features

=head1 DIAGNOSTICS

=head1 CONFIGURATION AND ENVIRONMENT

=head1 DEPENDENCIES

HTTP::Request
LWP::UserAgent
Bio::Das::Lite
Bio::Das::ProServer::SourceAdaptor

=head1 INCOMPATIBILITIES

=head1 BUGS AND LIMITATIONS

=head1 AUTHOR

t/32-auth-ip.t  view on Meta::CPAN

use strict;
use warnings;
use Test::More;
use Socket;
use HTTP::Request;

eval {
  require Net::IP;
};
if ($@) {
  plan skip_all => 'IP authentication requires Net::IP';
} else {
  plan tests => 15;
}

t/32-auth-ip.t  view on Meta::CPAN

               'authallow' => inet_ntoa(INADDR_LOOPBACK).';111.111.111.111-111.111.111.112 , 222.222/16 ;2.2.2.0 + 255',
              },
});

my $resp = $auth->authenticate({ 'peer_addr' => inet_aton('1.1.1.1') });
isa_ok($resp, 'HTTP::Response', 'socket IP authentication (deny)');

$resp = $auth->authenticate({ 'peer_addr' => INADDR_LOOPBACK });
ok(!$resp, 'socket IP authentication (allow)');

my $req = HTTP::Request->new();
$req->header('X-Forwarded-For' => '1.1.1.1');
$resp = $auth->authenticate({ 'request' => $req });
isa_ok($resp, 'HTTP::Response', 'header IP authentication (deny)');

$req->header('X-Forwarded-For' => inet_ntoa(INADDR_LOOPBACK));
$resp = $auth->authenticate({ 'request' => $req });
ok(!$resp, 'header IP authentication(allow)');

$req->header('X-Forwarded-For' => '111.111.111.100');
$resp = $auth->authenticate({ 'request' => $req });

t/33-auth-http.t  view on Meta::CPAN

  kill 3, $child_pid; wait;
}

my $server_err = 0;
$SIG{INT} = sub { $server_err = 1; };

if ($port) {
  pass("run test authentication server");

  # Parent process does the testing
  use HTTP::Request;

  for my $type (qw(cookie param header default)) {

    $auth = Bio::Das::ProServer::Authenticator::http->new({
							   config => {
								      authurl   => "http://127.0.0.1:$port?token=%token",
								      "auth$type" => 'key',
								     },
							  });

    for my $token (qw(allow deny)) {
      for my $attempt (qw(first cached)) {
        my $req = HTTP::Request->new('get',
                                     "http://my.example.com?key=$token",
                                     ['Cookie', "key=$token",
                                     'key', $token,
                                     'Authorization', $token]);
        my ($uri) = $req->uri() =~ m/\?(.*)/smx;
        my $resp = $auth->authenticate( {'request' => $req, 'cgi' => CGI->new($uri)} );
        ok( $token eq 'allow' ? !$resp : defined $resp && $resp->isa('HTTP::Response'), "$attempt $token $type authentication") || diag($resp);
      }
    }
  }



( run in 0.439 second using v1.01-cache-2.11-cpan-de7293f3b23 )