Apache-OWA
view release on metacpan or search on metacpan
package Apache::OWA;
use strict;
use Apache::DBI;
use DBI;
use Apache::Constants qw(OK NOT_FOUND SERVER_ERROR AUTH_REQUIRED);
use Apache::Request ();
use Data::Dumper;
use vars qw($VERSION %owa_mapping %owa_version);
my $DEBUG = 0;
$VERSION = '0.7';
my (@dbinfo, $sth, $sql, $r, $dbh, @pass_vars);
# i like to buffer and then flush... YMMV.
#local $| = 1;
###################################################################
sub auth_handler ($) {
$r = Apache::Request->new( shift );
($DEBUG) = $r->dir_config('DEBUG');
$r->warn('Apache::OWA::auth_handler start.') if ($DEBUG > 1);
my ($sent_pw, $user, $db);
# get username & password
(my $res, $sent_pw) = $r->get_basic_auth_pw;
return $res if $res != OK;
$user = $r->connection->user;
# need both username & password
unless ( $user && $sent_pw) {
$r->note_basic_auth_failure;
$r->warn('Apache::OWA::auth_handler exit(AUTH_REQUIRED)') if ($DEBUG > 1);
return AUTH_REQUIRED;
}
# get configuration
if ($r->dir_config('DB_AUTH')) {
$r->dir_config('DB') ?
$db = $r->dir_config('DB') :
$db = $ENV{'ORACLE_SID'};
@dbinfo = ($db,$user,$sent_pw);
}
elsif ( $r->dir_config('DB_PROC_AUTH') ) {
@dbinfo = split(/:/,$r->dir_config('DAD'));
}
# don't authenticate sub-requests
if ( $r->is_main() ) {
if ( $r->dir_config('DB_AUTH') ) {
$dbh = DBI->connect("dbi:Oracle:$dbinfo[0]",$dbinfo[1],$dbinfo[2],
{ PrintError => 0, RaiseError => 0, AutoCommit => 1 })
|| return AUTH_REQUIRED;
}
elsif ( $r->dir_config('DB_PROC_AUTH') ) {
my ( $proc ) = $r->dir_config('DB_PROC_AUTH');
$dbh = DBI->connect("dbi:Oracle:$dbinfo[0]",$dbinfo[1],$dbinfo[2],
{ PrintError => 0, RaiseError => 0, AutoCommit => 1 })
|| return SERVER_ERROR;
my $rv;
$sql = 'begin :rv := $proc (:user, :pw); end;';
$sth = $dbh->prepare($sql);
#$sth = $dbh->prepare_cached($sql);
$sth->bind_param(':user', $user);
$sth->bind_param(':pw', $sent_pw);
$sth->bind_param_inout(':rv', \$rv, 2);
$sth->execute || return SERVER_ERROR ;
$sth->finish;
$dbh->disconnect;
return AUTH_REQUIRED if $rv != 0;
}
# support for owa.auth_scheme and owa.protection_realm
# would pobably go here if i didn't think they were stupid...
}
# pass handling to the content handler
$r->handler('perl-script');
$r->push_handlers(PerlHandler=>\&handler );
$r->warn('Apache::OWA::auth_handler exit(OK)') if ($DEBUG > 1);
return OK;
}
#####################################################
#sub content_handler ($) {
sub handler ($) {
$r = Apache::Request->new( shift );
$Apache::OWA::owa_version{$_}/256,
'(', $Apache::OWA::owa_version{$_}, ')',
'</td></tr>';
}
push @strings, '</table>';
}
return \@strings;
}
#################################################################
Apache::Status->menu_item('OWA' => 'OWA info',\&owa_status_info) if Apache->module('Apache::Status');
1;
__END__
=head1 NAME
Apache::OWA - Run OWA applications under Apache/mod_perl
=head1 SYNOPSIS
Runs Oracle PL/SQL apllications written using Oracle's PL/SQL Web Toolkit under Apache/mod_perl.
=head1 REQUIREMENTS
DBI, DBD::Oracle, Apache::DBI, Apache::Request (libapreq), Oracle PL/SQL Web Toolkit (any version should work)
=head1 DESCRIPTION
Example configuration.
<Location /scott/>
SetHandler perl-script
PerlHandler Apache::OWA;
PerlSetVar DAD oracle:scott:tiger
</Location>
This configuration means that calling "http://server/scott/print_cgi_env" executes the
pl/sql procedure "scott.print_cgi_env".
Other configuration options:
PerlSetVar SCHEMA oas_public
This lets you execute procedures under a different schema (user)
than the ones specified in the DAD-string.
PerlSetVar DEBUG 1
0 - No debugging. This is the default.
1 - Light debugging and verbose errors sent to the browser.
Useful while developing procedures.
2 - Heavy debugging of Apache::OWA inetrnal stuff.
PerlAuthenHandler Apache::OWA
This invokes my special authentication handler that can do a few clever
things. Then it passes control on to the content-handler, so if you
use this you don't need to specify "PerlHandler Apache::OWA". It
might also be useful in combination with "PerlSetVar SCHEMA".
PerlSetVar DB_AUTH true
Uses database uername and password to authenticate. If no DAD-string
is set, it can also use the supplied username and password to execute
your PL/SQL application.
PerlSetVar DB_PROC_AUTH schema.function
Uses an arbitrary PL/SQL procedure or function to authenticate.
The procedure should take the username and password as arguments
and return 0 for success and more than 0 for failure.
PerlSetVar NEVER_USE_WEIRD_TYPES 1
Only set this if you know that you never use multi-value CGI variables
that need to be mapped to PL/SQL Table datatypes. Finding these datatypes
is some extra work and will slow down executions a little bit.
For further documentation see the README.
=head1 AUTHOR
Svante Sormark, svinto@ita.chalmers.se.
Latest version available from http://www.ita.chalmers.se/~svinto/apache
Contibutions from:
Slava Kalashnikov <slava@intes.odessa.ua>
Gunnar Hellekson <g.hellekson@trilux.com> and
Erich Morisse <e.morisse@trilux.com> of Trilux Internet Group, Ltd.
=head1 COPYRIGHT
The Apache::OWS module is free software; you can redistribute it and/or
modify it under the same terms as Perl or Apache.
=head1 SEE ALSO
L<Apache>, L<mod_perl>, L<DBI>, L<DBD::Oracle>, L<Apache::DBI>
=cut
( run in 0.585 second using v1.01-cache-2.11-cpan-2398b32b56e )