-
diff --git a/OpenSim.RegionServer/CAPS/AdminWebFront.cs b/OpenSim.RegionServer/CAPS/AdminWebFront.cs
new file mode 100644
index 0000000..ea32589
--- /dev/null
+++ b/OpenSim.RegionServer/CAPS/AdminWebFront.cs
@@ -0,0 +1,164 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.IO;
+
+namespace OpenSim.CAPS
+{
+ public class AdminWebFront : IRestHandler
+ {
+ private string AdminPage;
+ private string NewAccountForm;
+ private string LoginForm;
+ private string passWord = "Admin";
+
+ public AdminWebFront(string password)
+ {
+ passWord = password;
+ LoadAdminPage();
+ }
+
+ public string HandleREST(string requestBody, string requestURL, string requestMethod)
+ {
+ string responseString = "";
+ try
+ {
+ switch (requestURL)
+ {
+ case "/Admin":
+ if (requestMethod == "GET")
+ {
+ responseString = AdminPage;
+ }
+ break;
+ case "/Admin/Accounts":
+ if (requestMethod == "GET")
+ {
+ responseString = " Account management
";
+ responseString += "
";
+ responseString += " Create New Account
";
+ responseString += NewAccountForm;
+ }
+ break;
+ case "/Admin/Clients":
+ if (requestMethod == "GET")
+ {
+ responseString = " Listing connected Clients
";
+ OpenSim.world.Avatar TempAv;
+ foreach (libsecondlife.LLUUID UUID in OpenSimRoot.Instance.LocalWorld.Entities.Keys)
+ {
+ if (OpenSimRoot.Instance.LocalWorld.Entities[UUID].ToString() == "OpenSim.world.Avatar")
+ {
+ TempAv = (OpenSim.world.Avatar)OpenSimRoot.Instance.LocalWorld.Entities[UUID];
+ responseString += "";
+ 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());
+ responseString += "
";
+ }
+ }
+ }
+ break;
+ case "/Admin/NewAccount":
+ if (requestMethod == "POST")
+ {
+ string[] comp = new string[10];
+ string[] passw = new string[3];
+ string delimStr = "&";
+ char[] delimiter = delimStr.ToCharArray();
+ string delimStr2 = "=";
+ char[] delimiter2 = delimStr2.ToCharArray();
+
+ //Console.WriteLine(requestBody);
+ comp = requestBody.Split(delimiter);
+ passw = comp[3].Split(delimiter2);
+ if (passw[1] == passWord)
+ {
+ responseString = " New Account created
";
+ }
+ else
+ {
+ responseString = " Admin password is incorrect, please login with the correct password
";
+ responseString += "
" + LoginForm;
+ }
+ }
+ break;
+ case "/Admin/Login":
+ if (requestMethod == "POST")
+ {
+ // Console.WriteLine(requestBody);
+ if (requestBody == passWord)
+ {
+ responseString = " Login Successful
";
+ }
+ else
+ {
+ responseString = " Password Error
";
+ responseString += " Please Login with the correct password
";
+ responseString += "
" + LoginForm;
+ }
+ }
+ break;
+ case "/Admin/Welcome":
+ if (requestMethod == "GET")
+ {
+ responseString = "Welcome to the OpenSim Admin Page";
+ responseString += "
" + LoginForm;
+
+ }
+ break;
+ }
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.ToString());
+ }
+ return responseString;
+ }
+
+ private void LoadAdminPage()
+ {
+ try
+ {
+ StreamReader SR;
+ string lines;
+ AdminPage = "";
+ NewAccountForm = "";
+ LoginForm = "";
+ SR = File.OpenText("testadmin.htm");
+
+ while (!SR.EndOfStream)
+ {
+ lines = SR.ReadLine();
+ AdminPage += lines + "\n";
+
+ }
+ SR.Close();
+
+ SR = File.OpenText("newaccountform.htm");
+
+ while (!SR.EndOfStream)
+ {
+ lines = SR.ReadLine();
+ NewAccountForm += lines + "\n";
+
+ }
+ SR.Close();
+
+ SR = File.OpenText("login.htm");
+
+ while (!SR.EndOfStream)
+ {
+ lines = SR.ReadLine();
+ LoginForm += lines + "\n";
+
+ }
+ SR.Close();
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.ToString());
+ }
+
+ }
+
+ }
+}
diff --git a/OpenSim.RegionServer/CAPS/IRestHandler.cs b/OpenSim.RegionServer/CAPS/IRestHandler.cs
new file mode 100644
index 0000000..f269600
--- /dev/null
+++ b/OpenSim.RegionServer/CAPS/IRestHandler.cs
@@ -0,0 +1,11 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace OpenSim.CAPS
+{
+ public interface IRestHandler
+ {
+ string HandleREST(string requestBody, string requestURL, string requestMethod);
+ }
+}
diff --git a/OpenSim.RegionServer/CAPS/SimHttp.cs b/OpenSim.RegionServer/CAPS/SimHttp.cs
index c3f4801..a1073f0 100644
--- a/OpenSim.RegionServer/CAPS/SimHttp.cs
+++ b/OpenSim.RegionServer/CAPS/SimHttp.cs
@@ -48,17 +48,13 @@ namespace OpenSim.CAPS
{
public Thread HTTPD;
public HttpListener Listener;
- private string AdminPage;
- private string NewAccountForm;
- private string LoginForm;
- private string passWord = "Admin";
+ private Dictionary restHandlers = new Dictionary();
public SimCAPSHTTPServer()
{
OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Starting up HTTP Server");
HTTPD = new Thread(new ThreadStart(StartHTTP));
HTTPD.Start();
- LoadAdminPage();
}
public void StartHTTP()
@@ -84,7 +80,18 @@ namespace OpenSim.CAPS
}
}
- private string ParseXMLRPC(string requestBody)
+ public bool AddRestHandler(string path, IRestHandler handler)
+ {
+ if (!this.restHandlers.ContainsKey(path))
+ {
+ this.restHandlers.Add(path, handler);
+ return true;
+ }
+
+ //must already have a handler for that path so return false
+ return false;
+ }
+ protected virtual string ParseXMLRPC(string requestBody)
{
try
{
@@ -116,104 +123,34 @@ namespace OpenSim.CAPS
return "";
}
- private string ParseREST(string requestBody, string requestURL, string requestMethod)
+ protected virtual string ParseREST(string requestBody, string requestURL, string requestMethod)
{
+ string[] path;
+ string pathDelimStr = "/";
+ char[] pathDelimiter = pathDelimStr.ToCharArray();
+ path = requestURL.Split(pathDelimiter);
+
string responseString = "";
- try
+
+ //path[0] should be empty so we are interested in path[1]
+ if (path.Length > 1)
{
- switch (requestURL)
+ if ((path[1] != "") && (this.restHandlers.ContainsKey(path[1])))
{
- case "/Admin/Accounts":
- if (requestMethod == "GET")
- {
- responseString = " Account management
";
- responseString += "
";
- responseString += " Create New Account
";
- responseString += NewAccountForm;
- }
- break;
- case "/Admin/Clients":
- if (requestMethod == "GET")
- {
- responseString = " Listing connected Clients
";
- OpenSim.world.Avatar TempAv;
- foreach (libsecondlife.LLUUID UUID in OpenSimRoot.Instance.LocalWorld.Entities.Keys)
- {
- if (OpenSimRoot.Instance.LocalWorld.Entities[UUID].ToString() == "OpenSim.world.Avatar")
- {
- TempAv = (OpenSim.world.Avatar)OpenSimRoot.Instance.LocalWorld.Entities[UUID];
- responseString += "";
- 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());
- responseString += "
";
- }
- }
- }
- break;
- case "/Admin/NewAccount":
- if (requestMethod == "POST")
- {
- string[] comp = new string[10];
- string[] passw = new string[3];
- string delimStr = "&";
- char[] delimiter = delimStr.ToCharArray();
- string delimStr2 = "=";
- char[] delimiter2 = delimStr2.ToCharArray();
-
- //Console.WriteLine(requestBody);
- comp = requestBody.Split(delimiter);
- passw = comp[3].Split(delimiter2);
- if (passw[1] == passWord)
- {
- responseString = " New Account created
";
- }
- else
- {
- responseString = " Admin password is incorrect, please login with the correct password
";
- responseString += "
" + LoginForm;
- }
- }
- break;
- case "/Admin/Login":
- if (requestMethod == "POST")
- {
- // Console.WriteLine(requestBody);
- if (requestBody == passWord)
- {
- responseString = " Login Successful
";
- }
- else
- {
- responseString = " Password Error
";
- responseString += " Please Login with the correct password
";
- responseString += "
" + LoginForm;
- }
- }
- break;
- case "/Admin/Welcome":
- if (requestMethod == "GET")
- {
- responseString = "Welcome to the OpenSim Admin Page";
- responseString += "
" + LoginForm;
-
- }
- break;
+ responseString = this.restHandlers[path[1]].HandleREST(requestBody, requestURL, requestMethod);
}
}
- catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- }
-
+
return responseString;
}
- private string ParseLLSDXML(string requestBody)
+ protected virtual string ParseLLSDXML(string requestBody)
{
// dummy function for now - IMPLEMENT ME!
return "";
}
- public void HandleRequest(Object stateinfo)
+ public virtual void HandleRequest(Object stateinfo)
{
// Console.WriteLine("new http incoming");
HttpListenerContext context = (HttpListenerContext)stateinfo;
@@ -258,17 +195,9 @@ namespace OpenSim.CAPS
break;
case null:
- if ((request.HttpMethod == "GET") && (request.RawUrl == "/Admin"))
- {
- responseString = AdminPage;
- response.AddHeader("Content-type", "text/html");
- }
- else
- {
- // must be REST or invalid crap, so pass to the REST parser
- responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
- response.AddHeader("Content-type", "text/html");
- }
+ // must be REST or invalid crap, so pass to the REST parser
+ responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
+ response.AddHeader("Content-type", "text/html");
break;
}
@@ -280,52 +209,6 @@ namespace OpenSim.CAPS
output.Write(buffer, 0, buffer.Length);
output.Close();
}
-
- private void LoadAdminPage()
- {
- try
- {
- StreamReader SR;
- string lines;
- AdminPage = "";
- NewAccountForm = "";
- LoginForm = "";
- SR = File.OpenText("testadmin.htm");
-
- while (!SR.EndOfStream)
- {
- lines = SR.ReadLine();
- AdminPage += lines + "\n";
-
- }
- SR.Close();
-
- SR = File.OpenText("newaccountform.htm");
-
- while (!SR.EndOfStream)
- {
- lines = SR.ReadLine();
- NewAccountForm += lines + "\n";
-
- }
- SR.Close();
-
- SR = File.OpenText("login.htm");
-
- while (!SR.EndOfStream)
- {
- lines = SR.ReadLine();
- LoginForm += lines + "\n";
-
- }
- SR.Close();
- }
- catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- }
-
- }
}
diff --git a/OpenSim.RegionServer/OpenSim.RegionServer.csproj b/OpenSim.RegionServer/OpenSim.RegionServer.csproj
index 2455f79..f376e04 100644
--- a/OpenSim.RegionServer/OpenSim.RegionServer.csproj
+++ b/OpenSim.RegionServer/OpenSim.RegionServer.csproj
@@ -1,4 +1,4 @@
-
+
Local
8.0.50727
@@ -6,7 +6,8 @@
{4171D545-81F5-4C64-AD29-6D7414C38181}
Debug
AnyCPU
-
+
+
OpenSim.RegionServer
@@ -15,9 +16,11 @@
IE50
false
Library
-
+
+
OpenSim.RegionServer
-
+
+
@@ -28,7 +31,8 @@
TRACE;DEBUG
-
+
+
True
4096
False
@@ -37,7 +41,8 @@
False
False
4
-
+
+
False
@@ -46,7 +51,8 @@
TRACE
-
+
+
False
4096
True
@@ -55,26 +61,28 @@
False
False
4
-
+
+
-
+
System.dll
False
-
+
+
System.Xml.dll
False
-
+
..\bin\libsecondlife.dll
False
-
+
..\bin\Axiom.MathLib.dll
False
-
+
..\bin\Db4objects.Db4o.dll
False
@@ -84,25 +92,27 @@
OpenSim.Framework.Console
{7AED7536-7D6B-4E28-8016-B5A554C663B4}
{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- False
+ False
OpenSim.Physics.Manager
{0AAA0EEB-1F2C-4B4B-9BFA-7C3E45BCD348}
{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- False
+ False
OpenSim.Framework
{90D4F7AF-D75E-4DE8-A0E1-70CC242B31A1}
{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- False
+ False
Code
+
+
Code
@@ -183,4 +193,4 @@
-
+
\ No newline at end of file
diff --git a/OpenSim.RegionServer/OpenSim.RegionServer.dll.build b/OpenSim.RegionServer/OpenSim.RegionServer.dll.build
index 37e4c3a..4e44c4b 100644
--- a/OpenSim.RegionServer/OpenSim.RegionServer.dll.build
+++ b/OpenSim.RegionServer/OpenSim.RegionServer.dll.build
@@ -23,6 +23,8 @@
+
+
diff --git a/OpenSim.RegionServer/OpenSimMain.cs b/OpenSim.RegionServer/OpenSimMain.cs
index e26f200..7425fca 100644
--- a/OpenSim.RegionServer/OpenSimMain.cs
+++ b/OpenSim.RegionServer/OpenSimMain.cs
@@ -114,6 +114,7 @@ namespace OpenSim
OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:Startup() - Starting CAPS HTTP server");
OpenSimRoot.Instance.HttpServer = new SimCAPSHTTPServer();
+ OpenSimRoot.Instance.HttpServer.AddRestHandler("Admin", new AdminWebFront("Admin"));
timer1.Enabled = true;
timer1.Interval = 100;
diff --git a/bin/login.htm b/bin/login.htm
index 2becee9..683af10 100644
--- a/bin/login.htm
+++ b/bin/login.htm
@@ -1,5 +1,5 @@
\ No newline at end of file
--
cgit v1.1