LLLoginHandlers.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. {
  71. string first = requestData["first"].ToString();
  72. string last = requestData["last"].ToString();
  73. string passwd = requestData["passwd"].ToString();
  74. string startLocation = string.Empty;
  75. UUID scopeID = UUID.Zero;
  76. if (requestData["scope_id"] != null)
  77. scopeID = new UUID(requestData["scope_id"].ToString());
  78. if (requestData.ContainsKey("start"))
  79. startLocation = requestData["start"].ToString();
  80. string clientVersion = "Unknown";
  81. if (requestData.Contains("version"))
  82. clientVersion = requestData["version"].ToString();
  83. // We should do something interesting with the client version...
  84. //m_log.InfoFormat("[LOGIN]: XMLRPC Login Requested for {0} {1}, starting in {2}, using {3}", first, last, startLocation, clientVersion);
  85. LoginResponse reply = null;
  86. reply = m_LocalService.Login(first, last, passwd, startLocation, scopeID, clientVersion, remoteClient);
  87. XmlRpcResponse response = new XmlRpcResponse();
  88. response.Value = reply.ToHashtable();
  89. return response;
  90. }
  91. }
  92. return FailedXMLRPCResponse();
  93. }
  94. public XmlRpcResponse HandleXMLRPCSetLoginLevel(XmlRpcRequest request, IPEndPoint remoteClient)
  95. {
  96. Hashtable requestData = (Hashtable)request.Params[0];
  97. if (requestData != null)
  98. {
  99. if (requestData.ContainsKey("first") && requestData["first"] != null &&
  100. requestData.ContainsKey("last") && requestData["last"] != null &&
  101. requestData.ContainsKey("level") && requestData["level"] != null &&
  102. requestData.ContainsKey("passwd") && requestData["passwd"] != null)
  103. {
  104. string first = requestData["first"].ToString();
  105. string last = requestData["last"].ToString();
  106. string passwd = requestData["passwd"].ToString();
  107. int level = Int32.Parse(requestData["level"].ToString());
  108. m_log.InfoFormat("[LOGIN]: XMLRPC Set Level to {2} Requested by {0} {1}", first, last, level);
  109. Hashtable reply = m_LocalService.SetLevel(first, last, passwd, level, remoteClient);
  110. XmlRpcResponse response = new XmlRpcResponse();
  111. response.Value = reply;
  112. return response;
  113. }
  114. }
  115. XmlRpcResponse failResponse = new XmlRpcResponse();
  116. Hashtable failHash = new Hashtable();
  117. failHash["success"] = "false";
  118. failResponse.Value = failHash;
  119. return failResponse;
  120. }
  121. public OSD HandleLLSDLogin(OSD request, IPEndPoint remoteClient)
  122. {
  123. if (request.Type == OSDType.Map)
  124. {
  125. OSDMap map = (OSDMap)request;
  126. if (map.ContainsKey("first") && map.ContainsKey("last") && map.ContainsKey("passwd"))
  127. {
  128. string startLocation = string.Empty;
  129. if (map.ContainsKey("start"))
  130. startLocation = map["start"].AsString();
  131. UUID scopeID = UUID.Zero;
  132. if (map.ContainsKey("scope_id"))
  133. scopeID = new UUID(map["scope_id"].AsString());
  134. m_log.Info("[LOGIN]: LLSD Login Requested for: '" + map["first"].AsString() + "' '" + map["last"].AsString() + "' / " + startLocation);
  135. LoginResponse reply = null;
  136. reply = m_LocalService.Login(map["first"].AsString(), map["last"].AsString(), map["passwd"].AsString(), startLocation, scopeID, String.Empty, remoteClient);
  137. return reply.ToOSDMap();
  138. }
  139. }
  140. return FailedOSDResponse();
  141. }
  142. private XmlRpcResponse FailedXMLRPCResponse()
  143. {
  144. Hashtable hash = new Hashtable();
  145. hash["reason"] = "key";
  146. hash["message"] = "Incomplete login credentials. Check your username and password.";
  147. hash["login"] = "false";
  148. XmlRpcResponse response = new XmlRpcResponse();
  149. response.Value = hash;
  150. return response;
  151. }
  152. private OSD FailedOSDResponse()
  153. {
  154. OSDMap map = new OSDMap();
  155. map["reason"] = OSD.FromString("key");
  156. map["message"] = OSD.FromString("Invalid login credentials. Check your username and passwd.");
  157. map["login"] = OSD.FromString("false");
  158. return map;
  159. }
  160. }
  161. }