1
0

GridManagementAgent.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright (c) Contributors, http://www.openmetaverse.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. */
  28. using System.Collections;
  29. using libsecondlife;
  30. using Nwc.XmlRpc;
  31. using OpenSim.Framework.Servers;
  32. namespace OpenSim.Framework.Manager
  33. {
  34. /// <summary>
  35. /// Used to pass messages to the gridserver
  36. /// </summary>
  37. /// <param name="param">Pass this argument</param>
  38. public delegate void GridManagerCallback(string param);
  39. /// <summary>
  40. /// Serverside listener for grid commands
  41. /// </summary>
  42. public class GridManagementAgent
  43. {
  44. /// <summary>
  45. /// Passes grid server messages
  46. /// </summary>
  47. private GridManagerCallback thecallback;
  48. /// <summary>
  49. /// Security keys
  50. /// </summary>
  51. private string sendkey;
  52. private string recvkey;
  53. /// <summary>
  54. /// Our component type
  55. /// </summary>
  56. private string component_type;
  57. /// <summary>
  58. /// List of active sessions
  59. /// </summary>
  60. private static ArrayList Sessions;
  61. /// <summary>
  62. /// Initialises a new GridManagementAgent
  63. /// </summary>
  64. /// <param name="app_httpd">HTTP Daemon for this server</param>
  65. /// <param name="component_type">What component type are we?</param>
  66. /// <param name="sendkey">Security send key</param>
  67. /// <param name="recvkey">Security recieve key</param>
  68. /// <param name="thecallback">Message callback</param>
  69. public GridManagementAgent(BaseHttpServer app_httpd, string component_type, string sendkey, string recvkey, GridManagerCallback thecallback)
  70. {
  71. this.sendkey = sendkey;
  72. this.recvkey = recvkey;
  73. this.component_type = component_type;
  74. this.thecallback = thecallback;
  75. Sessions = new ArrayList();
  76. app_httpd.AddXmlRPCHandler("manager_login", XmlRpcLoginMethod);
  77. switch (component_type)
  78. {
  79. case "gridserver":
  80. GridServerManager.sendkey = this.sendkey;
  81. GridServerManager.recvkey = this.recvkey;
  82. GridServerManager.thecallback = thecallback;
  83. app_httpd.AddXmlRPCHandler("shutdown", GridServerManager.XmlRpcShutdownMethod);
  84. break;
  85. }
  86. }
  87. /// <summary>
  88. /// Checks if a session exists
  89. /// </summary>
  90. /// <param name="sessionID">The session ID</param>
  91. /// <returns>Exists?</returns>
  92. public static bool SessionExists(LLUUID sessionID)
  93. {
  94. return Sessions.Contains(sessionID);
  95. }
  96. /// <summary>
  97. /// Logs a new session to the grid manager
  98. /// </summary>
  99. /// <param name="request">the XMLRPC request</param>
  100. /// <returns>An XMLRPC reply</returns>
  101. public static XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request)
  102. {
  103. XmlRpcResponse response = new XmlRpcResponse();
  104. Hashtable requestData = (Hashtable)request.Params[0];
  105. Hashtable responseData = new Hashtable();
  106. // TODO: Switch this over to using OpenSim.Framework.Data
  107. if (requestData["username"].Equals("admin") && requestData["password"].Equals("supersecret"))
  108. {
  109. response.IsFault = false;
  110. LLUUID new_session = LLUUID.Random();
  111. Sessions.Add(new_session);
  112. responseData["session_id"] = new_session.ToString();
  113. responseData["msg"] = "Login OK";
  114. }
  115. else
  116. {
  117. response.IsFault = true;
  118. responseData["error"] = "Invalid username or password";
  119. }
  120. response.Value = responseData;
  121. return response;
  122. }
  123. }
  124. }