using System; using System.Collections.Generic; using System.Text; using System.IO; using OpenSim.world; namespace OpenSim.CAPS { public class AdminWebFront : IRestHandler { private string AdminPage; private string NewAccountForm; private string LoginForm; private string passWord = "Admin"; private World m_world; public AdminWebFront(string password, World world) { m_world = world; 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 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[] 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()); } } } }