1
0

LLLoginHandlers.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. using System;
  28. using System.Collections;
  29. using System.IO;
  30. using System.Reflection;
  31. using System.Net;
  32. using System.Text;
  33. using OpenSim.Server.Base;
  34. using OpenSim.Server.Handlers.Base;
  35. using OpenSim.Services.Interfaces;
  36. using OpenSim.Framework;
  37. using OpenSim.Framework.Servers.HttpServer;
  38. using OpenMetaverse;
  39. using OpenMetaverse.StructuredData;
  40. using Nwc.XmlRpc;
  41. using Nini.Config;
  42. using log4net;
  43. namespace OpenSim.Server.Handlers.Login
  44. {
  45. public class LLLoginHandlers
  46. {
  47. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  48. private ILoginService m_LocalService;
  49. private bool m_Proxy;
  50. public LLLoginHandlers(ILoginService service, bool hasProxy)
  51. {
  52. m_LocalService = service;
  53. m_Proxy = hasProxy;
  54. }
  55. public XmlRpcResponse HandleXMLRPCLogin(XmlRpcRequest request, IPEndPoint remoteClient)
  56. {
  57. Hashtable requestData = (Hashtable)request.Params[0];
  58. if (m_Proxy && request.Params[3] != null)
  59. {
  60. IPEndPoint ep = Util.GetClientIPFromXFF((string)request.Params[3]);
  61. if (ep != null)
  62. // Bang!
  63. remoteClient = ep;
  64. }
  65. if (requestData != null)
  66. {
  67. if (requestData.ContainsKey("first") && requestData["first"] != null &&
  68. requestData.ContainsKey("last") && requestData["last"] != null && (
  69. (requestData.ContainsKey("passwd") && requestData["passwd"] != null) ||
  70. (!requestData.ContainsKey("passwd") && requestData.ContainsKey("web_login_key") && requestData["web_login_key"] != null && requestData["web_login_key"].ToString() != UUID.Zero.ToString())
  71. ))
  72. {
  73. string first = requestData["first"].ToString();
  74. string last = requestData["last"].ToString();
  75. string passwd = null;
  76. if (requestData.ContainsKey("passwd"))
  77. {
  78. passwd = requestData["passwd"].ToString();
  79. }
  80. else if (requestData.ContainsKey("web_login_key"))
  81. {
  82. passwd = "$1$" + requestData["web_login_key"].ToString();
  83. m_log.InfoFormat("[LOGIN]: XMLRPC Login Req key {0}", passwd);
  84. }
  85. string startLocation = string.Empty;
  86. UUID scopeID = UUID.Zero;
  87. if (requestData["scope_id"] != null)
  88. scopeID = new UUID(requestData["scope_id"].ToString());
  89. if (requestData.ContainsKey("start"))
  90. startLocation = requestData["start"].ToString();
  91. string clientVersion = "Unknown";
  92. if (requestData.Contains("version") && requestData["version"] != null)
  93. clientVersion = requestData["version"].ToString();
  94. // We should do something interesting with the client version...
  95. string channel = "Unknown";
  96. if (requestData.Contains("channel") && requestData["channel"] != null)
  97. channel = requestData["channel"].ToString();
  98. string mac = "Unknown";
  99. if (requestData.Contains("mac") && requestData["mac"] != null)
  100. mac = requestData["mac"].ToString();
  101. string id0 = "Unknown";
  102. if (requestData.Contains("id0") && requestData["id0"] != null)
  103. id0 = requestData["id0"].ToString();
  104. //m_log.InfoFormat("[LOGIN]: XMLRPC Login Requested for {0} {1}, starting in {2}, using {3}", first, last, startLocation, clientVersion);
  105. LoginResponse reply = null;
  106. reply = m_LocalService.Login(first, last, passwd, startLocation, scopeID, clientVersion, channel, mac, id0, remoteClient);
  107. XmlRpcResponse response = new XmlRpcResponse();
  108. response.Value = reply.ToHashtable();
  109. return response;
  110. }
  111. }
  112. return FailedXMLRPCResponse();
  113. }
  114. public XmlRpcResponse HandleXMLRPCSetLoginLevel(XmlRpcRequest request, IPEndPoint remoteClient)
  115. {
  116. Hashtable requestData = (Hashtable)request.Params[0];
  117. if (requestData != null)
  118. {
  119. if (requestData.ContainsKey("first") && requestData["first"] != null &&
  120. requestData.ContainsKey("last") && requestData["last"] != null &&
  121. requestData.ContainsKey("level") && requestData["level"] != null &&
  122. requestData.ContainsKey("passwd") && requestData["passwd"] != null)
  123. {
  124. string first = requestData["first"].ToString();
  125. string last = requestData["last"].ToString();
  126. string passwd = requestData["passwd"].ToString();
  127. int level = Int32.Parse(requestData["level"].ToString());
  128. m_log.InfoFormat("[LOGIN]: XMLRPC Set Level to {2} Requested by {0} {1}", first, last, level);
  129. Hashtable reply = m_LocalService.SetLevel(first, last, passwd, level, remoteClient);
  130. XmlRpcResponse response = new XmlRpcResponse();
  131. response.Value = reply;
  132. return response;
  133. }
  134. }
  135. XmlRpcResponse failResponse = new XmlRpcResponse();
  136. Hashtable failHash = new Hashtable();
  137. failHash["success"] = "false";
  138. failResponse.Value = failHash;
  139. return failResponse;
  140. }
  141. public OSD HandleLLSDLogin(OSD request, IPEndPoint remoteClient)
  142. {
  143. if (request.Type == OSDType.Map)
  144. {
  145. OSDMap map = (OSDMap)request;
  146. if (map.ContainsKey("first") && map.ContainsKey("last") && map.ContainsKey("passwd"))
  147. {
  148. string startLocation = string.Empty;
  149. if (map.ContainsKey("start"))
  150. startLocation = map["start"].AsString();
  151. UUID scopeID = UUID.Zero;
  152. if (map.ContainsKey("scope_id"))
  153. scopeID = new UUID(map["scope_id"].AsString());
  154. m_log.Info("[LOGIN]: LLSD Login Requested for: '" + map["first"].AsString() + "' '" + map["last"].AsString() + "' / " + startLocation);
  155. LoginResponse reply = null;
  156. reply = m_LocalService.Login(map["first"].AsString(), map["last"].AsString(), map["passwd"].AsString(), startLocation, scopeID,
  157. map["version"].AsString(), map["channel"].AsString(), map["mac"].AsString(), map["id0"].AsString(), remoteClient);
  158. return reply.ToOSDMap();
  159. }
  160. }
  161. return FailedOSDResponse();
  162. }
  163. private XmlRpcResponse FailedXMLRPCResponse()
  164. {
  165. Hashtable hash = new Hashtable();
  166. hash["reason"] = "key";
  167. hash["message"] = "Incomplete login credentials. Check your username and password.";
  168. hash["login"] = "false";
  169. XmlRpcResponse response = new XmlRpcResponse();
  170. response.Value = hash;
  171. return response;
  172. }
  173. private OSD FailedOSDResponse()
  174. {
  175. OSDMap map = new OSDMap();
  176. map["reason"] = OSD.FromString("key");
  177. map["message"] = OSD.FromString("Invalid login credentials. Check your username and passwd.");
  178. map["login"] = OSD.FromString("false");
  179. return map;
  180. }
  181. }
  182. }