diff options
author | onefang | 2019-08-04 10:30:42 +1000 |
---|---|---|
committer | onefang | 2019-08-04 10:30:42 +1000 |
commit | bf27216a290c125f565d08700bb6693387fac9bf (patch) | |
tree | 6d65f274666c6fd9cf21d8a8561c0289535ce051 /OpenSim/Server/Handlers/Web | |
parent | Don't wait_for_text for anything between [], coz that's a grep thing. (diff) | |
download | opensim-SC_OLD-bf27216a290c125f565d08700bb6693387fac9bf.zip opensim-SC_OLD-bf27216a290c125f565d08700bb6693387fac9bf.tar.gz opensim-SC_OLD-bf27216a290c125f565d08700bb6693387fac9bf.tar.bz2 opensim-SC_OLD-bf27216a290c125f565d08700bb6693387fac9bf.tar.xz |
Add a basic generic web server, and a login page, plus stubs for the other basic pages.
And update everyone to suit.
Diffstat (limited to 'OpenSim/Server/Handlers/Web')
-rw-r--r-- | OpenSim/Server/Handlers/Web/WebServerInConnector.cs | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/OpenSim/Server/Handlers/Web/WebServerInConnector.cs b/OpenSim/Server/Handlers/Web/WebServerInConnector.cs new file mode 100644 index 0000000..94c636f --- /dev/null +++ b/OpenSim/Server/Handlers/Web/WebServerInConnector.cs | |||
@@ -0,0 +1,107 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.IO; | ||
32 | using System.Net; | ||
33 | using System.Reflection; | ||
34 | using System.Security; | ||
35 | using System.Text; | ||
36 | using log4net; | ||
37 | using OpenMetaverse; | ||
38 | using OpenMetaverse.StructuredData; | ||
39 | using Nini.Config; | ||
40 | using OpenSim.Framework; | ||
41 | using OpenSim.Framework.Servers.HttpServer; | ||
42 | using OpenSim.Server.Handlers.Base; | ||
43 | |||
44 | namespace OpenSim.Server.Handlers.Web | ||
45 | { | ||
46 | public class WebServerInConnector : ServiceConnector | ||
47 | { | ||
48 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | private IConfigSource m_Config; | ||
50 | private Hashtable mime = new Hashtable(); | ||
51 | |||
52 | public WebServerInConnector(IConfigSource config, IHttpServer server, string configName) : base(config, server, configName) | ||
53 | { | ||
54 | m_Config = config; | ||
55 | mime.Add(".html", "text/html"); | ||
56 | mime.Add(".htm", "text/html"); | ||
57 | mime.Add(".shtml", "text/html"); | ||
58 | mime.Add(".txt", "text/plain"); | ||
59 | mime.Add(".css", "text/css"); | ||
60 | mime.Add(".js", "application/javascript"); | ||
61 | mime.Add(".png", "image/png"); | ||
62 | mime.Add(".jpeg", "image/jpeg"); | ||
63 | server.AddHTTPHandler("/web/", WebRequestHandler); | ||
64 | } | ||
65 | |||
66 | private Hashtable WebRequestHandler(Hashtable request) | ||
67 | { | ||
68 | Hashtable reply = new Hashtable(); | ||
69 | |||
70 | string reqpath = (string) request["uri"]; | ||
71 | string[] query = (string[]) request["querystringkeys"]; | ||
72 | Hashtable headers = (Hashtable) request["headers"]; | ||
73 | string method = (string) request["http-method"]; | ||
74 | string type = (string) request["content-type"]; | ||
75 | string body = (string) request["body"]; | ||
76 | string file = Path.Combine(Util.webDir(), reqpath.Remove(0, 5)); | ||
77 | |||
78 | reply["int_response_code"] = 200; | ||
79 | if (File.Exists(file)) | ||
80 | { | ||
81 | string m = (string) mime[Path.GetExtension(file)]; | ||
82 | reply["content_type"] = m; | ||
83 | if (("image/jpeg" == m) || ("image/png" == m)) | ||
84 | { | ||
85 | reply["bin_response_data"] = File.ReadAllBytes(file); | ||
86 | } | ||
87 | else | ||
88 | { | ||
89 | StreamReader csr = File.OpenText(file); | ||
90 | reply["str_response_string"] = csr.ReadToEnd(); | ||
91 | csr.Close(); | ||
92 | } | ||
93 | } | ||
94 | else | ||
95 | { | ||
96 | m_log.ErrorFormat("[WEB SERVICE]: Unable to read {0}.", file); | ||
97 | reply["int_response_code"] = 404; | ||
98 | reply["content_type"] = "text/html"; | ||
99 | reply["str_response_string"] = "<html><title>404 Unknown page</title><head></head><body bgcolor=\"black\" text=\"white\" alink=\"red\" link=\"blue\" vlink=\"purple\">" + | ||
100 | "404 error, can't find the " + reqpath + " page.<p> </p></body></html>"; | ||
101 | } | ||
102 | |||
103 | return reply; | ||
104 | } | ||
105 | |||
106 | } | ||
107 | } | ||