From fc6c4dc399587f6f920d3f0759b1bd7a8b9b4ac8 Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Thu, 1 May 2008 16:41:01 +0000 Subject: * Cleaning code still. --- .../RemoteController/RemoteAdminPlugin.cs | 216 +++++++++++---------- 1 file changed, 116 insertions(+), 100 deletions(-) (limited to 'OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs') diff --git a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs index e540e4d..b7067e7 100644 --- a/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs +++ b/OpenSim/ApplicationPlugins/RemoteController/RemoteAdminPlugin.cs @@ -54,11 +54,13 @@ namespace OpenSim.ApplicationPlugins.RemoteController private BaseHttpServer m_httpd; private string requiredPassword = String.Empty; + #region IApplicationPlugin Members + public void Initialise(OpenSimMain openSim) { try { - if (openSim.ConfigSource.Configs["RemoteAdmin"] != null && + if (openSim.ConfigSource.Configs["RemoteAdmin"] != null && openSim.ConfigSource.Configs["RemoteAdmin"].GetBoolean("enabled", false)) { m_log.Info("[RADMIN]: Remote Admin Plugin Enabled"); @@ -82,6 +84,12 @@ namespace OpenSim.ApplicationPlugins.RemoteController } } + public void Close() + { + } + + #endregion + public XmlRpcResponse XmlRpcRestartMethod(XmlRpcRequest request) { XmlRpcResponse response = new XmlRpcResponse(); @@ -90,13 +98,14 @@ namespace OpenSim.ApplicationPlugins.RemoteController Hashtable responseData = new Hashtable(); m_log.Info("[RADMIN]: Request to restart Region."); - try { - checkStringParameters(request, new string[] { "password", "regionID" }); + try + { + checkStringParameters(request, new[] {"password", "regionID"}); if (requiredPassword != String.Empty && (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword)) throw new Exception("wrong password"); - + LLUUID regionID = new LLUUID((string) requestData["regionID"]); responseData["accepted"] = "true"; @@ -106,11 +115,11 @@ namespace OpenSim.ApplicationPlugins.RemoteController if (!m_app.SceneManager.TryGetScene(regionID, out rebootedScene)) throw new Exception("region not found"); - + responseData["rebooting"] = "true"; rebootedScene.Restart(30); - } - catch(Exception e) + } + catch (Exception e) { m_log.ErrorFormat("[RADMIN]: Restart region: failed: {0}", e.Message); m_log.DebugFormat("[RADMIN]: Restart region: failed: {0}", e.ToString()); @@ -130,13 +139,14 @@ namespace OpenSim.ApplicationPlugins.RemoteController Hashtable requestData = (Hashtable) request.Params[0]; Hashtable responseData = new Hashtable(); - try { - checkStringParameters(request, new string[] { "password", "message" }); + try + { + checkStringParameters(request, new[] {"password", "message"}); if (requiredPassword != String.Empty && (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword)) throw new Exception("wrong password"); - + string message = (string) requestData["message"]; m_log.InfoFormat("[RADMIN]: Broadcasting: {0}", message); @@ -145,7 +155,7 @@ namespace OpenSim.ApplicationPlugins.RemoteController m_app.SceneManager.SendGeneralMessage(message); } - catch(Exception e) + catch (Exception e) { m_log.ErrorFormat("[RADMIN]: Broadcasting: failed: {0}", e.Message); m_log.DebugFormat("[RADMIN]: Broadcasting: failed: {0}", e.ToString()); @@ -162,24 +172,25 @@ namespace OpenSim.ApplicationPlugins.RemoteController public XmlRpcResponse XmlRpcLoadHeightmapMethod(XmlRpcRequest request) { XmlRpcResponse response = new XmlRpcResponse(); - Hashtable requestData = (Hashtable)request.Params[0]; + Hashtable requestData = (Hashtable) request.Params[0]; m_log.DebugFormat("[RADMIN]: Load Terrain: XmlRpc {0}", request.ToString()); foreach (string k in requestData.Keys) { - m_log.DebugFormat("[RADMIN]: Load Terrain: XmlRpc {0}: >{1}< {2}", - k, (string)requestData[k], ((string)requestData[k]).Length); + m_log.DebugFormat("[RADMIN]: Load Terrain: XmlRpc {0}: >{1}< {2}", + k, requestData[k], ((string) requestData[k]).Length); } Hashtable responseData = new Hashtable(); - try { - checkStringParameters(request, new string[] { "password", "filename", "regionid"}); + try + { + checkStringParameters(request, new[] {"password", "filename", "regionid"}); if (requiredPassword != String.Empty && - (!requestData.Contains("password") || (string)requestData["password"] != requiredPassword)) + (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword)) throw new Exception("wrong password"); - string file = (string)requestData["filename"]; + string file = (string) requestData["filename"]; LLUUID regionID = (string) requestData["regionid"]; m_log.InfoFormat("[RADMIN]: Terrain Loading: {0}", file); @@ -198,7 +209,7 @@ namespace OpenSim.ApplicationPlugins.RemoteController response.Value = responseData; } - catch (Exception e) + catch (Exception e) { m_log.ErrorFormat("[RADMIN] Terrain Loading: failed: {0}", e.Message); m_log.DebugFormat("[RADMIN] Terrain Loading: failed: {0}", e.ToString()); @@ -217,7 +228,8 @@ namespace OpenSim.ApplicationPlugins.RemoteController Hashtable requestData = (Hashtable) request.Params[0]; Hashtable responseData = new Hashtable(); - try { + try + { if (requiredPassword != String.Empty && (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword)) throw new Exception("wrong password"); @@ -227,14 +239,14 @@ namespace OpenSim.ApplicationPlugins.RemoteController int timeout = 2000; - if (requestData.ContainsKey("shutdown") && + if (requestData.ContainsKey("shutdown") && ((string) requestData["shutdown"] == "delayed") && requestData.ContainsKey("milliseconds")) { timeout = (Int32) requestData["milliseconds"]; - m_app.SceneManager.SendGeneralMessage("Region is going down in " + ((int) (timeout/1000)).ToString() + + m_app.SceneManager.SendGeneralMessage("Region is going down in " + ((timeout / 1000)) + " second(s). Please save what you are doing and log out."); - } + } else { m_app.SceneManager.SendGeneralMessage("Region is going down now."); @@ -243,12 +255,12 @@ namespace OpenSim.ApplicationPlugins.RemoteController // Perform shutdown Timer shutdownTimer = new Timer(timeout); // Wait before firing shutdownTimer.AutoReset = false; - shutdownTimer.Elapsed += new ElapsedEventHandler(shutdownTimer_Elapsed); + shutdownTimer.Elapsed += shutdownTimer_Elapsed; shutdownTimer.Start(); responseData["success"] = "true"; } - catch (Exception e) + catch (Exception e) { m_log.ErrorFormat("[RADMIN] Shutdown: failed: {0}", e.Message); m_log.DebugFormat("[RADMIN] Shutdown: failed: {0}", e.ToString()); @@ -272,9 +284,9 @@ namespace OpenSim.ApplicationPlugins.RemoteController Hashtable requestData = (Hashtable) request.Params[0]; foreach (string p in param) { - if (!requestData.Contains(p)) + if (!requestData.Contains(p)) throw new Exception(String.Format("missing string parameter {0}", p)); - if (String.IsNullOrEmpty((string)requestData[p])) + if (String.IsNullOrEmpty((string) requestData[p])) throw new Exception(String.Format("parameter {0} is empty", p)); } } @@ -284,7 +296,7 @@ namespace OpenSim.ApplicationPlugins.RemoteController Hashtable requestData = (Hashtable) request.Params[0]; foreach (string p in param) { - if (!requestData.Contains(p)) + if (!requestData.Contains(p)) throw new Exception(String.Format("missing integer parameter {0}", p)); } } @@ -345,31 +357,35 @@ namespace OpenSim.ApplicationPlugins.RemoteController Hashtable requestData = (Hashtable) request.Params[0]; Hashtable responseData = new Hashtable(); - try { - checkStringParameters(request, new string[] { "password", - "region_name", - "region_master_first", "region_master_last", - "region_master_password", - "listen_ip", "external_address"}); - checkIntegerParams(request, new string[] { "region_x", "region_y", "listen_port"}); + try + { + checkStringParameters(request, new[] + { + "password", + "region_name", + "region_master_first", "region_master_last", + "region_master_password", + "listen_ip", "external_address" + }); + checkIntegerParams(request, new[] {"region_x", "region_y", "listen_port"}); // check password if (!String.IsNullOrEmpty(requiredPassword) && - (string)requestData["password"] != requiredPassword) throw new Exception("wrong password"); + (string) requestData["password"] != requiredPassword) throw new Exception("wrong password"); // extract or generate region ID now Scene scene = null; LLUUID regionID = LLUUID.Zero; - if (requestData.ContainsKey("region_id") && - !String.IsNullOrEmpty((string)requestData["region_id"])) + if (requestData.ContainsKey("region_id") && + !String.IsNullOrEmpty((string) requestData["region_id"])) { regionID = (string) requestData["region_id"]; - if (m_app.SceneManager.TryGetScene(regionID, out scene)) + if (m_app.SceneManager.TryGetScene(regionID, out scene)) throw new Exception(String.Format("region UUID already in use by region {0}, UUID {1}, <{2},{3}>", scene.RegionInfo.RegionName, scene.RegionInfo.RegionID, scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY)); - } - else + } + else { regionID = LLUUID.Random(); m_log.DebugFormat("[RADMIN] CreateRegion: new region UUID {0}", regionID); @@ -385,7 +401,7 @@ namespace OpenSim.ApplicationPlugins.RemoteController // check for collisions: region name, region UUID, // region location - if (m_app.SceneManager.TryGetScene(region.RegionName, out scene)) + if (m_app.SceneManager.TryGetScene(region.RegionName, out scene)) throw new Exception(String.Format("region name already in use by region {0}, UUID {1}, <{2},{3}>", scene.RegionInfo.RegionName, scene.RegionInfo.RegionID, scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY)); @@ -395,46 +411,46 @@ namespace OpenSim.ApplicationPlugins.RemoteController region.RegionLocX, region.RegionLocY, scene.RegionInfo.RegionName, scene.RegionInfo.RegionID, scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY)); - + // Security risk [and apparently not used] // if (requestData.ContainsKey("datastore")) // region.DataStore = (string) requestData["datastore"]; - region.InternalEndPoint = + region.InternalEndPoint = new IPEndPoint(IPAddress.Parse((string) requestData["listen_ip"]), 0); - + region.InternalEndPoint.Port = (Int32) requestData["listen_port"]; if (0 == region.InternalEndPoint.Port) throw new Exception("listen_port is 0"); if (m_app.SceneManager.TryGetScene(region.InternalEndPoint, out scene)) throw new Exception(String.Format("region internal IP {0} and port {1} already in use by region {2}, UUID {3}, <{4},{5}>", - region.InternalEndPoint.Address, + region.InternalEndPoint.Address, region.InternalEndPoint.Port, scene.RegionInfo.RegionName, scene.RegionInfo.RegionID, scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY)); - + region.ExternalHostName = (string) requestData["external_address"]; - + region.MasterAvatarFirstName = (string) requestData["region_master_first"]; region.MasterAvatarLastName = (string) requestData["region_master_last"]; region.MasterAvatarSandboxPassword = (string) requestData["region_master_password"]; - bool persist = Convert.ToBoolean((string)requestData["persist"]); - if (persist) + bool persist = Convert.ToBoolean((string) requestData["persist"]); + if (persist) { string regionConfigPath = Path.Combine(Path.Combine(Util.configDir(), "Regions"), String.Format("{0}x{1}-{2}.xml", - region.RegionLocX.ToString(), - region.RegionLocY.ToString(), - regionID.ToString())); - m_log.DebugFormat("[RADMIN] CreateRegion: persisting region {0} to {1}", + region.RegionLocX, + region.RegionLocY, + regionID)); + m_log.DebugFormat("[RADMIN] CreateRegion: persisting region {0} to {1}", region.RegionID, regionConfigPath); region.SaveRegionToFile("dynamic region", regionConfigPath); } - + m_app.CreateRegion(region); - responseData["success"] = "true"; + responseData["success"] = "true"; responseData["region_name"] = region.RegionName; responseData["region_uuid"] = region.RegionID.ToString(); @@ -497,48 +513,52 @@ namespace OpenSim.ApplicationPlugins.RemoteController Hashtable requestData = (Hashtable) request.Params[0]; Hashtable responseData = new Hashtable(); - try + try { // check completeness - checkStringParameters(request, new string[] { "password", "user_firstname", - "user_lastname", "user_password" }); - checkIntegerParams(request, new string[] { "start_region_x", "start_region_y" }); + checkStringParameters(request, new[] + { + "password", "user_firstname", + "user_lastname", "user_password" + }); + checkIntegerParams(request, new[] {"start_region_x", "start_region_y"}); // check password if (!String.IsNullOrEmpty(requiredPassword) && - (string)requestData["password"] != requiredPassword) throw new Exception("wrong password"); + (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"]); - + 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"]); + UserProfileData userProfile = m_app.CommunicationsManager.UserService.GetUserProfile(firstname, lastname); - if (null != userProfile) + if (null != userProfile) throw new Exception(String.Format("avatar {0} {1} already exists", firstname, lastname)); 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"; + + 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]: CreateUser: User {0} {1} created, UUID {2}", firstname, lastname, userID); } - catch (Exception e) + catch (Exception e) { m_log.ErrorFormat("[RADMIN] CreateUser: failed: {0}", e.Message); m_log.DebugFormat("[RADMIN] CreateUser: failed: {0}", e.ToString()); - responseData["success"] = "false"; + responseData["success"] = "false"; responseData["avatar_uuid"] = LLUUID.Zero.ToString(); - responseData["error"] = e.Message; + responseData["error"] = e.Message; response.Value = responseData; } @@ -553,33 +573,33 @@ namespace OpenSim.ApplicationPlugins.RemoteController Hashtable requestData = (Hashtable) request.Params[0]; Hashtable responseData = new Hashtable(); - try + try { // check completeness - foreach (string p in new string[] { "password", "filename" }) + foreach (string p in new[] {"password", "filename"}) { - if (!requestData.Contains(p)) + if (!requestData.Contains(p)) throw new Exception(String.Format("missing parameter {0}", p)); - if (String.IsNullOrEmpty((string)requestData[p])) + if (String.IsNullOrEmpty((string) requestData[p])) throw new Exception(String.Format("parameter {0} is empty")); } - + // check password if (!String.IsNullOrEmpty(requiredPassword) && - (string)requestData["password"] != requiredPassword) throw new Exception("wrong password"); - - string filename = (string)requestData["filename"]; + (string) requestData["password"] != requiredPassword) throw new Exception("wrong password"); + + string filename = (string) requestData["filename"]; if (requestData.Contains("region_uuid")) { - LLUUID region_uuid = (string)requestData["region_uuid"]; - if (!m_app.SceneManager.TrySetCurrentScene(region_uuid)) - throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString())); + LLUUID region_uuid = (string) requestData["region_uuid"]; + if (!m_app.SceneManager.TrySetCurrentScene(region_uuid)) + throw new Exception(String.Format("failed to switch to region {0}", region_uuid)); m_log.InfoFormat("[RADMIN] Switched to region {0}", region_uuid.ToString()); } else if (requestData.Contains("region_name")) { - string region_name = (string)requestData["region_name"]; - if (!m_app.SceneManager.TrySetCurrentScene(region_name)) + string region_name = (string) requestData["region_name"]; + 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}", region_name); } @@ -588,27 +608,23 @@ namespace OpenSim.ApplicationPlugins.RemoteController responseData["switched"] = "true"; m_app.SceneManager.LoadCurrentSceneFromXml(filename, true, new LLVector3(0, 0, 0)); - responseData["loaded"] = "true"; - - response.Value = responseData; + responseData["loaded"] = "true"; + + response.Value = responseData; } catch (Exception e) { m_log.InfoFormat("[RADMIN] LoadXml: {0}", e.Message); m_log.DebugFormat("[RADMIN] LoadXml: {0}", e.ToString()); - responseData["loaded"] = "false"; + responseData["loaded"] = "false"; responseData["switched"] = "false"; - responseData["error"] = e.Message; - - response.Value = responseData; + responseData["error"] = e.Message; + + response.Value = responseData; } - - return response; - } - public void Close() - { + return response; } } } \ No newline at end of file -- cgit v1.1