From: Teemu A. <in...@us...> - 2005-04-06 20:54:41
|
Update of /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Request In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6614/Request Modified Files: Apache2.pm Apache.pm CGI.pm LWP.pm Standalone.pm Log Message: Implemented forwarded_for() which enables us to see remote hosts behind trusted proxies. Only tested with Apache.pm but the others should work in theory. A server configuration option could be added which when enabled, parses the first non-trusted IP address out of the forwarded_for() and places it directly as remote_host(). Index: Apache2.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Request/Apache2.pm,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Apache2.pm 17 Mar 2005 14:58:04 -0000 1.3 --- Apache2.pm 6 Apr 2005 20:54:31 -0000 1.4 *************** *** 68,71 **** --- 68,73 ---- $self->server_name( $r->get_server_name ); $self->remote_host( $r->connection->remote_addr->ip_get ); + $self->forwarded_for( $r->headers_in->get('X-Forwarded-For') ); + $log->is_info && $log->info( "Finished creating Apache 2.x request" ); Index: Apache.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Request/Apache.pm,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** Apache.pm 17 Mar 2005 14:58:04 -0000 1.17 --- Apache.pm 6 Apr 2005 20:54:31 -0000 1.18 *************** *** 90,93 **** --- 90,95 ---- $self->server_name( $srv->server_hostname ); $self->remote_host( $self->apache->connection->remote_ip ); + $self->forwarded_for( $self->apache->headers_in->{'X-Forwarded-For'} ); + $log->is_info && $log->info( "Finished creating Apache 1.x request" ); Index: CGI.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Request/CGI.pm,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** CGI.pm 18 Mar 2005 04:09:51 -0000 1.23 --- CGI.pm 6 Apr 2005 20:54:31 -0000 1.24 *************** *** 57,60 **** --- 57,61 ---- $self->server_name( $cgi->server_name ); $self->remote_host( $cgi->remote_host ); + $self->forwarded_for( $ENV{'X-Forwarded-For'} ); # Then the rest of the parameters/uploads (works with other Index: LWP.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Request/LWP.pm,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** LWP.pm 18 Mar 2005 04:09:51 -0000 1.22 --- LWP.pm 6 Apr 2005 20:54:31 -0000 1.23 *************** *** 43,46 **** --- 43,47 ---- $self->cookie_header( $cookie ); $self->language_header( $lwp_request->header( 'Accept-Language' ) ); + $self->forwarded_for( $lwp_request->header( 'X-Forwarded-For' ) ); if ( $client ) { Index: Standalone.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/Request/Standalone.pm,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Standalone.pm 18 Mar 2005 04:09:51 -0000 1.14 --- Standalone.pm 6 Apr 2005 20:54:31 -0000 1.15 *************** *** 58,61 **** --- 58,62 ---- $self->server_name( $props->{server_name} ); $self->remote_host( $props->{remote_host} ); + $self->forwarded_for( $props->{forwarded_for} ); $log->is_debug && $log->debug( "Set request and server properties ok" ); *************** *** 147,165 **** OpenInteract2::Request->set_implementation_type( 'standalone' ); ! # Create all the request infomration offline... my %req_params = ( ! url => '/path/to/my/doc.html', ! referer => 'http://www.foo.bar/path/to/my/index.html', ! user_agent => 'OI2 Standalone Requester', ! server_name => 'www.foo.bar', ! remote_host => '192.168.1.1', ! param => { eyes => 'two', ! soda => [ 'rc', 'mr. pibb' ] }, ! cookie => [ 'lastSeen=1051797475;firstLogin=1051797075', ! OpenInteract2::Cookie->new( ... ), ], ! upload => { sendfile => OpenInteract2::Upload->new( ... ), ! screenshot => OpenInteract2::Upload->new( ... ) }, ! languages => [ 'en-UK', 'en-US', 'de', 'fr' ], ); --- 148,167 ---- OpenInteract2::Request->set_implementation_type( 'standalone' ); ! # Create all the request information offline... my %req_params = ( ! url => '/path/to/my/doc.html', ! referer => 'http://www.foo.bar/path/to/my/index.html', ! user_agent => 'OI2 Standalone Requester', ! server_name => 'www.foo.bar', ! remote_host => '192.168.1.1', ! forwarded_for => '154.12.0.4, 10.2.1.2', ! param => { eyes => 'two', ! soda => [ 'rc', 'mr. pibb' ] }, ! cookie => [ 'lastSeen=1051797475;firstLogin=1051797075', ! OpenInteract2::Cookie->new( ... ), ], ! upload => { sendfile => OpenInteract2::Upload->new( ... ), ! screenshot => OpenInteract2::Upload->new( ... ) }, ! languages => [ 'en-UK', 'en-US', 'de', 'fr' ], ); *************** *** 248,251 **** --- 250,257 ---- =item * + B<forwarded_for> - Set to the list of proxy IP addresses inbetween of the request. + + =item * + B<user_agent> - Set to the user agent for this request. |