diff --git a/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs b/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs index 21f4f3d86a..f64a07973e 100644 --- a/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs +++ b/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs @@ -55,11 +55,13 @@ namespace OpenSim.Server.Handlers.Hypergrid private IUserAgentService m_UserAgentService; private string m_LoginServerIP; + private bool m_Proxy = false; - public HomeAgentHandler(IUserAgentService userAgentService, string loginServerIP) + public HomeAgentHandler(IUserAgentService userAgentService, string loginServerIP, bool proxy) { m_UserAgentService = userAgentService; m_LoginServerIP = loginServerIP; + m_Proxy = proxy; } public Hashtable Handler(Hashtable request) @@ -153,7 +155,7 @@ namespace OpenSim.Server.Handlers.Hypergrid string ip_str = args["client_ip"].ToString(); try { - string callerIP = Util.GetCallerIP(request); + string callerIP = GetCallerIP(request); // Verify if this caller has authority to send the client IP if (callerIP == m_LoginServerIP) client_ipaddress = new IPEndPoint(IPAddress.Parse(ip_str), 0); @@ -198,6 +200,23 @@ namespace OpenSim.Server.Handlers.Hypergrid responsedata["str_response_string"] = OSDParser.SerializeJsonString(resp); } + private string GetCallerIP(Hashtable request) + { + if (!m_Proxy) + return Util.GetCallerIP(request); + + // We're behind a proxy + Hashtable headers = (Hashtable)request["headers"]; + if (headers.ContainsKey("X-Forwarded-For") && headers["X-Forwarded-For"] != null) + { + IPEndPoint ep = Util.GetClientIPFromXFF((string)headers["X-Forwarded-For"]); + if (ep != null) + return ep.Address.ToString(); + } + + // Oops + return Util.GetCallerIP(request); + } } } diff --git a/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs index 70157d5705..e5f6a5def5 100644 --- a/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs +++ b/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs @@ -67,6 +67,7 @@ namespace OpenSim.Server.Handlers.Hypergrid throw new Exception("UserAgent server connector cannot proceed because of missing service"); string loginServerIP = gridConfig.GetString("LoginServerIP", "127.0.0.1"); + bool proxy = gridConfig.GetBoolean("HasProxy", false); server.AddXmlRPCHandler("agent_is_coming_home", AgentIsComingHome, false); server.AddXmlRPCHandler("get_home_region", GetHomeRegion, false); @@ -74,7 +75,7 @@ namespace OpenSim.Server.Handlers.Hypergrid server.AddXmlRPCHandler("verify_client", VerifyClient, false); server.AddXmlRPCHandler("logout_agent", LogoutAgent, false); - server.AddHTTPHandler("/homeagent/", new HomeAgentHandler(m_HomeUsersService, loginServerIP).Handler); + server.AddHTTPHandler("/homeagent/", new HomeAgentHandler(m_HomeUsersService, loginServerIP, proxy).Handler); } public XmlRpcResponse GetHomeRegion(XmlRpcRequest request, IPEndPoint remoteClient) diff --git a/bin/Robust.HG.ini.example b/bin/Robust.HG.ini.example index 0d87c4b74f..b81642a179 100644 --- a/bin/Robust.HG.ini.example +++ b/bin/Robust.HG.ini.example @@ -224,6 +224,9 @@ ServiceConnectors = "8003/OpenSim.Server.Handlers.dll:AssetServiceConnector,8003 GridService = "OpenSim.Services.GridService.dll:GridService" GatekeeperService = "OpenSim.Services.HypergridService.dll:GatekeeperService" + ; If you run this user agent server behind a proxy, set this to true + ; HasProxy = true + ;; If you separate the UserAgentService from the LoginService, set this to ;; the IP address of the machine where your LoginService is ;LoginServerIP = "127.0.0.1"