cancel
Showing results for 
Search instead for 
Did you mean: 

Get the client IP in a Webscript called from Share

tonyrivet
Champ in-the-making
Champ in-the-making
Hi everyone,

I'm stuck with a little problem here :
I added a new custom action in the Share's document library. This action call a Webscript in which I want to get the client IP address.
Of course, as the webscript is called from Share, the remote address I get from the WebScriptRequest is localhost (127.0.0.1), instead of the end user IP address.

I think the only way to get the client IP in my webscript is to pass it as a parameter, but I don't know what is the best way to get this IP address from Share…

How can I do that ?
For example, is there any surf root object which could contain client information ?

Thank you in advance.
9 REPLIES 9

lpgc
Champ in-the-making
Champ in-the-making
Im not 100% sure, but webscripts are run in the server so ull get the server IP. Anyways it makes sense that you can get the IP of the client who called the webscript.

zladuric
Champ on-the-rise
Champ on-the-rise
You could either use the clientside parameter or use a "proxy" script at /share.

Kind of like /share/modules/create-site.post…
So instead of calling the webscript directly, you call your share webscript, then it gets the IP and stuff and passes it all to repo webscript.

tonyrivet
Champ in-the-making
Champ in-the-making
Thank you for your answers.

In fact, my problem is not 'how to pass the client IP to my webscript' but 'how to get it in the Share environment'.
Your advise was to use a Share webscript, but how can I retrieve the client IP in this script ? Is there any root object that contains client information ?

zladuric
Champ on-the-rise
Champ on-the-rise
You mean before you create your component response? In share webscript controller? I am not sure, maybe the <strong>url</strong> or <strong>user</strong>?
Something from here:
http://docs.alfresco.com/4.2/index.jsp?topic=%2Fcom.alfresco.enterprise.doc%2Freferences%2FAPISurfPl...

tonyrivet
Champ in-the-making
Champ in-the-making
I meant before I call my repo webscript, in the "share/modules/my-share-webscript.get.js".
Unfortunately, the url and user root objects don't have the client IP information (and I didn't find it either in the other root objects)…

I managed to get it by calling request.getRemoteAddr() in the site-index.jsp, but as my repo webscript is called on a document library action, I have to get the IP on the document library page…

Do you think of another way to do this ?

zladuric
Champ on-the-rise
Champ on-the-rise
So, you need the IP before the custom action is called? To append it to some URL of remote webscript or something, as parameter.

Well, I can only think of a Java backed webscript. Then it's doable.

Or something possibly not perfect - when you create your interface, use client-side javascript to make an ajax or jsonp or some such call to get the client IP address, then fix it in the callback.

tonyrivet
Champ in-the-making
Champ in-the-making
Not really… I think I wasn't clear the first time.

I'll try to be more precise :
I have a custom action in the document library, which goal is to automatically download a document in a shared folder on the client computer. My action calls a (repo) java backed webscript to process the document downloading. To build the remote path of the shared folder, I need the client local IP (I work on an internal network). I tried to get the remote address returned by the webscript request but, as the webscript is called from Share, it always returns the server address (localhost).

So I think the only way to get the client IP in my repo webscript, is to get it from Share, and pass it to my webscript as a parameter. The problem is : how to get it from Share ?

An ajax call to an external "get my ip" webscript returns the public IP address of my network, which is not what I want. Like I said before, I managed to get it in the site-index.jsp beacause I have access to the request in this JSP, but I still don't know how to get it in the document library context…

Maybe I miss something or maybe that is not possible… but as said lpgc, I think it makes sense to be able to get the IP of the current user…

zladuric
Champ on-the-rise
Champ on-the-rise
Well, the quick way would be to create a small local daemon there, so instead of the external "get my ip" call, you use your own resource, on the LAN.

But the proper way, I guess would be to write a java-backed controller, which would have access to
HTTPServletRequest.getRemoteAddr()
or something similar. You could then either put this info in the model or do whatever else you might need.

By the way, that's a very neat idea! As a part-time alfresco dev, and full-time sysadmin (at the moment, I'd love to make it the other way around), that sounds like excellent thing.

I can already see the label on that action:
"Get the MSO to my computer", or "Get me the new shipping schedule calendar" or some such Smiley Happy

tonyrivet
Champ in-the-making
Champ in-the-making
OK, finally, it works !

I didn't know it was possible to create Java Backed controllers on Share side. That's very usefull. I simply had to create a Share Java Backed webscript in which I can access to <java>HTTPServletRequest.getRemoteAddr()</java> that returns the correct client IP. Then I call my repo webscript passing this IP as a parameter.

You're right, it could lead to many interesting actions. In my case it simply aims to download documents automatically to a shared folder on the client machine…

Anyways, thanks a lot for your help !