From 934ae03d44716e7102d4548045a6aed891209603 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sun, 3 Oct 2010 20:35:26 -0700 Subject: Made the Gatekeeper proxy-able. --- .../Server/Handlers/Simulation/AgentHandlers.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'OpenSim/Server/Handlers/Simulation') diff --git a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs index 2997430..1f7e502 100644 --- a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs +++ b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs @@ -52,6 +52,8 @@ namespace OpenSim.Server.Handlers.Simulation private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private ISimulationService m_SimulationService; + protected bool m_Proxy = false; + public AgentHandler() { } public AgentHandler(ISimulationService sim) @@ -179,13 +181,31 @@ namespace OpenSim.Server.Handlers.Simulation resp["reason"] = OSD.FromString(reason); resp["success"] = OSD.FromBoolean(result); // Let's also send out the IP address of the caller back to the caller (HG 1.5) - resp["your_ip"] = OSD.FromString(Util.GetCallerIP(request)); + resp["your_ip"] = OSD.FromString(GetCallerIP(request)); // TODO: add reason if not String.Empty? responsedata["int_response_code"] = HttpStatusCode.OK; 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); + } + // subclasses can override this protected virtual bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out string reason) { -- cgit v1.1