diff --git a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs index 223900154f..e3a0321b21 100644 --- a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs +++ b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs @@ -86,6 +86,7 @@ namespace OpenSim.ApplicationPlugins.RemoteController m_httpd.AddXmlRPCHandler("admin_restart", XmlRpcRestartMethod); m_httpd.AddXmlRPCHandler("admin_load_heightmap", XmlRpcLoadHeightmapMethod); m_httpd.AddXmlRPCHandler("admin_create_user", XmlRpcCreateUserMethod); + m_httpd.AddXmlRPCHandler("admin_update_user", XmlRpcUpdateUserAccountMethod); m_httpd.AddXmlRPCHandler("admin_load_xml", XmlRpcLoadXMLMethod); } } @@ -564,6 +565,111 @@ namespace OpenSim.ApplicationPlugins.RemoteController return response; } + /// + /// Update the password of a user account. + /// + /// incoming XML RPC request + /// + /// XmlRpcUpdateUserAccountMethod takes the following XMLRPC + /// parameters + /// + /// parameter namedescription + /// password + /// admin password as set in OpenSim.ini + /// user_firstname + /// avatar's first name (cannot be changed) + /// user_lastname + /// avatar's last name (cannot be changed) + /// user_password + /// avatar's password (changeable) + /// start_region_x + /// avatar's start region coordinates, X + /// value (changeable) + /// start_region_y + /// avatar's start region coordinates, Y + /// value (changeable) + /// + /// + /// XmlRpcCreateUserMethod returns + /// + /// namedescription + /// success + /// true or false + /// error + /// error message if success is false + /// + /// + public XmlRpcResponse XmlRpcUpdateUserAccountMethod(XmlRpcRequest request) + { + m_log.Info("[RADMIN]: UpdateUserAccount: new request"); + XmlRpcResponse response = new XmlRpcResponse(); + Hashtable responseData = new Hashtable(); + + try + { + Hashtable requestData = (Hashtable) request.Params[0]; + + // check completeness + checkStringParameters(request, new string[] { "password", "user_firstname", + "user_lastname" }); + + // check password + if (!String.IsNullOrEmpty(requiredPassword) && + (string)requestData["password"] != requiredPassword) throw new Exception("wrong password"); + + // do the job + string firstname = (string) requestData["user_firstname"]; + string lastname = (string) requestData["user_lastname"]; + + + string passwd = String.Empty; + uint? regX = null; + uint? regY = null; + + if (requestData.ContainsKey("user_password")) passwd = (string) requestData["user_password"]; + if (requestData.ContainsKey("start_region_x")) regX = Convert.ToUInt32((Int32)requestData["start_region_x"]); + if (requestData.ContainsKey("start_region_y")) regY = Convert.ToUInt32((Int32)requestData["start_region_y"]); + + if (String.Empty == passwd && null == regX && null == regY) + throw new Exception("neither user_password nor start_region_x nor start_region_y provided"); + + UserProfileData userProfile = m_app.CommunicationsManager.UserService.GetUserProfile(firstname, lastname); + if (null == userProfile) + throw new Exception(String.Format("avatar {0} {1} does not exist", firstname, lastname)); + + if (null != passwd) + { + string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(passwd) + ":" + String.Empty); + userProfile.PasswordHash = md5PasswdHash; + } + + if (null != regX) userProfile.HomeRegionX = (uint)regX; + if (null != regY) userProfile.HomeRegionY = (uint)regY; + + if (!m_app.CommunicationsManager.UserService.UpdateUserProfile(userProfile)) + throw new Exception("did not manage to update user profile"); + + responseData["success"] = "true"; + + response.Value = responseData; + + m_log.InfoFormat("[RADMIN]: UpdateUserAccount: account for user {0} {1} updated, UUID {2}", firstname, lastname, + userProfile.ID); + } + catch (Exception e) + { + m_log.ErrorFormat("[RADMIN] UpdateUserAccount: failed: {0}", e.Message); + m_log.DebugFormat("[RADMIN] UpdateUserAccount: failed: {0}", e.ToString()); + + responseData["success"] = "false"; + responseData["error"] = e.Message; + + response.Value = responseData; + } + + return response; + } + public XmlRpcResponse XmlRpcLoadXMLMethod(XmlRpcRequest request) { m_log.Info("[RADMIN]: Received Load XML Administrator Request"); diff --git a/OpenSim/Framework/Communications/IUserService.cs b/OpenSim/Framework/Communications/IUserService.cs index 6ad72c0263..c1ae0e208a 100644 --- a/OpenSim/Framework/Communications/IUserService.cs +++ b/OpenSim/Framework/Communications/IUserService.cs @@ -64,6 +64,13 @@ namespace OpenSim.Framework.Communications /// LLUUID AddUserProfile(string firstName, string lastName, string pass, uint regX, uint regY); + /// + /// Update the user's profile. + /// + /// UserProfileData object with updated data. Should be obtained + /// via a call to GetUserProfile(). + /// true if the update could be applied, false if it could not be applied. + bool UpdateUserProfile(UserProfileData data); /// /// Adds a new friend to the database for XUser diff --git a/OpenSim/Framework/Communications/UserManagerBase.cs b/OpenSim/Framework/Communications/UserManagerBase.cs index d5b1e74e89..1b73152e35 100644 --- a/OpenSim/Framework/Communications/UserManagerBase.cs +++ b/OpenSim/Framework/Communications/UserManagerBase.cs @@ -153,11 +153,11 @@ namespace OpenSim.Framework.Communications } /// - /// Set's user profile from data object + /// Updates a user profile from data object /// /// /// - public bool SetUserProfile(UserProfileData data) + public bool UpdateUserProfile(UserProfileData data) { foreach (KeyValuePair plugin in _plugins) { @@ -168,7 +168,8 @@ namespace OpenSim.Framework.Communications } catch (Exception e) { - m_log.Info("[USERSTORAGE]: Unable to set user via " + plugin.Key + "(" + e.ToString() + ")"); + m_log.InfoFormat("[USERSTORAGE]: Unable to set user {0} {1} via {2}: {3}", data.FirstName, data.SurName, + plugin.Key, e.ToString()); } } return false; @@ -352,7 +353,7 @@ namespace OpenSim.Framework.Communications UserProfileData profile = GetUserProfile(agentID); profile.CurrentAgent = null; - SetUserProfile(profile); + UpdateUserProfile(profile); } @@ -539,7 +540,7 @@ namespace OpenSim.Framework.Communications // TODO: what is the logic should be? bool ret = false; ret = AddUserAgent(profile.CurrentAgent); - ret = ret & SetUserProfile(profile); + ret = ret & UpdateUserProfile(profile); return ret; } diff --git a/OpenSim/Region/Communications/OGS1/OGS1UserServices.cs b/OpenSim/Region/Communications/OGS1/OGS1UserServices.cs index 307751ec72..852fe5b617 100644 --- a/OpenSim/Region/Communications/OGS1/OGS1UserServices.cs +++ b/OpenSim/Region/Communications/OGS1/OGS1UserServices.cs @@ -437,6 +437,12 @@ namespace OpenSim.Region.Communications.OGS1 throw new Exception("The method or operation is not implemented."); } + // TODO + public bool UpdateUserProfile(UserProfileData data) + { + return false; + } + public bool UpdateUserProfileProperties(UserProfileData UserProfile) { m_log.Debug("[OGS1 USER SERVICES]: Asking UserServer to update profile.");