2007-03-27 09:35:03 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Text;
|
|
|
|
using System.IO;
|
2007-03-27 21:42:14 +00:00
|
|
|
using OpenSim.world;
|
2007-03-28 18:10:52 +00:00
|
|
|
using OpenSim.UserServer;
|
2007-03-29 19:05:34 +00:00
|
|
|
using OpenSim.Servers;
|
2007-03-30 10:14:15 +00:00
|
|
|
using OpenSim.Assets;
|
|
|
|
using OpenSim.Framework.Inventory;
|
2007-04-03 16:50:17 +00:00
|
|
|
using libsecondlife;
|
|
|
|
using OpenSim.RegionServer.world.scripting;
|
2007-04-03 19:12:07 +00:00
|
|
|
using Avatar=libsecondlife.Avatar;
|
2007-03-27 09:35:03 +00:00
|
|
|
|
|
|
|
namespace OpenSim.CAPS
|
|
|
|
{
|
2007-03-29 19:05:34 +00:00
|
|
|
public class AdminWebFront
|
2007-03-27 09:35:03 +00:00
|
|
|
{
|
|
|
|
private string AdminPage;
|
|
|
|
private string NewAccountForm;
|
|
|
|
private string LoginForm;
|
|
|
|
private string passWord = "Admin";
|
2007-03-27 21:42:14 +00:00
|
|
|
private World m_world;
|
2007-03-28 18:10:52 +00:00
|
|
|
private LoginServer _userServer;
|
2007-03-30 10:14:15 +00:00
|
|
|
private InventoryCache _inventoryCache;
|
2007-03-27 09:35:03 +00:00
|
|
|
|
2007-03-30 10:14:15 +00:00
|
|
|
public AdminWebFront(string password, World world, InventoryCache inventoryCache, LoginServer userserver)
|
2007-03-27 09:35:03 +00:00
|
|
|
{
|
2007-03-30 10:14:15 +00:00
|
|
|
_inventoryCache = inventoryCache;
|
2007-03-28 18:10:52 +00:00
|
|
|
_userServer = userserver;
|
2007-03-27 21:42:14 +00:00
|
|
|
m_world = world;
|
2007-03-27 09:35:03 +00:00
|
|
|
passWord = password;
|
|
|
|
LoadAdminPage();
|
|
|
|
}
|
|
|
|
|
2007-03-29 19:05:34 +00:00
|
|
|
public void LoadMethods( BaseHttpServer server )
|
2007-03-27 09:35:03 +00:00
|
|
|
{
|
2007-03-29 19:05:34 +00:00
|
|
|
server.AddRestHandler("GET", "/Admin", GetAdminPage);
|
|
|
|
server.AddRestHandler("GET", "/Admin/Welcome", GetWelcomePage);
|
|
|
|
server.AddRestHandler("GET", "/Admin/Accounts", GetAccountsPage );
|
2007-04-03 16:50:17 +00:00
|
|
|
server.AddRestHandler("GET", "/Admin/Clients", GetConnectedClientsPage);
|
|
|
|
server.AddRestHandler("GET", "/Admin/Entities", GetEntitiesPage);
|
|
|
|
server.AddRestHandler("GET", "/Admin/Scripts", GetScriptsPage);
|
|
|
|
server.AddRestHandler("GET", "/Admin/AddTestScript", AddTestScript );
|
2007-03-30 10:14:15 +00:00
|
|
|
server.AddRestHandler("GET", "/ClientInventory", GetClientsInventory);
|
2007-03-29 19:05:34 +00:00
|
|
|
|
|
|
|
server.AddRestHandler("POST", "/Admin/NewAccount", PostNewAccount );
|
2007-03-30 10:14:15 +00:00
|
|
|
server.AddRestHandler("POST", "/Admin/Login", PostLogin );
|
2007-03-29 19:05:34 +00:00
|
|
|
}
|
2007-03-29 19:22:01 +00:00
|
|
|
|
2007-04-11 14:14:19 +00:00
|
|
|
private string GetWelcomePage(string request, string path, string param)
|
2007-03-29 19:05:34 +00:00
|
|
|
{
|
|
|
|
string responseString;
|
|
|
|
responseString = "Welcome to the OpenSim Admin Page";
|
|
|
|
responseString += "<br><br><br> " + LoginForm;
|
|
|
|
return responseString;
|
|
|
|
}
|
|
|
|
|
2007-04-11 14:14:19 +00:00
|
|
|
private string PostLogin(string requestBody, string path, string param)
|
2007-03-29 19:05:34 +00:00
|
|
|
{
|
|
|
|
string responseString;
|
|
|
|
// Console.WriteLine(requestBody);
|
|
|
|
if (requestBody == passWord)
|
2007-03-27 09:35:03 +00:00
|
|
|
{
|
2007-03-29 19:05:34 +00:00
|
|
|
responseString = "<p> Login Successful </p>";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
responseString = "<p> Password Error </p>";
|
|
|
|
responseString += "<p> Please Login with the correct password </p>";
|
|
|
|
responseString += "<br><br> " + LoginForm;
|
|
|
|
}
|
|
|
|
return responseString;
|
|
|
|
}
|
2007-03-27 09:35:03 +00:00
|
|
|
|
2007-04-11 14:14:19 +00:00
|
|
|
private string PostNewAccount(string requestBody, string path, string param)
|
2007-03-29 19:05:34 +00:00
|
|
|
{
|
|
|
|
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();
|
2007-03-27 09:35:03 +00:00
|
|
|
|
2007-03-29 19:05:34 +00:00
|
|
|
//Console.WriteLine(requestBody);
|
|
|
|
comp = requestBody.Split(delimiter);
|
|
|
|
passw = comp[3].Split(delimiter2);
|
2007-03-29 20:55:44 +00:00
|
|
|
if (passw[1] == passWord) // check admin password is correct
|
2007-03-29 19:05:34 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
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);
|
2007-03-27 09:35:03 +00:00
|
|
|
}
|
2007-03-29 19:05:34 +00:00
|
|
|
responseString = "<p> New Account created </p>";
|
2007-03-27 09:35:03 +00:00
|
|
|
}
|
2007-03-29 19:05:34 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
responseString = "<p> Admin password is incorrect, please login with the correct password</p>";
|
|
|
|
responseString += "<br><br>" + LoginForm;
|
|
|
|
}
|
|
|
|
return responseString;
|
|
|
|
}
|
|
|
|
|
2007-04-11 14:14:19 +00:00
|
|
|
private string GetConnectedClientsPage(string request, string path, string param)
|
2007-03-29 19:05:34 +00:00
|
|
|
{
|
|
|
|
string responseString;
|
|
|
|
responseString = " <p> Listing connected Clients </p>";
|
|
|
|
OpenSim.world.Avatar TempAv;
|
|
|
|
foreach (libsecondlife.LLUUID UUID in m_world.Entities.Keys)
|
2007-03-27 09:35:03 +00:00
|
|
|
{
|
2007-03-29 19:05:34 +00:00
|
|
|
if (m_world.Entities[UUID].ToString() == "OpenSim.world.Avatar")
|
|
|
|
{
|
|
|
|
TempAv = (OpenSim.world.Avatar)m_world.Entities[UUID];
|
2007-03-30 10:14:15 +00:00
|
|
|
responseString += "<p> Client: ";
|
2007-04-03 13:37:11 +00:00
|
|
|
responseString += TempAv.firstname + " , " + TempAv.lastname + " , <A HREF=\"javascript:loadXMLDoc('ClientInventory/" + UUID.ToString() + "')\">" + UUID + "</A> , " + TempAv.ControllingClient.SessionID + " , " + TempAv.ControllingClient.CircuitCode + " , " + TempAv.ControllingClient.userEP.ToString();
|
2007-03-29 19:05:34 +00:00
|
|
|
responseString += "</p>";
|
|
|
|
}
|
2007-03-27 09:35:03 +00:00
|
|
|
}
|
|
|
|
return responseString;
|
|
|
|
}
|
|
|
|
|
2007-04-11 14:14:19 +00:00
|
|
|
private string AddTestScript(string request, string path, string param)
|
2007-04-03 16:50:17 +00:00
|
|
|
{
|
|
|
|
int index = path.LastIndexOf('/');
|
|
|
|
|
|
|
|
string lluidStr = path.Substring(index+1);
|
|
|
|
|
|
|
|
LLUUID id;
|
|
|
|
|
|
|
|
if( LLUUID.TryParse( lluidStr, out id ) )
|
|
|
|
{
|
|
|
|
// This is just here for concept purposes... Remove!
|
2007-04-03 20:08:30 +00:00
|
|
|
m_world.AddScript( m_world.Entities[id], new FollowRandomAvatar());
|
2007-04-03 16:50:17 +00:00
|
|
|
return String.Format("Added new script to object [{0}]", id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return String.Format("Couldn't parse [{0}]", lluidStr );
|
|
|
|
}
|
|
|
|
}
|
2007-04-11 14:14:19 +00:00
|
|
|
|
|
|
|
private string GetScriptsPage(string request, string path, string param)
|
2007-04-03 16:50:17 +00:00
|
|
|
{
|
|
|
|
return String.Empty;
|
|
|
|
}
|
2007-04-11 14:14:19 +00:00
|
|
|
|
|
|
|
private string GetEntitiesPage(string request, string path, string param)
|
2007-04-03 16:50:17 +00:00
|
|
|
{
|
|
|
|
string responseString;
|
|
|
|
responseString = " <p> Listing current entities</p><ul>";
|
|
|
|
|
|
|
|
foreach (Entity entity in m_world.Entities.Values)
|
|
|
|
{
|
|
|
|
string testScriptLink = "javascript:loadXMLDoc('Admin/AddTestScript/" + entity.uuid.ToString() + "');";
|
2007-04-03 19:12:07 +00:00
|
|
|
responseString += String.Format( "<li>[{0}] \"{1}\" @ {2} <a href=\"{3}\">add test script</a></li>", entity.uuid, entity.Name, entity.Pos, testScriptLink );
|
2007-04-03 16:50:17 +00:00
|
|
|
}
|
|
|
|
responseString += "</ul>";
|
|
|
|
return responseString;
|
|
|
|
}
|
|
|
|
|
2007-04-11 14:14:19 +00:00
|
|
|
private string GetClientsInventory(string request, string path, string param)
|
2007-03-30 10:14:15 +00:00
|
|
|
{
|
|
|
|
string[] line;
|
|
|
|
string delimStr = "/";
|
|
|
|
char[] delimiter = delimStr.ToCharArray();
|
|
|
|
string responseString;
|
|
|
|
responseString = " <p> Listing Inventory </p>";
|
|
|
|
|
|
|
|
line = path.Split(delimiter);
|
|
|
|
if (line.Length > 2)
|
|
|
|
{
|
|
|
|
if (line[1] == "ClientInventory")
|
|
|
|
{
|
|
|
|
AgentInventory inven = this._inventoryCache.GetAgentsInventory(new libsecondlife.LLUUID(line[2]));
|
|
|
|
responseString += " <p> Client: " + inven.AgentID.ToStringHyphenated() +" </p>";
|
|
|
|
if (inven != null)
|
|
|
|
{
|
|
|
|
foreach (InventoryItem item in inven.InventoryItems.Values)
|
|
|
|
{
|
|
|
|
responseString += "<p> InventoryItem: ";
|
2007-04-03 13:37:11 +00:00
|
|
|
responseString += item.Name +" , "+ item.ItemID +" , "+ item.Type +" , "+ item.FolderID +" , "+ item.AssetID +" , "+ item.Description ;
|
2007-03-30 10:14:15 +00:00
|
|
|
responseString += "</p>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return responseString;
|
|
|
|
}
|
|
|
|
|
2007-04-11 14:14:19 +00:00
|
|
|
private string GetCachedAssets(string request, string path, string param)
|
2007-03-30 10:14:15 +00:00
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2007-04-11 14:14:19 +00:00
|
|
|
private string GetAccountsPage(string request, string path, string param)
|
2007-03-29 19:05:34 +00:00
|
|
|
{
|
|
|
|
string responseString;
|
|
|
|
responseString = "<p> Account management </p>";
|
|
|
|
responseString += "<br> ";
|
|
|
|
responseString += "<p> Create New Account </p>";
|
|
|
|
responseString += NewAccountForm;
|
|
|
|
return responseString;
|
|
|
|
}
|
|
|
|
|
2007-04-11 14:14:19 +00:00
|
|
|
private string GetAdminPage(string request, string path, string param)
|
2007-03-29 19:05:34 +00:00
|
|
|
{
|
|
|
|
return AdminPage;
|
|
|
|
}
|
|
|
|
|
2007-03-27 09:35:03 +00:00
|
|
|
private void LoadAdminPage()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
StreamReader SR;
|
2007-04-03 16:50:17 +00:00
|
|
|
|
2007-03-27 09:35:03 +00:00
|
|
|
SR = File.OpenText("testadmin.htm");
|
2007-04-03 16:50:17 +00:00
|
|
|
AdminPage = SR.ReadToEnd();
|
2007-03-27 09:35:03 +00:00
|
|
|
SR.Close();
|
|
|
|
|
|
|
|
SR = File.OpenText("newaccountform.htm");
|
2007-04-03 16:50:17 +00:00
|
|
|
NewAccountForm = SR.ReadToEnd();
|
2007-03-27 09:35:03 +00:00
|
|
|
SR.Close();
|
|
|
|
|
|
|
|
SR = File.OpenText("login.htm");
|
2007-04-03 16:50:17 +00:00
|
|
|
LoginForm = SR.ReadToEnd();
|
2007-03-27 09:35:03 +00:00
|
|
|
SR.Close();
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Console.WriteLine(e.ToString());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|