using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using OpenSim.world;
using OpenSim.UserServer;
using OpenSim.Servers;
using OpenSim.Assets;
using OpenSim.Framework.Inventory;
namespace OpenSim.CAPS
{
public class AdminWebFront
{
private string AdminPage;
private string NewAccountForm;
private string LoginForm;
private string passWord = "Admin";
private World m_world;
private LoginServer _userServer;
private InventoryCache _inventoryCache;
public AdminWebFront(string password, World world, InventoryCache inventoryCache, LoginServer userserver)
{
_inventoryCache = inventoryCache;
_userServer = userserver;
m_world = world;
passWord = password;
LoadAdminPage();
}
public void LoadMethods( BaseHttpServer server )
{
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("GET", "/ClientInventory", GetClientsInventory);
server.AddRestHandler("POST", "/Admin/NewAccount", PostNewAccount );
server.AddRestHandler("POST", "/Admin/Login", PostLogin );
}
private string GetWelcomePage(string request, string path)
{
string responseString;
responseString = "Welcome to the OpenSim Admin Page";
responseString += "
" + LoginForm;
return responseString;
}
private string PostLogin(string requestBody, string path)
{
string responseString;
// Console.WriteLine(requestBody);
if (requestBody == passWord)
{
responseString = "
Login Successful
"; } else { responseString = "Password Error
"; responseString += "Please Login with the correct password
"; responseString += "New Account created
"; } else { responseString = "Admin password is incorrect, please login with the correct password
"; 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 += "Client: "; responseString += TempAv.firstname + " , " + TempAv.lastname + " , " + UUID + " , " + TempAv.ControllingClient.SessionID + " , " + TempAv.ControllingClient.CircuitCode + " , " + TempAv.ControllingClient.userEP.ToString();//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 GetClientsInventory(string request, string path) { string[] line; string delimStr = "/"; char[] delimiter = delimStr.ToCharArray(); string responseString; responseString = "Listing Inventory
"; line = path.Split(delimiter); if (line.Length > 2) { if (line[1] == "ClientInventory") { AgentInventory inven = this._inventoryCache.GetAgentsInventory(new libsecondlife.LLUUID(line[2])); responseString += "Client: " + inven.AgentID.ToStringHyphenated() +"
"; if (inven != null) { foreach (InventoryItem item in inven.InventoryItems.Values) { responseString += "InventoryItem: "; responseString += item.Name +" , "+ item.ItemID +" , "+ item.Type +" , "+ item.FolderID +" , "+ item.AssetID +" , "+ item.Description ; //String.Format("{0,-16}{1,-16}{2,-25}{3,-25}{4,-16},{5,-16}", item.Name, item.ItemID, item.Type, item.FolderID, item.AssetID, item.Description); responseString += "
"; } } } } return responseString; } private string GetCachedAssets(string request, string path) { return ""; } private string GetAccountsPage(string request, string path) { string responseString; responseString = "Account management
"; responseString += "Create New Account
"; responseString += NewAccountForm; return responseString; } private string GetAdminPage(string request, string path) { return AdminPage; } 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()); } } } }