LoginService.cs 35 KB

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