aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Servers
diff options
context:
space:
mode:
Diffstat (limited to 'Servers')
-rw-r--r--Servers/CapsHttpServer.cs332
-rw-r--r--Servers/OpenSim.Servers.csproj96
-rw-r--r--Servers/OpenSim.Servers.dll.build43
3 files changed, 471 insertions, 0 deletions
diff --git a/Servers/CapsHttpServer.cs b/Servers/CapsHttpServer.cs
new file mode 100644
index 0000000..1e62c81
--- /dev/null
+++ b/Servers/CapsHttpServer.cs
@@ -0,0 +1,332 @@
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
new file mode 100644
index 0000000..9c66943
--- /dev/null
+++ b/Servers/OpenSim.Servers.csproj
@@ -0,0 +1,96 @@
1<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2 <PropertyGroup>
3 <ProjectType>Local</ProjectType>
4 <ProductVersion>8.0.50727</ProductVersion>
5 <SchemaVersion>2.0</SchemaVersion>
6 <ProjectGuid>{A8E12EC9-CB2F-4D25-AFD0-626BF2162F5D}</ProjectGuid>
7 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
8 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
9 <ApplicationIcon></ApplicationIcon>
10 <AssemblyKeyContainerName>
11 </AssemblyKeyContainerName>
12 <AssemblyName>OpenSim.Servers</AssemblyName>
13 <DefaultClientScript>JScript</DefaultClientScript>
14 <DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>
15 <DefaultTargetSchema>IE50</DefaultTargetSchema>
16 <DelaySign>false</DelaySign>
17 <OutputType>Library</OutputType>
18 <AppDesignerFolder></AppDesignerFolder>
19 <RootNamespace>OpenSim.Servers</RootNamespace>
20 <StartupObject></StartupObject>
21 <FileUpgradeFlags>
22 </FileUpgradeFlags>
23 </PropertyGroup>
24 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
25 <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
26 <BaseAddress>285212672</BaseAddress>
27 <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
28 <ConfigurationOverrideFile>
29 </ConfigurationOverrideFile>
30 <DefineConstants>TRACE;DEBUG</DefineConstants>
31 <DocumentationFile></DocumentationFile>
32 <DebugSymbols>True</DebugSymbols>
33 <FileAlignment>4096</FileAlignment>
34 <Optimize>False</Optimize>
35 <OutputPath>..\bin\</OutputPath>
36 <RegisterForComInterop>False</RegisterForComInterop>
37 <RemoveIntegerChecks>False</RemoveIntegerChecks>
38 <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
39 <WarningLevel>4</WarningLevel>
40 <NoWarn></NoWarn>
41 </PropertyGroup>
42 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
43 <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
44 <BaseAddress>285212672</BaseAddress>
45 <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
46 <ConfigurationOverrideFile>
47 </ConfigurationOverrideFile>
48 <DefineConstants>TRACE</DefineConstants>
49 <DocumentationFile></DocumentationFile>
50 <DebugSymbols>False</DebugSymbols>
51 <FileAlignment>4096</FileAlignment>
52 <Optimize>True</Optimize>
53 <OutputPath>..\bin\</OutputPath>
54 <RegisterForComInterop>False</RegisterForComInterop>
55 <RemoveIntegerChecks>False</RemoveIntegerChecks>
56 <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
57 <WarningLevel>4</WarningLevel>
58 <NoWarn></NoWarn>
59 </PropertyGroup>
60 <ItemGroup>
61 <Reference Include="System" >
62 <HintPath>System.dll</HintPath>
63 <Private>False</Private>
64 </Reference>
65 <Reference Include="System.Xml" >
66 <HintPath>System.Xml.dll</HintPath>
67 <Private>False</Private>
68 </Reference>
69 <Reference Include="OpenSim.Framework.dll" >
70 <HintPath>..\bin\OpenSim.Framework.dll</HintPath>
71 <Private>False</Private>
72 </Reference>
73 <Reference Include="OpenSim.Framework.Console.dll" >
74 <HintPath>..\bin\OpenSim.Framework.Console.dll</HintPath>
75 <Private>False</Private>
76 </Reference>
77 <Reference Include="libsecondlife.dll" >
78 <HintPath>..\bin\libsecondlife.dll</HintPath>
79 <Private>False</Private>
80 </Reference>
81 </ItemGroup>
82 <ItemGroup>
83 </ItemGroup>
84 <ItemGroup>
85 <Compile Include="CapsHttpServer.cs">
86 <SubType>Code</SubType>
87 </Compile>
88 </ItemGroup>
89 <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
90 <PropertyGroup>
91 <PreBuildEvent>
92 </PreBuildEvent>
93 <PostBuildEvent>
94 </PostBuildEvent>
95 </PropertyGroup>
96</Project>
diff --git a/Servers/OpenSim.Servers.dll.build b/Servers/OpenSim.Servers.dll.build
new file mode 100644
index 0000000..1321629
--- /dev/null
+++ b/Servers/OpenSim.Servers.dll.build
@@ -0,0 +1,43 @@
1<?xml version="1.0" ?>
2<project name="OpenSim.Servers" default="build">
3 <target name="build">
4 <echo message="Build Directory is ${project::get-base-directory()}/${build.dir}" />
5 <mkdir dir="${project::get-base-directory()}/${build.dir}" />
6 <copy todir="${project::get-base-directory()}/${build.dir}">
7 <fileset basedir="${project::get-base-directory()}">
8 </fileset>
9 </copy>
10 <csc target="library" debug="${build.debug}" unsafe="False" define="TRACE;DEBUG" output="${project::get-base-directory()}/${build.dir}/${project::get-name()}.dll">
11 <resources prefix="OpenSim.Servers" dynamicprefix="true" >
12 </resources>
13 <sources failonempty="true">
14 <include name="CapsHttpServer.cs" />
15 </sources>
16 <references basedir="${project::get-base-directory()}">
17 <lib>
18 <include name="${project::get-base-directory()}" />
19 <include name="${project::get-base-directory()}/${build.dir}" />
20 </lib>
21 <include name="System.dll" />
22 <include name="System.Xml.dll" />
23 <include name="../bin/OpenSim.Framework.dll" />
24 <include name="../bin/OpenSim.Framework.Console.dll" />
25 <include name="../bin/libsecondlife.dll" />
26 </references>
27 </csc>
28 <echo message="Copying from [${project::get-base-directory()}/${build.dir}/] to [${project::get-base-directory()}/../bin/" />
29 <mkdir dir="${project::get-base-directory()}/../bin/"/>
30 <copy todir="${project::get-base-directory()}/../bin/">
31 <fileset basedir="${project::get-base-directory()}/${build.dir}/" >
32 <include name="*.dll"/>
33 <include name="*.exe"/>
34 </fileset>
35 </copy>
36 </target>
37 <target name="clean">
38 <delete dir="${bin.dir}" failonerror="false" />
39 <delete dir="${obj.dir}" failonerror="false" />
40 </target>
41 <target name="doc" description="Creates documentation.">
42 </target>
43</project>