From 42ba0712765b93f652a8671269e39ca647b8d05e Mon Sep 17 00:00:00 2001 From: MW Date: Mon, 26 Mar 2007 16:51:50 +0000 Subject: Added a very very very basic Web front end for admin use - ready to be used in sandbox mode for adding new accounts. --- OpenSim.RegionServer/AgentAssetUpload.cs | 19 ++- OpenSim.RegionServer/Assets/InventoryCache.cs | 10 ++ OpenSim.RegionServer/CAPS/SimHttp.cs | 166 ++++++++++++++++++++++++-- OpenSim.RegionServer/SimClient.cs | 18 ++- 4 files changed, 201 insertions(+), 12 deletions(-) (limited to 'OpenSim.RegionServer') diff --git a/OpenSim.RegionServer/AgentAssetUpload.cs b/OpenSim.RegionServer/AgentAssetUpload.cs index 5d40c88..a482e80 100644 --- a/OpenSim.RegionServer/AgentAssetUpload.cs +++ b/OpenSim.RegionServer/AgentAssetUpload.cs @@ -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)) diff --git a/OpenSim.RegionServer/Assets/InventoryCache.cs b/OpenSim.RegionServer/Assets/InventoryCache.cs index f50047a..3a4aa36 100644 --- a/OpenSim.RegionServer/Assets/InventoryCache.cs +++ b/OpenSim.RegionServer/Assets/InventoryCache.cs @@ -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)) diff --git a/OpenSim.RegionServer/CAPS/SimHttp.cs b/OpenSim.RegionServer/CAPS/SimHttp.cs index f5a8705..77c6bb8 100644 --- a/OpenSim.RegionServer/CAPS/SimHttp.cs +++ b/OpenSim.RegionServer/CAPS/SimHttp.cs @@ -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 = "

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 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 += "

"; + 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; + } + + 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 "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: - // must be REST or invalid crap, so pass to the REST parser - responseString = ParseREST(request.Url.OriginalString, requestBody); + 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()); + } + + } } diff --git a/OpenSim.RegionServer/SimClient.cs b/OpenSim.RegionServer/SimClient.cs index dea385c..811e8b8 100644 --- a/OpenSim.RegionServer/SimClient.cs +++ b/OpenSim.RegionServer/SimClient.cs @@ -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; -- cgit v1.1