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.
0.7.3-extended
Justin Clark-Casey (justincc) 2012-11-02 01:41:38 +00:00
parent 7ae128abbe
commit 8638766d79
3 changed files with 65 additions and 16 deletions

View File

@ -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",

View File

@ -42,18 +42,32 @@ using OpenSim.Framework.Servers.HttpServer;
namespace OpenSim.Server.Handlers.Asset
{
/// <summary>
/// Remote deletes allowed.
/// </summary>
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) :
/// <summary>
/// Asset types that can be deleted remotely.
/// </summary>
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);
}
}
}
}

View File

@ -61,7 +61,19 @@ ServiceConnectors = "8003/OpenSim.Server.Handlers.dll:AssetServiceConnector,8003
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