From 85fe8ed0857c075ebefabbad8a670499e047f41a Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Wed, 9 Jan 2008 22:05:28 +0000 Subject: [PATCH] * This update enables the web_login method. * Remember, the client doesn't support web_login to other grids in the current RC, however the next RC will. --- .../Framework/Communications/LoginService.cs | 148 ++++++++++++++++-- OpenSim/Framework/Servers/BaseHttpServer.cs | 7 +- OpenSim/Grid/UserServer/Main.cs | 2 + OpenSim/Region/Application/OpenSimMain.cs | 6 + .../Communications/Local/LocalLoginService.cs | 7 +- bin/http_loginform.html.example | 60 +++++++ 6 files changed, 210 insertions(+), 20 deletions(-) create mode 100644 bin/http_loginform.html.example diff --git a/OpenSim/Framework/Communications/LoginService.cs b/OpenSim/Framework/Communications/LoginService.cs index f0a0a0b66a..04b8501223 100644 --- a/OpenSim/Framework/Communications/LoginService.cs +++ b/OpenSim/Framework/Communications/LoginService.cs @@ -30,6 +30,7 @@ using System; using System.Collections; using System.Collections.Generic; using System.IO; +using System.Text.RegularExpressions; using System.Threading; using libsecondlife; using libsecondlife.StructuredData; @@ -359,21 +360,103 @@ namespace OpenSim.Framework.UserManagement public Hashtable ProcessHTMLLogin(Hashtable keysvals) { + + // Matches all unspecified characters + // Currently specified,; lowercase letters, upper case letters, numbers, underline + // period, space, parens, and dash. + + Regex wfcut = new Regex("[^a-zA-Z0-9_\\.\\$ \\(\\)\\-]"); + Hashtable returnactions = new Hashtable(); int statuscode = 200; - returnactions["int_response_code"] = statuscode; - returnactions["str_response_string"] = GetDefaultLoginForm(); + string firstname = ""; + string lastname = ""; + string location = ""; + string region =""; + string grid = ""; + string channel = ""; + string version = ""; + string lang = ""; + string password = ""; + string errormessages = ""; + + // the client requires the HTML form field be named 'username' + // however, the data it sends when it loads the first time is 'firstname' + // another one of those little nuances. + + + if (keysvals.Contains("firstname")) + firstname = wfcut.Replace((string)keysvals["firstname"],"",99999); + if (keysvals.Contains("username")) + firstname = wfcut.Replace((string)keysvals["username"],"",99999); + + if (keysvals.Contains("lastname")) + lastname = wfcut.Replace((string)keysvals["lastname"],"",99999); + + if (keysvals.Contains("location")) + location = wfcut.Replace((string)keysvals["location"],"",99999); + + if (keysvals.Contains("region")) + region = wfcut.Replace((string)keysvals["region"],"",99999); + + if (keysvals.Contains("grid")) + grid = wfcut.Replace((string)keysvals["grid"],"",99999); + + if (keysvals.Contains("channel")) + channel = wfcut.Replace((string)keysvals["channel"],"",99999); + + if (keysvals.Contains("version")) + version = wfcut.Replace((string)keysvals["version"],"",99999); + + if (keysvals.Contains("lang")) + lang = wfcut.Replace((string)keysvals["lang"],"",99999); + + if (keysvals.Contains("password")) + password = wfcut.Replace((string)keysvals["password"], "", 99999); + + + // load our login form. + string loginform = GetLoginForm(firstname,lastname,location,region,grid,channel,version,lang,password,errormessages); if (keysvals.ContainsKey("show_login_form")) { if ((string)keysvals["show_login_form"] == "TRUE") { - + returnactions["int_response_code"] = statuscode; + returnactions["str_response_string"] = loginform; } else { + UserProfileData user = GetTheUser(firstname, lastname); + bool goodweblogin = false; + if (user != null) + goodweblogin = AuthenticateUser(user, password); + + if (goodweblogin) + { + LLUUID webloginkey = LLUUID.Random(); + m_userManager.StoreWebLoginKey(user.UUID, webloginkey); + statuscode = 301; + + string redirectURL = "secondlife:///app/login?first_name=" + firstname + "&last_name=" + + lastname + + "&location=" + location + "&grid=Other&web_login_key=" + webloginkey.ToString(); + + returnactions["int_response_code"] = statuscode; + returnactions["str_redirect_location"] = redirectURL; + returnactions["str_response_string"] = "GoodLogin"; + } + else + { + errormessages = "The Username and password supplied did not match our records. Check your caps lock and try again"; + + loginform = GetLoginForm(firstname, lastname, location, region, grid, channel, version, lang, password, errormessages); + returnactions["int_response_code"] = statuscode; + returnactions["str_response_string"] = loginform; + + } } @@ -382,16 +465,36 @@ namespace OpenSim.Framework.UserManagement } - public string GetLoginForm() + public string GetLoginForm(string firstname, string lastname, string location, string region, + string grid, string channel, string version, string lang, + string password, string errormessages) { + // inject our values in the form at the markers + + string loginform=""; string file = Path.Combine(Util.configDir(), "http_loginform.html"); if (!File.Exists(file)) - return GetDefaultLoginForm(); - - StreamReader sr = File.OpenText(file); - string result = sr.ReadToEnd(); - sr.Close(); - return result; + { + loginform = GetDefaultLoginForm(); + } + else + { + StreamReader sr = File.OpenText(file); + loginform = sr.ReadToEnd(); + sr.Close(); + } + + loginform = loginform.Replace("[$firstname]", firstname); + loginform = loginform.Replace("[$lastname]", lastname); + loginform = loginform.Replace("[$location]", location); + loginform = loginform.Replace("[$region]", region); + loginform = loginform.Replace("[$grid]", grid); + loginform = loginform.Replace("[$channel]", channel); + loginform = loginform.Replace("[$version]", version); + loginform = loginform.Replace("[$lang]", lang); + loginform = loginform.Replace("[$password]", password); + loginform = loginform.Replace("[$errors]", errormessages); + return loginform; } public string GetDefaultLoginForm() @@ -405,7 +508,7 @@ namespace OpenSim.Framework.UserManagement responseString = responseString + ""; responseString = responseString + ""; responseString = responseString + "Second Life Login"; - responseString = responseString + ""; + responseString = responseString + "
"; responseString = responseString + "
"; responseString = responseString + "
"; @@ -434,6 +537,11 @@ namespace OpenSim.Framework.UserManagement responseString = responseString + ""; responseString = responseString + ""; responseString = responseString + ""; + responseString = responseString + ""; + responseString = responseString + ""; + responseString = responseString + ""; + responseString = responseString + ""; + responseString = responseString + ""; responseString = responseString + "
"; responseString = responseString + ""; responseString = responseString + "
"; @@ -444,7 +552,7 @@ namespace OpenSim.Framework.UserManagement responseString = responseString + "Forgot password?"; responseString = responseString + "
"; - responseString = responseString + "
[$clientchannelinfo] | [$clientversion]=[$clientlanguage]
"; + responseString = responseString + "
[$channel] | [$version]=[$lang]
"; responseString = responseString + ""; responseString = responseString + " + + + + \ No newline at end of file