OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
LLLoginHandlers.cs
Go to the documentation of this file.
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;
30 using System.IO;
31 using System.Reflection;
32 using System.Net;
33 using System.Text;
34 
35 using OpenSim.Server.Base;
36 using OpenSim.Server.Handlers.Base;
37 using OpenSim.Services.Interfaces;
38 using OpenSim.Framework;
39 using OpenSim.Framework.Servers.HttpServer;
40 
41 using OpenMetaverse;
42 using OpenMetaverse.StructuredData;
43 using Nwc.XmlRpc;
44 using Nini.Config;
45 using log4net;
46 
47 
48 namespace OpenSim.Server.Handlers.Login
49 {
50  public class LLLoginHandlers
51  {
52  private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53 
54  private ILoginService m_LocalService;
55  private bool m_Proxy;
56 
57 
58  public LLLoginHandlers(ILoginService service, bool hasProxy)
59  {
60  m_LocalService = service;
61  m_Proxy = hasProxy;
62  }
63 
64  public XmlRpcResponse HandleXMLRPCLogin(XmlRpcRequest request, IPEndPoint remoteClient)
65  {
66  Hashtable requestData = (Hashtable)request.Params[0];
67  if (m_Proxy && request.Params[3] != null)
68  {
69  IPEndPoint ep = Util.GetClientIPFromXFF((string)request.Params[3]);
70  if (ep != null)
71  // Bang!
72  remoteClient = ep;
73  }
74 
75  if (requestData != null)
76  {
77  // Debug code to show exactly what login parameters the viewer is sending us.
78  // TODO: Extract into a method that can be generally applied if one doesn't already exist.
79 // foreach (string key in requestData.Keys)
80 // {
81 // object value = requestData[key];
82 // Console.WriteLine("{0}:{1}", key, value);
83 // if (value is ArrayList)
84 // {
85 // ICollection col = value as ICollection;
86 // foreach (object item in col)
87 // Console.WriteLine(" {0}", item);
88 // }
89 // }
90 
91  if (requestData.ContainsKey("first") && requestData["first"] != null &&
92  requestData.ContainsKey("last") && requestData["last"] != null && (
93  (requestData.ContainsKey("passwd") && requestData["passwd"] != null) ||
94  (!requestData.ContainsKey("passwd") && requestData.ContainsKey("web_login_key") && requestData["web_login_key"] != null && requestData["web_login_key"].ToString() != UUID.Zero.ToString())
95  ))
96  {
97  string first = requestData["first"].ToString();
98  string last = requestData["last"].ToString();
99  string passwd = null;
100  if (requestData.ContainsKey("passwd"))
101  {
102  passwd = requestData["passwd"].ToString();
103  }
104  else if (requestData.ContainsKey("web_login_key"))
105  {
106  passwd = "$1$" + requestData["web_login_key"].ToString();
107  m_log.InfoFormat("[LOGIN]: XMLRPC Login Req key {0}", passwd);
108  }
109  string startLocation = string.Empty;
110  UUID scopeID = UUID.Zero;
111  if (requestData["scope_id"] != null)
112  scopeID = new UUID(requestData["scope_id"].ToString());
113  if (requestData.ContainsKey("start"))
114  startLocation = requestData["start"].ToString();
115 
116  string clientVersion = "Unknown";
117  if (requestData.Contains("version") && requestData["version"] != null)
118  clientVersion = requestData["version"].ToString();
119  // We should do something interesting with the client version...
120 
121  string channel = "Unknown";
122  if (requestData.Contains("channel") && requestData["channel"] != null)
123  channel = requestData["channel"].ToString();
124 
125  string mac = "Unknown";
126  if (requestData.Contains("mac") && requestData["mac"] != null)
127  mac = requestData["mac"].ToString();
128 
129  string id0 = "Unknown";
130  if (requestData.Contains("id0") && requestData["id0"] != null)
131  id0 = requestData["id0"].ToString();
132 
133  //m_log.InfoFormat("[LOGIN]: XMLRPC Login Requested for {0} {1}, starting in {2}, using {3}", first, last, startLocation, clientVersion);
134 
135 
136  bool LibOMVclient = false;
137  if (request.Params.Count > 4 && (string)request.Params[4] == "gridproxy")
138  LibOMVclient = true;
139 
140  LoginResponse reply = null;
141  reply = m_LocalService.Login(first, last, passwd, startLocation, scopeID, clientVersion, channel, mac, id0, remoteClient, LibOMVclient);
142 
143  XmlRpcResponse response = new XmlRpcResponse();
144  response.Value = reply.ToHashtable();
145  return response;
146 
147  }
148  }
149 
150  return FailedXMLRPCResponse();
151 
152  }
153  public XmlRpcResponse HandleXMLRPCLoginBlocked(XmlRpcRequest request, IPEndPoint client)
154  {
155  XmlRpcResponse response = new XmlRpcResponse();
156  Hashtable resp = new Hashtable();
157 
158  resp["reason"] = "presence";
159  resp["message"] = "Logins are currently restricted. Please try again later.";
160  resp["login"] = "false";
161  response.Value = resp;
162  return response;
163  }
164 
165  public XmlRpcResponse HandleXMLRPCSetLoginLevel(XmlRpcRequest request, IPEndPoint remoteClient)
166  {
167  Hashtable requestData = (Hashtable)request.Params[0];
168 
169  if (requestData != null)
170  {
171  if (requestData.ContainsKey("first") && requestData["first"] != null &&
172  requestData.ContainsKey("last") && requestData["last"] != null &&
173  requestData.ContainsKey("level") && requestData["level"] != null &&
174  requestData.ContainsKey("passwd") && requestData["passwd"] != null)
175  {
176  string first = requestData["first"].ToString();
177  string last = requestData["last"].ToString();
178  string passwd = requestData["passwd"].ToString();
179  int level = Int32.Parse(requestData["level"].ToString());
180 
181  m_log.InfoFormat("[LOGIN]: XMLRPC Set Level to {2} Requested by {0} {1}", first, last, level);
182 
183  Hashtable reply = m_LocalService.SetLevel(first, last, passwd, level, remoteClient);
184 
185  XmlRpcResponse response = new XmlRpcResponse();
186  response.Value = reply;
187 
188  return response;
189 
190  }
191  }
192 
193  XmlRpcResponse failResponse = new XmlRpcResponse();
194  Hashtable failHash = new Hashtable();
195  failHash["success"] = "false";
196  failResponse.Value = failHash;
197 
198  return failResponse;
199 
200  }
201 
202  public OSD HandleLLSDLogin(OSD request, IPEndPoint remoteClient)
203  {
204  if (request.Type == OSDType.Map)
205  {
206  OSDMap map = (OSDMap)request;
207 
208  if (map.ContainsKey("first") && map.ContainsKey("last") && map.ContainsKey("passwd"))
209  {
210  string startLocation = string.Empty;
211 
212  if (map.ContainsKey("start"))
213  startLocation = map["start"].AsString();
214 
215  UUID scopeID = UUID.Zero;
216 
217  if (map.ContainsKey("scope_id"))
218  scopeID = new UUID(map["scope_id"].AsString());
219 
220  m_log.Info("[LOGIN]: LLSD Login Requested for: '" + map["first"].AsString() + "' '" + map["last"].AsString() + "' / " + startLocation);
221 
222  LoginResponse reply = null;
223  reply = m_LocalService.Login(map["first"].AsString(), map["last"].AsString(), map["passwd"].AsString(), startLocation, scopeID,
224  map["version"].AsString(), map["channel"].AsString(), map["mac"].AsString(), map["id0"].AsString(), remoteClient,false);
225  return reply.ToOSDMap();
226 
227  }
228  }
229 
230  return FailedOSDResponse();
231  }
232 
234  {
235  sock.MaxPayloadSize = 16384; //16 kb payload
236  sock.InitialMsgTimeout = 5000; //5 second first message to trigger at least one of these events
237  sock.NoDelay_TCP_Nagle = true;
238  sock.OnData += delegate(object sender, WebsocketDataEventArgs data) { sock.Close("fail"); };
239  sock.OnPing += delegate(object sender, PingEventArgs pingdata) { sock.Close("fail"); };
240  sock.OnPong += delegate(object sender, PongEventArgs pongdata) { sock.Close("fail"); };
241  sock.OnText += delegate(object sender, WebsocketTextEventArgs text)
242  {
243  OSD request = null;
244  try
245  {
246  request = OSDParser.DeserializeJson(text.Data);
247  if (!(request is OSDMap))
248  {
249  sock.SendMessage(OSDParser.SerializeJsonString(FailedOSDResponse()));
250  }
251  else
252  {
253  OSDMap req = request as OSDMap;
254  string first = req["firstname"].AsString();
255  string last = req["lastname"].AsString();
256  string passwd = req["passwd"].AsString();
257  string start = req["startlocation"].AsString();
258  string version = req["version"].AsString();
259  string channel = req["channel"].AsString();
260  string mac = req["mac"].AsString();
261  string id0 = req["id0"].AsString();
262  UUID scope = UUID.Zero;
263  IPEndPoint endPoint =
264  (sender as WebSocketHttpServerHandler).GetRemoteIPEndpoint();
265  LoginResponse reply = null;
266  reply = m_LocalService.Login(first, last, passwd, start, scope, version,
267  channel, mac, id0, endPoint,false);
268  sock.SendMessage(OSDParser.SerializeJsonString(reply.ToOSDMap()));
269 
270  }
271 
272  }
273  catch (Exception)
274  {
275  sock.SendMessage(OSDParser.SerializeJsonString(FailedOSDResponse()));
276  }
277  finally
278  {
279  sock.Close("success");
280  }
281  };
282 
283  sock.HandshakeAndUpgrade();
284 
285  }
286 
287 
288  private XmlRpcResponse FailedXMLRPCResponse()
289  {
290  Hashtable hash = new Hashtable();
291  hash["reason"] = "key";
292  hash["message"] = "Incomplete login credentials. Check your username and password.";
293  hash["login"] = "false";
294 
295  XmlRpcResponse response = new XmlRpcResponse();
296  response.Value = hash;
297 
298  return response;
299  }
300 
301  private OSD FailedOSDResponse()
302  {
303  OSDMap map = new OSDMap();
304 
305  map["reason"] = OSD.FromString("key");
306  map["message"] = OSD.FromString("Invalid login credentials. Check your username and passwd.");
307  map["login"] = OSD.FromString("false");
308 
309  return map;
310  }
311 
312  }
313 
314 }
XmlRpcResponse HandleXMLRPCLoginBlocked(XmlRpcRequest request, IPEndPoint client)
This class implements websockets. It grabs the network context from C::Webserver and utilizes it dire...
OpenMetaverse.StructuredData.OSDMap OSDMap
OSD HandleLLSDLogin(OSD request, IPEndPoint remoteClient)
LLLoginHandlers(ILoginService service, bool hasProxy)
XmlRpcResponse HandleXMLRPCSetLoginLevel(XmlRpcRequest request, IPEndPoint remoteClient)
OpenMetaverse.StructuredData.OSD OSD
Interactive OpenSim region server
Definition: OpenSim.cs:55
void HandleWebSocketLoginEvents(string path, WebSocketHttpServerHandler sock)
XmlRpcResponse HandleXMLRPCLogin(XmlRpcRequest request, IPEndPoint remoteClient)