From bab33ad24a4b960dc97eb0e179e99e52b12a1706 Mon Sep 17 00:00:00 2001 From: onefang Date: Thu, 8 Aug 2019 04:11:54 +1000 Subject: Various clean ups. --- .../Server/Handlers/Web/WebServerInConnector.cs | 113 ++++++++------------- 1 file changed, 44 insertions(+), 69 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Server/Handlers/Web/WebServerInConnector.cs b/OpenSim/Server/Handlers/Web/WebServerInConnector.cs index 1dedfa3..bcfb7ac 100644 --- a/OpenSim/Server/Handlers/Web/WebServerInConnector.cs +++ b/OpenSim/Server/Handlers/Web/WebServerInConnector.cs @@ -1,30 +1,3 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - using System; using System.Collections; using System.Collections.Generic; @@ -34,11 +7,11 @@ using System.Reflection; using System.Security; using System.Text; using log4net; +using Nini.Config; using OpenMetaverse; using OpenMetaverse.StructuredData; -using Nini.Config; -using OpenSim.Framework; using OpenSim.Data.MySQL; +using OpenSim.Framework; using OpenSim.Framework.Servers.HttpServer; using OpenSim.Server.Handlers.Base; @@ -55,14 +28,12 @@ namespace OpenSim.Server.Handlers.Web public WebServerInConnector(IConfigSource config, IHttpServer server, string configName) : base(config, server, configName) { - m_Config = config; - string dllName = String.Empty; string connString = String.Empty; - // + m_Config = config; + // Try reading the [DatabaseService] section, if it exists - // IConfig dbConfig = m_Config.Configs["DatabaseService"]; if (dbConfig != null) { @@ -71,7 +42,6 @@ namespace OpenSim.Server.Handlers.Web if (connString == String.Empty) connString = dbConfig.GetString("ConnectionString", String.Empty); } - if (dllName.Equals(String.Empty)) throw new Exception("No StorageProvider configured"); @@ -80,8 +50,6 @@ namespace OpenSim.Server.Handlers.Web // m_Database = LoadPlugin(dllName, new Object[] { connString }); m_database = new MySQLRaw(connString); - if (m_database == null) - throw new Exception("Could not find a storage interface in the given module " + dllName); mime.Add(".gz", "application/gzip"); mime.Add(".js", "application/javascript"); @@ -111,24 +79,24 @@ namespace OpenSim.Server.Handlers.Web IConfig cfg = m_Config.Configs["GridInfoService"]; string HomeURI = Util.GetConfigVarFromSections(m_Config, "HomeURI", new string[] { "Startup", "Hypergrid" }, String.Empty); - ssi.Add("grid", cfg.GetString("gridname", "my grid")); - ssi.Add("uri", cfg.GetString("login", HomeURI)); - ssi.Add("version", VersionInfo.Version); + ssi.Add("grid", cfg.GetString("gridname", "my grid")); + ssi.Add("uri", cfg.GetString("login", HomeURI)); + ssi.Add("version", VersionInfo.Version); server.AddHTTPHandler("/web/", WebRequestHandler); } private Hashtable WebRequestHandler(Hashtable request) { - long locIn = m_database.Count("Presence", "RegionID != '00000000-0000-0000-0000-000000000000'"); // Locals online but not HGing, and HGers in world. - long HGin = m_database.Count("Presence", "UserID NOT IN (SELECT PrincipalID FROM UserAccounts)"); // HGers in world. - long locOut = m_database.Count("hg_traveling_data", "GridExternalName != '" + ssi["uri"] + "'"); // Locals that are HGing. + long locIn = m_database.Count("Presence", "RegionID != '00000000-0000-0000-0000-000000000000'"); // Locals online but not HGing, and HGers in world. + long HGin = m_database.Count("Presence", "UserID NOT IN (SELECT PrincipalID FROM UserAccounts)"); // HGers in world. + long locOut = m_database.Count("hg_traveling_data", "GridExternalName != '" + ssi["uri"] + "'"); // Locals that are HGing. Hashtable reply = new Hashtable(); - ssi["members"] = m_database.Count("UserAccounts").ToString(); - ssi["sims"] = m_database.Count("regions").ToString(); - ssi["inworld"] = (locIn - HGin).ToString(); - ssi["outworld"] = locOut.ToString(); - ssi["hgers"] = HGin.ToString(); - ssi["month"] = m_database.Count("GridUser", "Login > UNIX_TIMESTAMP(FROM_UNIXTIME(UNIX_TIMESTAMP(now()) - 2419200))").ToString(); + ssi["members"] = m_database.Count("UserAccounts").ToString(); + ssi["sims"] = m_database.Count("regions").ToString(); + ssi["inworld"] = (locIn - HGin).ToString(); + ssi["outworld"] = locOut.ToString(); + ssi["hgers"] = HGin.ToString(); + ssi["month"] = m_database.Count("GridUser", "Login > UNIX_TIMESTAMP(FROM_UNIXTIME(UNIX_TIMESTAMP(now()) - 2419200))").ToString(); string reqpath = (string) request["uri"]; string[] query = (string[]) request["querystringkeys"]; @@ -148,26 +116,26 @@ namespace OpenSim.Server.Handlers.Web reply["int_response_code"] = 200; if ("GET" == method) { - if (File.Exists(path)) - { - string m = (string) mime[Path.GetExtension(path).ToLower()]; - reply["content_type"] = m; - if ((null == m) || ("text/" != m.Substring(0, 5))) - reply["bin_response_data"] = File.ReadAllBytes(path); - else - { - StreamReader csr = File.OpenText(path); - string content = csr.ReadToEnd(); - // Slow and wasteful, but I'm expecting only tiny web files, not accessed very often. - foreach (DictionaryEntry v in ssi) - { - content = content.Replace("", (string) v.Value); - } - reply["str_response_string"] = content; - csr.Close(); - } - } - else + if (File.Exists(path)) + { + string m = (string) mime[Path.GetExtension(path).ToLower()]; + reply["content_type"] = m; + if ((null == m) || ("text/" != m.Substring(0, 5))) + reply["bin_response_data"] = File.ReadAllBytes(path); + else + { + StreamReader csr = File.OpenText(path); + string content = csr.ReadToEnd(); + // Slow and wasteful, but I'm expecting only tiny web files, not accessed very often. + foreach (DictionaryEntry v in ssi) + { + content = content.Replace("", (string) v.Value); + } + reply["str_response_string"] = content; + csr.Close(); + } + } + else { if ("account.html" == file) reply["str_response_string"] = loginPage(null, ""); @@ -303,7 +271,7 @@ namespace OpenSim.Server.Handlers.Web { return "\n \n " + title + "\n \n \n"; } - // account.html?token=&UUID=.... + private string table(List< Hashtable > rows, string[] fields, string caption, string URL, string id) { string tbl = ""; @@ -350,14 +318,17 @@ namespace OpenSim.Server.Handlers.Web } return tbl + "
" + caption + "
"; } + private string form(string action, string token, string form) { return "
\n" + hidden("token", token) + form + "
\n"; } + private string hidden(string name, string val) { return " \n"; } + private string text(string type, string title, string name, string val, int max, bool required) { string extra = ""; @@ -369,10 +340,12 @@ namespace OpenSim.Server.Handlers.Web val = "value=\"" + val + "\""; return "

" + title + " :

\n"; } + private string select(string title, string name, string options) { return "

" + title + " : \n \n

\n"; } + private string option(string title, bool selected) { string sel = ""; @@ -380,10 +353,12 @@ namespace OpenSim.Server.Handlers.Web sel = " selected"; return " \n"; } + private string button(string title) { return " \n"; } + private string footer() { return " \n\n"; -- cgit v1.1