From 99c7a43ffdb9c3b4dee984f7cd788742c6ee3e53 Mon Sep 17 00:00:00 2001 From: Melanie Date: Wed, 19 Aug 2009 04:39:02 +0100 Subject: [PATCH] Add rest console support to the user server. Will ask new questions at startup. To use, run it normally once, answering the questions, then run again with -console=rest. Also now supports -console=basic for a console that reads stdin --- OpenSim/Framework/UserConfig.cs | 14 ++++++++ OpenSim/Grid/UserServer/Main.cs | 39 ++++++++++++++++++++++- OpenSim/Server/Base/ServicesServerBase.cs | 28 ++++++++++++++++ prebuild.xml | 1 + 4 files changed, 81 insertions(+), 1 deletion(-) diff --git a/OpenSim/Framework/UserConfig.cs b/OpenSim/Framework/UserConfig.cs index 31838ad155..b9e366553c 100644 --- a/OpenSim/Framework/UserConfig.cs +++ b/OpenSim/Framework/UserConfig.cs @@ -46,6 +46,8 @@ namespace OpenSim.Framework public bool HttpSSL = ConfigSettings.DefaultUserServerHttpSSL; public uint DefaultUserLevel = 0; public string LibraryXmlfile = ""; + public string ConsoleUser = String.Empty; + public string ConsolePass = String.Empty; private Uri m_inventoryUrl; @@ -155,6 +157,12 @@ namespace OpenSim.Framework m_configMember.addConfigurationOption("default_loginLevel", ConfigurationOption.ConfigurationTypes.TYPE_UINT32, "Minimum Level a user should have to login [0 default]", "0", false); + m_configMember.addConfigurationOption("console_user", ConfigurationOption.ConfigurationTypes.TYPE_STRING, + "Remote console access user name [Default: disabled]", "0", false); + + m_configMember.addConfigurationOption("console_pass", ConfigurationOption.ConfigurationTypes.TYPE_STRING, + "Remote console access password [Default: disabled]", "0", false); + } public bool handleIncomingConfiguration(string configuration_key, object configuration_result) @@ -209,6 +217,12 @@ namespace OpenSim.Framework case "library_location": LibraryXmlfile = (string)configuration_result; break; + case "console_user": + ConsoleUser = (string)configuration_result; + break; + case "console_pass": + ConsolePass = (string)configuration_result; + break; } return true; diff --git a/OpenSim/Grid/UserServer/Main.cs b/OpenSim/Grid/UserServer/Main.cs index 86c2abb8d7..f47a96ef03 100644 --- a/OpenSim/Grid/UserServer/Main.cs +++ b/OpenSim/Grid/UserServer/Main.cs @@ -43,6 +43,7 @@ using OpenSim.Framework.Statistics; using OpenSim.Grid.Communications.OGS1; using OpenSim.Grid.Framework; using OpenSim.Grid.UserServer.Modules; +using Nini.Config; namespace OpenSim.Grid.UserServer { @@ -73,8 +74,22 @@ namespace OpenSim.Grid.UserServer protected AvatarCreationModule m_appearanceModule; + protected static string m_consoleType = "local"; + protected static IConfigSource m_config = null; + public static void Main(string[] args) { + ArgvConfigSource argvSource = new ArgvConfigSource(args); + argvSource.AddSwitch("Startup", "console", "c"); + + IConfig startupConfig = argvSource.Configs["Startup"]; + if (startupConfig != null) + { + m_consoleType = startupConfig.GetString("console", "local"); + } + + m_config = argvSource; + XmlConfigurator.Configure(); m_log.Info("Launching UserServer..."); @@ -87,7 +102,18 @@ namespace OpenSim.Grid.UserServer public OpenUser_Main() { - m_console = new LocalConsole("User"); + switch (m_consoleType) + { + case "rest": + m_console = new RemoteConsole("User"); + break; + case "basic": + m_console = new CommandConsole("User"); + break; + default: + m_console = new LocalConsole("User"); + break; + } MainConsole.Instance = m_console; } @@ -129,6 +155,17 @@ namespace OpenSim.Grid.UserServer m_httpServer = new BaseHttpServer(Cfg.HttpPort); + if (m_console is RemoteConsole) + { + System.Console.WriteLine("Initialized REST console"); + RemoteConsole c = (RemoteConsole)m_console; + c.SetServer(m_httpServer); + IConfig netConfig = m_config.AddConfig("Network"); + netConfig.Set("ConsoleUser", Cfg.ConsoleUser); + netConfig.Set("ConsolePass", Cfg.ConsolePass); + c.ReadConfig(m_config); + } + RegisterInterface(m_console); RegisterInterface(Cfg); diff --git a/OpenSim/Server/Base/ServicesServerBase.cs b/OpenSim/Server/Base/ServicesServerBase.cs index 619c2d1c96..1d9eb0d241 100644 --- a/OpenSim/Server/Base/ServicesServerBase.cs +++ b/OpenSim/Server/Base/ServicesServerBase.cs @@ -65,6 +65,10 @@ namespace OpenSim.Server.Base // private bool m_Running = true; + // PID file + // + private string m_pidFile = String.Empty; + // Handle all the automagical stuff // public ServicesServerBase(string prompt, string[] args) @@ -211,6 +215,11 @@ namespace OpenSim.Server.Base } } + if (startupConfig.GetString("PIDFile", String.Empty) != String.Empty) + { + CreatePIDFile(startupConfig.GetString("PIDFile")); + } + // Register the quit command // MainConsole.Instance.Commands.AddCommand("base", false, "quit", @@ -230,6 +239,8 @@ namespace OpenSim.Server.Base MainConsole.Instance.Prompt(); } + if (m_pidFile != String.Empty) + File.Delete(m_pidFile); return 0; } @@ -246,5 +257,22 @@ namespace OpenSim.Server.Base protected virtual void Initialise() { } + + protected void CreatePIDFile(string path) + { + try + { + string pidstring = System.Diagnostics.Process.GetCurrentProcess().Id.ToString(); + FileStream fs = File.Create(path); + System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); + Byte[] buf = enc.GetBytes(pidstring); + fs.Write(buf, 0, buf.Length); + fs.Close(); + m_pidFile = path; + } + catch (Exception) + { + } + } } } diff --git a/prebuild.xml b/prebuild.xml index 5e4416984b..4f110c4487 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -1178,6 +1178,7 @@ +