From ae490c7d6f74ec4dd3a29cc7d0aeab1d875ca4fa Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Fri, 4 Apr 2008 11:48:27 +0000 Subject: From: Dr Scofield ansgar and i have done a bit of clean up for the "create user" and "create region" XmlRpc methods in RemoteController (contributed earlier by ansgar), this add a bit of consistency checking, more error checking and also documentation of the expected XmlRpc parameters. --- .../RemoteController/RemoteAdminPlugin.cs | 334 ++++++++++++++------- 1 file changed, 231 insertions(+), 103 deletions(-) (limited to 'OpenSim/ApplicationPlugins/RemoteController') diff --git a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs index cfd3885..9d4bfea 100644 --- a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs +++ b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs @@ -28,6 +28,7 @@ using System; using System.Collections; using System.Net; +using System.IO; using System.Timers; using libsecondlife; using Mono.Addins; @@ -233,104 +234,228 @@ namespace OpenSim.ApplicationPlugins.LoadRegions m_app.Shutdown(); } + /// + /// Create a new region. + /// + /// incoming XML RPC request + /// + /// XmlRpcCreateRegionMethod takes the following XMLRPC + /// parameters + /// + /// parameter namedescription + /// password + /// admin password as set in OpenSim.ini + /// region_name + /// desired region name + /// region_id + /// (optional) desired region UUID + /// region_x + /// desired region X coordinate + /// region_y + /// desired region Y coordinate + /// region_master_first + /// firstname of region master + /// region_master_last + /// lastname of region master + /// listen_ip + /// internal IP address + /// listen_port + /// internal port + /// external_address + /// external IP address + /// datastore + /// datastore parameter (?) + /// + /// + /// XmlRpcCreateRegionMethod returns + /// + /// namedescription + /// success + /// true or false + /// error + /// error message if success is false + /// region_uuid + /// UUID of the newly created region + /// region_name + /// name of the newly created region + /// + /// public XmlRpcResponse XmlRpcCreateRegionMethod(XmlRpcRequest request) { m_log.Info("[RADMIN]: Received Create Region Administrator Request"); XmlRpcResponse response = new XmlRpcResponse(); Hashtable requestData = (Hashtable) request.Params[0]; Hashtable responseData = new Hashtable(); - if (requiredPassword != System.String.Empty && - (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword)) - { - responseData["created"] = "false"; - response.Value = responseData; - } - else - { - RegionInfo newRegionData = new RegionInfo(); - try + try { + // check completeness + foreach (string p in new string[] { "password", + "region_name", "region_x", "region_y", + "region_master_first", "region_master_last", + "listen_ip", "listen_port", "external_address"}) { - newRegionData.RegionID = (string) requestData["region_id"]; - newRegionData.RegionName = (string) requestData["region_name"]; - newRegionData.RegionLocX = Convert.ToUInt32((Int32) requestData["region_x"]); - newRegionData.RegionLocY = Convert.ToUInt32((Int32) requestData["region_y"]); - - // Security risk - newRegionData.DataStore = (string) requestData["datastore"]; + if (!requestData.Contains(p)) + throw new Exception(String.Format("missing parameter {0}", p)); + } - newRegionData.InternalEndPoint = new IPEndPoint( - IPAddress.Parse((string) requestData["listen_ip"]), 0); + // check password + if (!String.IsNullOrEmpty(requiredPassword) && + (string)requestData["password"] != requiredPassword) throw new Exception("wrong password"); + + // bool persist = Convert.ToBoolean((string)requestData["persist"]); + RegionInfo region = null; + // if (!persist) + // { + // region = new RegionInfo(); + // } + // else + // { + // region = new RegionInfo("DEFAULT REGION CONFIG", + // Path.Combine(regionConfigPath, "default.xml"), false); + // } + region = new RegionInfo(); + + + if (requestData.ContainsKey("region_id") && + !String.IsNullOrEmpty((string) requestData["region_id"])) + { + // FIXME: need to check whether region_id already + // in use + region.RegionID = (string) requestData["region_id"]; + } + else + { + region.RegionID = LLUUID.Random(); + } - newRegionData.InternalEndPoint.Port = (Int32) requestData["listen_port"]; - newRegionData.ExternalHostName = (string) requestData["external_address"]; + // FIXME: need to check whether region_name already + // in use + region.RegionName = (string) requestData["region_name"]; + region.RegionLocX = Convert.ToUInt32((Int32) requestData["region_x"]); + region.RegionLocY = Convert.ToUInt32((Int32) requestData["region_y"]); + + // Security risk + if (requestData.ContainsKey("datastore")) + region.DataStore = (string) requestData["datastore"]; + + region.InternalEndPoint = + new IPEndPoint(IPAddress.Parse((string) requestData["listen_ip"]), 0); + + // FIXME: need to check whether listen_port already in use! + region.InternalEndPoint.Port = (Int32) requestData["listen_port"]; + region.ExternalHostName = (string) requestData["external_address"]; + + region.MasterAvatarFirstName = (string) requestData["region_master_first"]; + region.MasterAvatarLastName = (string) requestData["region_master_last"]; + + m_app.CreateRegion(region, true); - newRegionData.MasterAvatarFirstName = (string) requestData["region_master_first"]; - newRegionData.MasterAvatarLastName = (string) requestData["region_master_last"]; + responseData["success"] = "true"; + responseData["region_name"] = region.RegionName; + responseData["region_uuid"] = region.RegionID.ToString(); - m_app.CreateRegion(newRegionData, true); + response.Value = responseData; + } + catch (Exception e) + { + responseData["success"] = "false"; + responseData["error"] = e.Message; - responseData["created"] = "true"; - response.Value = responseData; - } - catch (Exception e) - { - responseData["created"] = "false"; - responseData["error"] = e.ToString(); - response.Value = responseData; - } + response.Value = responseData; } return response; } + /// + /// Create a new user account. + /// + /// incoming XML RPC request + /// + /// XmlRpcCreateUserMethod takes the following XMLRPC + /// parameters + /// + /// parameter namedescription + /// password + /// admin password as set in OpenSim.ini + /// user_firstname + /// avatar's first name + /// user_lastname + /// avatar's last name + /// user_password + /// avatar's password + /// start_region_x + /// avatar's start region coordinates, X value + /// start_region_y + /// avatar's start region coordinates, Y value + /// + /// + /// XmlRpcCreateUserMethod returns + /// + /// namedescription + /// success + /// true or false + /// error + /// error message if success is false + /// avatar_uuid + /// UUID of the newly created avatar + /// account; LLUUID.Zero if failed. + /// + /// + /// public XmlRpcResponse XmlRpcCreateUserMethod(XmlRpcRequest request) { m_log.Info("[RADMIN]: Received Create User Administrator Request"); XmlRpcResponse response = new XmlRpcResponse(); Hashtable requestData = (Hashtable) request.Params[0]; Hashtable responseData = new Hashtable(); - if (requiredPassword != System.String.Empty && - (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword)) + + try { - responseData["created"] = "false"; + // check completeness + foreach (string p in new string[] { "password", + "user_firstname", "user_lastname", "user_password", + "start_region_x", "start_region_y" }) + { + if (!requestData.Contains(p)) + throw new Exception(String.Format("missing parameter {0}", p)); + } + + // 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) requestData["user_password"]; + uint regX = Convert.ToUInt32((Int32)requestData["start_region_x"]); + uint regY = Convert.ToUInt32((Int32)requestData["start_region_y"]); + + // FIXME: need to check whether "firstname lastname" + // already exists! + LLUUID userID = m_app.CreateUser(firstname, lastname, passwd, regX, regY); + + if (userID == LLUUID.Zero) throw new Exception(String.Format("failed to create new user {0} {1}", + firstname, lastname)); + + responseData["success"] = "true"; + responseData["avatar_uuid"] = userID.ToString(); + response.Value = responseData; + + m_log.InfoFormat("[RADMIN]: User {0} {1} created, UUID {2}", firstname, lastname, userID); } - else + catch (Exception e) { - try - { - string tempfirstname = (string) requestData["user_firstname"]; - string templastname = (string) requestData["user_lastname"]; - string tempPasswd = (string) requestData["user_password"]; - uint regX = Convert.ToUInt32((Int32) requestData["start_region_x"]); - uint regY = Convert.ToUInt32((Int32) requestData["start_region_y"]); - - LLUUID tempuserID = m_app.CreateUser(tempfirstname, templastname, tempPasswd, regX, regY); - - if (tempuserID == LLUUID.Zero) - { - responseData["created"] = "false"; - responseData["error"] = "Error creating user"; - responseData["avatar_uuid"] = LLUUID.Zero; - response.Value = responseData; - m_log.Error("[RADMIN]: Error creating user (" + tempfirstname + " " + templastname + ") :"); - } - else - { - responseData["created"] = "true"; - responseData["avatar_uuid"] = tempuserID; - response.Value = responseData; - m_log.Info("[RADMIN]: User " + tempfirstname + " " + templastname + " created. Userid " + tempuserID + " assigned."); - } - } - catch (Exception e) - { - responseData["created"] = "false"; - responseData["error"] = e.ToString(); - responseData["avatar_uuid"] = LLUUID.Zero; - response.Value = responseData; - } + m_log.ErrorFormat("[RADMIN] create user: failed: {0}", e.Message); + m_log.DebugFormat("[RADMIN] create user: failed: {0}", e.ToString()); + + responseData["success"] = "false"; + responseData["avatar_uuid"] = LLUUID.Zero.ToString(); + responseData["error"] = e.Message; + + response.Value = responseData; } return response; @@ -342,42 +467,45 @@ namespace OpenSim.ApplicationPlugins.LoadRegions XmlRpcResponse response = new XmlRpcResponse(); Hashtable requestData = (Hashtable) request.Params[0]; Hashtable responseData = new Hashtable(); - if (requiredPassword != System.String.Empty && - (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword)) - { - responseData["loaded"] = "false"; - responseData["switched"] = "false"; - response.Value = responseData; - } - else + + try { - try - { - string region_name = (string) requestData["region_name"]; - string filename = (string) requestData["filename"]; - - if (m_app.SceneManager.TrySetCurrentScene(region_name)) - { - m_log.Info("[RADMIN] Switched to region "+region_name); - responseData["switched"] = "true"; - m_app.SceneManager.LoadCurrentSceneFromXml(filename, true, new LLVector3(0, 0, 0)); - responseData["loaded"] = "true"; - response.Value = responseData; - } - else - { - m_log.Info("[RADMIN] Failed to switch to region "+region_name); - responseData["loaded"] = "false"; - responseData["switched"] = "false"; - response.Value = responseData; - } - } - catch (Exception e) + // check completeness + foreach (string p in new string[] { "password", + "region_name", "filename" }) { - responseData["loaded"] = "false"; - responseData["error"] = e.ToString(); - response.Value = responseData; + if (!requestData.Contains(p)) + throw new Exception(String.Format("missing parameter {0}", p)); } + + // check password + if (!String.IsNullOrEmpty(requiredPassword) && + (string)requestData["password"] != requiredPassword) throw new Exception("wrong password"); + + string region_name = (string)requestData["region_name"]; + string filename = (string)requestData["filename"]; + + if (!m_app.SceneManager.TrySetCurrentScene(region_name)) + throw new Exception(String.Format("failed to switch to region {0}", region_name)); + m_log.InfoFormat("[RADMIN] Switched to region {0}"); + + responseData["switched"] = "true"; + + m_app.SceneManager.LoadCurrentSceneFromXml(filename, true, new LLVector3(0, 0, 0)); + responseData["loaded"] = "true"; + + response.Value = responseData; + } + catch (Exception e) + { + m_log.InfoFormat("[RADMIN] LoadXml: {0}", e.Message); + m_log.DebugFormat("[RADMIN] LoadXML {0}: {1}", e.ToString()); + + responseData["loaded"] = "false"; + responseData["switched"] = "false"; + responseData["error"] = e.Message; + + response.Value = responseData; } return response; -- cgit v1.1