From 0772e19af25b8524fa2527a4d5f3bac496d07811 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sun, 3 Oct 2010 20:01:59 -0700 Subject: Added viewer's channel, mac, and id0 to agent circuit data. Also moved client ip address to agent circuit data, so that it's always there. --- .../Server/Handlers/Hypergrid/HomeAgentHandlers.cs | 2 +- OpenSim/Server/Handlers/Login/LLLoginHandlers.cs | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'OpenSim/Server') diff --git a/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs b/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs index d10d6fc..21f4f3d 100644 --- a/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs +++ b/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs @@ -157,7 +157,7 @@ namespace OpenSim.Server.Handlers.Hypergrid // Verify if this caller has authority to send the client IP if (callerIP == m_LoginServerIP) client_ipaddress = new IPEndPoint(IPAddress.Parse(ip_str), 0); - else + else // leaving this for now, but this warning should be removed m_log.WarnFormat("[HOME AGENT HANDLER]: Unauthorized machine {0} tried to set client ip to {1}", callerIP, ip_str); } catch diff --git a/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs b/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs index 30dc65e..48f5f99 100644 --- a/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs +++ b/OpenSim/Server/Handlers/Login/LLLoginHandlers.cs @@ -88,14 +88,26 @@ namespace OpenSim.Server.Handlers.Login startLocation = requestData["start"].ToString(); string clientVersion = "Unknown"; - if (requestData.Contains("version")) + if (requestData.Contains("version") && requestData["version"] != null) clientVersion = requestData["version"].ToString(); // We should do something interesting with the client version... + string channel = "Unknown"; + if (requestData.Contains("channel") && requestData["channel"] != null) + channel = requestData["channel"].ToString(); + + string mac = "Unknown"; + if (requestData.Contains("mac") && requestData["mac"] != null) + mac = requestData["mac"].ToString(); + + string id0 = "Unknown"; + if (requestData.Contains("id0") && requestData["id0"] != null) + id0 = requestData["id0"].ToString(); + //m_log.InfoFormat("[LOGIN]: XMLRPC Login Requested for {0} {1}, starting in {2}, using {3}", first, last, startLocation, clientVersion); LoginResponse reply = null; - reply = m_LocalService.Login(first, last, passwd, startLocation, scopeID, clientVersion, remoteClient); + reply = m_LocalService.Login(first, last, passwd, startLocation, scopeID, clientVersion, channel, mac, id0, remoteClient); XmlRpcResponse response = new XmlRpcResponse(); response.Value = reply.ToHashtable(); @@ -166,7 +178,8 @@ namespace OpenSim.Server.Handlers.Login m_log.Info("[LOGIN]: LLSD Login Requested for: '" + map["first"].AsString() + "' '" + map["last"].AsString() + "' / " + startLocation); LoginResponse reply = null; - reply = m_LocalService.Login(map["first"].AsString(), map["last"].AsString(), map["passwd"].AsString(), startLocation, scopeID, String.Empty, remoteClient); + reply = m_LocalService.Login(map["first"].AsString(), map["last"].AsString(), map["passwd"].AsString(), startLocation, scopeID, + map["version"].AsString(), map["channel"].AsString(), map["mac"].AsString(), map["id0"].AsString(), remoteClient); return reply.ToOSDMap(); } -- cgit v1.1 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. --- OpenSim/Server/Handlers/Hypergrid/AgentHandlers.cs | 3 ++- .../Hypergrid/GatekeeperServerConnector.cs | 6 +++++- .../Server/Handlers/Simulation/AgentHandlers.cs | 22 +++++++++++++++++++++- 3 files changed, 28 insertions(+), 3 deletions(-) (limited to 'OpenSim/Server') diff --git a/OpenSim/Server/Handlers/Hypergrid/AgentHandlers.cs b/OpenSim/Server/Handlers/Hypergrid/AgentHandlers.cs index c951653..31eefb1 100644 --- a/OpenSim/Server/Handlers/Hypergrid/AgentHandlers.cs +++ b/OpenSim/Server/Handlers/Hypergrid/AgentHandlers.cs @@ -54,9 +54,10 @@ namespace OpenSim.Server.Handlers.Hypergrid private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private IGatekeeperService m_GatekeeperService; - public GatekeeperAgentHandler(IGatekeeperService gatekeeper) + public GatekeeperAgentHandler(IGatekeeperService gatekeeper, bool proxy) { m_GatekeeperService = gatekeeper; + m_Proxy = proxy; } protected override bool CreateAgent(GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out string reason) diff --git a/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs index dcb2725..49de8b1 100644 --- a/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs +++ b/OpenSim/Server/Handlers/Hypergrid/GatekeeperServerConnector.cs @@ -51,6 +51,8 @@ namespace OpenSim.Server.Handlers.Hypergrid get { return m_GatekeeperService; } } + bool m_Proxy = false; + public GatekeeperServiceInConnector(IConfigSource config, IHttpServer server, ISimulationService simService) : base(config, server, String.Empty) { @@ -65,11 +67,13 @@ namespace OpenSim.Server.Handlers.Hypergrid if (m_GatekeeperService == null) throw new Exception("Gatekeeper server connector cannot proceed because of missing service"); + m_Proxy = gridConfig.GetBoolean("HasProxy", false); + HypergridHandlers hghandlers = new HypergridHandlers(m_GatekeeperService); server.AddXmlRPCHandler("link_region", hghandlers.LinkRegionRequest, false); server.AddXmlRPCHandler("get_region", hghandlers.GetRegion, false); - server.AddHTTPHandler("/foreignagent/", new GatekeeperAgentHandler(m_GatekeeperService).Handler); + server.AddHTTPHandler("/foreignagent/", new GatekeeperAgentHandler(m_GatekeeperService, m_Proxy).Handler); } public GatekeeperServiceInConnector(IConfigSource config, IHttpServer server) 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 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