From 37231e0941cec02a8d24a1f08e946525cca33afb Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sun, 3 Oct 2010 21:21:02 -0700 Subject: Made the home agent handler check for xff if behind a proxy. --- .../Server/Handlers/Hypergrid/HomeAgentHandlers.cs | 23 ++++++++++++++++++++-- .../Handlers/Hypergrid/UserAgentServerConnector.cs | 3 ++- 2 files changed, 23 insertions(+), 3 deletions(-) (limited to 'OpenSim/Server') diff --git a/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs b/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs index 21f4f3d..f64a079 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 70157d5..e5f6a5d 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) -- cgit v1.1