Example #1
0
        public static IConfigSource LoadConfig(IConfigSource source)
        {
            string iniFileName = source.Configs["Startup"].GetString("inifile", CONFIG_FILE);
            string iniFilePath = Path.Combine(Util.configDir(), iniFileName);

            source.Merge(DefaultConfig());

            if (!File.Exists(iniFilePath))
            {
                m_log.FatalFormat("[CONFIG]: File {0} not found, could not load any configuration.", iniFilePath);
                m_log.FatalFormat("[CONFIG]: Did you copy the AssetInventoryServer.ini.example file to AssetInventoryServer.ini?");
                Environment.Exit(1);
            }

            source.Merge(new IniConfigSource(iniFilePath));
            return source;
        }
        /// <summary>
        /// Loads the region configuration
        /// </summary>
        /// <param name="argvSource">Parameters passed into the process when started</param>
        /// <param name="configSettings"></param>
        /// <param name="networkInfo"></param>
        /// <returns>A configuration that gets passed to modules</returns>
        public IConfigSource LoadConfigSettings()
        {
            bool iniFileExists = false;

            List<string> sources = new List<string>();

            string iniFileName = "OpenSim.ini";
            string iniFilePath = Path.Combine(".", iniFileName);

            if (IsUri(iniFileName))
            {
                if (!sources.Contains(iniFileName))
                    sources.Add(iniFileName);
            }
            else
            {
                if (File.Exists(iniFilePath))
                {
                    if (!sources.Contains(iniFilePath))
                        sources.Add(iniFilePath);
                }
            }

            m_config = new IniConfigSource();
            m_config.Merge(DefaultConfig());

            m_log.Info("[CONFIG] Reading configuration settings");

            if (sources.Count == 0)
            {
                m_log.FatalFormat("[CONFIG] Could not load any configuration");
                m_log.FatalFormat("[CONFIG] Did you copy the OpenSim.ini.example file to OpenSim.ini?");
                Environment.Exit(1);
            }

            for (int i = 0 ; i < sources.Count ; i++)
            {
                if (ReadConfig(sources[i]))
                    iniFileExists = true;
                AddIncludes(sources);
            }

            if (!iniFileExists)
            {
                m_log.FatalFormat("[CONFIG] Could not load any configuration");
                m_log.FatalFormat("[CONFIG] Configuration exists, but there was an error loading it!");
                Environment.Exit(1);
            }

            return m_config;
        }
        /// <summary>
        ///     Provide same ini loader functionality for standard ini and master ini - file system or XML over http
        /// </summary>
        /// <param name="iniPath">Full path to the ini</param>
        /// <param name="i"></param>
        /// <param name="source"></param>
        /// <returns></returns>
        private bool ReadConfig(string iniPath, int i, IConfigSource source)
        {
            bool success = false;

            if (!IsUri(iniPath))
            {
                if (showIniLoading)
                    Console.WriteLine(string.Format("[CONFIG]: Reading configuration file {0}",
                                                    Util.BasePathCombine(iniPath)));

                source.Merge(new IniConfigSource(iniPath, IniFileType.AuroraStyle));
                if (inidbg)
                {
                    WriteConfigFile(i, source);
                }
                success = true;
            }
            else
            {
                // The ini file path is a http URI
                // Try to read it
                try
                {
                    string file = Utilities.Utilities.ReadExternalWebsite(iniPath);
                    string filename = Path.GetTempFileName();
                    File.WriteAllText(filename, file);

                    if (showIniLoading)
                        Console.WriteLine(string.Format("[CONFIG]: Reading configuration file {0}",
                                                        Util.BasePathCombine(iniPath)));

                    source.Merge(new IniConfigSource(filename, IniFileType.AuroraStyle));
                    if (inidbg)
                    {
                        WriteConfigFile(i, source);
                    }
                    File.Delete(filename);
                    success = true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(string.Format("[CONFIG]: Exception reading config from URI {0}\n" + e, iniPath));
                    Environment.Exit(1);
                }
            }
            return success;
        }
        /// <summary>
        /// Loads the region configuration
        /// </summary>
        /// <param name="argvSource">Parameters passed into the process when started</param>
        /// <returns>A configuration that gets passed to modules</returns>
        public IConfigSource LoadConfigSettings(IConfigSource argvSource)
        {
            bool iniFileExists = false;

            IConfig startupConfig = argvSource.Configs["Startup"];

            List<string> sources = new List<string>();

            inidbg =
                startupConfig.GetBoolean("inidbg", false);

            string masterFileName =
                startupConfig.GetString("inimaster", String.Empty);

            string iniFileName =
                startupConfig.GetString("inifile", "OpenSim.ini");

            //Be mindful of these when modifying...
            //1) When file A includes file B, if the same directive is found in both, that the value in file B wins.
            //2) That inifile may be used with or without inimaster being used.
            //3) That any values for directives pulled in via inifile (Config Set 2) override directives of the same name found in the directive set (Config Set 1) created by reading in bin/Opensim.ini and its subsequently included files or that created by reading in whatever file inimaster points to and its subsequently included files.
            
            if (IsUri(masterFileName))
            {
                if (!sources.Contains(masterFileName))
                    sources.Add(masterFileName);
            }
            else
            {
                string masterFilePath = Path.GetFullPath(
                        Path.Combine(Util.configDir(), masterFileName));

                if (masterFileName != String.Empty &&
                        File.Exists(masterFilePath) &&
                        (!sources.Contains(masterFilePath)))
                    sources.Add(masterFilePath);
                if (iniFileName == "") //Then it doesn't exist and we need to set this
                    Application.iniFilePath = masterFilePath;
            }

            if (iniFileName != "")
            {
                if (IsUri(iniFileName))
                {
                    if (!sources.Contains(iniFileName))
                        sources.Add(iniFileName);
                    Application.iniFilePath = iniFileName;
                }
                else
                {
                    Application.iniFilePath = Path.GetFullPath(
                            Path.Combine(Util.configDir(), iniFileName));

                    if (File.Exists(Application.iniFilePath))
                    {
                        if (!sources.Contains(Application.iniFilePath))
                            sources.Add(Application.iniFilePath);
                    }
                }
            }

            string iniDirName =
                    startupConfig.GetString("inidirectory", "");
            string iniDirPath =
                    Path.Combine(Util.configDir(), iniDirName);

            if (Directory.Exists(iniDirPath) && iniDirName != "")
            {
                m_log.InfoFormat("Searching folder {0} for config ini files",
                        iniDirPath);

                string[] fileEntries = Directory.GetFiles(iniDirName);
                foreach (string filePath in fileEntries)
                {
                    if (Path.GetExtension(filePath).ToLower() == ".ini")
                    {
                        if (!sources.Contains(Path.GetFullPath(filePath)))
                            sources.Add(Path.GetFullPath(filePath));
                    }
                }
            }


            m_config = new IniConfigSource();
            
            m_log.Info("[CONFIG]: Reading configuration settings");

            if (sources.Count == 0)
            {
                m_log.FatalFormat("[CONFIG]: Could not load any configuration");
                m_log.FatalFormat("[CONFIG]: Did you copy the OpenSim.ini.example file to OpenSim.ini?");
                throw new NotSupportedException();
            }

            for (int i = 0 ; i < sources.Count ; i++)
            {
                if (ReadConfig(sources[i], i))
                    iniFileExists = true;
                AddIncludes(sources, ref i);
            }

            if (!iniFileExists)
            {
                m_log.FatalFormat("[CONFIG]: Could not load any configuration");
                m_log.FatalFormat("[CONFIG]: Configuration exists, but there was an error loading it!");
                throw new NotSupportedException();
            }

            // Make sure command line options take precedence
            m_config.Merge(argvSource);

            return m_config;
        }
Example #5
0
        /// <summary>
        /// Loads the region configuration
        /// </summary>
        /// <param name="argvSource">Parameters passed into the process when started</param>
        /// <returns>A configuration that gets passed to modules</returns>
        public IConfigSource LoadConfigSettings(IConfigSource argvSource)
        {
            bool iniFileExists = false;

            IConfig startupConfig = argvSource.Configs["Startup"];

            List<string> sources = new List<string>();

            string masterFileName =
                    startupConfig.GetString("inimaster", String.Empty);

            if (IsUri(masterFileName))
            {
                if (!sources.Contains(masterFileName))
                    sources.Add(masterFileName);
            }
            else
            {
                string masterFilePath = Path.GetFullPath(
                        Path.Combine(Util.configDir(), masterFileName));

                if (masterFileName != String.Empty &&
                        File.Exists(masterFilePath) &&
                        (!sources.Contains(masterFilePath)))
                    sources.Add(masterFilePath);
            }


            string iniFileName =
                    startupConfig.GetString("inifile", "OpenSim.ini");

            if (IsUri(iniFileName))
            {
                if (!sources.Contains(iniFileName))
                    sources.Add(iniFileName);
                Application.iniFilePath = iniFileName;
            }
            else
            {
                Application.iniFilePath = Path.GetFullPath(
                        Path.Combine(Util.configDir(), iniFileName));

                if (File.Exists(Application.iniFilePath))
                {
                    if (!sources.Contains(Application.iniFilePath))
                        sources.Add(Application.iniFilePath);
                }
            }

            string iniDirName =
                    startupConfig.GetString("inidirectory", "Configuration/Modules");
            string iniDirPath =
                    Path.Combine(Util.configDir(), iniDirName);

            if (Directory.Exists(iniDirPath))
            {
                m_log.InfoFormat("Searching folder {0} for config ini files",
                        iniDirPath);

                string[] fileEntries = Directory.GetFiles(iniDirName);
                foreach (string filePath in fileEntries)
                {
                    if (Path.GetExtension(filePath).ToLower() == ".ini")
                    {
                        if (!sources.Contains(Path.GetFullPath(filePath)))
                            sources.Add(Path.GetFullPath(filePath));
                    }
                }
            }


            m_config = new IniConfigSource();
            
            m_log.Info("[CONFIG]: Reading configuration settings");

            if (sources.Count == 0)
            {
                m_log.FatalFormat("[CONFIG]: Could not load any configuration");
                m_log.FatalFormat("[CONFIG]: Did you copy the OpenSim.ini.example file to OpenSim.ini?");
                throw new NotSupportedException();
            }

            for (int i = 0 ; i < sources.Count ; i++)
            {
                if (ReadConfig(sources[i]))
                    iniFileExists = true;
                AddIncludes(sources);
            }

            if (!iniFileExists)
            {
                m_log.FatalFormat("[CONFIG]: Could not load any configuration");
                m_log.FatalFormat("[CONFIG]: Configuration exists, but there was an error loading it!");
                throw new NotSupportedException();
            }

            // Make sure command line options take precedence
            m_config.Merge(argvSource);

            return m_config;
        }
        /// <summary>
        /// Loads the region configuration
        /// </summary>
        /// <param name="argvSource">Parameters passed into the process when started</param>
        /// <param name="configSettings"></param>
        /// <param name="networkInfo"></param>
        /// <returns>A configuration that gets passed to modules</returns>
        public IConfigSource LoadConfigSettings(IConfig startupConfig)
        {
            bool iniFileExists = false;

            List<string> sources = new List<string>();

            string masterFileName = startupConfig.GetString("inimaster", "OpenSimDefaults.ini");

            if (masterFileName == "none")
                masterFileName = String.Empty;

            if (IsUri(masterFileName))
            {
                if (!sources.Contains(masterFileName))
                    sources.Add(masterFileName);
            }
            else
            {
                string masterFilePath = Path.GetFullPath(
                        Path.Combine(Util.configDir(), masterFileName));

                if (masterFileName != String.Empty)
                {
                    if (File.Exists(masterFilePath))
                    {
                        if (!sources.Contains(masterFilePath))
                            sources.Add(masterFilePath);
                    }
                    else
                    {
                        m_log.ErrorFormat("Master ini file {0} not found", Path.GetFullPath(masterFilePath));
                        Environment.Exit(1);
                    }
                }
            }

            string iniFileName = startupConfig.GetString("inifile", Path.Combine(".", "OpenSim.ini"));

            if (IsUri(iniFileName))
            {
                if (!sources.Contains(iniFileName))
                    sources.Add(iniFileName);
            }
            else
            {
                if (File.Exists(iniFileName))
                {
                    if (!sources.Contains(iniFileName))
                        sources.Add(iniFileName);
                }
            }

            m_config = new IniConfigSource();
            m_config.Merge(DefaultConfig());

            m_log.Info("[CONFIG] Reading configuration settings");

            if (sources.Count == 0)
            {
                m_log.FatalFormat("[CONFIG] Could not load any configuration");
                m_log.FatalFormat("[CONFIG] Did you copy the OpenSim.ini.example file to OpenSim.ini?");
                Environment.Exit(1);
            }

            for (int i = 0 ; i < sources.Count ; i++)
            {
                if (ReadConfig(sources[i]))
                    iniFileExists = true;
                AddIncludes(sources);
            }

            if (!iniFileExists)
            {
                m_log.FatalFormat("[CONFIG] Could not load any configuration");
                m_log.FatalFormat("[CONFIG] Configuration exists, but there was an error loading it!");
                Environment.Exit(1);
            }

            return m_config;
        }
        /// <summary>
        ///   Provide same ini loader functionality for standard ini and master ini - file system or XML over http
        /// </summary>
        /// <param name = "iniPath">Full path to the ini</param>
        /// <returns></returns>
        private bool ReadConfig(string iniPath, int i, IConfigSource source)
        {
            bool success = false;

            if (!IsUri(iniPath))
            {
                if (showIniLoading)
                    Console.WriteLine(string.Format("[CONFIG]: Reading configuration file {0}", Util.BasePathCombine(iniPath)));

                source.Merge(new IniConfigSource(iniPath, IniFileType.AuroraStyle));
                if (inidbg)
                {
                    WriteConfigFile(i, source);
                }
                success = true;
            }
            else
            {
                Console.WriteLine(string.Format("[CONFIG]: {0} is a http:// URI, fetching ...", iniPath));

                // The ini file path is a http URI
                // Try to read it
                try
                {
                    XmlReader r = XmlReader.Create(iniPath);
                    XmlConfigSource cs = new XmlConfigSource(r);
                    source.Merge(cs);

                    success = true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(string.Format("[CONFIG]: Exception reading config from URI {0}\n" + e, iniPath));
                    Environment.Exit(1);
                }
            }
            return success;
        }
        /// <summary>
        /// Configure the plugin. This is the equivilent of our parameterized constructor
        /// for regular Robust connectors. But, we just get our configuration and return
        /// the port we want to run our connector on back to the application. Then the 
        /// application will send our server to the Initialize method
        /// </summary>
        /// <param name='config'>
        /// IConfigSource - Main Config.
        /// </param>
		public uint Configure(IConfigSource config)
		{
			m_log.Info("[SLIPSTREAM]: Running Configuration");
			Config = config;

			IConfig startconfig = Config.Configs["Startup"];
			string configdirectory = startconfig.GetString("ConfigDirectory", ".");

			ConfigFile = Path.Combine(configdirectory, "SlipStream.ini");
			m_log.InfoFormat("[SLIPSTREAM]: Configuration {0}", ConfigFile);

			// Look in our main config first
			IConfig serverConfig = Config.Configs[ConfigName];
            if (serverConfig == null)
            {
				// Look for individual config file
				serverConfig = GetConfig ();
			    if (serverConfig == null)
				    throw new Exception(String.Format("[SlipStream]: Cannot file configuration for {0}, not loaded!", ConfigName));
                Config.Merge(serverConfig.ConfigSource);
            }

			uint serverPort = (uint) serverConfig.GetInt("ServerPort", 0);
            ServiceModuleName = serverConfig.GetString("LocalServiceModule",
                    String.Empty);

            // Just something to test the config 
			m_log.InfoFormat("[SLIPSTREAM]: CodeWord {0}", serverConfig.GetString ("CodeWord","Blaah!"));

            if (ServiceModuleName == String.Empty)
                throw new Exception("No LocalServiceModule in config file");

            // We want to ship these plugins disabled to allow the user to make
            // adjustments to the ini prior to running. The bootstrap ini will be downloaded
            // when the plugin is enabled the first time. It should have an Enable and it
            // should be set to false. The user can disable the module in the console, make
            // edits (including setting Enable to true) then re-enable the plugin. It will 
            // load and run w/o restarting their Robust.
			if (serverConfig.GetBoolean("Enabled", false) == false)
			{
				m_log.Info("[SLIPSTREAM]: Module Disabled");
				Enabled = false;
				return 0;
			}
			else
				Enabled = true;

			return (uint) serverPort;
		}
Example #9
0
        /// <summary>
        /// Loads the region configuration
        /// </summary>
        /// <param name="argvSource">Parameters passed into the process when started</param>
        /// <returns>A configuration that gets passed to modules</returns>
        public IConfigSource LoadConfigSettings(IConfigSource argvSource)
        {
            iniFilePath = "";
            bool iniFileExists = false;

            IConfig startupConfig = argvSource.Configs["Startup"];

            List<string> sources = new List<string> ();

            bool oldoptions =
                startupConfig.GetBoolean ("oldoptions", false);

            inidbg =
                startupConfig.GetBoolean ("inidbg", inidbg);

            showIniLoading =
                startupConfig.GetBoolean ("inishowfileloading", showIniLoading);
            string basePath = Util.configDir();
            if (oldoptions)
            {
                string masterFileName =
                    startupConfig.GetString ("inimaster", String.Empty);

                string iniGridName =
                    startupConfig.GetString ("inigrid", String.Empty);

                if (iniGridName == string.Empty) //Read the old name then
                    iniGridName =
                        startupConfig.GetString ("inifile", String.Empty);

                string iniSimName =
                    startupConfig.GetString ("inisim", defaultIniFile);

                //Be mindful of these when modifying...
                //1) When file A includes file B, if the same directive is found in both, that the value in file B wins.
                //2) That inifile may be used with or without inimaster being used.
                //3) That any values for directives pulled in via inifile (Config Set 2) override directives of the same name found in the directive set (Config Set 1) created by reading in bin/Aurora.ini and its subsequently included files or that created by reading in whatever file inimaster points to and its subsequently included files.

                if (IsUri (masterFileName))
                {
                    if (!sources.Contains (masterFileName))
                        sources.Add (masterFileName);
                }
                else
                {
                    string masterFilePath = Util.BasePathCombine (masterFileName);

                    if (masterFileName != String.Empty &&
                            File.Exists (masterFilePath) &&
                            (!sources.Contains (masterFilePath)))
                        sources.Add (masterFilePath);
                    if (iniGridName == "") //Then it doesn't exist and we need to set this
                        iniFilePath = masterFilePath;
                    if (iniSimName == "") //Then it doesn't exist and we need to set this
                        iniFilePath = masterFilePath;
                }

                if (iniGridName != "")
                {
                    if (IsUri (iniGridName))
                    {
                        if (!sources.Contains (iniGridName))
                            sources.Add (iniGridName);
                        iniFilePath = iniGridName;
                    }
                    else
                    {
                        iniFilePath = Util.BasePathCombine (iniGridName);

                        if (File.Exists (iniFilePath))
                        {
                            if (!sources.Contains (iniFilePath))
                                sources.Add (iniFilePath);
                        }
                    }
                }

                if (iniSimName != "")
                {
                    if (IsUri (iniSimName))
                    {
                        if (!sources.Contains (iniSimName))
                            sources.Add (iniSimName);
                        iniFilePath = iniSimName;
                    }
                    else
                    {
                        iniFilePath = Util.BasePathCombine (iniSimName);

                        if (File.Exists (iniFilePath))
                        {
                            if (!sources.Contains (iniFilePath))
                                sources.Add (iniFilePath);
                        }
                    }
                }

                string iniDirName =
                        startupConfig.GetString ("inidirectory", "");

                if (iniDirName != "" && Directory.Exists (iniDirName))
                {
                    m_log.InfoFormat ("Searching folder {0} for config ini files",
                            iniDirName);

                    string[] fileEntries = Directory.GetFiles (iniDirName);
                    foreach (string filePath in fileEntries)
                    {
                        if (Path.GetExtension (filePath).ToLower () == ".ini")
                        {
                            if (!sources.Contains (Path.Combine (iniDirName, filePath)))
                                sources.Add (Path.Combine (iniDirName, filePath));
                        }
                    }
                }
            }
            else
            {
                string mainIniDirectory = startupConfig.GetString ("mainIniDirectory", "");
                if(mainIniDirectory != "")
                    basePath = mainIniDirectory;

                string mainIniFileName = startupConfig.GetString ("mainIniFileName", defaultIniFile);

                string secondaryIniFileName = startupConfig.GetString ("secondaryIniFileName", "");

                if(mainIniFileName == "")
                {
                }
                else if (IsUri (mainIniFileName))
                {
                    if (!sources.Contains (mainIniFileName))
                        sources.Add (mainIniFileName);
                }
                else
                {
                    string mainIniFilePath = Path.Combine (mainIniDirectory, mainIniFileName);
                    if (!sources.Contains (mainIniFilePath))
                        sources.Add (mainIniFilePath);
                }

                if (secondaryIniFileName == "")
                {
                }
                else if (IsUri (secondaryIniFileName))
                {
                    if (!sources.Contains (secondaryIniFileName))
                        sources.Add (secondaryIniFileName);
                }
                else
                {
                    string secondaryIniFilePath = Path.Combine (mainIniDirectory, secondaryIniFileName);
                    if (!sources.Contains (secondaryIniFilePath))
                        sources.Add (secondaryIniFilePath);
                }
            }

            m_config = new IniConfigSource();
            
            m_log.Info("[Config]: Reading configuration settings");

            if (sources.Count == 0)
            {
                m_log.FatalFormat("[CONFIG]: Could not load any configuration");
                m_log.FatalFormat("[CONFIG]: Did you copy the " + defaultIniFile + ".example file to " + defaultIniFile + "?");
                throw new NotSupportedException();
            }

            List<string> triedPaths = new List<string> ();
            for (int i = 0 ; i < sources.Count ; i++)
            {
                if (ReadConfig(sources[i], i))
                    iniFileExists = true;
                AddIncludes (sources, basePath, ref i, ref triedPaths);
            }

            FixDefines (ref m_config);

            if (!iniFileExists)
            {
                m_log.FatalFormat("[CONFIG]: Could not load any configuration");
                m_log.FatalFormat("[CONFIG]: Configuration exists, but there was an error loading it!");
                throw new NotSupportedException();
            }
            // Make sure command line options take precedence
            m_config.Merge(argvSource);

            return m_config;
        }
        public uint Configure(IConfigSource config)
        {
            Config = config;

            IConfig startconfig = Config.Configs["Startup"];
            string configdirectory = startconfig.GetString("ConfigDirectory", ".");

            ConfigFile = Path.Combine(configdirectory, CONFIG_FILE);

            IConfig wifiConfig = Config.Configs[ConfigName];

            if (wifiConfig == null)
            {
                // No [WifiService] in the main configuration. We need to read it from its own file
                if (!File.Exists(ConfigFile))
                {
                    // We need to copy the one that comes in the package
                    if (!Directory.Exists(configdirectory))
                        Directory.CreateDirectory(configdirectory);

                    string embeddedConfig = Path.Combine(AssemblyDirectory, CONFIG_FILE);
                    File.Copy(embeddedConfig, ConfigFile);
                    m_log.ErrorFormat("[Wifi]: PLEASE EDIT {0} BEFORE RUNNING THIS SERVICE", ConfigFile);
                    throw new Exception("Wifi addin must be configured prior to running");
                }
                else
                {
                    m_log.DebugFormat("[Wifi]: Configuring from {0}...", ConfigFile);

                    IConfigSource configsource = new IniConfigSource(ConfigFile);
                    AdjustStorageProvider(configsource);

                    wifiConfig = configsource.Configs[ConfigName];

                    // Merge everything and expand eventual key values used by our config
                    Config.Merge(configsource);
                    Config.ExpandKeyValues();
                }

                if (wifiConfig == null)
                    throw new Exception(string.Format("[Wifi]: Could not load configuration from {0}. Unable to proceed.", ConfigFile));

            }

            Enabled = wifiConfig.GetBoolean("Enabled", false);

            // Let's look for the port in WifiService first, then look elsewhere
            int port = wifiConfig.GetInt("ServerPort", -1);
            if (port > 0)
                return (uint)port;

            IConfig section = Config.Configs["Const"];
            if (section != null)
            {
                port = section.GetInt("PublicPort", -1);
                if (port > 0)
                    return (uint)port;
            }

            if (port < 0)
                throw new Exception("[Wifi]: Could not find port in configuration file");

            return 0;
        }