Discussion:
Getting the client's IP address
Maury Markowitz
2003-07-08 12:12:01 UTC
Permalink
I solved this some time ago, but I'm not sure I posted the results to the group. This is a definite FAQ, so:

On NT it is not possible to retrieve the client's IP address using the request.headerForKey("x-webobjects-remote-addr"); call, the header in question is not placed into the dictionary.

After a bit of poking about I discovered this is due to a bug in the Apple-supplied IIS web adaptor. The bug is that the Apple code uses ALL_RAW as the key into IIS to retrieve the header information, which the IIS documentation clearly states returns the headers supplied by the client browser only. Things like the client IP address are added by the server, and don't appear in ALL_RAW.

The solution is to modify the copyHeaders method of WebObjects.c in the IIS subproject to make additional calls to IIS to retrieve these headers, and then copy them into the output. The existing code esssentially makes a single call using ALL_RAW and the parses the results. You should add additional code to retrieve the server-side headers as well.

Just above the line:

if (p->GetServerVariable(p->ConnID, "ALL_RAW", stackBuf, &bufsz) == TRUE)

...you should add additional calls like:

buf = getHeader(p, "REMOTE_ADDR");
req_addHeader(req, "REMOTE_ADDR", buf, STR_COPYKEY|STR_COPYVALUE);
WOFREE(buf);

There are a number of such calls I recommend, AUTH_USER, AUTH_PASSWORD, AUTH_TYPE, LOGON_USER, REMOTE_ADDR, REMOTE_HOST, REMOTE_USER. This makes the IIS adaptor work like any other and the "normal" method of getting the client IP address will now work fine.

Recompile, install and enjoy!

Maury
Kaelin Colclasure
2003-07-09 15:53:01 UTC
Permalink
Where (e.g. under what deployment platforms / scenarios) does the
header "x-webobjects-remote-addr" apply? I'm working with a single Mac
OS X machine which has a Development install of WebObjects, and when I
access my application through the Apache adaptor I have to use the
"remote_addr" header -- "x-webobjects-remote-addr" does not get set.

Should I be checking for both? And if so, which one should be given
precedence?

-- Kaelin
Post by Maury Markowitz
I solved this some time ago, but I'm not sure I posted the results to
On NT it is not possible to retrieve the client's IP address using the
request.headerForKey("x-webobjects-remote-addr"); call, the header in
question is not placed into the dictionary.
After a bit of poking about I discovered this is due to a bug in the
Apple-supplied IIS web adaptor. The bug is that the Apple code uses
ALL_RAW as the key into IIS to retrieve the header information, which
the IIS documentation clearly states returns the headers supplied by
the client browser only. Things like the client IP address are added
by the server, and don't appear in ALL_RAW.
The solution is to modify the copyHeaders method of WebObjects.c in
the IIS subproject to make additional calls to IIS to retrieve these
headers, and then copy them into the output. The existing code
esssentially makes a single call using ALL_RAW and the parses the
results. You should add additional code to retrieve the server-side
headers as well.
if (p->GetServerVariable(p->ConnID, "ALL_RAW", stackBuf, &bufsz)
== TRUE)
buf = getHeader(p, "REMOTE_ADDR");
req_addHeader(req, "REMOTE_ADDR", buf, STR_COPYKEY|STR_COPYVALUE);
WOFREE(buf);
There are a number of such calls I recommend, AUTH_USER,
AUTH_PASSWORD, AUTH_TYPE, LOGON_USER, REMOTE_ADDR, REMOTE_HOST,
REMOTE_USER. This makes the IIS adaptor work like any other and the
"normal" method of getting the client IP address will now work fine.
Recompile, install and enjoy!
Maury
_______________________________________________
WebObjects-dev mailing list
http://www.omnigroup.com/mailman/listinfo/webobjects-dev
Maury Markowitz
2003-07-09 16:04:44 UTC
Permalink
Post by Kaelin Colclasure
Where (e.g. under what deployment platforms / scenarios) does the
header "x-webobjects-remote-addr" apply? I'm working with a
single Mac OS X machine which has a Development install of
WebObjects, and when I access my application through the Apache
adaptor I have to use the "remote_addr" header --
"x-webobjects-remote-addr" does not get set.
Should I be checking for both? And if so, which one should be given
precedence?
I believe the x-webobjects headers were added in order to eliminate the differences between web servers. That is, some server might report the client IP as "CLIENT_ADDR" instead of "REMOTE_ADDR", but either one would still appear in x-webobjects-remote-addr.

That's the theory anyway, the reality seems to be that these are not at all well implemented. In my case neither of these headers worked due to the adaptor bug, and in yours the header is not being properly copied over to the x-webobjects version.

I'd say "go with what works", with the added proviso that you might want to put in some debugging output or comments to remind you to change it if you ever have to port it.

Maury
Chuck Hill
2003-09-22 23:48:06 UTC
Permalink
Are you testing this in DirectConnect mode? I don't think it works there.
Trying printing out all of the headers and if the IP address is there. It
might not be getting sent or passed along, the Apache mod_webobjects
adaptor does not pass all headers unless you are using a patched version
(or maybe 5.2, I've not checked). I don't recall which ones were missing.
If it is not in the request's headers, no code is going to retrieve it.


Chuck
Post by Scott Lopatin
I have read all the emails about recording IP addresses from visitors.
request().headerForKey("user-agent");
request().headerForKey("remote_host");
request().headerForKey("remote_addr");
request().headerForKey("x-webobjects-remote-host");
request().headerForKey("host");
request().headerForKey("x-webobjects-remote-addr");
request().headerForKey("aRequest._originatingAddress().getHostAddress()"
);
No luck. I'm trying to record the IP address of the client from a page
which gets the WORequest from a direct action method.
Does anyone know how to properly record this? All I am getting is the
server's address in the originatingAddress value.
Thanks,
Scott
_______________________________________________
WebObjects-dev mailing list
http://www.omnigroup.com/mailman/listinfo/webobjects-dev
--

Chuck Hill ***@global-village.net
Global Village Consulting Inc. http://www.global-village.net
Scott Lopatin
2003-09-22 23:24:09 UTC
Permalink
I have read all the emails about recording IP addresses from visitors.

I've tried all methods:

request().headerForKey("user-agent");
request().headerForKey("remote_host");
request().headerForKey("remote_addr");
request().headerForKey("x-webobjects-remote-host");
request().headerForKey("host");
request().headerForKey("x-webobjects-remote-addr");
request().headerForKey("aRequest._originatingAddress().getHostAddress()"
);

No luck. I'm trying to record the IP address of the client from a page
which gets the WORequest from a direct action method.

Does anyone know how to properly record this? All I am getting is the
server's address in the originatingAddress value.

Thanks,
Scott
Andy Beier
2003-09-23 14:54:05 UTC
Permalink
In order to retrieve the client IP you need to run the request through a
WebObjects adapter (The CGI WebObjects CGI will work). If you're on the
Mac what I typically do is enable my personal webserver and call my app
like this:

http://localhost/cgi-bin/WebObjects/<app name>.woa/-<port number>

Also to make testing easier I usually put this argument in the "Launch
Arguments": -WOPort 8080 so the application instance will always launch
on 8080.

Good luck!


-----Original Message-----
From: Scott Lopatin [mailto:***@lm.mmc.com]
Sent: Monday, September 22, 2003 6:17 PM
To: webobjects-***@omnigroup.com
Subject: IP Address Log from Direct Action

I have read all the emails about recording IP addresses from visitors.

I've tried all methods:

request().headerForKey("user-agent");
request().headerForKey("remote_host");
request().headerForKey("remote_addr");
request().headerForKey("x-webobjects-remote-host");
request().headerForKey("host");
request().headerForKey("x-webobjects-remote-addr");
request().headerForKey("aRequest._originatingAddress().getHostAddress()"

);

No luck. I'm trying to record the IP address of the client from a page
which gets the WORequest from a direct action method.

Does anyone know how to properly record this? All I am getting is the
server's address in the originatingAddress value.

Thanks,
Scott
Scott Lopatin
2003-09-23 19:12:37 UTC
Permalink
Chuck,

I'm testing this deployed.

Where would I get a patched version of the adaptor? I'm using 5.2 and
the IP isn't in the header at all!

It seems some people have this working on deployment...

Thanks,
Scott
Post by Chuck Hill
Are you testing this in DirectConnect mode? I don't think it works
there.
Trying printing out all of the headers and if the IP address is there.
It
might not be getting sent or passed along, the Apache mod_webobjects
adaptor does not pass all headers unless you are using a patched
version
(or maybe 5.2, I've not checked). I don't recall which ones were
missing.
If it is not in the request's headers, no code is going to retrieve it.
Chuck
Post by Scott Lopatin
I have read all the emails about recording IP addresses from visitors.
request().headerForKey("user-agent");
request().headerForKey("remote_host");
request().headerForKey("remote_addr");
request().headerForKey("x-webobjects-remote-host");
request().headerForKey("host");
request().headerForKey("x-webobjects-remote-addr");
request().headerForKey("aRequest._originatingAddress().getHostAddress(
)"
);
No luck. I'm trying to record the IP address of the client from a page
which gets the WORequest from a direct action method.
Does anyone know how to properly record this? All I am getting is the
server's address in the originatingAddress value.
Thanks,
Scott
_______________________________________________
WebObjects-dev mailing list
http://www.omnigroup.com/mailman/listinfo/webobjects-dev
--
Global Village Consulting Inc.
http://www.global-village.net
_______________________________________________
WebObjects-dev mailing list
http://www.omnigroup.com/mailman/listinfo/webobjects-dev
Jonathan Fleming
2003-09-24 00:32:04 UTC
Permalink
Hi Scott,
I don't know if this is going to be of any value to you, but it might.

Indeed, using the

hKeys = context().request().headerKeys();

call indicates that the "x-webobjects-remote-addr" header key
was not being passed to WebObjects. Instead the new header key
seems to be "remote-addr"

Most of the documentation online still refers to the
"x-webobjects-remote-addr" header key. However, this should correct your
problem.

Let me know how you get on and I'll shut up if I'm wrong.

Jonathan F :^)
"We do our best! And when our best is not enough... we do even better."
Subject: Re: IP Address Log from Direct Action
Date: Tue, 23 Sep 2003 16:55:20 -0400
Chuck,
I'm testing this deployed.
Where would I get a patched version of the adaptor? I'm using 5.2 and the
IP isn't in the header at all!
It seems some people have this working on deployment...
Thanks,
Scott
Post by Chuck Hill
Are you testing this in DirectConnect mode? I don't think it works
there.
Trying printing out all of the headers and if the IP address is there.
It
might not be getting sent or passed along, the Apache mod_webobjects
adaptor does not pass all headers unless you are using a patched version
(or maybe 5.2, I've not checked). I don't recall which ones were
missing.
If it is not in the request's headers, no code is going to retrieve it.
Chuck
Post by Scott Lopatin
I have read all the emails about recording IP addresses from visitors.
request().headerForKey("user-agent");
request().headerForKey("remote_host");
request().headerForKey("remote_addr");
request().headerForKey("x-webobjects-remote-host");
request().headerForKey("host");
request().headerForKey("x-webobjects-remote-addr");
request().headerForKey("aRequest._originatingAddress().getHostAddress( )"
);
No luck. I'm trying to record the IP address of the client from a page
which gets the WORequest from a direct action method.
Does anyone know how to properly record this? All I am getting is the
server's address in the originatingAddress value.
Thanks,
Scott
_______________________________________________
WebObjects-dev mailing list
http://www.omnigroup.com/mailman/listinfo/webobjects-dev
--
Global Village Consulting Inc. http://www.global-village.net
_______________________________________________
WebObjects-dev mailing list
http://www.omnigroup.com/mailman/listinfo/webobjects-dev
_______________________________________________
WebObjects-dev mailing list
http://www.omnigroup.com/mailman/listinfo/webobjects-dev
_________________________________________________________________
It's fast, it's easy and it's free. Get MSN Messenger today!
http://www.msn.co.uk/messenger

Loading...