access log and the request object

2001-04-04 Thread Andrew Lau




Hi, 
 
I am currently developing a Perl based apache 
module and was wondering if such a functionality was available.  From 
within the module would it be possible to modify the request object so that the 
url that gets logged to the access.log is different from what the client 
actually requested?
 
For example, if a client requested /file which was 
redirected to this module could it modify either the request object or some 
apache internal so that it gets written in the access log as 
/file?session=1234567890abcdef  .
 
I apologize if this is readily available from some 
FAQ as i have been unable to find this information.  Thanks for your 
time.
 
Sincerely,
 
Andrew Lau
 
Andrew LauMassachusetts Institute of Technology 
2000[EMAIL PROTECTED]http://web.mit.edu/amlau/www


Re: access log and the request object

2001-04-04 Thread darren chamberlain

Andrew Lau ([EMAIL PROTECTED]) said something to this effect on
04/04/2001:
> I am currently developing a Perl based apache module and was
> wondering if such a functionality was available.  From within
> the module would it be possible to modify the request object so
> that the url that gets logged to the access.log is different
> from what the client actually requested?
> 
> For example, if a client requested /file which was redirected
> to this module could it modify either the request object or
> some apache internal so that it gets written in the access log
> as /file?session=1234567890abcdef  .
> 
> I apologize if this is readily available from some FAQ as i
> have been unable to find this information.  Thanks for your
> time.

This is untested, but I believe that mod_log_config logs, as part
of the %r CustomLog directive, r->the_request, which is the first
line of the request (i.e., "GET /file HTTP/1.0"). It might be
possible to do something like:

my @request = split / /, $r->the_request;
$request[1] = sprintf "%s?session=%s", $request[1], $r->param('session');
$r->the_request(join ' ', @request);

assuming that $r->the_request is not read-only.

Another option is to use CustomLog to log something other than
%r, like %{session}e to log an environment variable, or %q to log
the query string:

CustomLog "%h %l %u %t \"%m %U%q %H\" %>s %b"

%m is the method, %U is the requested url, %q is the query
%string (or '' if no query string), %H is the request protocol.

(darren)

-- 
Everybody wants to go to heaven, but nobody wants to die.



Re: access log and the request object

2001-04-04 Thread Mike Cameron



How about writing your own log handler
   PerlLogHandler My::LogModule
or in your code
$r->push_handler(PerlLogHandler    => \&MyLoghandler);
sub MyLoghandler{
  my $r=Apache::Request;
  code to log info to file
}
the push_handler method does not pass the request object to the subroutine.
Andrew Lau wrote:

Hi, I
am currently developing a Perl based apache module and was wondering if
such a functionality was available.  From within the module would
it be possible to modify the request object so that the url that gets logged
to the access.log is different from what the client actually requested? For
example, if a client requested /file which was redirected to this module
could it modify either the request object or some apache internal so that
it gets written in the access log as /file?session=1234567890abcdef 
. I apologize if this
is readily available from some FAQ as i have been unable to find this information. 
Thanks for your time. Sincerely, Andrew
Lau Andrew Lau
Massachusetts Institute of Technology
2000
[EMAIL PROTECTED]
http://web.mit.edu/amlau/www





Re: access log and the request object

2001-04-05 Thread test



I once used this: 
Is PerlCleanupHandler the same as LogHandler?
As far as I remember putting the code in the cleanup phase would mean
logging after finishing the request cycle with no delay for the client.
Is that true?
 




SetHandler  perl-script
PerlHandler Bankers::BedrijfswagensLijst
PerlCleanupHandler  Apache::LogDBI



package  Apache::LogDBI;

use Apache::Constants qw(:common);

use strict;
use DBI ();
use Apache::Util qw(ht_time);

use constant DSN=>  'dbi:mysql:koeweide';
use constant DB_TABLE   =>  'access_log';
use constant DB_AUTH=>  ':';

sub handler {
my $orig =shift;
my $r = $orig->last;
my $date= ht_time($orig->request_time, '%Y-%m-%d %H;%M:%S'
,0);
my $host= $r->get_remote_host;
my $method  = $r->method;
my $url = $orig->uri;
my $user= $r->connection->user;
my $referer = $r->header_in('Referer');
my $browser = $r->header_in('User-agent');
my $status  = $orig->status;
my $bytes   = $r->bytes_sent;

my $dbh = DBI->connect(DSN,split ':', DB_AUTH);
my $sth = $dbh->prepare("insert into ${\DB_TABLE} values 
(?,?,?,?,?,?,?,?,?)");

$sth->execute($date,$host,$method,$url,$user,$browser,$referer,$status,$bytes);
$sth->finish;


return OK;

}

1;


__END__






On Wed, 4 Apr 2001, darren chamberlain wrote:

> Andrew Lau ([EMAIL PROTECTED]) said something to this effect on
> 04/04/2001:
> > I am currently developing a Perl based apache module and was
> > wondering if such a functionality was available.  From within
> > the module would it be possible to modify the request object so
> > that the url that gets logged to the access.log is different
> > from what the client actually requested?
> > 
> > For example, if a client requested /file which was redirected
> > to this module could it modify either the request object or
> > some apache internal so that it gets written in the access log
> > as /file?session=1234567890abcdef  .
> > 
> > I apologize if this is readily available from some FAQ as i
> > have been unable to find this information.  Thanks for your
> > time.
> 
> This is untested, but I believe that mod_log_config logs, as part
> of the %r CustomLog directive, r->the_request, which is the first
> line of the request (i.e., "GET /file HTTP/1.0"). It might be
> possible to do something like:
> 
> my @request = split / /, $r->the_request;
> $request[1] = sprintf "%s?session=%s", $request[1], $r->param('session');
> $r->the_request(join ' ', @request);
> 
> assuming that $r->the_request is not read-only.
> 
> Another option is to use CustomLog to log something other than
> %r, like %{session}e to log an environment variable, or %q to log
> the query string:
> 
> CustomLog "%h %l %u %t \"%m %U%q %H\" %>s %b"
> 
> %m is the method, %U is the requested url, %q is the query
> %string (or '' if no query string), %H is the request protocol.
> 
> (darren)
> 
> -- 
> Everybody wants to go to heaven, but nobody wants to die.
>