aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server
diff options
context:
space:
mode:
authoronefang2019-08-05 01:41:34 +1000
committeronefang2019-08-05 01:41:34 +1000
commit5fae30eb8863f3f39e6853584fd49197c52e8835 (patch)
treed4b8d58cde836103b17dec6539c59d4524caf3c9 /OpenSim/Server
parentWarning-- (diff)
downloadopensim-SC-5fae30eb8863f3f39e6853584fd49197c52e8835.zip
opensim-SC-5fae30eb8863f3f39e6853584fd49197c52e8835.tar.gz
opensim-SC-5fae30eb8863f3f39e6853584fd49197c52e8835.tar.bz2
opensim-SC-5fae30eb8863f3f39e6853584fd49197c52e8835.tar.xz
More basic web server.
Diffstat (limited to 'OpenSim/Server')
-rw-r--r--OpenSim/Server/Handlers/Web/WebServerInConnector.cs53
1 files changed, 46 insertions, 7 deletions
diff --git a/OpenSim/Server/Handlers/Web/WebServerInConnector.cs b/OpenSim/Server/Handlers/Web/WebServerInConnector.cs
index 94c636f..e7fb2fc 100644
--- a/OpenSim/Server/Handlers/Web/WebServerInConnector.cs
+++ b/OpenSim/Server/Handlers/Web/WebServerInConnector.cs
@@ -45,27 +45,60 @@ namespace OpenSim.Server.Handlers.Web
45{ 45{
46 public class WebServerInConnector : ServiceConnector 46 public class WebServerInConnector : ServiceConnector
47 { 47 {
48 // This is all slow and clunky, it's not a real web server, just something to use if you don't want a real one.
48 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49 private IConfigSource m_Config; 50 private IConfigSource m_Config;
50 private Hashtable mime = new Hashtable(); 51 private Hashtable mime = new Hashtable();
52 private Hashtable ssi = new Hashtable();
51 53
52 public WebServerInConnector(IConfigSource config, IHttpServer server, string configName) : base(config, server, configName) 54 public WebServerInConnector(IConfigSource config, IHttpServer server, string configName) : base(config, server, configName)
53 { 55 {
54 m_Config = config; 56 m_Config = config;
57 mime.Add(".gz", "application/gzip");
58 mime.Add(".js", "application/javascript");
59 mime.Add(".json", "application/json");
60 mime.Add(".pdf", "application/pdf");
61 mime.Add(".rtf", "application/rtf");
62 mime.Add(".zip", "application/zip");
63 mime.Add(".xz", "application/x-xz");
64 mime.Add(".gif", "image/gif");
65 mime.Add(".png", "image/png");
66 mime.Add(".jp2", "image/jp2");
67 mime.Add(".jpg2", "image/jp2");
68 mime.Add(".jpe", "image/jpeg");
69 mime.Add(".jpg", "image/jpeg");
70 mime.Add(".jpeg", "image/jpeg");
71 mime.Add(".svg", "image/svg+xml");
72 mime.Add(".svgz", "image/svg+xml");
73 mime.Add(".tif", "image/tiff");
74 mime.Add(".tiff", "image/tiff");
75 mime.Add(".css", "text/css");
55 mime.Add(".html", "text/html"); 76 mime.Add(".html", "text/html");
56 mime.Add(".htm", "text/html"); 77 mime.Add(".htm", "text/html");
57 mime.Add(".shtml", "text/html"); 78 mime.Add(".shtml", "text/html");
79// mime.Add(".md", "text/markdown");
80// mime.Add(".markdown","text/markdown");
58 mime.Add(".txt", "text/plain"); 81 mime.Add(".txt", "text/plain");
59 mime.Add(".css", "text/css"); 82
60 mime.Add(".js", "application/javascript"); 83 IConfig cfg = m_Config.Configs["GridInfoService"];
61 mime.Add(".png", "image/png"); 84 string HomeURI = Util.GetConfigVarFromSections<string>(m_Config, "HomeURI", new string[] { "Startup", "Hypergrid" }, String.Empty);
62 mime.Add(".jpeg", "image/jpeg"); 85 ssi.Add("grid", cfg.GetString("gridname", "my grid"));
86 ssi.Add("uri", cfg.GetString("login", HomeURI));
87 ssi.Add("version", VersionInfo.Version);
63 server.AddHTTPHandler("/web/", WebRequestHandler); 88 server.AddHTTPHandler("/web/", WebRequestHandler);
64 } 89 }
65 90
66 private Hashtable WebRequestHandler(Hashtable request) 91 private Hashtable WebRequestHandler(Hashtable request)
67 { 92 {
68 Hashtable reply = new Hashtable(); 93 Hashtable reply = new Hashtable();
94 // Looks like we have to jump through hoops to do simple database queries. B-(
95 ssi["members"] = "?"; // SELECT COUNT(PrincipalID) FROM UserAccounts
96 ssi["inworld"] = "?"; // SELECT COUNT(UserID) FROM presence_culled; Includes locals and HGers in world, but not locals HGing.
97 // SELECT COUNT(UserID) FROM users_online; Includes local online only.
98 ssi["outworld"] = "?"; // SELECT COUNT(UserID) FROM hg_traveling_data WHERE GridExternalName != ssi["uri"]; Includes locals that are HGing.
99// ssi["hgers"] = "?"; // This is complex.
100 ssi["sims"] = "?"; // SELECT COUNT(uuid) FROM regions
101// ssi["month"] = "?"; // SELECT COUNT(UserID) FROM Presence WHERE LastSeen < one month ago 2017-11-28 09:01:51; Includes external HGers, and locals on now.
69 102
70 string reqpath = (string) request["uri"]; 103 string reqpath = (string) request["uri"];
71 string[] query = (string[]) request["querystringkeys"]; 104 string[] query = (string[]) request["querystringkeys"];
@@ -78,16 +111,22 @@ namespace OpenSim.Server.Handlers.Web
78 reply["int_response_code"] = 200; 111 reply["int_response_code"] = 200;
79 if (File.Exists(file)) 112 if (File.Exists(file))
80 { 113 {
81 string m = (string) mime[Path.GetExtension(file)]; 114 string m = (string) mime[Path.GetExtension(file).ToLower()];
82 reply["content_type"] = m; 115 reply["content_type"] = m;
83 if (("image/jpeg" == m) || ("image/png" == m)) 116 if ((null == m) || ("text/" != m.Substring(0, 5)))
84 { 117 {
85 reply["bin_response_data"] = File.ReadAllBytes(file); 118 reply["bin_response_data"] = File.ReadAllBytes(file);
86 } 119 }
87 else 120 else
88 { 121 {
89 StreamReader csr = File.OpenText(file); 122 StreamReader csr = File.OpenText(file);
90 reply["str_response_string"] = csr.ReadToEnd(); 123 string content = csr.ReadToEnd();
124 // Slow and wasteful, but I'm expecting only tiny web files, not accessed very often.
125 foreach (DictionaryEntry v in ssi)
126 {
127 content = content.Replace("<!--#echo var=\"" + ((string) v.Key) + "\" -->", (string) v.Value);
128 }
129 reply["str_response_string"] = content;
91 csr.Close(); 130 csr.Close();
92 } 131 }
93 } 132 }