Greetings,
When I deploy orthanc server with proxy like Nginx, then in Lua script , if i use function
IncomingHttpRequestFilter(method, uri, ip, username, httpHeaders) , the ip value in parameter always the nginx server’s ip, and the same to the function OnStoredInstance(instanceId, tags, metadata) metadata[‘RemoteIP’], how can i get the real client ip?
Hi,
You will have to configure nginx to add x-forwarded-for header to the request with the original IP address. https://calvin.me/forward-ip-addresses-when-using-nginx-proxy You can then check the x-forwarded-for header in your Kia script to get the original request IP address.
Hth.
James
James Manners • Director
Suite 3, Level 2, 10 Queens Road, Melbourne, Victoria 3004, Australia
T: 03 9017 5230 M: 0422 973 235 E: james@binary.com.au W: binary.com.au
I have add the config in nginx config file, but it also get the nginx server ip, not the real client ip. follow is my nginx conf:
server {
listen 6042;
server_name 10.209.156.109;
location / {
proxy_pass http://10.209.156.113:6042;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto http;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Host $remote_addr;
}
}
the orthanc logs is:
W1103 13:47:40.650809 LuaContext.cpp:93] Lua says: IncomingHttpRequestFilter 10.209.156.109
my test lua code:
function IncomingHttpRequestFilter(method, uri, ip, username, httpHeaders)
print("IncomingHttpRequestFilter "…ip)
return true
end
my pc’s real ip is 10.209.156.101, i use the chrome to access the web viewer.
You will need to update your lua script to print the http_headers not ip. Like this.
function IncomingHttpRequestFilter(method, uri, ip, username, httpHeaders)
print("IncomingHttpRequestFilter "…httpHeaders[“X-Forwarded-For”])
return true
end
You may need to inspect the httpHeaders table to find out the exact key as I’m not sure if headers are normalised to lowercase or preserve the upper&lower case letter.
James Manners • Director
Suite 3, Level 2, 10 Queens Road, Melbourne, Victoria 3004, Australia
T: 03 9017 5230 M: 0422 973 235 E: james@binary.com.au W: binary.com.au
Yes, i can get the real client ip from httpHeaders in function IncomingHttpRequestFilter , but in function OnStoredInstance(instanceId, tags, metadata), i can only get the ip with metadata[‘RemoteIP’], and it’s also the nginx server ip.
I want to distinguish who uploaded the dicom files by the ip address. Is there any other way to distinguish who uploaded the file?
The trick is to access the origin object in your plugin, and write the extra information to the metadata store associated with the study/series/instance. It can then be retrieved later.
We do this with the remote_aet, as the routing from orthanc depends on what the upstream system referred to orthanc as. In our case, Orthanc acts as a sort of multiplexor, taking data from a range of source systems, modifying it, then emitting it to a destination based on the AET.
Hope that helps.
Yes, with remote_aet we can do this if remote_aet have value. But my usage scenario is that user uploads directly through the web viewer, so remote_aet has no value.
I find this in the orthanc book https://book.orthanc-server.com/users/lua.html:
- ip: The IP address of the host that has issued the HTTP request (e.g. 127.0.0.1).
So I am curious how Orthanc obtained the IP address.
Any one can help me?
The answer to “I am curious how Orthanc obtained the IP address” can be found in the source code:
=> As can be seen, the “remote IP” address comes from the “remote_addr” field of the “mg_request_info” structure of civetweb:
https://github.com/civetweb/civetweb/blob/master/docs/api/mg_request_info.md
If you want to dig deeper, here is the source code of civetweb (for which I won’t provide support):
https://github.com/civetweb/civetweb/blob/master/src/civetweb.c