Added a very very very basic Web front end for admin use - ready to be used in sandbox mode for adding new accounts.

tourmaline
MW 2007-03-26 16:51:50 +00:00
parent 7f18a96763
commit 42ba071276
8 changed files with 341 additions and 14 deletions

View File

@ -9,7 +9,7 @@ namespace OpenSim.Framework.Utilities
public class Util
{
private static Random randomClass = new Random();
private static uint nextXferID = 10000;
private static uint nextXferID = 5000;
private static object XferLock = new object();
public static ulong UIntsToLong(uint X, uint Y)

View File

@ -79,7 +79,6 @@ namespace OpenSim
}
/* for now we will only support uploading of textures
else if (pack.AssetBlock.Type == 13 | pack.AssetBlock.Type == 5)
{
@ -92,7 +91,7 @@ namespace OpenSim
asset.Data = pack.AssetBlock.AssetData;
}*/
}
if (asset != null)
{
@ -169,6 +168,22 @@ namespace OpenSim
#endregion
public AssetBase AddUploadToAssetCache(LLUUID transactionID)
{
AssetBase asset = null;
if(this.transactions.ContainsKey(transactionID))
{
AssetTransaction trans = this.transactions[transactionID];
if (trans.UploadComplete)
{
OpenSimRoot.Instance.AssetCache.AddAsset(trans.Asset);
asset = trans.Asset;
}
}
return asset;
}
public void CreateInventoryItem(CreateInventoryItemPacket packet)
{
if(this.transactions.ContainsKey(packet.InventoryBlock.TransactionID))

View File

@ -57,6 +57,16 @@ namespace OpenSim.Assets
this._agentsInventory.Add(agentInventory.AgentID, agentInventory);
}
public AgentInventory GetAgentsInventory(LLUUID agentID)
{
if (this._agentsInventory.ContainsKey(agentID))
{
return this._agentsInventory[agentID];
}
return null;
}
public void ClientLeaving(LLUUID clientID)
{
if (this._agentsInventory.ContainsKey(clientID))

View File

@ -48,12 +48,17 @@ namespace OpenSim.CAPS
{
public Thread HTTPD;
public HttpListener Listener;
private string AdminPage;
private string NewAccountForm;
private string LoginForm;
private string passWord = "Admin";
public SimCAPSHTTPServer()
{
OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Starting up HTTP Server");
HTTPD = new Thread(new ThreadStart(StartHTTP));
HTTPD.Start();
LoadAdminPage();
}
public void StartHTTP()
@ -79,7 +84,7 @@ namespace OpenSim.CAPS
}
}
static string ParseXMLRPC(string requestBody)
private string ParseXMLRPC(string requestBody)
{
try
{
@ -111,19 +116,101 @@ namespace OpenSim.CAPS
return "";
}
static string ParseREST(string requestBody, string requestURL)
private string ParseREST(string requestBody, string requestURL, string requestMethod)
{
return "";
string responseString = "";
switch (requestURL)
{
case "/Admin/Accounts":
if (requestMethod == "GET")
{
responseString = "<p> Account management </p>";
responseString += "<br> ";
responseString += "<p> Create New Account </p>";
responseString += NewAccountForm;
}
break;
case "/Admin/Clients":
if (requestMethod == "GET")
{
responseString = " <p> Listing connected Clients </p>" ;
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 += "<p>";
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 += "</p>";
}
}
}
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 = "<p> New Account created </p>";
}
else
{
responseString = "<p> Admin password is incorrect, please login with the correct password</p>";
responseString += "<br><br>" + LoginForm;
}
}
break;
case "/Admin/Login":
if (requestMethod == "POST")
{
Console.WriteLine(requestBody);
if (requestBody == passWord)
{
responseString = "<p> Login Successful </p>";
}
else
{
responseString = "<p> PassWord Error </p>";
responseString += "<p> Please Login with the correct password </p>";
responseString += "<br><br> " + LoginForm;
}
}
break;
case "/Admin/Welcome":
if (requestMethod == "GET")
{
responseString = "Welcome to the OpenSim Admin Page";
responseString += "<br><br><br> " + LoginForm;
}
break;
}
return responseString;
}
static string ParseLLSDXML(string requestBody)
private string ParseLLSDXML(string requestBody)
{
// dummy function for now - IMPLEMENT ME!
return "";
}
static void HandleRequest(Object stateinfo)
public void HandleRequest(Object stateinfo)
{
// Console.WriteLine("new http incoming");
HttpListenerContext context = (HttpListenerContext)stateinfo;
HttpListenerRequest request = context.Request;
@ -140,6 +227,9 @@ namespace OpenSim.CAPS
body.Close();
reader.Close();
//Console.WriteLine(request.HttpMethod + " " + request.RawUrl + " Http/" + request.ProtocolVersion.ToString() + " content type: " + request.ContentType);
//Console.WriteLine(requestBody);
string responseString = "";
switch (request.ContentType)
{
@ -156,10 +246,26 @@ namespace OpenSim.CAPS
response.AddHeader("Content-type", "application/xml");
break;
case null:
// must be REST or invalid crap, so pass to the REST parser
responseString = ParseREST(request.Url.OriginalString, requestBody);
case "application/x-www-form-urlencoded":
// a form data POST so send to the REST parser
responseString = ParseREST(requestBody, request.RawUrl, request.HttpMethod);
response.AddHeader("Content-type", "text/html");
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");
}
break;
}
byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
@ -169,6 +275,52 @@ 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());
}
}
}

View File

@ -287,7 +287,7 @@ namespace OpenSim
//this.UploadAssets.HandleUploadPacket(request, LLUUID.Random());
//}
//else
//{*/
//{
this.UploadAssets.HandleUploadPacket(request, request.AssetBlock.TransactionID.Combine(this.SecureSessionID));
//}
break;
@ -318,13 +318,25 @@ namespace OpenSim
OpenSimRoot.Instance.InventoryCache.FetchInventoryDescendents(this, Fetch);
break;
case PacketType.UpdateInventoryItem:
/* UpdateInventoryItemPacket update = (UpdateInventoryItemPacket)Pack;
/*
UpdateInventoryItemPacket update = (UpdateInventoryItemPacket)Pack;
for (int i = 0; i < update.InventoryData.Length; i++)
{
if (update.InventoryData[i].TransactionID != LLUUID.Zero)
{
AssetBase asset = OpenSimRoot.Instance.AssetCache.GetAsset(update.InventoryData[i].TransactionID.Combine(this.SecureSessionID));
OpenSimRoot.Instance.InventoryCache.UpdateInventoryItem(this, update.InventoryData[i].ItemID, asset);
if (asset != null)
{
OpenSimRoot.Instance.InventoryCache.UpdateInventoryItem(this, update.InventoryData[i].ItemID, asset);
}
else
{
asset = this.UploadAssets.AddUploadToAssetCache(update.InventoryData[i].TransactionID);
if (asset != null)
{
OpenSimRoot.Instance.InventoryCache.UpdateInventoryItem(this, update.InventoryData[i].ItemID, asset);
}
}
}
}*/
break;

5
bin/login.htm Normal file
View File

@ -0,0 +1,5 @@
<form action="javascript:setpass();" name="logon" id="logon">
<p> Admin PassWord: <input type="password" id="Adminpss" size="17" maxlength="34"> </P>
<input type="button" name="button" value="Login"
onclick="javascript:setpass(this.parentNode);">
</form>

9
bin/newaccountform.htm Normal file
View File

@ -0,0 +1,9 @@
<form action="javascript:get(document.getElementById('myform'));" name="myform" id="myform">
<p> First Name: <input type="text" id="FirstName" size="17" maxlength="44"> </P>
<p> Last Name:
<input type="text" id="LastName" size="17" maxlength="44"> </p>
<p> PassWord:
<input type="password" id="PassWord" size="17" maxlength="44"> </p>
<br>
<input type="button" name="button" value="Create" onclick="javascript:get(this.parentNode);">
</form>

124
bin/testadmin.htm Normal file
View File

@ -0,0 +1,124 @@
<html>
<head>
<script type="text/javascript">
var http_request
var adminpadd
function loadXMLDoc(url)
{
http_request=null
// code for Mozilla, etc.
if (window.XMLHttpRequest)
{
http_request=new XMLHttpRequest()
}
// code for IE
else if (window.ActiveXObject)
{
http_request=new ActiveXObject("Microsoft.XMLHTTP")
}
if (http_request!=null)
{
http_request.onreadystatechange=state_Change
http_request.open("GET",url,true)
http_request.send(null)
}
else
{
alert("Your browser does not support XMLHTTP.")
}
}
function state_Change()
{
// if xmlhttp shows "loaded"
if (http_request.readyState==4)
{
// if "OK"
if (http_request.status==200)
{
document.getElementById('T1').innerHTML=http_request.responseText
}
else
{
alert("Problem retrieving data:" + http_request.statusText)
}
}
}
//var http_request = false;
function makePOSTRequest(url, parameters) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
// set type accordingly to anticipated content type
//http_request.overrideMimeType('text/xml');
http_request.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
http_request.onreadystatechange =state_Change
http_request.open('POST', url, true);
http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http_request.setRequestHeader("Content-length", parameters.length);
http_request.setRequestHeader("Connection", "close");
http_request.send(parameters);
}
function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
//alert(http_request.responseText);
result = http_request.responseText;
document.getElementById('T1').innerHTML = result;
} else {
alert('There was a problem with the request.');
}
}
}
function get(obj) {
var poststr = "FirstName=" + encodeURI( document.getElementById("FirstName").value ) +
"&LastName=" + encodeURI( document.getElementById("LastName").value )
+ "&PassWord=" + encodeURI( document.getElementById("PassWord").value )
+ "&AdminPass=" + adminpass;
makePOSTRequest('Admin/NewAccount', poststr);
}
function setpass(obj)
{
adminpass = encodeURI( document.getElementById("Adminpss").value );
makePOSTRequest('Admin/Login', adminpass);
}
</script>
</head>
<body onload="loadXMLDoc('Admin/Welcome')">
<div id="T1" style="border:1px solid black;height:500;width:600">
<br>
</div><br />
<button onclick="loadXMLDoc('Admin/Clients')">Clients</button>
<button onclick="loadXMLDoc('Admin/Accounts')">Accounts</button>
</body>
</html>