diff options
Diffstat (limited to 'OpenSim/Server/Handlers')
4 files changed, 107 insertions, 21 deletions
diff --git a/OpenSim/Server/Handlers/Hypergrid/HeloServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/HeloServerConnector.cs new file mode 100644 index 0000000..39baa32 --- /dev/null +++ b/OpenSim/Server/Handlers/Hypergrid/HeloServerConnector.cs | |||
@@ -0,0 +1,79 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Net; | ||
32 | using System.Reflection; | ||
33 | using Nini.Config; | ||
34 | using log4net; | ||
35 | using OpenSim.Server.Base; | ||
36 | using OpenSim.Services.Interfaces; | ||
37 | using OpenSim.Framework.Servers.HttpServer; | ||
38 | using OpenSim.Server.Handlers.Base; | ||
39 | |||
40 | namespace OpenSim.Server.Handlers.Hypergrid | ||
41 | { | ||
42 | public class HeloServiceInConnector : ServiceConnector | ||
43 | { | ||
44 | public HeloServiceInConnector(IConfigSource config, IHttpServer server, string configName) : | ||
45 | base(config, server, configName) | ||
46 | { | ||
47 | server.AddStreamHandler(new HeloServerGetHandler("opensim-robust")); | ||
48 | } | ||
49 | } | ||
50 | |||
51 | public class HeloServerGetHandler : BaseStreamHandler | ||
52 | { | ||
53 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
54 | |||
55 | private string m_HandlersType; | ||
56 | |||
57 | public HeloServerGetHandler(string handlersType) : | ||
58 | base("GET", "/helo") | ||
59 | { | ||
60 | m_HandlersType = handlersType; | ||
61 | } | ||
62 | |||
63 | public override byte[] Handle(string path, Stream requestData, | ||
64 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
65 | { | ||
66 | return OKResponse(httpResponse); | ||
67 | } | ||
68 | |||
69 | private byte[] OKResponse(OSHttpResponse httpResponse) | ||
70 | { | ||
71 | m_log.Debug("[HELO]: hi, I was called"); | ||
72 | httpResponse.AddHeader("X-Handlers-Provided", m_HandlersType); | ||
73 | httpResponse.StatusCode = (int)HttpStatusCode.OK; | ||
74 | httpResponse.StatusDescription = "OK"; | ||
75 | return new byte[0]; | ||
76 | } | ||
77 | |||
78 | } | ||
79 | } | ||
diff --git a/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs b/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs index e50481a..d10d6fc 100644 --- a/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs +++ b/OpenSim/Server/Handlers/Hypergrid/HomeAgentHandlers.cs | |||
@@ -54,9 +54,12 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
54 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 54 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
55 | private IUserAgentService m_UserAgentService; | 55 | private IUserAgentService m_UserAgentService; |
56 | 56 | ||
57 | public HomeAgentHandler(IUserAgentService userAgentService) | 57 | private string m_LoginServerIP; |
58 | |||
59 | public HomeAgentHandler(IUserAgentService userAgentService, string loginServerIP) | ||
58 | { | 60 | { |
59 | m_UserAgentService = userAgentService; | 61 | m_UserAgentService = userAgentService; |
62 | m_LoginServerIP = loginServerIP; | ||
60 | } | 63 | } |
61 | 64 | ||
62 | public Hashtable Handler(Hashtable request) | 65 | public Hashtable Handler(Hashtable request) |
@@ -120,6 +123,7 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
120 | string regionname = string.Empty; | 123 | string regionname = string.Empty; |
121 | string gatekeeper_host = string.Empty; | 124 | string gatekeeper_host = string.Empty; |
122 | int gatekeeper_port = 0; | 125 | int gatekeeper_port = 0; |
126 | IPEndPoint client_ipaddress = null; | ||
123 | 127 | ||
124 | if (args.ContainsKey("gatekeeper_host") && args["gatekeeper_host"] != null) | 128 | if (args.ContainsKey("gatekeeper_host") && args["gatekeeper_host"] != null) |
125 | gatekeeper_host = args["gatekeeper_host"].AsString(); | 129 | gatekeeper_host = args["gatekeeper_host"].AsString(); |
@@ -144,6 +148,24 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
144 | if (args.ContainsKey("destination_name") && args["destination_name"] != null) | 148 | if (args.ContainsKey("destination_name") && args["destination_name"] != null) |
145 | regionname = args["destination_name"].ToString(); | 149 | regionname = args["destination_name"].ToString(); |
146 | 150 | ||
151 | if (args.ContainsKey("client_ip") && args["client_ip"] != null) | ||
152 | { | ||
153 | string ip_str = args["client_ip"].ToString(); | ||
154 | try | ||
155 | { | ||
156 | string callerIP = Util.GetCallerIP(request); | ||
157 | // Verify if this caller has authority to send the client IP | ||
158 | if (callerIP == m_LoginServerIP) | ||
159 | client_ipaddress = new IPEndPoint(IPAddress.Parse(ip_str), 0); | ||
160 | else | ||
161 | m_log.WarnFormat("[HOME AGENT HANDLER]: Unauthorized machine {0} tried to set client ip to {1}", callerIP, ip_str); | ||
162 | } | ||
163 | catch | ||
164 | { | ||
165 | m_log.DebugFormat("[HOME AGENT HANDLER]: Exception parsing client ip address from {0}", ip_str); | ||
166 | } | ||
167 | } | ||
168 | |||
147 | GridRegion destination = new GridRegion(); | 169 | GridRegion destination = new GridRegion(); |
148 | destination.RegionID = uuid; | 170 | destination.RegionID = uuid; |
149 | destination.RegionLocX = x; | 171 | destination.RegionLocX = x; |
@@ -166,7 +188,7 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
166 | OSDMap resp = new OSDMap(2); | 188 | OSDMap resp = new OSDMap(2); |
167 | string reason = String.Empty; | 189 | string reason = String.Empty; |
168 | 190 | ||
169 | bool result = m_UserAgentService.LoginAgentToGrid(aCircuit, gatekeeper, destination, out reason); | 191 | bool result = m_UserAgentService.LoginAgentToGrid(aCircuit, gatekeeper, destination, client_ipaddress, out reason); |
170 | 192 | ||
171 | resp["reason"] = OSD.FromString(reason); | 193 | resp["reason"] = OSD.FromString(reason); |
172 | resp["success"] = OSD.FromBoolean(result); | 194 | resp["success"] = OSD.FromBoolean(result); |
diff --git a/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs b/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs index 6b1152b..70157d5 100644 --- a/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs +++ b/OpenSim/Server/Handlers/Hypergrid/UserAgentServerConnector.cs | |||
@@ -66,13 +66,15 @@ namespace OpenSim.Server.Handlers.Hypergrid | |||
66 | if (m_HomeUsersService == null) | 66 | if (m_HomeUsersService == null) |
67 | throw new Exception("UserAgent server connector cannot proceed because of missing service"); | 67 | throw new Exception("UserAgent server connector cannot proceed because of missing service"); |
68 | 68 | ||
69 | string loginServerIP = gridConfig.GetString("LoginServerIP", "127.0.0.1"); | ||
70 | |||
69 | server.AddXmlRPCHandler("agent_is_coming_home", AgentIsComingHome, false); | 71 | server.AddXmlRPCHandler("agent_is_coming_home", AgentIsComingHome, false); |
70 | server.AddXmlRPCHandler("get_home_region", GetHomeRegion, false); | 72 | server.AddXmlRPCHandler("get_home_region", GetHomeRegion, false); |
71 | server.AddXmlRPCHandler("verify_agent", VerifyAgent, false); | 73 | server.AddXmlRPCHandler("verify_agent", VerifyAgent, false); |
72 | server.AddXmlRPCHandler("verify_client", VerifyClient, false); | 74 | server.AddXmlRPCHandler("verify_client", VerifyClient, false); |
73 | server.AddXmlRPCHandler("logout_agent", LogoutAgent, false); | 75 | server.AddXmlRPCHandler("logout_agent", LogoutAgent, false); |
74 | 76 | ||
75 | server.AddHTTPHandler("/homeagent/", new HomeAgentHandler(m_HomeUsersService).Handler); | 77 | server.AddHTTPHandler("/homeagent/", new HomeAgentHandler(m_HomeUsersService, loginServerIP).Handler); |
76 | } | 78 | } |
77 | 79 | ||
78 | public XmlRpcResponse GetHomeRegion(XmlRpcRequest request, IPEndPoint remoteClient) | 80 | public XmlRpcResponse GetHomeRegion(XmlRpcRequest request, IPEndPoint remoteClient) |
diff --git a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs index 392927a..2997430 100644 --- a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs +++ b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs | |||
@@ -179,7 +179,7 @@ namespace OpenSim.Server.Handlers.Simulation | |||
179 | resp["reason"] = OSD.FromString(reason); | 179 | resp["reason"] = OSD.FromString(reason); |
180 | resp["success"] = OSD.FromBoolean(result); | 180 | resp["success"] = OSD.FromBoolean(result); |
181 | // Let's also send out the IP address of the caller back to the caller (HG 1.5) | 181 | // Let's also send out the IP address of the caller back to the caller (HG 1.5) |
182 | resp["your_ip"] = OSD.FromString(GetCallerIP(request)); | 182 | resp["your_ip"] = OSD.FromString(Util.GetCallerIP(request)); |
183 | 183 | ||
184 | // TODO: add reason if not String.Empty? | 184 | // TODO: add reason if not String.Empty? |
185 | responsedata["int_response_code"] = HttpStatusCode.OK; | 185 | responsedata["int_response_code"] = HttpStatusCode.OK; |
@@ -355,23 +355,6 @@ namespace OpenSim.Server.Handlers.Simulation | |||
355 | m_SimulationService.ReleaseAgent(regionID, id, ""); | 355 | m_SimulationService.ReleaseAgent(regionID, id, ""); |
356 | } | 356 | } |
357 | 357 | ||
358 | private string GetCallerIP(Hashtable req) | ||
359 | { | ||
360 | if (req.ContainsKey("headers")) | ||
361 | { | ||
362 | try | ||
363 | { | ||
364 | Hashtable headers = (Hashtable)req["headers"]; | ||
365 | if (headers.ContainsKey("remote_addr") && headers["remote_addr"] != null) | ||
366 | return headers["remote_addr"].ToString(); | ||
367 | } | ||
368 | catch (Exception e) | ||
369 | { | ||
370 | m_log.WarnFormat("[AGENT HANDLER]: exception in GetCallerIP: {0}", e.Message); | ||
371 | } | ||
372 | } | ||
373 | return string.Empty; | ||
374 | } | ||
375 | } | 358 | } |
376 | 359 | ||
377 | } | 360 | } |