From 514a3230563e19708588945f90e81760377f1265 Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Thu, 29 Mar 2007 19:05:34 +0000 Subject: * RestMethod now uses same pattern as XmlRpcMethod * Made /Admin use RestMethod * HttpServer is now a mini-webapp-server yay! --- OpenSim.RegionServer/CAPS/AdminWebFront.cs | 221 ++++++++++++++--------------- OpenSim.RegionServer/OpenSimMain.cs | 3 +- 2 files changed, 112 insertions(+), 112 deletions(-) (limited to 'OpenSim.RegionServer') diff --git a/OpenSim.RegionServer/CAPS/AdminWebFront.cs b/OpenSim.RegionServer/CAPS/AdminWebFront.cs index 8224050..3596ffa 100644 --- a/OpenSim.RegionServer/CAPS/AdminWebFront.cs +++ b/OpenSim.RegionServer/CAPS/AdminWebFront.cs @@ -4,10 +4,11 @@ using System.Text; using System.IO; using OpenSim.world; using OpenSim.UserServer; +using OpenSim.Servers; namespace OpenSim.CAPS { - public class AdminWebFront : IRestHandler + public class AdminWebFront { private string AdminPage; private string NewAccountForm; @@ -24,126 +25,124 @@ namespace OpenSim.CAPS LoadAdminPage(); } - public string HandleREST(string requestBody, string requestURL, string requestMethod) + public void LoadMethods( BaseHttpServer server ) { - string responseString = ""; - try + server.AddRestHandler("GET", "/Admin", GetAdminPage); + server.AddRestHandler("GET", "/Admin/Welcome", GetWelcomePage); + server.AddRestHandler("GET", "/Admin/Accounts", GetAccountsPage ); + server.AddRestHandler("GET", "/Admin/Clients", GetConnectedClientsPage ); + + server.AddRestHandler("POST", "/Admin/NewAccount", PostNewAccount ); + server.AddRestHandler("POST", "/Admin/Login", PostLogin ); + } + + private string GetWelcomePage( string request ) + { + string responseString; + responseString = "Welcome to the OpenSim Admin Page"; + responseString += "


" + LoginForm; + return responseString; + } + + private string PostLogin(string requestBody) + { + string responseString; +// Console.WriteLine(requestBody); + if (requestBody == passWord) + { + responseString = "

Login Successful

"; + } + else + { + responseString = "

Password Error

"; + responseString += "

Please Login with the correct password

"; + responseString += "

" + LoginForm; + } + return responseString; + } + + private string PostNewAccount(string requestBody) + { + string responseString; + string firstName = ""; + string secondName = ""; + string userPasswd = ""; + string[] comp; + string[] passw; + string[] line; + 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) { - 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 m_world.Entities.Keys) - { - if (m_world.Entities[UUID].ToString() == "OpenSim.world.Avatar") - { - TempAv = (OpenSim.world.Avatar)m_world.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 firstName = ""; - string secondName = ""; - string userPasswd = ""; - string[] comp; - string[] passw; - string[] line; - 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) - { - line = comp[0].Split(delimiter2); //split firstname - if (line.Length > 1) - { - firstName = line[1]; - } - line = comp[1].Split(delimiter2); //split secondname - if (line.Length > 1) - { - secondName = line[1]; - } - line = comp[2].Split(delimiter2); //split user password - if (line.Length > 1) - { - userPasswd = line[1]; - } - if (this._userServer != null) - { - this._userServer.CreateUserAccount(firstName, secondName, userPasswd); - } - 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; + line = comp[0].Split(delimiter2); //split firstname + if (line.Length > 1) + { + firstName = line[1]; } + line = comp[1].Split(delimiter2); //split secondname + if (line.Length > 1) + { + secondName = line[1]; + } + line = comp[2].Split(delimiter2); //split user password + if (line.Length > 1) + { + userPasswd = line[1]; + } + if (this._userServer != null) + { + this._userServer.CreateUserAccount(firstName, secondName, userPasswd); + } + responseString = "

New Account created

"; } - catch (Exception e) + else { - Console.WriteLine(e.ToString()); + responseString = "

Admin password is incorrect, please login with the correct password

"; + responseString += "

" + LoginForm; + } + return responseString; + } + + private string GetConnectedClientsPage( string request ) + { + string responseString; + responseString = "

Listing connected Clients

"; + OpenSim.world.Avatar TempAv; + foreach (libsecondlife.LLUUID UUID in m_world.Entities.Keys) + { + if (m_world.Entities[UUID].ToString() == "OpenSim.world.Avatar") + { + TempAv = (OpenSim.world.Avatar)m_world.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 += "

"; + } } return responseString; } + private string GetAccountsPage( string request ) + { + string responseString; + responseString = "

Account management

"; + responseString += "
"; + responseString += "

Create New Account

"; + responseString += NewAccountForm; + return responseString; + } + + private string GetAdminPage( string request ) + { + return AdminPage; + } + private void LoadAdminPage() { try diff --git a/OpenSim.RegionServer/OpenSimMain.cs b/OpenSim.RegionServer/OpenSimMain.cs index 51ec12b..36e1817 100644 --- a/OpenSim.RegionServer/OpenSimMain.cs +++ b/OpenSim.RegionServer/OpenSimMain.cs @@ -199,7 +199,8 @@ namespace OpenSim } } - HttpServer.AddRestHandler("Admin", new AdminWebFront("Admin", LocalWorld, adminLoginServer )); + AdminWebFront adminWebFront = new AdminWebFront("Admin", LocalWorld, adminLoginServer); + adminWebFront.LoadMethods( HttpServer ); m_console.WriteLine("Main.cs:Startup() - Starting HTTP server"); HttpServer.Start(); -- cgit v1.1