From f2742fb6043c6b7332afd026d77a29b25369934c Mon Sep 17 00:00:00 2001 From: mingchen Date: Fri, 25 Jul 2008 02:30:07 +0000 Subject: [PATCH] *Added CommandIntentions that is used to describe a console commands hazard. HAZARDOUS if it modifies the simulator, NON_HAZARDOUS if it does a command that doesn't modify the simulator but does a background command such as a forced backup, and STATISTICAL if it returns debug or more information. *This is useful for implementing a protection system from unwanted script execution or for application modules needing to know what a command does. --- .../Region/Environment/Interfaces/ICommand.cs | 9 +++++++ .../Environment/Interfaces/ICommander.cs | 2 ++ .../Framework/InterfaceCommander/Commander.cs | 9 ++++++- .../InterfaceCommander/CommanderTestModule.cs | 2 +- .../World/Permissions/PermissionsModule.cs | 4 ++-- .../World/Serialiser/SerialiserModule.cs | 4 ++-- .../Modules/World/Terrain/TerrainModule.cs | 24 +++++++++---------- 7 files changed, 36 insertions(+), 18 deletions(-) diff --git a/OpenSim/Region/Environment/Interfaces/ICommand.cs b/OpenSim/Region/Environment/Interfaces/ICommand.cs index 4eeb16cf88..c1da2c3deb 100644 --- a/OpenSim/Region/Environment/Interfaces/ICommand.cs +++ b/OpenSim/Region/Environment/Interfaces/ICommand.cs @@ -29,12 +29,21 @@ using System.Collections.Generic; namespace OpenSim.Region.Environment.Interfaces { + public enum CommandIntentions + { + COMMAND_STATISTICAL, + COMMAND_NON_HAZARDOUS, + COMMAND_HAZARDOUS + }; + public interface ICommand { void AddArgument(string name, string helptext, string type); Dictionary Arguments { get; } string Help { get; } string Name { get; } + CommandIntentions Intentions { get; } + void Run(object[] args); void ShowConsoleHelp(); } diff --git a/OpenSim/Region/Environment/Interfaces/ICommander.cs b/OpenSim/Region/Environment/Interfaces/ICommander.cs index c4102af7d7..f2260c3645 100644 --- a/OpenSim/Region/Environment/Interfaces/ICommander.cs +++ b/OpenSim/Region/Environment/Interfaces/ICommander.cs @@ -27,6 +27,8 @@ namespace OpenSim.Region.Environment.Interfaces { + + public interface ICommander { void ProcessConsoleCommand(string function, string[] args); diff --git a/OpenSim/Region/Environment/Modules/Framework/InterfaceCommander/Commander.cs b/OpenSim/Region/Environment/Modules/Framework/InterfaceCommander/Commander.cs index 84487e85ac..82f18a1efe 100644 --- a/OpenSim/Region/Environment/Modules/Framework/InterfaceCommander/Commander.cs +++ b/OpenSim/Region/Environment/Modules/Framework/InterfaceCommander/Commander.cs @@ -47,12 +47,14 @@ namespace OpenSim.Region.Environment.Modules.Framework.InterfaceCommander private Action m_command; private string m_help; private string m_name; + private CommandIntentions m_intentions; //A permission type system could implement this and know what a command intends on doing. - public Command(string name, Action command, string help) + public Command(string name, CommandIntentions intention, Action command, string help) { m_name = name; m_command = command; m_help = help; + m_intentions = intention; } #region ICommand Members @@ -67,6 +69,11 @@ namespace OpenSim.Region.Environment.Modules.Framework.InterfaceCommander get { return m_name; } } + public CommandIntentions Intentions + { + get { return m_intentions; } + } + public string Help { get { return m_help; } diff --git a/OpenSim/Region/Environment/Modules/Framework/InterfaceCommander/CommanderTestModule.cs b/OpenSim/Region/Environment/Modules/Framework/InterfaceCommander/CommanderTestModule.cs index 8d1371cf4a..c56924090e 100644 --- a/OpenSim/Region/Environment/Modules/Framework/InterfaceCommander/CommanderTestModule.cs +++ b/OpenSim/Region/Environment/Modules/Framework/InterfaceCommander/CommanderTestModule.cs @@ -56,7 +56,7 @@ namespace OpenSim.Region.Environment.Modules.Framework.InterfaceCommander public void PostInitialise() { - Command testCommand = new Command("hello", InterfaceHelloWorld, "Says a simple debugging test string"); + Command testCommand = new Command("hello", CommandIntentions.COMMAND_STATISTICAL, InterfaceHelloWorld, "Says a simple debugging test string"); testCommand.AddArgument("world", "Write world here", "string"); m_commander.RegisterCommand("hello", testCommand); diff --git a/OpenSim/Region/Environment/Modules/World/Permissions/PermissionsModule.cs b/OpenSim/Region/Environment/Modules/World/Permissions/PermissionsModule.cs index 23db4841a6..f9a0bdb543 100644 --- a/OpenSim/Region/Environment/Modules/World/Permissions/PermissionsModule.cs +++ b/OpenSim/Region/Environment/Modules/World/Permissions/PermissionsModule.cs @@ -182,13 +182,13 @@ namespace OpenSim.Region.Environment.Modules.World.Permissions //Register Debug Commands - Command bypassCommand = new Command("bypass", InterfaceBypassPermissions, "Force the permissions a specific way to test permissions"); + Command bypassCommand = new Command("bypass", CommandIntentions.COMMAND_HAZARDOUS, InterfaceBypassPermissions, "Force the permissions a specific way to test permissions"); bypassCommand.AddArgument("enable_bypass_perms", "true to enable bypassing all perms", "Boolean"); bypassCommand.AddArgument("bypass_perms_value", "true/false: true will ignore all perms; false will restrict everything", "Boolean"); m_commander.RegisterCommand("bypass", bypassCommand); - Command debugCommand = new Command("debug", InterfaceDebugPermissions, "Force the permissions a specific way to test permissions"); + Command debugCommand = new Command("debug", CommandIntentions.COMMAND_STATISTICAL, InterfaceDebugPermissions, "Force the permissions a specific way to test permissions"); debugCommand.AddArgument("enable_debug_perms", "true to enable debugging to console all perms", "Boolean"); m_commander.RegisterCommand("debug", debugCommand); diff --git a/OpenSim/Region/Environment/Modules/World/Serialiser/SerialiserModule.cs b/OpenSim/Region/Environment/Modules/World/Serialiser/SerialiserModule.cs index cefd15f970..ce59ecc135 100644 --- a/OpenSim/Region/Environment/Modules/World/Serialiser/SerialiserModule.cs +++ b/OpenSim/Region/Environment/Modules/World/Serialiser/SerialiserModule.cs @@ -199,10 +199,10 @@ namespace OpenSim.Region.Environment.Modules.World.Serialiser private void LoadCommanderCommands() { - Command serialiseSceneCommand = new Command("save", InterfaceSaveRegion, "Saves the named region into the exports directory."); + Command serialiseSceneCommand = new Command("save", CommandIntentions.COMMAND_NON_HAZARDOUS, InterfaceSaveRegion, "Saves the named region into the exports directory."); serialiseSceneCommand.AddArgument("region-name", "The name of the region you wish to export", "String"); - Command serialiseAllScenesCommand = new Command("save-all", InterfaceSaveAllRegions, "Saves all regions into the exports directory."); + Command serialiseAllScenesCommand = new Command("save-all",CommandIntentions.COMMAND_NON_HAZARDOUS, InterfaceSaveAllRegions, "Saves all regions into the exports directory."); m_commander.RegisterCommand("save", serialiseSceneCommand); m_commander.RegisterCommand("save-all", serialiseAllScenesCommand); diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainModule.cs b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainModule.cs index 9892794a48..8fbc62eb7a 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainModule.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainModule.cs @@ -804,19 +804,19 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain supportedFileExtensions += " " + loader.Key + " (" + loader.Value + ")"; Command loadFromFileCommand = - new Command("load", InterfaceLoadFile, "Loads a terrain from a specified file."); + new Command("load", CommandIntentions.COMMAND_HAZARDOUS, InterfaceLoadFile, "Loads a terrain from a specified file."); loadFromFileCommand.AddArgument("filename", "The file you wish to load from, the file extension determines the loader to be used. Supported extensions include: " + supportedFileExtensions, "String"); Command saveToFileCommand = - new Command("save", InterfaceSaveFile, "Saves the current heightmap to a specified file."); + new Command("save", CommandIntentions.COMMAND_NON_HAZARDOUS, InterfaceSaveFile, "Saves the current heightmap to a specified file."); saveToFileCommand.AddArgument("filename", "The destination filename for your heightmap, the file extension determines the format to save in. Supported extensions include: " + supportedFileExtensions, "String"); Command loadFromTileCommand = - new Command("load-tile", InterfaceLoadTileFile, "Loads a terrain from a section of a larger file."); + new Command("load-tile", CommandIntentions.COMMAND_HAZARDOUS, InterfaceLoadTileFile, "Loads a terrain from a section of a larger file."); loadFromTileCommand.AddArgument("filename", "The file you wish to load from, the file extension determines the loader to be used. Supported extensions include: " + supportedFileExtensions, "String"); @@ -829,40 +829,40 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain // Terrain adjustments Command fillRegionCommand = - new Command("fill", InterfaceFillTerrain, "Fills the current heightmap with a specified value."); + new Command("fill", CommandIntentions.COMMAND_HAZARDOUS, InterfaceFillTerrain, "Fills the current heightmap with a specified value."); fillRegionCommand.AddArgument("value", "The numeric value of the height you wish to set your region to.", "Double"); Command elevateCommand = - new Command("elevate", InterfaceElevateTerrain, "Raises the current heightmap by the specified amount."); + new Command("elevate", CommandIntentions.COMMAND_HAZARDOUS, InterfaceElevateTerrain, "Raises the current heightmap by the specified amount."); elevateCommand.AddArgument("amount", "The amount of height to add to the terrain in meters.", "Double"); Command lowerCommand = - new Command("lower", InterfaceLowerTerrain, "Lowers the current heightmap by the specified amount."); + new Command("lower", CommandIntentions.COMMAND_HAZARDOUS, InterfaceLowerTerrain, "Lowers the current heightmap by the specified amount."); lowerCommand.AddArgument("amount", "The amount of height to remove from the terrain in meters.", "Double"); Command multiplyCommand = - new Command("multiply", InterfaceMultiplyTerrain, "Multiplies the heightmap by the value specified."); + new Command("multiply", CommandIntentions.COMMAND_HAZARDOUS, InterfaceMultiplyTerrain, "Multiplies the heightmap by the value specified."); multiplyCommand.AddArgument("value", "The value to multiply the heightmap by.", "Double"); Command bakeRegionCommand = - new Command("bake", InterfaceBakeTerrain, "Saves the current terrain into the regions revert map."); + new Command("bake", CommandIntentions.COMMAND_HAZARDOUS, InterfaceBakeTerrain, "Saves the current terrain into the regions revert map."); Command revertRegionCommand = - new Command("revert", InterfaceRevertTerrain, "Loads the revert map terrain into the regions heightmap."); + new Command("revert", CommandIntentions.COMMAND_HAZARDOUS, InterfaceRevertTerrain, "Loads the revert map terrain into the regions heightmap."); // Debug Command showDebugStatsCommand = - new Command("stats", InterfaceShowDebugStats, + new Command("stats", CommandIntentions.COMMAND_STATISTICAL, InterfaceShowDebugStats, "Shows some information about the regions heightmap for debugging purposes."); Command experimentalBrushesCommand = - new Command("newbrushes", InterfaceEnableExperimentalBrushes, + new Command("newbrushes", CommandIntentions.COMMAND_HAZARDOUS, InterfaceEnableExperimentalBrushes, "Enables experimental brushes which replace the standard terrain brushes. WARNING: This is a debug setting and may be removed at any time."); experimentalBrushesCommand.AddArgument("Enabled?", "true / false - Enable new brushes", "Boolean"); //Plugins Command pluginRunCommand = - new Command("effect", InterfaceRunPluginEffect, "Runs a specified plugin effect"); + new Command("effect", CommandIntentions.COMMAND_HAZARDOUS, InterfaceRunPluginEffect, "Runs a specified plugin effect"); pluginRunCommand.AddArgument("name", "The plugin effect you wish to run, or 'list' to see all plugins", "String"); m_commander.RegisterCommand("load", loadFromFileCommand);