From ce7beb6f20cb09e19e0f695f445cfa860b9e9c78 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Fri, 2 Nov 2012 01:41:38 +0000
Subject: 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.
---
.../Server/Handlers/Asset/AssetServerConnector.cs | 17 +++++++-
.../Handlers/Asset/AssetServerDeleteHandler.cs | 50 ++++++++++++++++------
2 files changed, 52 insertions(+), 15 deletions(-)
(limited to 'OpenSim')
diff --git a/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs b/OpenSim/Server/Handlers/Asset/AssetServerConnector.cs
index 4123f49..ff45d94 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 9a8aee6..986394b 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];
-
- AssetBase asset = m_AssetService.Get(assetID);
- if (asset != null && (int)(asset.Flags & AssetFlags.Maptile) != 0)
- {
- result = m_AssetService.Delete(assetID);
- }
- else
+ if (m_allowedTypes != AllowedRemoteDeleteTypes.None)
{
- m_log.DebugFormat(
- "[ASSET SERVER DELETE HANDLER]: Request to delete asset {0}, but flags are not Maptile", assetID);
+ string assetID = p[0];
+
+ 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);
+ }
+ }
}
}
--
cgit v1.1