clockwerk-opensim-stable – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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 public LLLoginHandlers(ILoginService service, bool hasProxy)
58 {
59 m_LocalService = service;
60 m_Proxy = hasProxy;
61 }
62  
63 public XmlRpcResponse HandleXMLRPCLogin(XmlRpcRequest request, IPEndPoint remoteClient)
64 {
65 Hashtable requestData = (Hashtable)request.Params[0];
66 if (m_Proxy && request.Params[3] != null)
67 {
68 IPEndPoint ep = Util.GetClientIPFromXFF((string)request.Params[3]);
69 if (ep != null)
70 // Bang!
71 remoteClient = ep;
72 }
73  
74 if (requestData != null)
75 {
76 // Debug code to show exactly what login parameters the viewer is sending us.
77 // TODO: Extract into a method that can be generally applied if one doesn't already exist.
78 // foreach (string key in requestData.Keys)
79 // {
80 // object value = requestData[key];
81 // Console.WriteLine("{0}:{1}", key, value);
82 // if (value is ArrayList)
83 // {
84 // ICollection col = value as ICollection;
85 // foreach (object item in col)
86 // Console.WriteLine(" {0}", item);
87 // }
88 // }
89  
90 if (requestData.ContainsKey("first") && requestData["first"] != null &&
91 requestData.ContainsKey("last") && requestData["last"] != null && (
92 (requestData.ContainsKey("passwd") && requestData["passwd"] != null) ||
93 (!requestData.ContainsKey("passwd") && requestData.ContainsKey("web_login_key") && requestData["web_login_key"] != null && requestData["web_login_key"].ToString() != UUID.Zero.ToString())
94 ))
95 {
96 string first = requestData["first"].ToString();
97 string last = requestData["last"].ToString();
98 string passwd = null;
99 if (requestData.ContainsKey("passwd"))
100 {
101 passwd = requestData["passwd"].ToString();
102 }
103 else if (requestData.ContainsKey("web_login_key"))
104 {
105 passwd = "$1$" + requestData["web_login_key"].ToString();
106 m_log.InfoFormat("[LOGIN]: XMLRPC Login Req key {0}", passwd);
107 }
108 string startLocation = string.Empty;
109 UUID scopeID = UUID.Zero;
110 if (requestData["scope_id"] != null)
111 scopeID = new UUID(requestData["scope_id"].ToString());
112 if (requestData.ContainsKey("start"))
113 startLocation = requestData["start"].ToString();
114  
115 string clientVersion = "Unknown";
116 if (requestData.Contains("version") && requestData["version"] != null)
117 clientVersion = requestData["version"].ToString();
118 // We should do something interesting with the client version...
119  
120 string channel = "Unknown";
121 if (requestData.Contains("channel") && requestData["channel"] != null)
122 channel = requestData["channel"].ToString();
123  
124 string mac = "Unknown";
125 if (requestData.Contains("mac") && requestData["mac"] != null)
126 mac = requestData["mac"].ToString();
127  
128 string id0 = "Unknown";
129 if (requestData.Contains("id0") && requestData["id0"] != null)
130 id0 = requestData["id0"].ToString();
131  
132 //m_log.InfoFormat("[LOGIN]: XMLRPC Login Requested for {0} {1}, starting in {2}, using {3}", first, last, startLocation, clientVersion);
133  
134 LoginResponse reply = null;
135 reply = m_LocalService.Login(first, last, passwd, startLocation, scopeID, clientVersion, channel, mac, id0, remoteClient);
136  
137 XmlRpcResponse response = new XmlRpcResponse();
138 response.Value = reply.ToHashtable();
139 return response;
140  
141 }
142 }
143  
144 return FailedXMLRPCResponse();
145  
146 }
147  
148 public XmlRpcResponse HandleXMLRPCSetLoginLevel(XmlRpcRequest request, IPEndPoint remoteClient)
149 {
150 Hashtable requestData = (Hashtable)request.Params[0];
151  
152 if (requestData != null)
153 {
154 if (requestData.ContainsKey("first") && requestData["first"] != null &&
155 requestData.ContainsKey("last") && requestData["last"] != null &&
156 requestData.ContainsKey("level") && requestData["level"] != null &&
157 requestData.ContainsKey("passwd") && requestData["passwd"] != null)
158 {
159 string first = requestData["first"].ToString();
160 string last = requestData["last"].ToString();
161 string passwd = requestData["passwd"].ToString();
162 int level = Int32.Parse(requestData["level"].ToString());
163  
164 m_log.InfoFormat("[LOGIN]: XMLRPC Set Level to {2} Requested by {0} {1}", first, last, level);
165  
166 Hashtable reply = m_LocalService.SetLevel(first, last, passwd, level, remoteClient);
167  
168 XmlRpcResponse response = new XmlRpcResponse();
169 response.Value = reply;
170  
171 return response;
172  
173 }
174 }
175  
176 XmlRpcResponse failResponse = new XmlRpcResponse();
177 Hashtable failHash = new Hashtable();
178 failHash["success"] = "false";
179 failResponse.Value = failHash;
180  
181 return failResponse;
182  
183 }
184  
185 public OSD HandleLLSDLogin(OSD request, IPEndPoint remoteClient)
186 {
187 if (request.Type == OSDType.Map)
188 {
189 OSDMap map = (OSDMap)request;
190  
191 if (map.ContainsKey("first") && map.ContainsKey("last") && map.ContainsKey("passwd"))
192 {
193 string startLocation = string.Empty;
194  
195 if (map.ContainsKey("start"))
196 startLocation = map["start"].AsString();
197  
198 UUID scopeID = UUID.Zero;
199  
200 if (map.ContainsKey("scope_id"))
201 scopeID = new UUID(map["scope_id"].AsString());
202  
203 m_log.Info("[LOGIN]: LLSD Login Requested for: '" + map["first"].AsString() + "' '" + map["last"].AsString() + "' / " + startLocation);
204  
205 LoginResponse reply = null;
206 reply = m_LocalService.Login(map["first"].AsString(), map["last"].AsString(), map["passwd"].AsString(), startLocation, scopeID,
207 map["version"].AsString(), map["channel"].AsString(), map["mac"].AsString(), map["id0"].AsString(), remoteClient);
208 return reply.ToOSDMap();
209  
210 }
211 }
212  
213 return FailedOSDResponse();
214 }
215  
216 private XmlRpcResponse FailedXMLRPCResponse()
217 {
218 Hashtable hash = new Hashtable();
219 hash["reason"] = "key";
220 hash["message"] = "Incomplete login credentials. Check your username and password.";
221 hash["login"] = "false";
222  
223 XmlRpcResponse response = new XmlRpcResponse();
224 response.Value = hash;
225  
226 return response;
227 }
228  
229 private OSD FailedOSDResponse()
230 {
231 OSDMap map = new OSDMap();
232  
233 map["reason"] = OSD.FromString("key");
234 map["message"] = OSD.FromString("Invalid login credentials. Check your username and passwd.");
235 map["login"] = OSD.FromString("false");
236  
237 return map;
238 }
239  
240 }
241  
242 }