From ce7beb6f20cb09e19e0f695f445cfa860b9e9c78 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 2 Nov 2012 01:41:38 +0000 Subject: [PATCH] Add [AssetService] AllowRemoteDeleteAllTypes (default false). This allows a closed grid to delete asset types other than maptile remotely. Only operational if AllowRemoteDelete = true also. Defaults to false - do not enable if anybody other than you can make asset service requests. --- .../Handlers/Asset/AssetServerConnector.cs | 17 ++++++- .../Asset/AssetServerDeleteHandler.cs | 50 +++++++++++++------ bin/Robust.ini.example | 14 +++++- 3 files changed, 65 insertions(+), 16 deletions(-) diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs index 4123f491bb..ff45d94b7a 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs @@ -67,10 +67,25 @@ namespace OpenSim.Server.Handlers.Asset throw new Exception(String.Format("Failed to load AssetService from {0}; config is {1}", assetService, m_ConfigName)); bool allowDelete = serverConfig.GetBoolean("AllowRemoteDelete", false); + bool allowDeleteAllTypes = serverConfig.GetBoolean("AllowRemoteDeleteAllTypes", false); + + AllowedRemoteDeleteTypes allowedRemoteDeleteTypes; + + if (!allowDelete) + { + allowedRemoteDeleteTypes = AllowedRemoteDeleteTypes.None; + } + else + { + if (allowDeleteAllTypes) + allowedRemoteDeleteTypes = AllowedRemoteDeleteTypes.All; + else + allowedRemoteDeleteTypes = AllowedRemoteDeleteTypes.MapTile; + } server.AddStreamHandler(new AssetServerGetHandler(m_AssetService)); server.AddStreamHandler(new AssetServerPostHandler(m_AssetService)); - server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowDelete)); + server.AddStreamHandler(new AssetServerDeleteHandler(m_AssetService, allowedRemoteDeleteTypes)); MainConsole.Instance.Commands.AddCommand("Assets", false, "show asset", diff --git a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs index 9a8aee632c..986394bf59 100644 --- a/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs +++ b/OpenSim/Server/Handlers/Asset/AssetServerDeleteHandler.cs @@ -42,18 +42,32 @@ using OpenSim.Framework.Servers.HttpServer; namespace OpenSim.Server.Handlers.Asset { + /// + /// Remote deletes allowed. + /// + public enum AllowedRemoteDeleteTypes + { + None, + MapTile, + All + } + public class AssetServerDeleteHandler : BaseStreamHandler { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private IAssetService m_AssetService; - protected bool m_allowDelete; - public AssetServerDeleteHandler(IAssetService service, bool allowDelete) : + /// + /// Asset types that can be deleted remotely. + /// + private AllowedRemoteDeleteTypes m_allowedTypes; + + public AssetServerDeleteHandler(IAssetService service, AllowedRemoteDeleteTypes allowedTypes) : base("DELETE", "/assets") { m_AssetService = service; - m_allowDelete = allowDelete; + m_allowedTypes = allowedTypes; } public override byte[] Handle(string path, Stream request, @@ -63,19 +77,27 @@ namespace OpenSim.Server.Handlers.Asset string[] p = SplitParams(path); - if (p.Length > 0 && m_allowDelete) + if (p.Length > 0) { - string assetID = p[0]; + if (m_allowedTypes != AllowedRemoteDeleteTypes.None) + { + string assetID = p[0]; - AssetBase asset = m_AssetService.Get(assetID); - if (asset != null && (int)(asset.Flags & AssetFlags.Maptile) != 0) - { - result = m_AssetService.Delete(assetID); - } - else - { - m_log.DebugFormat( - "[ASSET SERVER DELETE HANDLER]: Request to delete asset {0}, but flags are not Maptile", assetID); + AssetBase asset = m_AssetService.Get(assetID); + if (asset != null) + { + if (m_allowedTypes == AllowedRemoteDeleteTypes.All + || (int)(asset.Flags & AssetFlags.Maptile) != 0) + { + result = m_AssetService.Delete(assetID); + } + else + { + m_log.DebugFormat( + "[ASSET SERVER DELETE HANDLER]: Request to delete asset {0}, but type is {1} and allowed remote delete types are {2}", + assetID, (AssetFlags)asset.Flags, m_allowedTypes); + } + } } } diff --git a/bin/Robust.ini.example b/bin/Robust.ini.example index 2eb551d44b..7503c5e0a2 100644 --- a/bin/Robust.ini.example +++ b/bin/Robust.ini.example @@ -77,7 +77,19 @@ MapGetServiceConnector = "8002/OpenSim.Server.Handlers.dll:MapGetServiceConnecto LocalServiceModule = "OpenSim.Services.AssetService.dll:AssetService" DefaultAssetLoader = "OpenSim.Framework.AssetLoader.Filesystem.dll" AssetLoaderArgs = "./assets/AssetSets.xml" - AllowRemoteDelete = "false" + + ; Allow maptile assets to remotely deleted by remote calls to the asset service. + ; There is no harm in having this as false - it just means that historical maptile assets are not deleted. + ; This only applies to maptiles served via the version 1 viewer mechanisms + ; Default is false + AllowRemoteDelete = false + + ; Allow all assets to be remotely deleted. + ; Only set this to true if you are operating a grid where you control all calls to the asset service + ; (where a necessary condition is that you control all simulators) and you need this for admin purposes. + ; If set to true, AllowRemoteDelete = true is required as well. + ; Default is false. + AllowRemoteDeleteAllTypes = false ; * This configuration loads the inventory server modules. It duplicates ; * the function of the legacy inventory server