aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Servers
diff options
context:
space:
mode:
authorlbsa712007-03-27 10:40:25 +0000
committerlbsa712007-03-27 10:40:25 +0000
commitb9c73c4859fd267cded06f44d3fe86157e5e9f3d (patch)
treeb3e496166d9e3d37ca74f8ece6bbea247b7a5282 /Servers
parentAdded REST-handler interface for the http server and changed the Admin Web fr... (diff)
downloadopensim-SC_OLD-b9c73c4859fd267cded06f44d3fe86157e5e9f3d.zip
opensim-SC_OLD-b9c73c4859fd267cded06f44d3fe86157e5e9f3d.tar.gz
opensim-SC_OLD-b9c73c4859fd267cded06f44d3fe86157e5e9f3d.tar.bz2
opensim-SC_OLD-b9c73c4859fd267cded06f44d3fe86157e5e9f3d.tar.xz
* Enabled the OpenSim.Servers project
Diffstat (limited to '')
-rw-r--r--Servers/CapsHttpServer.cs332
-rw-r--r--Servers/OpenSim.Servers.csproj5
-rw-r--r--Servers/OpenSim.Servers.dll.build1
3 files changed, 1 insertions, 337 deletions
diff --git a/Servers/CapsHttpServer.cs b/Servers/CapsHttpServer.cs
deleted file mode 100644
index 1e62c81..0000000
--- a/Servers/CapsHttpServer.cs
+++ /dev/null
@@ -1,332 +0,0 @@
1/*
2Copyright (c) OpenSimCAPS project, http://osgrid.org/
3
4
5* All rights reserved.
6*
7* Redistribution and use in source and binary forms, with or without
8* modification, are permitted provided that the following conditions are met:
9* * Redistributions of source code must retain the above copyright
10* notice, this list of conditions and the following disclaimer.
11* * Redistributions in binary form must reproduce the above copyright
12* notice, this list of conditions and the following disclaimer in the
13* documentation and/or other materials provided with the distribution.
14* * Neither the name of the <organization> nor the
15* names of its contributors may be used to endorse or promote products
16* derived from this software without specific prior written permission.
17*
18* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
19* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
22* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30using System;
31using System.Text;
32using Nwc.XmlRpc;
33using System.Threading;
34using System.Text.RegularExpressions;
35using System.Net;
36using System.IO;
37using System.Collections;
38using System.Collections.Generic;
39using libsecondlife;
40using OpenSim.Framework.Console;
41using OpenSim.Framework.Interfaces;
42
43namespace OpenSim.Servers
44{
45 // Dummy HTTP server, does nothing useful for now
46
47 public class CapsHttpServer
48 {
49 public Thread HTTPD;
50 public HttpListener Listener;
51 private string AdminPage;
52 private string NewAccountForm;
53 private string LoginForm;
54 private string passWord = "Admin";
55
56 public CapsHttpServer()
57 {
58 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Starting up HTTP Server");
59 HTTPD = new Thread(new ThreadStart(StartHTTP));
60 HTTPD.Start();
61 LoadAdminPage();
62 }
63
64 public void StartHTTP()
65 {
66 try
67 {
68 OpenSim.Framework.Console.MainConsole.Instance.WriteLine("SimHttp.cs:StartHTTP() - Spawned main thread OK");
69 Listener = new HttpListener();
70
71 Listener.Prefixes.Add("http://+:" + OpenSimRoot.Instance.Cfg.IPListenPort + "/");
72 Listener.Start();
73
74 HttpListenerContext context;
75 while (true)
76 {
77 context = Listener.GetContext();
78 ThreadPool.QueueUserWorkItem(new WaitCallback(HandleRequest), context);
79 }
80 }
81 catch (Exception e)
82 {
83 OpenSim.Framework.Console.MainConsole.Instance.WriteLine(e.Message);
84 }
85 }
86
87 private string ParseXMLRPC(string requestBody)
88 {
89 try
90 {
91 XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody);
92
93 Hashtable requestData = (Hashtable)request.Params[0];
94 switch (request.MethodName)
95 {
96 case "expect_user":
97 AgentCircuitData agent_data = new AgentCircuitData();
98 agent_data.SessionID = new LLUUID((string)requestData["session_id"]);
99 agent_data.SecureSessionID = new LLUUID((string)requestData["secure_session_id"]);
100 agent_data.firstname = (string)requestData["firstname"];
101 agent_data.lastname = (string)requestData["lastname"];
102 agent_data.AgentID = new LLUUID((string)requestData["agent_id"]);
103 agent_data.circuitcode = Convert.ToUInt32(requestData["circuit_code"]);
104 if (OpenSimRoot.Instance.GridServers.GridServer.GetName() == "Remote")
105 {
106 ((RemoteGridBase)OpenSimRoot.Instance.GridServers.GridServer).agentcircuits.Add((uint)agent_data.circuitcode, agent_data);
107 }
108 return "<?xml version=\"1.0\"?><methodResponse><params /></methodResponse>";
109 break;
110 }
111 }
112 catch (Exception e)
113 {
114 Console.WriteLine(e.ToString());
115 }
116 return "";
117 }
118
119 private string ParseREST(string requestBody, string requestURL, string requestMethod)
120 {
121 string responseString = "";
122 try
123 {
124 switch (requestURL)
125 {
126 case "/Admin/Accounts":
127 if (requestMethod == "GET")
128 {
129 responseString = "<p> Account management </p>";
130 responseString += "<br> ";
131 responseString += "<p> Create New Account </p>";
132 responseString += NewAccountForm;
133 }
134 break;
135 case "/Admin/Clients":
136 if (requestMethod == "GET")
137 {
138 responseString = " <p> Listing connected Clients </p>";
139 OpenSim.world.Avatar TempAv;
140 foreach (libsecondlife.LLUUID UUID in OpenSimRoot.Instance.LocalWorld.Entities.Keys)
141 {
142 if (OpenSimRoot.Instance.LocalWorld.Entities[UUID].ToString() == "OpenSim.world.Avatar")
143 {
144 TempAv = (OpenSim.world.Avatar)OpenSimRoot.Instance.LocalWorld.Entities[UUID];
145 responseString += "<p>";
146 responseString += String.Format("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16},{5,-16}", TempAv.firstname, TempAv.lastname, UUID, TempAv.ControllingClient.SessionID, TempAv.ControllingClient.CircuitCode, TempAv.ControllingClient.userEP.ToString());
147 responseString += "</p>";
148 }
149 }
150 }
151 break;
152 case "/Admin/NewAccount":
153 if (requestMethod == "POST")
154 {
155 string[] comp = new string[10];
156 string[] passw = new string[3];
157 string delimStr = "&";
158 char[] delimiter = delimStr.ToCharArray();
159 string delimStr2 = "=";
160 char[] delimiter2 = delimStr2.ToCharArray();
161
162 //Console.WriteLine(requestBody);
163 comp = requestBody.Split(delimiter);
164 passw = comp[3].Split(delimiter2);
165 if (passw[1] == passWord)
166 {
167 responseString = "<p> New Account created </p>";
168 }
169 else
170 {
171 responseString = "<p> Admin password is incorrect, please login with the correct password</p>";
172 responseString += "<br><br>" + LoginForm;
173 }
174 }
175 break;
176 case "/Admin/Login":
177 if (requestMethod == "POST")
178 {
179 // Console.WriteLine(requestBody);
180 if (requestBody == passWord)
181 {
182 responseString = "<p> Login Successful </p>";
183 }
184 else
185 {
186 responseString = "<p> Password Error </p>";
187 responseString += "<p> Please Login with the correct password </p>";
188 responseString += "<br><br> " + LoginForm;
189 }
190 }
191 break;
192 case "/Admin/Welcome":
193 if (requestMethod == "GET")
194 {
195 responseString = "Welcome to the OpenSim Admin Page";
196 responseString += "<br><br><br> " + LoginForm;
197
198 }
199 break;
200 }
201 }
202 catch (Exception e)
203 {
204 Console.WriteLine(e.ToString());
205 }
206
207 return responseString;
208 }
209
210 private string ParseLLSDXML(string requestBody)
211 {
212 // dummy function for now - IMPLEMENT ME!
213 return "";
214 }
215
216 public void HandleRequest(Object stateinfo)
217 {
218 // Console.WriteLine("new http incoming");
219 HttpListenerContext context = (HttpListenerContext)stateinfo;
220
221 HttpListenerRequest request = context.Request;
222 HttpListenerResponse response = context.Response;
223
224 response.KeepAlive = false;
225 response.SendChunked = false;
226
227 System.IO.Stream body = request.InputStream;
228 System.Text.Encoding encoding = System.Text.Encoding.UTF8;
229 System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding);
230
231 string requestBody = reader.ReadToEnd();
232 body.Close();
233 reader.Close();
234
235 //Console.WriteLine(request.HttpMethod + " " + request.RawUrl + " Http/" + request.ProtocolVersion.ToString() + " content type: " + request.ContentType);
236 //Console.WriteLine(requestBody);
237
238 string responseString = "";
239 switch (request.ContentType)
240 {
241 case "text/xml":
242 // must be XML-RPC, so pass to the XML-RPC parser
243
244 responseString = ParseXMLRPC(requestBody);
245 response.AddHeader("Content-type", "text/xml");
246 break;
247
248 case "application/xml":
249 // probably LLSD we hope, otherwise it should be ignored by the parser
250 responseString = ParseLLSDXML(requestBody);
251 response.AddHeader("Content-type", "application/xml");
252 break;
253
254 case "application/x-www-form-urlencoded":
255 // a form data POST so send to the REST parser
256 responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
257 response.AddHeader("Content-type", "text/html");
258 break;
259
260 case null:
261 if ((request.HttpMethod == "GET") && (request.RawUrl == "/Admin"))
262 {
263 responseString = AdminPage;
264 response.AddHeader("Content-type", "text/html");
265 }
266 else
267 {
268 // must be REST or invalid crap, so pass to the REST parser
269 responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
270 response.AddHeader("Content-type", "text/html");
271 }
272 break;
273
274 }
275
276 byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
277 System.IO.Stream output = response.OutputStream;
278 response.SendChunked = false;
279 response.ContentLength64 = buffer.Length;
280 output.Write(buffer, 0, buffer.Length);
281 output.Close();
282 }
283
284 private void LoadAdminPage()
285 {
286 try
287 {
288 StreamReader SR;
289 string lines;
290 AdminPage = "";
291 NewAccountForm = "";
292 LoginForm = "";
293 SR = File.OpenText("testadmin.htm");
294
295 while (!SR.EndOfStream)
296 {
297 lines = SR.ReadLine();
298 AdminPage += lines + "\n";
299
300 }
301 SR.Close();
302
303 SR = File.OpenText("newaccountform.htm");
304
305 while (!SR.EndOfStream)
306 {
307 lines = SR.ReadLine();
308 NewAccountForm += lines + "\n";
309
310 }
311 SR.Close();
312
313 SR = File.OpenText("login.htm");
314
315 while (!SR.EndOfStream)
316 {
317 lines = SR.ReadLine();
318 LoginForm += lines + "\n";
319
320 }
321 SR.Close();
322 }
323 catch (Exception e)
324 {
325 Console.WriteLine(e.ToString());
326 }
327
328 }
329 }
330
331
332}
diff --git a/Servers/OpenSim.Servers.csproj b/Servers/OpenSim.Servers.csproj
index 9c66943..bc386fd 100644
--- a/Servers/OpenSim.Servers.csproj
+++ b/Servers/OpenSim.Servers.csproj
@@ -3,7 +3,7 @@
3 <ProjectType>Local</ProjectType> 3 <ProjectType>Local</ProjectType>
4 <ProductVersion>8.0.50727</ProductVersion> 4 <ProductVersion>8.0.50727</ProductVersion>
5 <SchemaVersion>2.0</SchemaVersion> 5 <SchemaVersion>2.0</SchemaVersion>
6 <ProjectGuid>{A8E12EC9-CB2F-4D25-AFD0-626BF2162F5D}</ProjectGuid> 6 <ProjectGuid>{EAC45D69-AA44-45FB-B0CE-A95272A9B67B}</ProjectGuid>
7 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> 7 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
8 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> 8 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
9 <ApplicationIcon></ApplicationIcon> 9 <ApplicationIcon></ApplicationIcon>
@@ -82,9 +82,6 @@
82 <ItemGroup> 82 <ItemGroup>
83 </ItemGroup> 83 </ItemGroup>
84 <ItemGroup> 84 <ItemGroup>
85 <Compile Include="CapsHttpServer.cs">
86 <SubType>Code</SubType>
87 </Compile>
88 </ItemGroup> 85 </ItemGroup>
89 <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" /> 86 <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
90 <PropertyGroup> 87 <PropertyGroup>
diff --git a/Servers/OpenSim.Servers.dll.build b/Servers/OpenSim.Servers.dll.build
index 1321629..1d6b315 100644
--- a/Servers/OpenSim.Servers.dll.build
+++ b/Servers/OpenSim.Servers.dll.build
@@ -11,7 +11,6 @@
11 <resources prefix="OpenSim.Servers" dynamicprefix="true" > 11 <resources prefix="OpenSim.Servers" dynamicprefix="true" >
12 </resources> 12 </resources>
13 <sources failonempty="true"> 13 <sources failonempty="true">
14 <include name="CapsHttpServer.cs" />
15 </sources> 14 </sources>
16 <references basedir="${project::get-base-directory()}"> 15 <references basedir="${project::get-base-directory()}">
17 <lib> 16 <lib>