LoginService.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  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 OpenSim 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.Collections.Generic;
  30. using System.IO;
  31. using System.Reflection;
  32. using System.Text.RegularExpressions;
  33. using System.Threading;
  34. using System.Web;
  35. using OpenMetaverse;
  36. using OpenMetaverse.StructuredData;
  37. using log4net;
  38. using Nwc.XmlRpc;
  39. using OpenSim.Framework.Communications.Cache;
  40. using OpenSim.Framework.Statistics;
  41. namespace OpenSim.Framework.Communications
  42. {
  43. public abstract class LoginService
  44. {
  45. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  46. protected string m_welcomeMessage = "Welcome to OpenSim";
  47. protected int m_minLoginLevel = 0;
  48. protected UserManagerBase m_userManager = null;
  49. protected Mutex m_loginMutex = new Mutex(false);
  50. /// <summary>
  51. /// Used during login to send the skeleton of the OpenSim Library to the client.
  52. /// </summary>
  53. protected LibraryRootFolder m_libraryRootFolder;
  54. /// <summary>
  55. /// Constructor
  56. /// </summary>
  57. /// <param name="userManager"></param>
  58. /// <param name="libraryRootFolder"></param>
  59. /// <param name="welcomeMess"></param>
  60. public LoginService(UserManagerBase userManager, LibraryRootFolder libraryRootFolder,
  61. string welcomeMess)
  62. {
  63. m_userManager = userManager;
  64. m_libraryRootFolder = libraryRootFolder;
  65. if (welcomeMess != String.Empty)
  66. {
  67. m_welcomeMessage = welcomeMess;
  68. }
  69. }
  70. /// <summary>
  71. /// Customises the login response and fills in missing values. This method also tells the login region to
  72. /// expect a client connection.
  73. /// </summary>
  74. /// <param name="response">The existing response</param>
  75. /// <param name="theUser">The user profile</param>
  76. /// <returns>true on success, false if the region was not successfully told to expect a user connection</returns>
  77. public abstract bool CustomiseResponse(LoginResponse response, UserProfileData theUser, string startLocationRequest);
  78. /// <summary>
  79. /// If the user is already logged in, try to notify the region that the user they've got is dead.
  80. /// </summary>
  81. /// <param name="theUser"></param>
  82. public virtual void LogOffUser(UserProfileData theUser, string message)
  83. {
  84. }
  85. /// <summary>
  86. /// Get the initial login inventory skeleton (in other words, the folder structure) for the given user.
  87. /// </summary>
  88. /// <param name="userID"></param>
  89. /// <returns></returns>
  90. /// <exception cref='System.Exception'>This will be thrown if there is a problem with the inventory service</exception>
  91. protected abstract InventoryData GetInventorySkeleton(UUID userID);
  92. /// <summary>
  93. /// Called when we receive the client's initial XMLRPC login_to_simulator request message
  94. /// </summary>
  95. /// <param name="request">The XMLRPC request</param>
  96. /// <returns>The response to send</returns>
  97. public virtual XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request)
  98. {
  99. // Temporary fix
  100. m_loginMutex.WaitOne();
  101. try
  102. {
  103. //CFK: CustomizeResponse contains sufficient strings to alleviate the need for this.
  104. //CKF: m_log.Info("[LOGIN]: Attempting login now...");
  105. XmlRpcResponse response = new XmlRpcResponse();
  106. Hashtable requestData = (Hashtable) request.Params[0];
  107. bool GoodXML = (requestData.Contains("first") && requestData.Contains("last") &&
  108. (requestData.Contains("passwd") || requestData.Contains("web_login_key")));
  109. //bool GoodLogin;
  110. string startLocationRequest = "last";
  111. UserProfileData userProfile;
  112. LoginResponse logResponse = new LoginResponse();
  113. string firstname;
  114. string lastname;
  115. if (GoodXML)
  116. {
  117. if (requestData.Contains("start"))
  118. {
  119. startLocationRequest = (string)requestData["start"];
  120. }
  121. firstname = (string)requestData["first"];
  122. lastname = (string) requestData["last"];
  123. m_log.InfoFormat(
  124. "[LOGIN BEGIN]: XMLRPC Received login request message from user '{0}' '{1}'",
  125. firstname, lastname);
  126. string clientVersion = "Unknown";
  127. if (requestData.Contains("version"))
  128. {
  129. clientVersion = (string)requestData["version"];
  130. }
  131. m_log.DebugFormat(
  132. "[LOGIN]: XMLRPC Client is {0}, start location is {1}", clientVersion, startLocationRequest);
  133. if (!TryAuthenticateXmlRpcLogin(request, firstname, lastname, out userProfile))
  134. {
  135. return logResponse.CreateLoginFailedResponse();
  136. }
  137. }
  138. else
  139. {
  140. m_log.Info(
  141. "[LOGIN END]: XMLRPC login_to_simulator login message did not contain all the required data");
  142. return logResponse.CreateGridErrorResponse();
  143. }
  144. if (userProfile.GodLevel < m_minLoginLevel)
  145. {
  146. return logResponse.CreateLoginBlockedResponse();
  147. }
  148. else
  149. {
  150. // If we already have a session...
  151. if (userProfile.CurrentAgent != null && userProfile.CurrentAgent.AgentOnline)
  152. {
  153. //TODO: The following statements can cause trouble:
  154. // If agentOnline could not turn from true back to false normally
  155. // because of some problem, for instance, the crashment of server or client,
  156. // the user cannot log in any longer.
  157. userProfile.CurrentAgent.AgentOnline = false;
  158. m_userManager.CommitAgent(ref userProfile);
  159. // try to tell the region that their user is dead.
  160. LogOffUser(userProfile, " XMLRPC You were logged off because you logged in from another location");
  161. // Reject the login
  162. m_log.InfoFormat(
  163. "[LOGIN END]: XMLRPC Notifying user {0} {1} that they are already logged in",
  164. firstname, lastname);
  165. return logResponse.CreateAlreadyLoggedInResponse();
  166. }
  167. // Otherwise...
  168. // Create a new agent session
  169. m_userManager.ResetAttachments(userProfile.ID);
  170. CreateAgent(userProfile, request);
  171. try
  172. {
  173. UUID agentID = userProfile.ID;
  174. InventoryData inventData;
  175. try
  176. {
  177. inventData = GetInventorySkeleton(agentID);
  178. }
  179. catch (Exception e)
  180. {
  181. m_log.ErrorFormat(
  182. "[LOGIN END]: Error retrieving inventory skeleton of agent {0} - {1}",
  183. agentID, e);
  184. return logResponse.CreateLoginInventoryFailedResponse();
  185. }
  186. ArrayList AgentInventoryArray = inventData.InventoryArray;
  187. Hashtable InventoryRootHash = new Hashtable();
  188. InventoryRootHash["folder_id"] = inventData.RootFolderID.ToString();
  189. ArrayList InventoryRoot = new ArrayList();
  190. InventoryRoot.Add(InventoryRootHash);
  191. userProfile.RootInventoryFolderID = inventData.RootFolderID;
  192. // Inventory Library Section
  193. Hashtable InventoryLibRootHash = new Hashtable();
  194. InventoryLibRootHash["folder_id"] = "00000112-000f-0000-0000-000100bba000";
  195. ArrayList InventoryLibRoot = new ArrayList();
  196. InventoryLibRoot.Add(InventoryLibRootHash);
  197. logResponse.InventoryLibRoot = InventoryLibRoot;
  198. logResponse.InventoryLibraryOwner = GetLibraryOwner();
  199. logResponse.InventoryRoot = InventoryRoot;
  200. logResponse.InventorySkeleton = AgentInventoryArray;
  201. logResponse.InventoryLibrary = GetInventoryLibrary();
  202. logResponse.CircuitCode = Util.RandomClass.Next();
  203. logResponse.Lastname = userProfile.SurName;
  204. logResponse.Firstname = userProfile.FirstName;
  205. logResponse.AgentID = agentID;
  206. logResponse.SessionID = userProfile.CurrentAgent.SessionID;
  207. logResponse.SecureSessionID = userProfile.CurrentAgent.SecureSessionID;
  208. logResponse.Message = GetMessage();
  209. logResponse.BuddList = ConvertFriendListItem(m_userManager.GetUserFriendList(agentID));
  210. logResponse.StartLocation = startLocationRequest;
  211. if (CustomiseResponse(logResponse, userProfile, startLocationRequest))
  212. {
  213. userProfile.LastLogin = userProfile.CurrentAgent.LoginTime;
  214. CommitAgent(ref userProfile);
  215. // If we reach this point, then the login has successfully logged onto the grid
  216. if (StatsManager.UserStats != null)
  217. StatsManager.UserStats.AddSuccessfulLogin();
  218. m_log.DebugFormat(
  219. "[LOGIN END]: XMLRPC Authentication of user {0} {1} successful. Sending response to client.",
  220. firstname, lastname);
  221. return logResponse.ToXmlRpcResponse();
  222. }
  223. else
  224. {
  225. m_log.ErrorFormat("[LOGIN END]: XMLRPC informing user {0} {1} that login failed due to an unavailable region", firstname, lastname);
  226. return logResponse.CreateDeadRegionResponse();
  227. }
  228. }
  229. catch (Exception e)
  230. {
  231. m_log.Error("[LOGIN END]: XMLRPC Login failed, " + e);
  232. m_log.Error(e.StackTrace);
  233. }
  234. }
  235. m_log.Info("[LOGIN END]: XMLRPC Login failed. Sending back blank XMLRPC response");
  236. return response;
  237. }
  238. finally
  239. {
  240. m_loginMutex.ReleaseMutex();
  241. }
  242. }
  243. protected virtual bool TryAuthenticateXmlRpcLogin(XmlRpcRequest request, string firstname, string lastname, out UserProfileData userProfile)
  244. {
  245. Hashtable requestData = (Hashtable)request.Params[0];
  246. bool GoodLogin = false;
  247. userProfile = GetTheUser(firstname, lastname);
  248. if (userProfile == null)
  249. {
  250. m_log.Info("[LOGIN END]: XMLRPC Could not find a profile for " + firstname + " " + lastname);
  251. }
  252. else
  253. {
  254. if (requestData.Contains("passwd"))
  255. {
  256. string passwd = (string) requestData["passwd"];
  257. GoodLogin = AuthenticateUser(userProfile, passwd);
  258. }
  259. else if (requestData.Contains("web_login_key"))
  260. {
  261. try
  262. {
  263. UUID webloginkey = new UUID((string) requestData["web_login_key"]);
  264. GoodLogin = AuthenticateUser(userProfile, webloginkey);
  265. }
  266. catch (Exception e)
  267. {
  268. m_log.InfoFormat(
  269. "[LOGIN END]: XMLRPC Bad web_login_key: {0} for user {1} {2}, exception {3}",
  270. requestData["web_login_key"], firstname, lastname, e);
  271. }
  272. }
  273. }
  274. return GoodLogin;
  275. }
  276. protected virtual bool TryAuthenticateLLSDLogin( string firstname, string lastname, string passwd, out UserProfileData userProfile)
  277. {
  278. bool GoodLogin = false;
  279. userProfile = GetTheUser(firstname, lastname);
  280. if (userProfile == null)
  281. {
  282. m_log.Info("[LOGIN]: LLSD Could not find a profile for " + firstname + " " + lastname);
  283. return false;
  284. }
  285. GoodLogin = AuthenticateUser(userProfile, passwd);
  286. return GoodLogin;
  287. }
  288. /// <summary>
  289. /// Called when we receive the client's initial LLSD login_to_simulator request message
  290. /// </summary>
  291. /// <param name="request">The LLSD request</param>
  292. /// <returns>The response to send</returns>
  293. public OSD LLSDLoginMethod(OSD request)
  294. {
  295. // Temporary fix
  296. m_loginMutex.WaitOne();
  297. try
  298. {
  299. // bool GoodLogin = false;
  300. string startLocationRequest = "last";
  301. UserProfileData userProfile = null;
  302. LoginResponse logResponse = new LoginResponse();
  303. if (request.Type == OSDType.Map)
  304. {
  305. OSDMap map = (OSDMap)request;
  306. if (map.ContainsKey("first") && map.ContainsKey("last") && map.ContainsKey("passwd"))
  307. {
  308. string firstname = map["first"].AsString();
  309. string lastname = map["last"].AsString();
  310. string passwd = map["passwd"].AsString();
  311. if (map.ContainsKey("start"))
  312. {
  313. m_log.Info("[LOGIN]: LLSD StartLocation Requested: " + map["start"].AsString());
  314. startLocationRequest = map["start"].AsString();
  315. }
  316. m_log.Info("[LOGIN]: LLSD Login Requested for: '" + firstname+"' '"+lastname+"' / "+passwd);
  317. if (!TryAuthenticateLLSDLogin( firstname, lastname, passwd, out userProfile))
  318. {
  319. return logResponse.CreateLoginFailedResponseLLSD();
  320. }
  321. }
  322. else
  323. return logResponse.CreateLoginFailedResponseLLSD();
  324. }
  325. else
  326. return logResponse.CreateLoginFailedResponseLLSD();
  327. if (userProfile.GodLevel < m_minLoginLevel)
  328. {
  329. return logResponse.CreateLoginBlockedResponseLLSD();
  330. }
  331. else
  332. {
  333. // If we already have a session...
  334. if (userProfile.CurrentAgent != null && userProfile.CurrentAgent.AgentOnline)
  335. {
  336. userProfile.CurrentAgent.AgentOnline = false;
  337. m_userManager.CommitAgent(ref userProfile);
  338. // try to tell the region that their user is dead.
  339. LogOffUser(userProfile, " LLSD You were logged off because you logged in from another location");
  340. // Reject the login
  341. m_log.InfoFormat(
  342. "[LOGIN END]: LLSD Notifying user {0} {1} that they are already logged in",
  343. userProfile.FirstName, userProfile.SurName);
  344. userProfile.CurrentAgent = null;
  345. return logResponse.CreateAlreadyLoggedInResponseLLSD();
  346. }
  347. // Otherwise...
  348. // Create a new agent session
  349. m_userManager.ResetAttachments(userProfile.ID);
  350. CreateAgent(userProfile, request);
  351. try
  352. {
  353. UUID agentID = userProfile.ID;
  354. //InventoryData inventData = GetInventorySkeleton(agentID);
  355. InventoryData inventData = null;
  356. try
  357. {
  358. inventData = GetInventorySkeleton(agentID);
  359. }
  360. catch (Exception e)
  361. {
  362. m_log.ErrorFormat(
  363. "[LOGIN END]: LLSD Error retrieving inventory skeleton of agent {0}, {1} - {2}",
  364. agentID, e.GetType(), e.Message);
  365. return logResponse.CreateLoginFailedResponseLLSD();// .CreateLoginInventoryFailedResponseLLSD ();
  366. }
  367. ArrayList AgentInventoryArray = inventData.InventoryArray;
  368. Hashtable InventoryRootHash = new Hashtable();
  369. InventoryRootHash["folder_id"] = inventData.RootFolderID.ToString();
  370. ArrayList InventoryRoot = new ArrayList();
  371. InventoryRoot.Add(InventoryRootHash);
  372. userProfile.RootInventoryFolderID = inventData.RootFolderID;
  373. // Inventory Library Section
  374. Hashtable InventoryLibRootHash = new Hashtable();
  375. InventoryLibRootHash["folder_id"] = "00000112-000f-0000-0000-000100bba000";
  376. ArrayList InventoryLibRoot = new ArrayList();
  377. InventoryLibRoot.Add(InventoryLibRootHash);
  378. logResponse.InventoryLibRoot = InventoryLibRoot;
  379. logResponse.InventoryLibraryOwner = GetLibraryOwner();
  380. logResponse.InventoryRoot = InventoryRoot;
  381. logResponse.InventorySkeleton = AgentInventoryArray;
  382. logResponse.InventoryLibrary = GetInventoryLibrary();
  383. logResponse.CircuitCode = (Int32)Util.RandomClass.Next();
  384. logResponse.Lastname = userProfile.SurName;
  385. logResponse.Firstname = userProfile.FirstName;
  386. logResponse.AgentID = agentID;
  387. logResponse.SessionID = userProfile.CurrentAgent.SessionID;
  388. logResponse.SecureSessionID = userProfile.CurrentAgent.SecureSessionID;
  389. logResponse.Message = GetMessage();
  390. logResponse.BuddList = ConvertFriendListItem(m_userManager.GetUserFriendList(agentID));
  391. logResponse.StartLocation = startLocationRequest;
  392. try
  393. {
  394. CustomiseResponse(logResponse, userProfile, startLocationRequest);
  395. }
  396. catch (Exception ex)
  397. {
  398. m_log.Info("[LOGIN]: LLSD " + ex.ToString());
  399. return logResponse.CreateDeadRegionResponseLLSD();
  400. }
  401. userProfile.LastLogin = userProfile.CurrentAgent.LoginTime;
  402. CommitAgent(ref userProfile);
  403. // If we reach this point, then the login has successfully logged onto the grid
  404. if (StatsManager.UserStats != null)
  405. StatsManager.UserStats.AddSuccessfulLogin();
  406. m_log.DebugFormat(
  407. "[LOGIN END]: LLSD Authentication of user {0} {1} successful. Sending response to client.",
  408. userProfile.FirstName, userProfile.SurName);
  409. return logResponse.ToLLSDResponse();
  410. }
  411. catch (Exception ex)
  412. {
  413. m_log.Info("[LOGIN]: LLSD " + ex.ToString());
  414. return logResponse.CreateFailedResponseLLSD();
  415. }
  416. }
  417. }
  418. finally
  419. {
  420. m_loginMutex.ReleaseMutex();
  421. }
  422. }
  423. public Hashtable ProcessHTMLLogin(Hashtable keysvals)
  424. {
  425. // Matches all unspecified characters
  426. // Currently specified,; lowercase letters, upper case letters, numbers, underline
  427. // period, space, parens, and dash.
  428. Regex wfcut = new Regex("[^a-zA-Z0-9_\\.\\$ \\(\\)\\-]");
  429. Hashtable returnactions = new Hashtable();
  430. int statuscode = 200;
  431. string firstname = String.Empty;
  432. string lastname = String.Empty;
  433. string location = String.Empty;
  434. string region =String.Empty;
  435. string grid = String.Empty;
  436. string channel = String.Empty;
  437. string version = String.Empty;
  438. string lang = String.Empty;
  439. string password = String.Empty;
  440. string errormessages = String.Empty;
  441. // the client requires the HTML form field be named 'username'
  442. // however, the data it sends when it loads the first time is 'firstname'
  443. // another one of those little nuances.
  444. if (keysvals.Contains("firstname"))
  445. firstname = wfcut.Replace((string)keysvals["firstname"], String.Empty, 99999);
  446. if (keysvals.Contains("username"))
  447. firstname = wfcut.Replace((string)keysvals["username"], String.Empty, 99999);
  448. if (keysvals.Contains("lastname"))
  449. lastname = wfcut.Replace((string)keysvals["lastname"], String.Empty, 99999);
  450. if (keysvals.Contains("location"))
  451. location = wfcut.Replace((string)keysvals["location"], String.Empty, 99999);
  452. if (keysvals.Contains("region"))
  453. region = wfcut.Replace((string)keysvals["region"], String.Empty, 99999);
  454. if (keysvals.Contains("grid"))
  455. grid = wfcut.Replace((string)keysvals["grid"], String.Empty, 99999);
  456. if (keysvals.Contains("channel"))
  457. channel = wfcut.Replace((string)keysvals["channel"], String.Empty, 99999);
  458. if (keysvals.Contains("version"))
  459. version = wfcut.Replace((string)keysvals["version"], String.Empty, 99999);
  460. if (keysvals.Contains("lang"))
  461. lang = wfcut.Replace((string)keysvals["lang"], String.Empty, 99999);
  462. if (keysvals.Contains("password"))
  463. password = wfcut.Replace((string)keysvals["password"], String.Empty, 99999);
  464. // load our login form.
  465. string loginform = GetLoginForm(firstname, lastname, location, region, grid, channel, version, lang, password, errormessages);
  466. if (keysvals.ContainsKey("show_login_form"))
  467. {
  468. UserProfileData user = GetTheUser(firstname, lastname);
  469. bool goodweblogin = false;
  470. if (user != null)
  471. goodweblogin = AuthenticateUser(user, password);
  472. if (goodweblogin)
  473. {
  474. UUID webloginkey = UUID.Random();
  475. m_userManager.StoreWebLoginKey(user.ID, webloginkey);
  476. statuscode = 301;
  477. string redirectURL = "about:blank?redirect-http-hack=" +
  478. HttpUtility.UrlEncode("secondlife:///app/login?first_name=" + firstname + "&last_name=" +
  479. lastname +
  480. "&location=" + location + "&grid=Other&web_login_key=" + webloginkey.ToString());
  481. //m_log.Info("[WEB]: R:" + redirectURL);
  482. returnactions["int_response_code"] = statuscode;
  483. returnactions["str_redirect_location"] = redirectURL;
  484. returnactions["str_response_string"] = "<HTML><BODY>GoodLogin</BODY></HTML>";
  485. }
  486. else
  487. {
  488. errormessages = "The Username and password supplied did not match our records. Check your caps lock and try again";
  489. loginform = GetLoginForm(firstname, lastname, location, region, grid, channel, version, lang, password, errormessages);
  490. returnactions["int_response_code"] = statuscode;
  491. returnactions["str_response_string"] = loginform;
  492. }
  493. }
  494. else
  495. {
  496. returnactions["int_response_code"] = statuscode;
  497. returnactions["str_response_string"] = loginform;
  498. }
  499. return returnactions;
  500. }
  501. public string GetLoginForm(string firstname, string lastname, string location, string region,
  502. string grid, string channel, string version, string lang,
  503. string password, string errormessages)
  504. {
  505. // inject our values in the form at the markers
  506. string loginform=String.Empty;
  507. string file = Path.Combine(Util.configDir(), "http_loginform.html");
  508. if (!File.Exists(file))
  509. {
  510. loginform = GetDefaultLoginForm();
  511. }
  512. else
  513. {
  514. StreamReader sr = File.OpenText(file);
  515. loginform = sr.ReadToEnd();
  516. sr.Close();
  517. }
  518. loginform = loginform.Replace("[$firstname]", firstname);
  519. loginform = loginform.Replace("[$lastname]", lastname);
  520. loginform = loginform.Replace("[$location]", location);
  521. loginform = loginform.Replace("[$region]", region);
  522. loginform = loginform.Replace("[$grid]", grid);
  523. loginform = loginform.Replace("[$channel]", channel);
  524. loginform = loginform.Replace("[$version]", version);
  525. loginform = loginform.Replace("[$lang]", lang);
  526. loginform = loginform.Replace("[$password]", password);
  527. loginform = loginform.Replace("[$errors]", errormessages);
  528. return loginform;
  529. }
  530. public string GetDefaultLoginForm()
  531. {
  532. string responseString =
  533. "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
  534. responseString += "<html xmlns=\"http://www.w3.org/1999/xhtml\">";
  535. responseString += "<head>";
  536. responseString += "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
  537. responseString += "<meta http-equiv=\"cache-control\" content=\"no-cache\">";
  538. responseString += "<meta http-equiv=\"Pragma\" content=\"no-cache\">";
  539. responseString += "<title>OpenSim Login</title>";
  540. responseString += "<body><br />";
  541. responseString += "<div id=\"login_box\">";
  542. responseString += "<form action=\"/go.cgi\" method=\"GET\" id=\"login-form\">";
  543. responseString += "<div id=\"message\">[$errors]</div>";
  544. responseString += "<fieldset id=\"firstname\">";
  545. responseString += "<legend>First Name:</legend>";
  546. responseString += "<input type=\"text\" id=\"firstname_input\" size=\"15\" maxlength=\"100\" name=\"username\" value=\"[$firstname]\" />";
  547. responseString += "</fieldset>";
  548. responseString += "<fieldset id=\"lastname\">";
  549. responseString += "<legend>Last Name:</legend>";
  550. responseString += "<input type=\"text\" size=\"15\" maxlength=\"100\" name=\"lastname\" value=\"[$lastname]\" />";
  551. responseString += "</fieldset>";
  552. responseString += "<fieldset id=\"password\">";
  553. responseString += "<legend>Password:</legend>";
  554. responseString += "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">";
  555. responseString += "<tr>";
  556. responseString += "<td colspan=\"2\"><input type=\"password\" size=\"15\" maxlength=\"100\" name=\"password\" value=\"[$password]\" /></td>";
  557. responseString += "</tr>";
  558. responseString += "<tr>";
  559. responseString += "<td valign=\"middle\"><input type=\"checkbox\" name=\"remember_password\" id=\"remember_password\" [$remember_password] style=\"margin-left:0px;\"/></td>";
  560. responseString += "<td><label for=\"remember_password\">Remember password</label></td>";
  561. responseString += "</tr>";
  562. responseString += "</table>";
  563. responseString += "</fieldset>";
  564. responseString += "<input type=\"hidden\" name=\"show_login_form\" value=\"FALSE\" />";
  565. responseString += "<input type=\"hidden\" name=\"method\" value=\"login\" />";
  566. responseString += "<input type=\"hidden\" id=\"grid\" name=\"grid\" value=\"[$grid]\" />";
  567. responseString += "<input type=\"hidden\" id=\"region\" name=\"region\" value=\"[$region]\" />";
  568. responseString += "<input type=\"hidden\" id=\"location\" name=\"location\" value=\"[$location]\" />";
  569. responseString += "<input type=\"hidden\" id=\"channel\" name=\"channel\" value=\"[$channel]\" />";
  570. responseString += "<input type=\"hidden\" id=\"version\" name=\"version\" value=\"[$version]\" />";
  571. responseString += "<input type=\"hidden\" id=\"lang\" name=\"lang\" value=\"[$lang]\" />";
  572. responseString += "<div id=\"submitbtn\">";
  573. responseString += "<input class=\"input_over\" type=\"submit\" value=\"Connect\" />";
  574. responseString += "</div>";
  575. responseString += "<div id=\"connecting\" style=\"visibility:hidden\"> Connecting...</div>";
  576. responseString += "<div id=\"helplinks\">";
  577. responseString += "<a href=\"#join now link\" target=\"_blank\"></a> | ";
  578. responseString += "<a href=\"#forgot password link\" target=\"_blank\"></a>";
  579. responseString += "</div>";
  580. responseString += "<div id=\"channelinfo\"> [$channel] | [$version]=[$lang]</div>";
  581. responseString += "</form>";
  582. responseString += "<script language=\"JavaScript\">";
  583. responseString += "document.getElementById('firstname_input').focus();";
  584. responseString += "</script>";
  585. responseString += "</div>";
  586. responseString += "</div>";
  587. responseString += "</body>";
  588. responseString += "</html>";
  589. return responseString;
  590. }
  591. /// <summary>
  592. /// Saves a target agent to the database
  593. /// </summary>
  594. /// <param name="profile">The users profile</param>
  595. /// <returns>Successful?</returns>
  596. public bool CommitAgent(ref UserProfileData profile)
  597. {
  598. return m_userManager.CommitAgent(ref profile);
  599. }
  600. /// <summary>
  601. /// Checks a user against it's password hash
  602. /// </summary>
  603. /// <param name="profile">The users profile</param>
  604. /// <param name="password">The supplied password</param>
  605. /// <returns>Authenticated?</returns>
  606. public virtual bool AuthenticateUser(UserProfileData profile, string password)
  607. {
  608. bool passwordSuccess = false;
  609. //m_log.InfoFormat("[LOGIN]: Authenticating {0} {1} ({2})", profile.FirstName, profile.SurName, profile.ID);
  610. // Web Login method seems to also occasionally send the hashed password itself
  611. // we do this to get our hash in a form that the server password code can consume
  612. // when the web-login-form submits the password in the clear (supposed to be over SSL!)
  613. if (!password.StartsWith("$1$"))
  614. password = "$1$" + Util.Md5Hash(password);
  615. password = password.Remove(0, 3); //remove $1$
  616. string s = Util.Md5Hash(password + ":" + profile.PasswordSalt);
  617. // Testing...
  618. //m_log.Info("[LOGIN]: SubHash:" + s + " userprofile:" + profile.passwordHash);
  619. //m_log.Info("[LOGIN]: userprofile:" + profile.passwordHash + " SubCT:" + password);
  620. passwordSuccess = (profile.PasswordHash.Equals(s.ToString(), StringComparison.InvariantCultureIgnoreCase)
  621. || profile.PasswordHash.Equals(password, StringComparison.InvariantCultureIgnoreCase));
  622. return passwordSuccess;
  623. }
  624. public virtual bool AuthenticateUser(UserProfileData profile, UUID webloginkey)
  625. {
  626. bool passwordSuccess = false;
  627. m_log.InfoFormat("[LOGIN]: Authenticating {0} {1} ({2})", profile.FirstName, profile.SurName, profile.ID);
  628. // Match web login key unless it's the default weblogin key UUID.Zero
  629. passwordSuccess = ((profile.WebLoginKey==webloginkey) && profile.WebLoginKey != UUID.Zero);
  630. return passwordSuccess;
  631. }
  632. /// <summary>
  633. ///
  634. /// </summary>
  635. /// <param name="profile"></param>
  636. /// <param name="request"></param>
  637. public void CreateAgent(UserProfileData profile, XmlRpcRequest request)
  638. {
  639. m_userManager.CreateAgent(profile, request);
  640. }
  641. public void CreateAgent(UserProfileData profile, OSD request)
  642. {
  643. m_userManager.CreateAgent(profile, request);
  644. }
  645. /// <summary>
  646. ///
  647. /// </summary>
  648. /// <param name="firstname"></param>
  649. /// <param name="lastname"></param>
  650. /// <returns></returns>
  651. public virtual UserProfileData GetTheUser(string firstname, string lastname)
  652. {
  653. return m_userManager.GetUserProfile(firstname, lastname);
  654. }
  655. /// <summary>
  656. ///
  657. /// </summary>
  658. /// <returns></returns>
  659. public virtual string GetMessage()
  660. {
  661. return m_welcomeMessage;
  662. }
  663. private static LoginResponse.BuddyList ConvertFriendListItem(List<FriendListItem> LFL)
  664. {
  665. LoginResponse.BuddyList buddylistreturn = new LoginResponse.BuddyList();
  666. foreach (FriendListItem fl in LFL)
  667. {
  668. LoginResponse.BuddyList.BuddyInfo buddyitem = new LoginResponse.BuddyList.BuddyInfo(fl.Friend);
  669. buddyitem.BuddyID = fl.Friend;
  670. buddyitem.BuddyRightsHave = (int)fl.FriendListOwnerPerms;
  671. buddyitem.BuddyRightsGiven = (int) fl.FriendPerms;
  672. buddylistreturn.AddNewBuddy(buddyitem);
  673. }
  674. return buddylistreturn;
  675. }
  676. /// <summary>
  677. /// Converts the inventory library skeleton into the form required by the rpc request.
  678. /// </summary>
  679. /// <returns></returns>
  680. protected virtual ArrayList GetInventoryLibrary()
  681. {
  682. Dictionary<UUID, InventoryFolderImpl> rootFolders
  683. = m_libraryRootFolder.RequestSelfAndDescendentFolders();
  684. ArrayList folderHashes = new ArrayList();
  685. foreach (InventoryFolderBase folder in rootFolders.Values)
  686. {
  687. Hashtable TempHash = new Hashtable();
  688. TempHash["name"] = folder.Name;
  689. TempHash["parent_id"] = folder.ParentID.ToString();
  690. TempHash["version"] = (Int32)folder.Version;
  691. TempHash["type_default"] = (Int32)folder.Type;
  692. TempHash["folder_id"] = folder.ID.ToString();
  693. folderHashes.Add(TempHash);
  694. }
  695. return folderHashes;
  696. }
  697. /// <summary>
  698. ///
  699. /// </summary>
  700. /// <returns></returns>
  701. protected virtual ArrayList GetLibraryOwner()
  702. {
  703. //for now create random inventory library owner
  704. Hashtable TempHash = new Hashtable();
  705. TempHash["agent_id"] = "11111111-1111-0000-0000-000100bba000";
  706. ArrayList inventoryLibOwner = new ArrayList();
  707. inventoryLibOwner.Add(TempHash);
  708. return inventoryLibOwner;
  709. }
  710. public class InventoryData
  711. {
  712. public ArrayList InventoryArray = null;
  713. public UUID RootFolderID = UUID.Zero;
  714. public InventoryData(ArrayList invList, UUID rootID)
  715. {
  716. InventoryArray = invList;
  717. RootFolderID = rootID;
  718. }
  719. }
  720. }
  721. }