LLLoginHandlers.cs 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. // Debug code to show exactly what login parameters the viewer is sending us.
  68. // TODO: Extract into a method that can be generally applied if one doesn't already exist.
  69. // foreach (string key in requestData.Keys)
  70. // {
  71. // object value = requestData[key];
  72. // Console.WriteLine("{0}:{1}", key, value);
  73. // if (value is ArrayList)
  74. // {
  75. // ICollection col = value as ICollection;
  76. // foreach (object item in col)
  77. // Console.WriteLine(" {0}", item);
  78. // }
  79. // }
  80. if (requestData.ContainsKey("first") && requestData["first"] != null &&
  81. requestData.ContainsKey("last") && requestData["last"] != null && (
  82. (requestData.ContainsKey("passwd") && requestData["passwd"] != null) ||
  83. (!requestData.ContainsKey("passwd") && requestData.ContainsKey("web_login_key") && requestData["web_login_key"] != null && requestData["web_login_key"].ToString() != UUID.Zero.ToString())
  84. ))
  85. {
  86. string first = requestData["first"].ToString();
  87. string last = requestData["last"].ToString();
  88. string passwd = null;
  89. if (requestData.ContainsKey("passwd"))
  90. {
  91. passwd = requestData["passwd"].ToString();
  92. }
  93. else if (requestData.ContainsKey("web_login_key"))
  94. {
  95. passwd = "$1$" + requestData["web_login_key"].ToString();
  96. m_log.InfoFormat("[LOGIN]: XMLRPC Login Req key {0}", passwd);
  97. }
  98. string startLocation = string.Empty;
  99. UUID scopeID = UUID.Zero;
  100. if (requestData["scope_id"] != null)
  101. scopeID = new UUID(requestData["scope_id"].ToString());
  102. if (requestData.ContainsKey("start"))
  103. startLocation = requestData["start"].ToString();
  104. string clientVersion = "Unknown";
  105. if (requestData.Contains("version") && requestData["version"] != null)
  106. clientVersion = requestData["version"].ToString();
  107. // We should do something interesting with the client version...
  108. string channel = "Unknown";
  109. if (requestData.Contains("channel") && requestData["channel"] != null)
  110. channel = requestData["channel"].ToString();
  111. string mac = "Unknown";
  112. if (requestData.Contains("mac") && requestData["mac"] != null)
  113. mac = requestData["mac"].ToString();
  114. string id0 = "Unknown";
  115. if (requestData.Contains("id0") && requestData["id0"] != null)
  116. id0 = requestData["id0"].ToString();
  117. //m_log.InfoFormat("[LOGIN]: XMLRPC Login Requested for {0} {1}, starting in {2}, using {3}", first, last, startLocation, clientVersion);
  118. LoginResponse reply = null;
  119. reply = m_LocalService.Login(first, last, passwd, startLocation, scopeID, clientVersion, channel, mac, id0, remoteClient);
  120. XmlRpcResponse response = new XmlRpcResponse();
  121. response.Value = reply.ToHashtable();
  122. return response;
  123. }
  124. }
  125. return FailedXMLRPCResponse();
  126. }
  127. public XmlRpcResponse HandleXMLRPCSetLoginLevel(XmlRpcRequest request, IPEndPoint remoteClient)
  128. {
  129. Hashtable requestData = (Hashtable)request.Params[0];
  130. if (requestData != null)
  131. {
  132. if (requestData.ContainsKey("first") && requestData["first"] != null &&
  133. requestData.ContainsKey("last") && requestData["last"] != null &&
  134. requestData.ContainsKey("level") && requestData["level"] != null &&
  135. requestData.ContainsKey("passwd") && requestData["passwd"] != null)
  136. {
  137. string first = requestData["first"].ToString();
  138. string last = requestData["last"].ToString();
  139. string passwd = requestData["passwd"].ToString();
  140. int level = Int32.Parse(requestData["level"].ToString());
  141. m_log.InfoFormat("[LOGIN]: XMLRPC Set Level to {2} Requested by {0} {1}", first, last, level);
  142. Hashtable reply = m_LocalService.SetLevel(first, last, passwd, level, remoteClient);
  143. XmlRpcResponse response = new XmlRpcResponse();
  144. response.Value = reply;
  145. return response;
  146. }
  147. }
  148. XmlRpcResponse failResponse = new XmlRpcResponse();
  149. Hashtable failHash = new Hashtable();
  150. failHash["success"] = "false";
  151. failResponse.Value = failHash;
  152. return failResponse;
  153. }
  154. public OSD HandleLLSDLogin(OSD request, IPEndPoint remoteClient)
  155. {
  156. if (request.Type == OSDType.Map)
  157. {
  158. OSDMap map = (OSDMap)request;
  159. if (map.ContainsKey("first") && map.ContainsKey("last") && map.ContainsKey("passwd"))
  160. {
  161. string startLocation = string.Empty;
  162. if (map.ContainsKey("start"))
  163. startLocation = map["start"].AsString();
  164. UUID scopeID = UUID.Zero;
  165. if (map.ContainsKey("scope_id"))
  166. scopeID = new UUID(map["scope_id"].AsString());
  167. m_log.Info("[LOGIN]: LLSD Login Requested for: '" + map["first"].AsString() + "' '" + map["last"].AsString() + "' / " + startLocation);
  168. LoginResponse reply = null;
  169. reply = m_LocalService.Login(map["first"].AsString(), map["last"].AsString(), map["passwd"].AsString(), startLocation, scopeID,
  170. map["version"].AsString(), map["channel"].AsString(), map["mac"].AsString(), map["id0"].AsString(), remoteClient);
  171. return reply.ToOSDMap();
  172. }
  173. }
  174. return FailedOSDResponse();
  175. }
  176. private XmlRpcResponse FailedXMLRPCResponse()
  177. {
  178. Hashtable hash = new Hashtable();
  179. hash["reason"] = "key";
  180. hash["message"] = "Incomplete login credentials. Check your username and password.";
  181. hash["login"] = "false";
  182. XmlRpcResponse response = new XmlRpcResponse();
  183. response.Value = hash;
  184. return response;
  185. }
  186. private OSD FailedOSDResponse()
  187. {
  188. OSDMap map = new OSDMap();
  189. map["reason"] = OSD.FromString("key");
  190. map["message"] = OSD.FromString("Invalid login credentials. Check your username and passwd.");
  191. map["login"] = OSD.FromString("false");
  192. return map;
  193. }
  194. }
  195. }