EstateAccess.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.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 OpenSimulator 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. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.Globalization;
  31. using System.Text;
  32. using log4net;
  33. using Nini.Config;
  34. using OpenMetaverse;
  35. using Mono.Addins;
  36. using OpenSim.Framework;
  37. using OpenSim.Framework.Servers.HttpServer;
  38. using OpenSim.Region.Framework.Interfaces;
  39. using OpenSim.Region.Framework.Scenes;
  40. using Caps=OpenSim.Framework.Capabilities.Caps;
  41. namespace OpenSim.Region.ClientStack.Linden
  42. {
  43. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "EstateAcessCapModule")]
  44. public class EstateAccessCapModule : INonSharedRegionModule
  45. {
  46. // private static readonly ILog m_log =
  47. // LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  48. private Scene m_scene;
  49. private bool m_Enabled = false;
  50. private string m_capUrl;
  51. //IEstateModule m_EstateModule;
  52. #region INonSharedRegionModule Members
  53. public void Initialise(IConfigSource pSource)
  54. {
  55. IConfig config = pSource.Configs["ClientStack.LindenCaps"];
  56. if (config == null)
  57. return;
  58. m_capUrl = config.GetString("Cap_EstateAccess", string.Empty);
  59. if (!String.IsNullOrEmpty(m_capUrl) && m_capUrl.Equals("localhost"))
  60. m_Enabled = true;
  61. }
  62. public void AddRegion(Scene scene)
  63. {
  64. if (!m_Enabled)
  65. return;
  66. m_scene = scene;
  67. }
  68. public void RemoveRegion(Scene scene)
  69. {
  70. if (!m_Enabled)
  71. return;
  72. if (m_scene == scene)
  73. {
  74. m_scene.EventManager.OnRegisterCaps -= RegisterCaps;
  75. m_scene = null;
  76. }
  77. }
  78. public void RegionLoaded(Scene scene)
  79. {
  80. if (!m_Enabled)
  81. return;
  82. if (scene.RegionInfo == null || scene.RegionInfo.EstateSettings == null)
  83. {
  84. m_Enabled = false;
  85. return;
  86. }
  87. IEstateModule m_EstateModule = scene.RequestModuleInterface<IEstateModule>();
  88. if(m_EstateModule == null)
  89. {
  90. m_Enabled = false;
  91. return;
  92. }
  93. scene.EventManager.OnRegisterCaps += RegisterCaps;
  94. }
  95. public void Close()
  96. {
  97. }
  98. public string Name
  99. {
  100. get { return "EstateAccessCapModule"; }
  101. }
  102. public Type ReplaceableInterface
  103. {
  104. get { return null; }
  105. }
  106. #endregion
  107. public void RegisterCaps(UUID agentID, Caps caps)
  108. {
  109. string capUrl = "/CAPS/" + UUID.Random() + "/";
  110. caps.RegisterHandler(
  111. "EstateAccess",
  112. new RestHTTPHandler(
  113. "GET",
  114. capUrl,
  115. httpMethod => ProcessRequest(httpMethod, agentID, caps),
  116. "EstateAccess",
  117. agentID.ToString())); ;
  118. }
  119. public Hashtable ProcessRequest(Hashtable request, UUID AgentId, Caps cap)
  120. {
  121. Hashtable responsedata = new Hashtable();
  122. responsedata["int_response_code"] = 200; //501; //410; //404;
  123. responsedata["content_type"] = "text/plain";
  124. ScenePresence avatar;
  125. if (!m_scene.TryGetScenePresence(AgentId, out avatar))
  126. {
  127. responsedata["str_response_string"] = "<llsd><array /></llsd>"; ;
  128. responsedata["keepalive"] = false;
  129. return responsedata;
  130. }
  131. if (m_scene.RegionInfo == null
  132. || m_scene.RegionInfo.EstateSettings == null
  133. ||!m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  134. {
  135. responsedata["str_response_string"] = "<llsd><array /></llsd>"; ;
  136. return responsedata;
  137. }
  138. EstateSettings regionSettings = m_scene.RegionInfo.EstateSettings;
  139. UUID[] managers = regionSettings.EstateManagers;
  140. UUID[] allowed = regionSettings.EstateAccess;
  141. UUID[] groups = regionSettings.EstateGroups;
  142. EstateBan[] EstateBans = regionSettings.EstateBans;
  143. StringBuilder sb = LLSDxmlEncode.Start();
  144. LLSDxmlEncode.AddMap(sb);
  145. if (allowed != null && allowed.Length > 0)
  146. {
  147. LLSDxmlEncode.AddArray("AllowedAgents", sb);
  148. for (int i = 0; i < allowed.Length; ++i)
  149. {
  150. UUID id = allowed[i];
  151. if (id == UUID.Zero)
  152. continue;
  153. LLSDxmlEncode.AddMap(sb);
  154. LLSDxmlEncode.AddElem("id", id, sb);
  155. LLSDxmlEncode.AddEndMap(sb);
  156. }
  157. LLSDxmlEncode.AddEndArray(sb);
  158. }
  159. if (groups != null && groups.Length > 0)
  160. {
  161. LLSDxmlEncode.AddArray("AllowedGroups", sb);
  162. for (int i = 0; i < groups.Length; ++i)
  163. {
  164. UUID id = groups[i];
  165. if (id == UUID.Zero)
  166. continue;
  167. LLSDxmlEncode.AddMap(sb);
  168. LLSDxmlEncode.AddElem("id", id, sb);
  169. LLSDxmlEncode.AddEndMap(sb);
  170. }
  171. LLSDxmlEncode.AddEndArray(sb);
  172. }
  173. if (EstateBans != null && EstateBans.Length > 0)
  174. {
  175. LLSDxmlEncode.AddArray("BannedAgents", sb);
  176. for (int i = 0; i < EstateBans.Length; ++i)
  177. {
  178. EstateBan ban = EstateBans[i];
  179. UUID id = ban.BannedUserID;
  180. if (id == UUID.Zero)
  181. continue;
  182. LLSDxmlEncode.AddMap(sb);
  183. LLSDxmlEncode.AddElem("id", id, sb);
  184. LLSDxmlEncode.AddElem("banning_id", ban.BanningUserID, sb);
  185. LLSDxmlEncode.AddElem("last_login_date", "na", sb); // We will not have this. This information is far at grid
  186. if (ban.BanTime == 0)
  187. LLSDxmlEncode.AddElem("ban_date", "0000-00-00 00:00", sb);
  188. else
  189. LLSDxmlEncode.AddElem("ban_date", (Util.ToDateTime(ban.BanTime)).ToString("yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture), sb);
  190. LLSDxmlEncode.AddEndMap(sb);
  191. }
  192. LLSDxmlEncode.AddEndArray(sb);
  193. }
  194. if (managers != null && managers.Length > 0)
  195. {
  196. LLSDxmlEncode.AddArray("Managers", sb);
  197. for (int i = 0; i < managers.Length; ++i)
  198. {
  199. LLSDxmlEncode.AddMap(sb);
  200. LLSDxmlEncode.AddElem("agent_id", managers[i], sb);
  201. LLSDxmlEncode.AddEndMap(sb);
  202. }
  203. LLSDxmlEncode.AddEndArray(sb);
  204. }
  205. LLSDxmlEncode.AddEndMap(sb);
  206. responsedata["str_response_string"] = LLSDxmlEncode.End(sb);
  207. return responsedata;
  208. }
  209. }
  210. }