EPrints Technical Mailing List Archive

Message: #02073


< Previous (by date) | Next (by date) > | < Previous (in thread) | Next (in thread) > | Messages - Most Recent First | Threads - Most Recent First

[EP-tech] x-forwarded ip in access table


Hi,

 

We have just moved our server and needed to modify the apache .conf files to use X-Forwarded-For, so we get the correct IP’s into the access and error logs.  This is all working correctly.

 

The collection of ip’s in the access table was not handling the x-forward header info.

 

Fixed it by editing this file, perl_lib/EPrints/Apache/LogHandler.pm, and adding extra code to pick up the header info and fall back to regular ip if not defined.

 

sub _generic

{

       my( $r, $epdata ) = @_;

 

       my $c = $r->connection;

       my $ip = $c->remote_ip;

 

+      my $ip_XForward = $r->headers_in->{ "X-Forwarded-For" };     

+      if (defined $ip_XForward)

+      {

+             $ip = $ip_XForward;

+      }

      

       $epdata->{datestamp} = EPrints::Time::get_iso_timestamp( $r->request_time );

       $epdata->{requester_id} = $ip;

       $epdata->{referring_entity_id} = $r->headers_in->{ "Referer" };

       $epdata->{requester_user_agent} = $r->headers_in->{ "User-Agent" };

 

       # Sanity check referring URL (don't store non-HTTP referrals)

       if( !$epdata->{referring_entity_id} || $epdata->{referring_entity_id} !~ /^https?:/ )

       {

              $epdata->{referring_entity_id} = '';

       }

 

       return $epdata;

}

 

 

Cheers

 

Matt


This email (including any attached files) is confidential and is for the intended recipient(s) only. If you received this email by mistake, please, as a courtesy, tell the sender, then delete this email.

The views and opinions are the originator's and do not necessarily reflect those of the University of Southern Queensland. Although all reasonable precautions were taken to ensure that this email contained no viruses at the time it was sent we accept no liability for any losses arising from its receipt.

The University of Southern Queensland is a registered provider of education with the Australian Government.
(CRICOS Institution Code QLD 00244B / NSW 02225M, TEQSA PRV12081 )