RemoteAdminPlugin.cs 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429
  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 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. using System;
  28. using System.Collections;
  29. using System.IO;
  30. using System.Net;
  31. using System.Reflection;
  32. using System.Timers;
  33. using OpenMetaverse;
  34. using log4net;
  35. using Nini.Config;
  36. using Nwc.XmlRpc;
  37. using OpenSim.Framework;
  38. using OpenSim.Framework.Servers;
  39. using OpenSim.Region.Environment.Interfaces;
  40. using OpenSim.Region.Environment.Modules.World.Terrain;
  41. using OpenSim.Region.Environment.Scenes;
  42. namespace OpenSim.ApplicationPlugins.RemoteController
  43. {
  44. public class RemoteAdminPlugin : IApplicationPlugin
  45. {
  46. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  47. private OpenSimBase m_app;
  48. private BaseHttpServer m_httpd;
  49. private IConfig m_config;
  50. private IConfigSource m_configSource;
  51. private string requiredPassword = String.Empty;
  52. // TODO: required by IPlugin, but likely not at all right
  53. string m_name = "RemoteAdminPlugin";
  54. string m_version = "0.0";
  55. public string Version { get { return m_version; } }
  56. public string Name { get { return m_name; } }
  57. public void Initialise()
  58. {
  59. m_log.Info("[RADMIN]: " + Name + " cannot be default-initialized!");
  60. throw new PluginNotInitialisedException (Name);
  61. }
  62. public void Initialise(OpenSimBase openSim)
  63. {
  64. m_configSource = openSim.ConfigSource.Source;
  65. try
  66. {
  67. if (m_configSource.Configs["RemoteAdmin"] == null ||
  68. !m_configSource.Configs["RemoteAdmin"].GetBoolean("enabled", false))
  69. {
  70. // No config or disabled
  71. }
  72. else
  73. {
  74. m_config = m_configSource.Configs["RemoteAdmin"];
  75. m_log.Info("[RADMIN]: Remote Admin Plugin Enabled");
  76. requiredPassword = m_config.GetString("access_password", String.Empty);
  77. m_app = openSim;
  78. m_httpd = openSim.HttpServer;
  79. m_httpd.AddXmlRPCHandler("admin_create_region", XmlRpcCreateRegionMethod, false);
  80. m_httpd.AddXmlRPCHandler("admin_delete_region", XmlRpcDeleteRegionMethod, false);
  81. m_httpd.AddXmlRPCHandler("admin_shutdown", XmlRpcShutdownMethod, false);
  82. m_httpd.AddXmlRPCHandler("admin_broadcast", XmlRpcAlertMethod, false);
  83. m_httpd.AddXmlRPCHandler("admin_restart", XmlRpcRestartMethod, false);
  84. m_httpd.AddXmlRPCHandler("admin_load_heightmap", XmlRpcLoadHeightmapMethod, false);
  85. m_httpd.AddXmlRPCHandler("admin_create_user", XmlRpcCreateUserMethod, false);
  86. //This handler creates a user with a email,
  87. m_httpd.AddXmlRPCHandler("admin_create_user_email", XmlRpcCreateUserMethodEmail, false);
  88. m_httpd.AddXmlRPCHandler("admin_exists_user", XmlRpcUserExistsMethod, false);
  89. m_httpd.AddXmlRPCHandler("admin_update_user", XmlRpcUpdateUserAccountMethod, false);
  90. m_httpd.AddXmlRPCHandler("admin_load_xml", XmlRpcLoadXMLMethod, false);
  91. m_httpd.AddXmlRPCHandler("admin_save_xml", XmlRpcSaveXMLMethod, false);
  92. m_httpd.AddXmlRPCHandler("admin_load_oar", XmlRpcLoadOARMethod, false);
  93. m_httpd.AddXmlRPCHandler("admin_save_oar", XmlRpcSaveOARMethod, false);
  94. m_httpd.AddXmlRPCHandler("admin_region_query", XmlRpcRegionQueryMethod, false);
  95. }
  96. }
  97. catch (NullReferenceException)
  98. {
  99. // Ignore.
  100. }
  101. }
  102. public XmlRpcResponse XmlRpcRestartMethod(XmlRpcRequest request)
  103. {
  104. XmlRpcResponse response = new XmlRpcResponse();
  105. Hashtable responseData = new Hashtable();
  106. try {
  107. Hashtable requestData = (Hashtable) request.Params[0];
  108. m_log.Info("[RADMIN]: Request to restart Region.");
  109. checkStringParameters(request, new string[] { "password", "regionID" });
  110. if (requiredPassword != String.Empty &&
  111. (!requestData.Contains("password") || (string)requestData["password"] != requiredPassword))
  112. {
  113. throw new Exception("wrong password");
  114. }
  115. UUID regionID = new UUID((string) requestData["regionID"]);
  116. responseData["accepted"] = "true";
  117. responseData["success"] = "true";
  118. response.Value = responseData;
  119. Scene rebootedScene;
  120. if (!m_app.SceneManager.TryGetScene(regionID, out rebootedScene))
  121. throw new Exception("region not found");
  122. responseData["rebooting"] = "true";
  123. response.Value = responseData;
  124. rebootedScene.Restart(30);
  125. }
  126. catch(Exception e)
  127. {
  128. m_log.ErrorFormat("[RADMIN]: Restart region: failed: {0}", e.Message);
  129. m_log.DebugFormat("[RADMIN]: Restart region: failed: {0}", e.ToString());
  130. responseData["accepted"] = "false";
  131. responseData["success"] = "false";
  132. responseData["rebooting"] = "false";
  133. responseData["error"] = e.Message;
  134. response.Value = responseData;
  135. }
  136. return response;
  137. }
  138. public XmlRpcResponse XmlRpcAlertMethod(XmlRpcRequest request)
  139. {
  140. XmlRpcResponse response = new XmlRpcResponse();
  141. Hashtable responseData = new Hashtable();
  142. try {
  143. Hashtable requestData = (Hashtable) request.Params[0];
  144. checkStringParameters(request, new string[] { "password", "message" });
  145. if (requiredPassword != String.Empty &&
  146. (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword))
  147. throw new Exception("wrong password");
  148. string message = (string) requestData["message"];
  149. m_log.InfoFormat("[RADMIN]: Broadcasting: {0}", message);
  150. responseData["accepted"] = "true";
  151. responseData["success"] = "true";
  152. response.Value = responseData;
  153. m_app.SceneManager.SendGeneralMessage(message);
  154. }
  155. catch(Exception e)
  156. {
  157. m_log.ErrorFormat("[RADMIN]: Broadcasting: failed: {0}", e.Message);
  158. m_log.DebugFormat("[RADMIN]: Broadcasting: failed: {0}", e.ToString());
  159. responseData["accepted"] = "false";
  160. responseData["success"] = "false";
  161. responseData["error"] = e.Message;
  162. response.Value = responseData;
  163. }
  164. return response;
  165. }
  166. public XmlRpcResponse XmlRpcLoadHeightmapMethod(XmlRpcRequest request)
  167. {
  168. XmlRpcResponse response = new XmlRpcResponse();
  169. Hashtable responseData = new Hashtable();
  170. try {
  171. Hashtable requestData = (Hashtable)request.Params[0];
  172. m_log.DebugFormat("[RADMIN]: Load Terrain: XmlRpc {0}", request.ToString());
  173. // foreach (string k in requestData.Keys)
  174. // {
  175. // m_log.DebugFormat("[RADMIN]: Load Terrain: XmlRpc {0}: >{1}< {2}",
  176. // k, (string)requestData[k], ((string)requestData[k]).Length);
  177. // }
  178. checkStringParameters(request, new string[] { "password", "filename", "regionid"});
  179. if (requiredPassword != String.Empty &&
  180. (!requestData.Contains("password") || (string)requestData["password"] != requiredPassword))
  181. throw new Exception("wrong password");
  182. string file = (string)requestData["filename"];
  183. UUID regionID = (UUID)(string) requestData["regionid"];
  184. m_log.InfoFormat("[RADMIN]: Terrain Loading: {0}", file);
  185. responseData["accepted"] = "true";
  186. Scene region = null;
  187. if (!m_app.SceneManager.TryGetScene(regionID, out region))
  188. throw new Exception("1: unable to get a scene with that name");
  189. ITerrainModule terrainModule = region.RequestModuleInterface<ITerrainModule>();
  190. if (null == terrainModule) throw new Exception("terrain module not available");
  191. terrainModule.LoadFromFile(file);
  192. responseData["success"] = "true";
  193. response.Value = responseData;
  194. }
  195. catch (Exception e)
  196. {
  197. m_log.ErrorFormat("[RADMIN] Terrain Loading: failed: {0}", e.Message);
  198. m_log.DebugFormat("[RADMIN] Terrain Loading: failed: {0}", e.ToString());
  199. responseData["success"] = "false";
  200. responseData["error"] = e.Message;
  201. }
  202. return response;
  203. }
  204. public XmlRpcResponse XmlRpcShutdownMethod(XmlRpcRequest request)
  205. {
  206. m_log.Info("[RADMIN]: Received Shutdown Administrator Request");
  207. XmlRpcResponse response = new XmlRpcResponse();
  208. Hashtable responseData = new Hashtable();
  209. try {
  210. Hashtable requestData = (Hashtable) request.Params[0];
  211. if (requiredPassword != String.Empty &&
  212. (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword))
  213. throw new Exception("wrong password");
  214. responseData["accepted"] = "true";
  215. response.Value = responseData;
  216. int timeout = 2000;
  217. if (requestData.ContainsKey("shutdown") &&
  218. ((string) requestData["shutdown"] == "delayed") &&
  219. requestData.ContainsKey("milliseconds"))
  220. {
  221. timeout = (Int32) requestData["milliseconds"];
  222. m_app.SceneManager.SendGeneralMessage("Region is going down in " + ((int) (timeout/1000)).ToString() +
  223. " second(s). Please save what you are doing and log out.");
  224. }
  225. else
  226. {
  227. m_app.SceneManager.SendGeneralMessage("Region is going down now.");
  228. }
  229. // Perform shutdown
  230. Timer shutdownTimer = new Timer(timeout); // Wait before firing
  231. shutdownTimer.AutoReset = false;
  232. shutdownTimer.Elapsed += new ElapsedEventHandler(shutdownTimer_Elapsed);
  233. shutdownTimer.Start();
  234. responseData["success"] = "true";
  235. }
  236. catch (Exception e)
  237. {
  238. m_log.ErrorFormat("[RADMIN] Shutdown: failed: {0}", e.Message);
  239. m_log.DebugFormat("[RADMIN] Shutdown: failed: {0}", e.ToString());
  240. responseData["accepted"] = "false";
  241. responseData["error"] = e.Message;
  242. response.Value = responseData;
  243. }
  244. return response;
  245. }
  246. private void shutdownTimer_Elapsed(object sender, ElapsedEventArgs e)
  247. {
  248. m_app.Shutdown();
  249. }
  250. private static void checkStringParameters(XmlRpcRequest request, string[] param)
  251. {
  252. Hashtable requestData = (Hashtable) request.Params[0];
  253. foreach (string p in param)
  254. {
  255. if (!requestData.Contains(p))
  256. throw new Exception(String.Format("missing string parameter {0}", p));
  257. if (String.IsNullOrEmpty((string)requestData[p]))
  258. throw new Exception(String.Format("parameter {0} is empty", p));
  259. }
  260. }
  261. private static void checkIntegerParams(XmlRpcRequest request, string[] param)
  262. {
  263. Hashtable requestData = (Hashtable) request.Params[0];
  264. foreach (string p in param)
  265. {
  266. if (!requestData.Contains(p))
  267. throw new Exception(String.Format("missing integer parameter {0}", p));
  268. }
  269. }
  270. /// <summary>
  271. /// Create a new region.
  272. /// <summary>
  273. /// <param name="request">incoming XML RPC request</param>
  274. /// <remarks>
  275. /// XmlRpcCreateRegionMethod takes the following XMLRPC
  276. /// parameters
  277. /// <list type="table">
  278. /// <listheader><term>parameter name</term><description>description</description></listheader>
  279. /// <item><term>password</term>
  280. /// <description>admin password as set in OpenSim.ini</description></item>
  281. /// <item><term>region_name</term>
  282. /// <description>desired region name</description></item>
  283. /// <item><term>region_id</term>
  284. /// <description>(optional) desired region UUID</description></item>
  285. /// <item><term>region_x</term>
  286. /// <description>desired region X coordinate (integer)</description></item>
  287. /// <item><term>region_y</term>
  288. /// <description>desired region Y coordinate (integer)</description></item>
  289. /// <item><term>region_master_first</term>
  290. /// <description>firstname of region master</description></item>
  291. /// <item><term>region_master_last</term>
  292. /// <description>lastname of region master</description></item>
  293. /// <item><term>region_master_uuid</term>
  294. /// <description>explicit UUID to use for master avatar (optional)</description></item>
  295. /// <item><term>listen_ip</term>
  296. /// <description>internal IP address (dotted quad)</description></item>
  297. /// <item><term>listen_port</term>
  298. /// <description>internal port (integer)</description></item>
  299. /// <item><term>external_address</term>
  300. /// <description>external IP address</description></item>
  301. /// <item><term>persist</term>
  302. /// <description>if true, persist the region info
  303. /// ('true' or 'false')</description></item>
  304. /// </list>
  305. ///
  306. /// XmlRpcCreateRegionMethod returns
  307. /// <list type="table">
  308. /// <listheader><term>name</term><description>description</description></listheader>
  309. /// <item><term>success</term>
  310. /// <description>true or false</description></item>
  311. /// <item><term>error</term>
  312. /// <description>error message if success is false</description></item>
  313. /// <item><term>region_uuid</term>
  314. /// <description>UUID of the newly created region</description></item>
  315. /// <item><term>region_name</term>
  316. /// <description>name of the newly created region</description></item>
  317. /// </list>
  318. /// </remarks>
  319. public XmlRpcResponse XmlRpcCreateRegionMethod(XmlRpcRequest request)
  320. {
  321. m_log.Info("[RADMIN]: CreateRegion: new request");
  322. XmlRpcResponse response = new XmlRpcResponse();
  323. Hashtable responseData = new Hashtable();
  324. lock (this)
  325. {
  326. int m_regionLimit = m_config.GetInt("region_limit", 0);
  327. try {
  328. Hashtable requestData = (Hashtable) request.Params[0];
  329. checkStringParameters(request, new string[] { "password",
  330. "region_name",
  331. "region_master_first", "region_master_last",
  332. "region_master_password",
  333. "listen_ip", "external_address"});
  334. checkIntegerParams(request, new string[] {"region_x", "region_y", "listen_port"});
  335. // check password
  336. if (!String.IsNullOrEmpty(requiredPassword) &&
  337. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  338. // check whether we still have space left (iff we are using limits)
  339. if (m_regionLimit != 0 && m_app.SceneManager.Scenes.Count >= m_regionLimit)
  340. throw new Exception(String.Format("cannot instantiate new region, server capacity {0} already reached; delete regions first", m_regionLimit));
  341. // extract or generate region ID now
  342. Scene scene = null;
  343. UUID regionID = UUID.Zero;
  344. if (requestData.ContainsKey("region_id") &&
  345. !String.IsNullOrEmpty((string)requestData["region_id"]))
  346. {
  347. regionID = (UUID)(string)requestData["region_id"];
  348. if (m_app.SceneManager.TryGetScene(regionID, out scene))
  349. throw new Exception(String.Format("region UUID already in use by region {0}, UUID {1}, <{2},{3}>",
  350. scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
  351. scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
  352. }
  353. else
  354. {
  355. regionID = UUID.Random();
  356. m_log.DebugFormat("[RADMIN] CreateRegion: new region UUID {0}", regionID);
  357. }
  358. // create volatile or persistent region info
  359. RegionInfo region = new RegionInfo();
  360. region.RegionID = regionID;
  361. region.RegionName = (string) requestData["region_name"];
  362. region.RegionLocX = Convert.ToUInt32(requestData["region_x"]);
  363. region.RegionLocY = Convert.ToUInt32(requestData["region_y"]);
  364. // check for collisions: region name, region UUID,
  365. // region location
  366. if (m_app.SceneManager.TryGetScene(region.RegionName, out scene))
  367. throw new Exception(String.Format("region name already in use by region {0}, UUID {1}, <{2},{3}>",
  368. scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
  369. scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
  370. if (m_app.SceneManager.TryGetScene(region.RegionLocX, region.RegionLocY, out scene))
  371. throw new Exception(String.Format("region location <{0},{1}> already in use by region {2}, UUID {3}, <{4},{5}>",
  372. region.RegionLocX, region.RegionLocY,
  373. scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
  374. scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
  375. region.InternalEndPoint =
  376. new IPEndPoint(IPAddress.Parse((string) requestData["listen_ip"]), 0);
  377. region.InternalEndPoint.Port = Convert.ToInt32(requestData["listen_port"]);
  378. if (0 == region.InternalEndPoint.Port) throw new Exception("listen_port is 0");
  379. if (m_app.SceneManager.TryGetScene(region.InternalEndPoint, out scene))
  380. throw new Exception(String.Format("region internal IP {0} and port {1} already in use by region {2}, UUID {3}, <{4},{5}>",
  381. region.InternalEndPoint.Address,
  382. region.InternalEndPoint.Port,
  383. scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
  384. scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
  385. region.ExternalHostName = (string)requestData["external_address"];
  386. string masterFirst = (string)requestData["region_master_first"];
  387. string masterLast = (string)requestData["region_master_last"];
  388. string masterPassword = (string)requestData["region_master_password"];
  389. UUID userID = UUID.Zero;
  390. if (requestData.ContainsKey("region_master_uuid"))
  391. {
  392. // ok, client wants us to use an explicit UUID
  393. // regardless of what the avatar name provided
  394. userID = new UUID((string)requestData["region_master_uuid"]);
  395. }
  396. else
  397. {
  398. // no client supplied UUID: look it up...
  399. UserProfileData userProfile = m_app.CommunicationsManager.UserService.GetUserProfile(masterFirst, masterLast);
  400. if (null == userProfile)
  401. {
  402. m_log.InfoFormat("master avatar does not exist, creating it");
  403. // ...or create new user
  404. userID = m_app.CommunicationsManager.UserAdminService.AddUser(
  405. masterFirst, masterLast, masterPassword, "", region.RegionLocX, region.RegionLocY);
  406. if (userID == UUID.Zero) throw new Exception(String.Format("failed to create new user {0} {1}",
  407. masterFirst, masterLast));
  408. }
  409. else
  410. {
  411. userID = userProfile.ID;
  412. }
  413. }
  414. region.MasterAvatarFirstName = masterFirst;
  415. region.MasterAvatarLastName = masterLast;
  416. region.MasterAvatarSandboxPassword = masterPassword;
  417. region.MasterAvatarAssignedUUID = userID;
  418. bool persist = Convert.ToBoolean((string)requestData["persist"]);
  419. if (persist)
  420. {
  421. // default place for region XML files is in the
  422. // Regions directory of the config dir (aka /bin)
  423. string regionConfigPath = Path.Combine(Util.configDir(), "Regions");
  424. try
  425. {
  426. // OpenSim.ini can specify a different regions dir
  427. IConfig startupConfig = (IConfig)m_configSource.Configs["Startup"];
  428. regionConfigPath = startupConfig.GetString("regionload_regionsdir", regionConfigPath).Trim();
  429. }
  430. catch (Exception)
  431. {
  432. // No INI setting recorded.
  433. }
  434. string regionXmlPath = Path.Combine(regionConfigPath,
  435. String.Format(m_config.GetString("region_file_template", "{0}x{1}-{2}.xml"),
  436. region.RegionLocX.ToString(),
  437. region.RegionLocY.ToString(),
  438. regionID.ToString(),
  439. region.InternalEndPoint.Port.ToString(),
  440. region.RegionName.Replace(" ", "_").Replace(":", "_").Replace("/", "_")));
  441. m_log.DebugFormat("[RADMIN] CreateRegion: persisting region {0} to {1}",
  442. region.RegionID, regionXmlPath);
  443. region.SaveRegionToFile("dynamic region", regionXmlPath);
  444. }
  445. m_app.CreateRegion(region);
  446. responseData["success"] = "true";
  447. responseData["region_name"] = region.RegionName;
  448. responseData["region_uuid"] = region.RegionID.ToString();
  449. response.Value = responseData;
  450. }
  451. catch (Exception e)
  452. {
  453. m_log.ErrorFormat("[RADMIN] CreateRegion: failed {0}", e.Message);
  454. m_log.DebugFormat("[RADMIN] CreateRegion: failed {0}", e.ToString());
  455. responseData["success"] = "false";
  456. responseData["error"] = e.Message;
  457. response.Value = responseData;
  458. }
  459. return response;
  460. }
  461. }
  462. /// <summary>
  463. /// Delete a new region.
  464. /// <summary>
  465. /// <param name="request">incoming XML RPC request</param>
  466. /// <remarks>
  467. /// XmlRpcCreateRegionMethod takes the following XMLRPC
  468. /// parameters
  469. /// <list type="table">
  470. /// <listheader><term>parameter name</term><description>description</description></listheader>
  471. /// <item><term>password</term>
  472. /// <description>admin password as set in OpenSim.ini</description></item>
  473. /// <item><term>region_name</term>
  474. /// <description>desired region name</description></item>
  475. /// <item><term>region_id</term>
  476. /// <description>(optional) desired region UUID</description></item>
  477. /// </list>
  478. ///
  479. /// XmlRpcCreateRegionMethod returns
  480. /// <list type="table">
  481. /// <listheader><term>name</term><description>description</description></listheader>
  482. /// <item><term>success</term>
  483. /// <description>true or false</description></item>
  484. /// <item><term>error</term>
  485. /// <description>error message if success is false</description></item>
  486. /// </list>
  487. /// </remarks>
  488. public XmlRpcResponse XmlRpcDeleteRegionMethod(XmlRpcRequest request)
  489. {
  490. m_log.Info("[RADMIN]: DeleteRegion: new request");
  491. XmlRpcResponse response = new XmlRpcResponse();
  492. Hashtable responseData = new Hashtable();
  493. lock (this)
  494. {
  495. try {
  496. Hashtable requestData = (Hashtable) request.Params[0];
  497. checkStringParameters(request, new string[] {"password", "region_name"});
  498. Scene scene = null;
  499. string regionName = (string)requestData["region_name"];
  500. if (!m_app.SceneManager.TryGetScene(regionName, out scene))
  501. throw new Exception(String.Format("region \"{0}\" does not exist", regionName));
  502. m_app.RemoveRegion(scene, true);
  503. responseData["success"] = "true";
  504. responseData["region_name"] = regionName;
  505. response.Value = responseData;
  506. }
  507. catch (Exception e)
  508. {
  509. m_log.ErrorFormat("[RADMIN] DeleteRegion: failed {0}", e.Message);
  510. m_log.DebugFormat("[RADMIN] DeleteRegion: failed {0}", e.ToString());
  511. responseData["success"] = "false";
  512. responseData["error"] = e.Message;
  513. response.Value = responseData;
  514. }
  515. return response;
  516. }
  517. }
  518. /// <summary>
  519. /// Create a new user account.
  520. /// <summary>
  521. /// <param name="request">incoming XML RPC request</param>
  522. /// <remarks>
  523. /// XmlRpcCreateUserMethod takes the following XMLRPC
  524. /// parameters
  525. /// <list type="table">
  526. /// <listheader><term>parameter name</term><description>description</description></listheader>
  527. /// <item><term>password</term>
  528. /// <description>admin password as set in OpenSim.ini</description></item>
  529. /// <item><term>user_firstname</term>
  530. /// <description>avatar's first name</description></item>
  531. /// <item><term>user_lastname</term>
  532. /// <description>avatar's last name</description></item>
  533. /// <item><term>user_password</term>
  534. /// <description>avatar's password</description></item>
  535. /// <item><term>start_region_x</term>
  536. /// <description>avatar's start region coordinates, X value</description></item>
  537. /// <item><term>start_region_y</term>
  538. /// <description>avatar's start region coordinates, Y value</description></item>
  539. /// </list>
  540. ///
  541. /// XmlRpcCreateUserMethod returns
  542. /// <list type="table">
  543. /// <listheader><term>name</term><description>description</description></listheader>
  544. /// <item><term>success</term>
  545. /// <description>true or false</description></item>
  546. /// <item><term>error</term>
  547. /// <description>error message if success is false</description></item>
  548. /// <item><term>avatar_uuid</term>
  549. /// <description>UUID of the newly created avatar
  550. /// account; UUID.Zero if failed.
  551. /// </description></item>
  552. /// </list>
  553. /// </remarks>
  554. public XmlRpcResponse XmlRpcCreateUserMethod(XmlRpcRequest request)
  555. {
  556. m_log.Info("[RADMIN]: CreateUser: new request");
  557. XmlRpcResponse response = new XmlRpcResponse();
  558. Hashtable responseData = new Hashtable();
  559. lock (this)
  560. {
  561. try
  562. {
  563. Hashtable requestData = (Hashtable) request.Params[0];
  564. // check completeness
  565. checkStringParameters(request, new string[] { "password", "user_firstname",
  566. "user_lastname", "user_password", });
  567. checkIntegerParams(request, new string[] { "start_region_x", "start_region_y" });
  568. // check password
  569. if (!String.IsNullOrEmpty(requiredPassword) &&
  570. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  571. // do the job
  572. string firstname = (string) requestData["user_firstname"];
  573. string lastname = (string) requestData["user_lastname"];
  574. string passwd = (string) requestData["user_password"];
  575. string email = ""; //Empty string for email
  576. uint regX = Convert.ToUInt32((Int32)requestData["start_region_x"]);
  577. uint regY = Convert.ToUInt32((Int32)requestData["start_region_y"]);
  578. UserProfileData userProfile = m_app.CommunicationsManager.UserService.GetUserProfile(firstname, lastname);
  579. if (null != userProfile)
  580. throw new Exception(String.Format("avatar {0} {1} already exists", firstname, lastname));
  581. UUID userID = m_app.CommunicationsManager.UserAdminService.AddUser(firstname, lastname,
  582. passwd, email, regX, regY);
  583. if (userID == UUID.Zero) throw new Exception(String.Format("failed to create new user {0} {1}",
  584. firstname, lastname));
  585. responseData["success"] = "true";
  586. responseData["avatar_uuid"] = userID.ToString();
  587. response.Value = responseData;
  588. m_log.InfoFormat("[RADMIN]: CreateUser: User {0} {1} created, UUID {2}", firstname, lastname, userID);
  589. }
  590. catch (Exception e)
  591. {
  592. m_log.ErrorFormat("[RADMIN] CreateUser: failed: {0}", e.Message);
  593. m_log.DebugFormat("[RADMIN] CreateUser: failed: {0}", e.ToString());
  594. responseData["success"] = "false";
  595. responseData["avatar_uuid"] = UUID.Zero.ToString();
  596. responseData["error"] = e.Message;
  597. response.Value = responseData;
  598. }
  599. return response;
  600. }
  601. }
  602. /// <summary>
  603. /// Create a new user account.
  604. /// <summary>
  605. /// <param name="request">incoming XML RPC request</param>
  606. /// <remarks>
  607. /// XmlRpcCreateUserMethod takes the following XMLRPC
  608. /// parameters
  609. /// <list type="table">
  610. /// <listheader><term>parameter name</term><description>description</description></listheader>
  611. /// <item><term>password</term>
  612. /// <description>admin password as set in OpenSim.ini</description></item>
  613. /// <item><term>user_firstname</term>
  614. /// <description>avatar's first name</description></item>
  615. /// <item><term>user_lastname</term>
  616. /// <description>avatar's last name</description></item>
  617. /// <item><term>user_password</term>
  618. /// <description>avatar's password</description></item>
  619. /// <item><term>start_region_x</term>
  620. /// <description>avatar's start region coordinates, X value</description></item>
  621. /// <item><term>start_region_y</term>
  622. /// <description>avatar's start region coordinates, Y value</description></item>
  623. /// <item><term>user_email</term>
  624. /// <description>email of avatar</description></item>
  625. /// </list>
  626. ///
  627. /// XmlRpcCreateUserMethod returns
  628. /// <list type="table">
  629. /// <listheader><term>name</term><description>description</description></listheader>
  630. /// <item><term>success</term>
  631. /// <description>true or false</description></item>
  632. /// <item><term>error</term>
  633. /// <description>error message if success is false</description></item>
  634. /// <item><term>avatar_uuid</term>
  635. /// <description>UUID of the newly created avatar
  636. /// account; UUID.Zero if failed.
  637. /// </description></item>
  638. /// </list>
  639. /// </remarks>
  640. public XmlRpcResponse XmlRpcCreateUserMethodEmail(XmlRpcRequest request)
  641. {
  642. m_log.Info("[RADMIN]: CreateUser: new request");
  643. XmlRpcResponse response = new XmlRpcResponse();
  644. Hashtable responseData = new Hashtable();
  645. lock (this)
  646. {
  647. try
  648. {
  649. Hashtable requestData = (Hashtable)request.Params[0];
  650. // check completeness
  651. checkStringParameters(request, new string[] { "password", "user_firstname",
  652. "user_lastname", "user_password", "user_email" });
  653. checkIntegerParams(request, new string[] { "start_region_x", "start_region_y" });
  654. // check password
  655. if (!String.IsNullOrEmpty(requiredPassword) &&
  656. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  657. // do the job
  658. string firstname = (string)requestData["user_firstname"];
  659. string lastname = (string)requestData["user_lastname"];
  660. string passwd = (string)requestData["user_password"];
  661. string email = (string)requestData["user_email"];
  662. uint regX = Convert.ToUInt32((Int32)requestData["start_region_x"]);
  663. uint regY = Convert.ToUInt32((Int32)requestData["start_region_y"]);
  664. UserProfileData userProfile = m_app.CommunicationsManager.UserService.GetUserProfile(firstname, lastname);
  665. if (null != userProfile)
  666. throw new Exception(String.Format("avatar {0} {1} already exists", firstname, lastname));
  667. UUID userID
  668. = m_app.CommunicationsManager.UserAdminService.AddUser(
  669. firstname, lastname, passwd, email, regX, regY);
  670. if (userID == UUID.Zero) throw new Exception(String.Format("failed to create new user {0} {1}",
  671. firstname, lastname));
  672. responseData["success"] = "true";
  673. responseData["avatar_uuid"] = userID.ToString();
  674. response.Value = responseData;
  675. m_log.InfoFormat("[RADMIN]: CreateUser: User {0} {1} created, UUID {2}", firstname, lastname, userID);
  676. }
  677. catch (Exception e)
  678. {
  679. m_log.ErrorFormat("[RADMIN] CreateUser: failed: {0}", e.Message);
  680. m_log.DebugFormat("[RADMIN] CreateUser: failed: {0}", e.ToString());
  681. responseData["success"] = "false";
  682. responseData["avatar_uuid"] = UUID.Zero.ToString();
  683. responseData["error"] = e.Message;
  684. response.Value = responseData;
  685. }
  686. return response;
  687. }
  688. }
  689. /// <summary>
  690. /// Check whether a certain user account exists.
  691. /// <summary>
  692. /// <param name="request">incoming XML RPC request</param>
  693. /// <remarks>
  694. /// XmlRpcUserExistsMethod takes the following XMLRPC
  695. /// parameters
  696. /// <list type="table">
  697. /// <listheader><term>parameter name</term><description>description</description></listheader>
  698. /// <item><term>password</term>
  699. /// <description>admin password as set in OpenSim.ini</description></item>
  700. /// <item><term>user_firstname</term>
  701. /// <description>avatar's first name</description></item>
  702. /// <item><term>user_lastname</term>
  703. /// <description>avatar's last name</description></item>
  704. /// </list>
  705. ///
  706. /// XmlRpcCreateUserMethod returns
  707. /// <list type="table">
  708. /// <listheader><term>name</term><description>description</description></listheader>
  709. /// <item><term>user_firstname</term>
  710. /// <description>avatar's first name</description></item>
  711. /// <item><term>user_lastname</term>
  712. /// <description>avatar's last name</description></item>
  713. /// <item><term>success</term>
  714. /// <description>true or false</description></item>
  715. /// <item><term>error</term>
  716. /// <description>error message if success is false</description></item>
  717. /// </list>
  718. /// </remarks>
  719. public XmlRpcResponse XmlRpcUserExistsMethod(XmlRpcRequest request)
  720. {
  721. m_log.Info("[RADMIN]: UserExists: new request");
  722. XmlRpcResponse response = new XmlRpcResponse();
  723. Hashtable responseData = new Hashtable();
  724. try
  725. {
  726. Hashtable requestData = (Hashtable) request.Params[0];
  727. // check completeness
  728. checkStringParameters(request, new string[] { "password", "user_firstname", "user_lastname"});
  729. string firstname = (string) requestData["user_firstname"];
  730. string lastname = (string) requestData["user_lastname"];
  731. UserProfileData userProfile = m_app.CommunicationsManager.UserService.GetUserProfile(firstname, lastname);
  732. responseData["user_firstname"] = firstname;
  733. responseData["user_lastname"] = lastname;
  734. if (null == userProfile)
  735. responseData["success"] = false;
  736. else
  737. responseData["success"] = true;
  738. response.Value = responseData;
  739. }
  740. catch (Exception e)
  741. {
  742. m_log.ErrorFormat("[RADMIN] UserExists: failed: {0}", e.Message);
  743. m_log.DebugFormat("[RADMIN] UserExists: failed: {0}", e.ToString());
  744. responseData["success"] = "false";
  745. responseData["error"] = e.Message;
  746. response.Value = responseData;
  747. }
  748. return response;
  749. }
  750. /// <summary>
  751. /// Update the password of a user account.
  752. /// <summary>
  753. /// <param name="request">incoming XML RPC request</param>
  754. /// <remarks>
  755. /// XmlRpcUpdateUserAccountMethod takes the following XMLRPC
  756. /// parameters
  757. /// <list type="table">
  758. /// <listheader><term>parameter name</term><description>description</description></listheader>
  759. /// <item><term>password</term>
  760. /// <description>admin password as set in OpenSim.ini</description></item>
  761. /// <item><term>user_firstname</term>
  762. /// <description>avatar's first name (cannot be changed)</description></item>
  763. /// <item><term>user_lastname</term>
  764. /// <description>avatar's last name (cannot be changed)</description></item>
  765. /// <item><term>user_password</term>
  766. /// <description>avatar's password (changeable)</description></item>
  767. /// <item><term>start_region_x</term>
  768. /// <description>avatar's start region coordinates, X
  769. /// value (changeable)</description></item>
  770. /// <item><term>start_region_y</term>
  771. /// <description>avatar's start region coordinates, Y
  772. /// value (changeable)</description></item>
  773. /// </list>
  774. ///
  775. /// XmlRpcCreateUserMethod returns
  776. /// <list type="table">
  777. /// <listheader><term>name</term><description>description</description></listheader>
  778. /// <item><term>success</term>
  779. /// <description>true or false</description></item>
  780. /// <item><term>error</term>
  781. /// <description>error message if success is false</description></item>
  782. /// </list>
  783. /// </remarks>
  784. public XmlRpcResponse XmlRpcUpdateUserAccountMethod(XmlRpcRequest request)
  785. {
  786. m_log.Info("[RADMIN]: UpdateUserAccount: new request");
  787. XmlRpcResponse response = new XmlRpcResponse();
  788. Hashtable responseData = new Hashtable();
  789. lock (this)
  790. {
  791. try
  792. {
  793. Hashtable requestData = (Hashtable) request.Params[0];
  794. // check completeness
  795. checkStringParameters(request, new string[] { "password", "user_firstname",
  796. "user_lastname" });
  797. // check password
  798. if (!String.IsNullOrEmpty(requiredPassword) &&
  799. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  800. // do the job
  801. string firstname = (string) requestData["user_firstname"];
  802. string lastname = (string) requestData["user_lastname"];
  803. string passwd = String.Empty;
  804. uint? regX = null;
  805. uint? regY = null;
  806. uint? ulaX = null;
  807. uint? ulaY = null;
  808. uint? ulaZ = null;
  809. uint? usaX = null;
  810. uint? usaY = null;
  811. uint? usaZ = null;
  812. if (requestData.ContainsKey("user_password")) passwd = (string) requestData["user_password"];
  813. if (requestData.ContainsKey("start_region_x")) regX = Convert.ToUInt32((Int32)requestData["start_region_x"]);
  814. if (requestData.ContainsKey("start_region_y")) regY = Convert.ToUInt32((Int32)requestData["start_region_y"]);
  815. if (requestData.ContainsKey("start_lookat_x")) ulaY = Convert.ToUInt32((Int32)requestData["start_lookat_x"]);
  816. if (requestData.ContainsKey("start_lookat_y")) ulaY = Convert.ToUInt32((Int32)requestData["start_lookat_y"]);
  817. if (requestData.ContainsKey("start_lookat_z")) ulaY = Convert.ToUInt32((Int32)requestData["start_lookat_z"]);
  818. if (requestData.ContainsKey("start_standat_x")) usaY = Convert.ToUInt32((Int32)requestData["start_standat_x"]);
  819. if (requestData.ContainsKey("start_standat_y")) usaY = Convert.ToUInt32((Int32)requestData["start_standat_y"]);
  820. if (requestData.ContainsKey("start_standat_z")) usaY = Convert.ToUInt32((Int32)requestData["start_standat_z"]);
  821. UserProfileData userProfile = m_app.CommunicationsManager.UserService.GetUserProfile(firstname, lastname);
  822. if (null == userProfile)
  823. throw new Exception(String.Format("avatar {0} {1} does not exist", firstname, lastname));
  824. if (null != passwd)
  825. {
  826. string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(passwd) + ":" + String.Empty);
  827. userProfile.PasswordHash = md5PasswdHash;
  828. }
  829. if (null != regX) userProfile.HomeRegionX = (uint)regX;
  830. if (null != regY) userProfile.HomeRegionY = (uint)regY;
  831. if (null != usaX) userProfile.HomeLocationX = (uint)usaX;
  832. if (null != usaY) userProfile.HomeLocationY = (uint)usaY;
  833. if (null != usaZ) userProfile.HomeLocationZ = (uint)usaZ;
  834. if (null != ulaX) userProfile.HomeLookAtX = (uint)ulaX;
  835. if (null != ulaY) userProfile.HomeLookAtY = (uint)ulaY;
  836. if (null != ulaZ) userProfile.HomeLookAtZ = (uint)ulaZ;
  837. if (!m_app.CommunicationsManager.UserService.UpdateUserProfile(userProfile))
  838. throw new Exception("did not manage to update user profile");
  839. responseData["success"] = "true";
  840. response.Value = responseData;
  841. m_log.InfoFormat("[RADMIN]: UpdateUserAccount: account for user {0} {1} updated, UUID {2}", firstname, lastname,
  842. userProfile.ID);
  843. }
  844. catch (Exception e)
  845. {
  846. m_log.ErrorFormat("[RADMIN] UpdateUserAccount: failed: {0}", e.Message);
  847. m_log.DebugFormat("[RADMIN] UpdateUserAccount: failed: {0}", e.ToString());
  848. responseData["success"] = "false";
  849. responseData["error"] = e.Message;
  850. response.Value = responseData;
  851. }
  852. }
  853. return response;
  854. }
  855. /// <summary>
  856. /// Load an OAR file into a region..
  857. /// <summary>
  858. /// <param name="request">incoming XML RPC request</param>
  859. /// <remarks>
  860. /// XmlRpcLoadOARMethod takes the following XMLRPC
  861. /// parameters
  862. /// <list type="table">
  863. /// <listheader><term>parameter name</term><description>description</description></listheader>
  864. /// <item><term>password</term>
  865. /// <description>admin password as set in OpenSim.ini</description></item>
  866. /// <item><term>filename</term>
  867. /// <description>file name of the OAR file</description></item>
  868. /// <item><term>region_uuid</term>
  869. /// <description>UUID of the region</description></item>
  870. /// <item><term>region_name</term>
  871. /// <description>region name</description></item>
  872. /// </list>
  873. ///
  874. /// <code>region_uuid</code> takes precedence over
  875. /// <code>region_name</code> if both are present; one of both
  876. /// must be present.
  877. ///
  878. /// XmlRpcLoadOARMethod returns
  879. /// <list type="table">
  880. /// <listheader><term>name</term><description>description</description></listheader>
  881. /// <item><term>success</term>
  882. /// <description>true or false</description></item>
  883. /// <item><term>error</term>
  884. /// <description>error message if success is false</description></item>
  885. /// </list>
  886. /// </remarks>
  887. public XmlRpcResponse XmlRpcLoadOARMethod(XmlRpcRequest request)
  888. {
  889. m_log.Info("[RADMIN]: Received Load OAR Administrator Request");
  890. XmlRpcResponse response = new XmlRpcResponse();
  891. Hashtable responseData = new Hashtable();
  892. lock (this)
  893. {
  894. try
  895. {
  896. Hashtable requestData = (Hashtable) request.Params[0];
  897. // check completeness
  898. foreach (string p in new string[] { "password", "filename" })
  899. {
  900. if (!requestData.Contains(p))
  901. throw new Exception(String.Format("missing parameter {0}", p));
  902. if (String.IsNullOrEmpty((string)requestData[p]))
  903. throw new Exception(String.Format("parameter {0} is empty"));
  904. }
  905. // check password
  906. if (!String.IsNullOrEmpty(requiredPassword) &&
  907. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  908. string filename = (string)requestData["filename"];
  909. Scene scene = null;
  910. if (requestData.Contains("region_uuid"))
  911. {
  912. UUID region_uuid = (UUID)(string)requestData["region_uuid"];
  913. if (!m_app.SceneManager.TryGetScene(region_uuid, out scene))
  914. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  915. }
  916. else if (requestData.Contains("region_name"))
  917. {
  918. string region_name = (string)requestData["region_name"];
  919. if (!m_app.SceneManager.TryGetScene(region_name, out scene))
  920. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  921. }
  922. else throw new Exception("neither region_name nor region_uuid given");
  923. IRegionArchiverModule archiver = scene.RequestModuleInterface<IRegionArchiverModule>();
  924. if (archiver != null)
  925. archiver.DearchiveRegion(filename);
  926. else
  927. throw new Exception("Archiver module not present for scene");
  928. responseData["loaded"] = "true";
  929. response.Value = responseData;
  930. }
  931. catch (Exception e)
  932. {
  933. m_log.InfoFormat("[RADMIN] LoadOAR: {0}", e.Message);
  934. m_log.DebugFormat("[RADMIN] LoadOAR: {0}", e.ToString());
  935. responseData["loaded"] = "false";
  936. responseData["error"] = e.Message;
  937. response.Value = responseData;
  938. }
  939. return response;
  940. }
  941. }
  942. /// <summary>
  943. /// Save a region to an OAR file
  944. /// <summary>
  945. /// <param name="request">incoming XML RPC request</param>
  946. /// <remarks>
  947. /// XmlRpcSaveOARMethod takes the following XMLRPC
  948. /// parameters
  949. /// <list type="table">
  950. /// <listheader><term>parameter name</term><description>description</description></listheader>
  951. /// <item><term>password</term>
  952. /// <description>admin password as set in OpenSim.ini</description></item>
  953. /// <item><term>filename</term>
  954. /// <description>file name for the OAR file</description></item>
  955. /// <item><term>region_uuid</term>
  956. /// <description>UUID of the region</description></item>
  957. /// <item><term>region_name</term>
  958. /// <description>region name</description></item>
  959. /// </list>
  960. ///
  961. /// <code>region_uuid</code> takes precedence over
  962. /// <code>region_name</code> if both are present; one of both
  963. /// must be present.
  964. ///
  965. /// XmlRpcLoadOARMethod returns
  966. /// <list type="table">
  967. /// <listheader><term>name</term><description>description</description></listheader>
  968. /// <item><term>success</term>
  969. /// <description>true or false</description></item>
  970. /// <item><term>error</term>
  971. /// <description>error message if success is false</description></item>
  972. /// </list>
  973. /// </remarks>
  974. public XmlRpcResponse XmlRpcSaveOARMethod(XmlRpcRequest request)
  975. {
  976. m_log.Info("[RADMIN]: Received Save OAR Administrator Request");
  977. XmlRpcResponse response = new XmlRpcResponse();
  978. Hashtable responseData = new Hashtable();
  979. try
  980. {
  981. Hashtable requestData = (Hashtable) request.Params[0];
  982. // check completeness
  983. foreach (string p in new string[] { "password", "filename" })
  984. {
  985. if (!requestData.Contains(p))
  986. throw new Exception(String.Format("missing parameter {0}", p));
  987. if (String.IsNullOrEmpty((string)requestData[p]))
  988. throw new Exception(String.Format("parameter {0} is empty"));
  989. }
  990. // check password
  991. if (!String.IsNullOrEmpty(requiredPassword) &&
  992. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  993. string filename = (string)requestData["filename"];
  994. Scene scene = null;
  995. if (requestData.Contains("region_uuid"))
  996. {
  997. UUID region_uuid = (UUID)(string)requestData["region_uuid"];
  998. if (!m_app.SceneManager.TryGetScene(region_uuid, out scene))
  999. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  1000. }
  1001. else if (requestData.Contains("region_name"))
  1002. {
  1003. string region_name = (string)requestData["region_name"];
  1004. if (!m_app.SceneManager.TryGetScene(region_name, out scene))
  1005. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  1006. }
  1007. else throw new Exception("neither region_name nor region_uuid given");
  1008. IRegionArchiverModule archiver = scene.RequestModuleInterface<IRegionArchiverModule>();
  1009. if (archiver != null)
  1010. archiver.ArchiveRegion(filename);
  1011. else
  1012. throw new Exception("Archiver module not present for scene");
  1013. responseData["saved"] = "true";
  1014. response.Value = responseData;
  1015. }
  1016. catch (Exception e)
  1017. {
  1018. m_log.InfoFormat("[RADMIN] SaveOAR: {0}", e.Message);
  1019. m_log.DebugFormat("[RADMIN] SaveOAR: {0}", e.ToString());
  1020. responseData["saved"] = "false";
  1021. responseData["error"] = e.Message;
  1022. response.Value = responseData;
  1023. }
  1024. return response;
  1025. }
  1026. public XmlRpcResponse XmlRpcLoadXMLMethod(XmlRpcRequest request)
  1027. {
  1028. m_log.Info("[RADMIN]: Received Load XML Administrator Request");
  1029. XmlRpcResponse response = new XmlRpcResponse();
  1030. Hashtable responseData = new Hashtable();
  1031. lock (this)
  1032. {
  1033. try
  1034. {
  1035. Hashtable requestData = (Hashtable) request.Params[0];
  1036. // check completeness
  1037. foreach (string p in new string[] { "password", "filename" })
  1038. {
  1039. if (!requestData.Contains(p))
  1040. throw new Exception(String.Format("missing parameter {0}", p));
  1041. if (String.IsNullOrEmpty((string)requestData[p]))
  1042. throw new Exception(String.Format("parameter {0} is empty"));
  1043. }
  1044. // check password
  1045. if (!String.IsNullOrEmpty(requiredPassword) &&
  1046. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  1047. string filename = (string)requestData["filename"];
  1048. if (requestData.Contains("region_uuid"))
  1049. {
  1050. UUID region_uuid = (UUID)(string)requestData["region_uuid"];
  1051. if (!m_app.SceneManager.TrySetCurrentScene(region_uuid))
  1052. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  1053. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_uuid.ToString());
  1054. }
  1055. else if (requestData.Contains("region_name"))
  1056. {
  1057. string region_name = (string)requestData["region_name"];
  1058. if (!m_app.SceneManager.TrySetCurrentScene(region_name))
  1059. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  1060. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_name);
  1061. }
  1062. else throw new Exception("neither region_name nor region_uuid given");
  1063. responseData["switched"] = "true";
  1064. string xml_version = "1";
  1065. if (requestData.Contains("xml_version"))
  1066. {
  1067. xml_version = (string)requestData["xml_version"];
  1068. }
  1069. switch (xml_version)
  1070. {
  1071. case "1":
  1072. m_app.SceneManager.LoadCurrentSceneFromXml(filename, true, new Vector3(0, 0, 0));
  1073. break;
  1074. case "2":
  1075. m_app.SceneManager.LoadCurrentSceneFromXml2(filename);
  1076. break;
  1077. default:
  1078. throw new Exception(String.Format("unknown Xml{0} format", xml_version));
  1079. }
  1080. responseData["loaded"] = "true";
  1081. response.Value = responseData;
  1082. }
  1083. catch (Exception e)
  1084. {
  1085. m_log.InfoFormat("[RADMIN] LoadXml: {0}", e.Message);
  1086. m_log.DebugFormat("[RADMIN] LoadXml: {0}", e.ToString());
  1087. responseData["loaded"] = "false";
  1088. responseData["switched"] = "false";
  1089. responseData["error"] = e.Message;
  1090. response.Value = responseData;
  1091. }
  1092. return response;
  1093. }
  1094. }
  1095. public XmlRpcResponse XmlRpcSaveXMLMethod(XmlRpcRequest request)
  1096. {
  1097. m_log.Info("[RADMIN]: Received Save XML Administrator Request");
  1098. XmlRpcResponse response = new XmlRpcResponse();
  1099. Hashtable responseData = new Hashtable();
  1100. try
  1101. {
  1102. Hashtable requestData = (Hashtable)request.Params[0];
  1103. // check completeness
  1104. foreach (string p in new string[] { "password", "filename" })
  1105. {
  1106. if (!requestData.Contains(p))
  1107. throw new Exception(String.Format("missing parameter {0}", p));
  1108. if (String.IsNullOrEmpty((string)requestData[p]))
  1109. throw new Exception(String.Format("parameter {0} is empty"));
  1110. }
  1111. // check password
  1112. if (!String.IsNullOrEmpty(requiredPassword) &&
  1113. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  1114. string filename = (string)requestData["filename"];
  1115. if (requestData.Contains("region_uuid"))
  1116. {
  1117. UUID region_uuid = (UUID)(string)requestData["region_uuid"];
  1118. if (!m_app.SceneManager.TrySetCurrentScene(region_uuid))
  1119. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  1120. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_uuid.ToString());
  1121. }
  1122. else if (requestData.Contains("region_name"))
  1123. {
  1124. string region_name = (string)requestData["region_name"];
  1125. if (!m_app.SceneManager.TrySetCurrentScene(region_name))
  1126. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  1127. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_name);
  1128. }
  1129. else throw new Exception("neither region_name nor region_uuid given");
  1130. responseData["switched"] = "true";
  1131. string xml_version = "1";
  1132. if (requestData.Contains("xml_version"))
  1133. {
  1134. xml_version = (string)requestData["xml_version"];
  1135. }
  1136. switch (xml_version)
  1137. {
  1138. case "1":
  1139. m_app.SceneManager.SaveCurrentSceneToXml(filename);
  1140. break;
  1141. case "2":
  1142. m_app.SceneManager.SaveCurrentSceneToXml2(filename);
  1143. break;
  1144. default:
  1145. throw new Exception(String.Format("unknown Xml{0} format", xml_version));
  1146. }
  1147. responseData["saved"] = "true";
  1148. response.Value = responseData;
  1149. }
  1150. catch (Exception e)
  1151. {
  1152. m_log.InfoFormat("[RADMIN] LoadXml: {0}", e.Message);
  1153. m_log.DebugFormat("[RADMIN] LoadXml: {0}", e.ToString());
  1154. responseData["loaded"] = "false";
  1155. responseData["switched"] = "false";
  1156. responseData["error"] = e.Message;
  1157. response.Value = responseData;
  1158. }
  1159. return response;
  1160. }
  1161. public XmlRpcResponse XmlRpcRegionQueryMethod(XmlRpcRequest request)
  1162. {
  1163. m_log.Info("[RADMIN]: Received Query XML Administrator Request");
  1164. XmlRpcResponse response = new XmlRpcResponse();
  1165. Hashtable responseData = new Hashtable();
  1166. try
  1167. {
  1168. responseData["success"] = "true";
  1169. Hashtable requestData = (Hashtable)request.Params[0];
  1170. // check completeness
  1171. if (!requestData.Contains("password"))
  1172. throw new Exception(String.Format("missing required parameter"));
  1173. if (!String.IsNullOrEmpty(requiredPassword) &&
  1174. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  1175. if (requestData.Contains("region_uuid"))
  1176. {
  1177. UUID region_uuid = (UUID)(string)requestData["region_uuid"];
  1178. if (!m_app.SceneManager.TrySetCurrentScene(region_uuid))
  1179. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  1180. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_uuid.ToString());
  1181. }
  1182. else if (requestData.Contains("region_name"))
  1183. {
  1184. string region_name = (string)requestData["region_name"];
  1185. if (!m_app.SceneManager.TrySetCurrentScene(region_name))
  1186. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  1187. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_name);
  1188. }
  1189. else throw new Exception("neither region_name nor region_uuid given");
  1190. Scene s = m_app.SceneManager.CurrentScene;
  1191. int health = s.GetHealth();
  1192. responseData["health"] = health;
  1193. response.Value = responseData;
  1194. }
  1195. catch (Exception e)
  1196. {
  1197. m_log.InfoFormat("[RADMIN] RegionQuery: {0}", e.Message);
  1198. responseData["success"] = "false";
  1199. responseData["error"] = e.Message;
  1200. response.Value = responseData;
  1201. }
  1202. return response;
  1203. }
  1204. public void Dispose()
  1205. {
  1206. }
  1207. }
  1208. }